ui(editor): fix editor child styling

This commit is contained in:
Matthew Penner 2023-01-12 12:08:11 -07:00
parent 76b67cb889
commit bc7737840a
No known key found for this signature in database
8 changed files with 48 additions and 14 deletions

View file

@ -48,7 +48,7 @@ export default ({ className }: { className?: string }) => {
<h2 css={tw`mb-6 text-2xl text-neutral-100`}>Import Egg</h2> <h2 css={tw`mb-6 text-2xl text-neutral-100`}>Import Egg</h2>
<Editor <Editor
className="h-64 overflow-hidden rounded" childClassName={tw`h-64 rounded`}
initialContent={''} initialContent={''}
fetchContent={value => { fetchContent={value => {
fetchFileContent = value; fetchFileContent = value;

View file

@ -33,7 +33,7 @@ const RowCheckbox = ({ id }: { id: number }) => {
<AdminCheckbox <AdminCheckbox
name={id.toString()} name={id.toString()}
checked={isChecked} checked={isChecked}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { onChange={(e: ChangeEvent<HTMLInputElement>) => {
if (e.currentTarget.checked) { if (e.currentTarget.checked) {
appendSelectedNest(id); appendSelectedNest(id);
} else { } else {

View file

@ -49,7 +49,7 @@ export default ({ className }: { className?: string }) => {
<FlashMessageRender byKey={'egg:export'} css={tw`mb-6`} /> <FlashMessageRender byKey={'egg:export'} css={tw`mb-6`} />
<Editor <Editor
className="h-[32rem] overflow-scroll rounded" childClassName={tw`h-[32rem] rounded`}
initialContent={content ?? ''} initialContent={content ?? ''}
language={LanguageDescription.of({ name: 'json', support: json() })} language={LanguageDescription.of({ name: 'json', support: json() })}
/> />

View file

@ -64,7 +64,8 @@ export default function EggInstallContainer() {
<Form> <Form>
<Editor <Editor
className="mb-4 h-96 overflow-scroll" className="mb-4"
childClassName={tw`h-96`}
initialContent={egg.scriptInstall || ''} initialContent={egg.scriptInstall || ''}
fetchContent={value => { fetchContent={value => {
fetchFileContent = value; fetchFileContent = value;

View file

@ -19,7 +19,7 @@ const EggRouter = () => {
const { data: egg, error, isValidating, mutate } = useEggFromRoute(); const { data: egg, error, isValidating, mutate } = useEggFromRoute();
useEffect(() => { useEffect(() => {
mutate(); void mutate();
}, []); }, []);
useEffect(() => { useEffect(() => {

View file

@ -135,7 +135,7 @@ export const EggProcessContainer = forwardRef<any, EggProcessContainerProps>(fun
<div css={tw`mb-5`}> <div css={tw`mb-5`}>
<Label>Startup Configuration</Label> <Label>Startup Configuration</Label>
<Editor <Editor
className="h-32 overflow-scroll rounded" childClassName={tw`h-32 rounded`}
initialContent={values.configStartup} initialContent={values.configStartup}
fetchContent={value => { fetchContent={value => {
fetchStartupConfiguration = value; fetchStartupConfiguration = value;
@ -147,7 +147,7 @@ export const EggProcessContainer = forwardRef<any, EggProcessContainerProps>(fun
<div css={tw`mb-1`}> <div css={tw`mb-1`}>
<Label>Configuration Files</Label> <Label>Configuration Files</Label>
<Editor <Editor
className="h-48 overflow-scroll rounded" childClassName={tw`h-48 rounded`}
initialContent={values.configFiles} initialContent={values.configFiles}
fetchContent={value => { fetchContent={value => {
fetchFilesConfiguration = value; fetchFilesConfiguration = value;
@ -185,13 +185,23 @@ export default function EggSettingsContainer() {
const submit = async (values: Values, { setSubmitting }: FormikHelpers<Values>) => { const submit = async (values: Values, { setSubmitting }: FormikHelpers<Values>) => {
clearFlashes('egg'); clearFlashes('egg');
values.configStartup = (await ref.current?.getStartupConfiguration()) || ''; values.configStartup = (await ref.current?.getStartupConfiguration()) ?? '';
values.configFiles = (await ref.current?.getFilesConfiguration()) || ''; values.configFiles = (await ref.current?.getFilesConfiguration()) ?? '';
const dockerImages: Record<string, string> = {};
for (const v of values.dockerImages.split('\n')) {
const parts = v.trim().split('|');
const image = parts[0] ?? '';
const alias = parts[1] ?? image;
dockerImages[alias] = image;
}
console.log(dockerImages);
updateEgg(egg.id, { updateEgg(egg.id, {
...values, ...values,
// TODO dockerImages,
dockerImages: {},
}) })
.catch(error => { .catch(error => {
console.error(error); console.error(error);
@ -207,8 +217,11 @@ export default function EggSettingsContainer() {
name: egg.name, name: egg.name,
description: egg.description || '', description: egg.description || '',
startup: egg.startup, startup: egg.startup,
// TODO dockerImages: Object.keys(egg.dockerImages)
dockerImages: egg.dockerImages.toString(), .map(key => {
return `${egg.dockerImages[key]}|${key}`;
})
.join('\n'),
configStop: egg.configStop || '', configStop: egg.configStop || '',
configStartup: JSON.stringify(egg.configStartup, null, '\t') || '', configStartup: JSON.stringify(egg.configStartup, null, '\t') || '',
configFiles: JSON.stringify(egg.configFiles, null, '\t') || '', configFiles: JSON.stringify(egg.configFiles, null, '\t') || '',

View file

@ -30,6 +30,8 @@ import {
} from '@codemirror/view'; } from '@codemirror/view';
import type { CSSProperties } from 'react'; import type { CSSProperties } from 'react';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import type { TwStyle } from 'twin.macro';
import tw, { styled } from 'twin.macro';
import { ayuMirageHighlightStyle, ayuMirageTheme } from './theme'; import { ayuMirageHighlightStyle, ayuMirageTheme } from './theme';
@ -78,10 +80,24 @@ const defaultExtensions: Extension = [
indentUnit.of('\t'), indentUnit.of('\t'),
]; ];
const EditorContainer = styled.div<{ overrides?: TwStyle }>`
//min-height: 12rem;
${tw`relative`};
& > div {
${props => props.overrides};
&.cm-focused {
outline: none;
}
}
`;
export interface EditorProps { export interface EditorProps {
// DOM // DOM
className?: string; className?: string;
style?: CSSProperties; style?: CSSProperties;
childClassName?: TwStyle;
// CodeMirror Config // CodeMirror Config
extensions?: Extension[]; extensions?: Extension[];
@ -211,5 +227,7 @@ export function Editor(props: EditorProps) {
props.fetchContent(async () => view.state.doc.toJSON().join('\n')); props.fetchContent(async () => view.state.doc.toJSON().join('\n'));
}, [view, props.fetchContent, props.onContentSaved]); }, [view, props.fetchContent, props.onContentSaved]);
return <div ref={ref} className={`relative ${props.className ?? ''}`.trimEnd()} style={props.style} />; return (
<EditorContainer ref={ref} className={props.className} style={props.style} overrides={props.childClassName} />
);
} }

View file

@ -130,6 +130,8 @@ export default () => {
<div css={tw`relative`}> <div css={tw`relative`}>
<SpinnerOverlay visible={loading} /> <SpinnerOverlay visible={loading} />
<Editor <Editor
style={{ height: 'calc(100vh - 20rem)' }}
childClassName={tw`rounded-md h-full`}
filename={filename} filename={filename}
initialContent={content} initialContent={content}
language={language} language={language}