cleaned up styling for editor

This commit is contained in:
ari committed 2022-05-13 17:26:44 -04:00
1 parent bfc95db6f6
commit 4cfc429980
25 files changed
+532 -230

No files matched your search

@@ -0,0 +1,20 @@
.input-boolean {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
max-width: fit-content;
border: 1px solid var(--secondary-accent);
border-radius: 5px;
padding: 0.5em;
background-color: var(--secondary);
}
.input-boolean:hover, .input-boolean:hover * {
cursor: pointer;
background-color: var(--secondary-opaque);
}
.input-boolean * {
user-select: none;
}
@@ -0,0 +1,26 @@
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { useState } from "react";
import InputBoolean from "./InputBoolean";
export default {
title: 'Inputs/InputBoolean',
component: InputBoolean,
parameters: { actions: { argTypesRegex: '^on.*' } },
} as ComponentMeta<typeof InputBoolean>;
const Template: ComponentStory<typeof InputBoolean> = args => {
const [state, onChange] = useState(args.value)
return <div className="page">
<InputBoolean {...args} value={state} onChange={v => {
args.onChange(v)
onChange(v)
}} />
</div>
}
export const SimpleText = Template.bind({})
SimpleText.args = {
label: "Template",
}
@@ -1,3 +1,4 @@
import "./InputBoolean.css";
import InputWrapper from "./InputWrapper";
export interface Props {
@@ -10,12 +11,8 @@ export default function InputBoolean({
value = false,
onChange,
}: Props) {
return <InputWrapper label={label}>
<span className="checkbox" onClick={e => {
e.preventDefault()
onChange(!value)
}}>
{value ? '✔️' : ' '}
</span>
</InputWrapper>
return <div className="input-boolean" onClick={() => onChange(!value)}>
<input type="checkbox" checked={value} onChange={() => { }} />
<label>{label}</label>
</div>
}
@@ -1,5 +1,5 @@
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { useState } from "react";
import { useState, useEffect } from 'react';
import { InputList } from "./InputList";
@@ -12,7 +12,12 @@ export default {
const Template: ComponentStory<typeof InputList> = args => {
const [value, setValue] = useState('')
const [value, setValue] = useState(args.current);
useEffect(() => {
if (value !== args.current) {
setValue(args.current)
}
}, [args.current])
return <div className="page">
<InputList {...args} current={value} onChange={setValue} />
</div>
@@ -27,3 +32,15 @@ SimpleText.args = {
"Toots"
]
}
export const InvalidSelection = Template.bind({})
InvalidSelection.args = {
current: "Derek",
label: "Entity ID",
options: [
'Bob',
'Martin',
"Toots"
]
}
+20 -4
View File
@@ -15,17 +15,33 @@ export const InputList: FC<Props<any>> = ({
current, options, onChange, label,
...selattr
}) => {
const { classes } = useInputListStyles({});
return <InputWrapper label={label} labelSize={'small'} noMargin>
const invalidCurrent = !options.includes(current);
const { classes } = useInputListStyles({
invalidCurrent
});
return <InputWrapper label={label} labelSize={'small'} noMargin error={invalidCurrent && "Invalid Selection"}>
<select
title={invalidCurrent ? "Invalid Selection" : ""}
className={classes.input}
{...selattr} value={current}
onChange={e => {
e.preventDefault();
onChange(e.currentTarget.value as any);
console.log(e.currentTarget.id)
console.log(e.currentTarget.value)
console.log(e.currentTarget.innerHTML)
if (e.currentTarget.id === 'invalid') {
onChange(options[0])
} else {
onChange(e.currentTarget.value as any);
}
}}
>
{options.map((t, i) => <option id={String(i)} key={i}>{t}</option>)}
{options.map((t, i) => <option id={String(i)} key={i} value={t}>{t}</option>)}
{invalidCurrent ? <option
id={'invalid'}
value={current}
style={{ display: 'none' }}
>!{current}!</option> : <></>}
</select>
</InputWrapper>
}
@@ -9,6 +9,7 @@ export interface Props {
value: string;
onChange: (v: string) => void;
additionalTooltipFilters?: Record<string, string>;
error?: string;
resizable?: boolean;
}
export default function InputTextArea({
@@ -16,13 +17,14 @@ export default function InputTextArea({
textBoxFor,
value = "",
onChange,
error,
additionalTooltipFilters = {},
resizable = false,
}: Props) {
const { classes } = useInputTextAreaStyles({ resizable });
const tooltip = useToolTip();
const [isFocused, setIsFocused] = useState(false)
return <InputWrapper label={label} labelSize={(value === '') && !isFocused ? 'normal' : 'small'}>
return <InputWrapper error={error} label={label} labelSize={(value === '') && !isFocused ? 'normal' : 'small'}>
<textarea
className={classes.input}
value={value}
@@ -7,12 +7,14 @@ export interface Props {
labelSize?: 'normal' | 'small';
noMargin?: boolean;
className?: string;
error?: string;
}
const InputWrapper: FC<Props> = ({ label, children, labelSize = 'normal', noMargin = false, className = "" }) => {
const { classes } = useInputWrapperStyles({ labelSize, noMargin })
const InputWrapper: FC<Props> = ({ error, label, children, labelSize = 'normal', noMargin = false, className = "" }) => {
const { classes } = useInputWrapperStyles({ labelSize, noMargin, hasError: !!error })
return <div className={[classes.wrapper, className].join(" ")}>
<label className={classes.label}>{label}</label>
{children}
<span className={classes.error}>{error}</span>
</div>
}
export default InputWrapper;
+28 -15
View File
@@ -1,6 +1,7 @@
import * as yaml from "js-yaml";
import { useEffect, useRef, useState } from "react";
import { useState } from "react";
import InputTextArea from "./InputTextArea";
import { useDelayedFunction, useDelayEffect } from 'utils/useDelay';
export interface Props<T extends {}> {
label: string;
@@ -14,25 +15,37 @@ export default function InputYaml<T>({
onChange,
resizable,
}: Props<T>) {
const [text, setText] = useState("");
useEffect(() => {
setText(yaml.dump(value));
}, [value]);
const delayId = useRef<null | number>(null);
const delayedUpdate = (update: string) => {
setText(update)
if (delayId.current) {
window.clearTimeout(delayId.current);
delayId.current = null;
const [{ text, error }, setState] = useState<{
text: string,
error: undefined | string,
}>({
text: yaml.dump(value),
error: undefined
});
const setText = (t: string) => {
try {
console.log(yaml.dump(yaml.load(t)));
setState({ text: t, error: undefined })
} catch (_) {
setState({ text: t, error: "! Invalid Yaml !" })
}
delayId.current = window.setTimeout(() => {
onChange(yaml.load(update) as any)
}, 1000);
}
useDelayEffect(() => {
if (!error && (yaml.dump(value) !== text)) {
if (text) {
onChange(yaml.load(text) as any)
} else if (Array.isArray(value)) {
onChange([] as any)
} else {
onChange({} as any)
}
}
}, [text], 1000)
return <InputTextArea
error={error}
label={label}
value={text}
onChange={delayedUpdate}
onChange={setText}
resizable={resizable}
/>
}
+19 -5
View File
@@ -35,6 +35,7 @@ export const useButtonStyles = createAppUseStyles<{}>(theme => ({
export const useInputWrapperStyles = createAppUseStyles<{
labelSize: 'normal' | 'small',
noMargin: boolean,
hasError: boolean,
}>(theme => {
return {
wrapper: ({ noMargin }) => ({
@@ -51,7 +52,16 @@ export const useInputWrapperStyles = createAppUseStyles<{
top: labelSize === 'normal' ? '0.5em' : '0.25em',
fontWeight: 'bold',
color: theme.primaryAccent,
})
}),
error: ({ hasError }) => (hasError ? {
textAlign: 'center',
color: theme.red,
padding: '0.25em',
border: `1px solid ${theme.red}`,
borderTop: 'none',
borderBottomRightRadius: 5,
borderBottomLeftRadius: 5,
} : {})
}
})
@@ -111,13 +121,17 @@ export const useInputNumberStyles = createAppUseStyles<{}>(theme => {
}
});
export const useInputListStyles = createAppUseStyles<{}>(theme => {
export const useInputListStyles = createAppUseStyles<{
invalidCurrent: boolean;
}>(theme => {
const styles = commonInputStyle(theme);
return {
input: {
input: ({ invalidCurrent }) => ({
...styles.input,
cursor: 'pointer'
}
cursor: 'pointer',
borderColor: invalidCurrent ? theme.redAccent : styles.input.borderColor,
color: invalidCurrent ? theme.redLight : styles.input.color,
}),
}
});