Compare commits

...

2 Commits

Author SHA1 Message Date
ba76193d33
feat: auto-close preview screen when input value is longer than 30000 chars
All checks were successful
/ deploy_site (push) Successful in 4m44s
2024-11-12 10:50:42 +09:00
b843facac6
chore: use modoern compiler for scss preprocessing 2024-11-12 10:33:41 +09:00
3 changed files with 41 additions and 6 deletions

View File

@ -24,17 +24,37 @@ interface TransformGridItemProp {
export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
const [value, setValue] = useRecoilState(EditorValueState)
const [options, setOptions] = useState(transform.options)
const [previewDisabled, setPreviewDisabled] = useState(false)
const [alreadyClosed, setAlreadyClosed] = useState(false)
const [closed, setClosed] = useLocalStorage(`transform_closed__${transform.name}`, false)
const [result, setResult] = useState<WrappedTransformResult>({
error: false,
value: ''
})
useEffect(() => {
setAlreadyClosed(closed)
}, [])
useEffect(() => {
if (closed)
return
transform
.fn(value, options)
.then(setResult.bind(this))
}, [value, options])
}, [value, options, closed])
useEffect(() => {
if (value.length > 30000) {
setClosed(true)
setPreviewDisabled(true)
return
}
setClosed(alreadyClosed)
setPreviewDisabled(false)
}, [value])
const onCheckboxOptionChanged =
(option: TransformCheckboxOption) =>
@ -92,6 +112,14 @@ export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
setValue(result.value)
}
const onLabelClicked = () => {
if (previewDisabled)
return
setClosed(!closed)
setAlreadyClosed(!closed)
}
return (
<div className={clsx(style.item, closed && style.closed)}>
<div className={style.toolbar}>
@ -100,8 +128,8 @@ export const TransformGridItem: FC<TransformGridItemProp> = ({ transform }) => {
</Button>
<h2
onClick={() => setClosed(!closed)}
className={style.name}>
onClick={onLabelClicked}
className={clsx(style.name, previewDisabled && style.previewDisabled)}>
{transform.name}
</h2>

View File

@ -16,9 +16,9 @@
.name {
font-size: inherit;
padding: 14px 6px;
cursor: pointer;
&:hover {
&:hover:not(.previewDisabled) {
cursor: pointer;
text-decoration: underline dotted;
}
}

View File

@ -4,4 +4,11 @@ import react from '@vitejs/plugin-react-swc'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler' // or "modern"
}
}
}
})