Skip to content

Commit

Permalink
feat: make plaintext modal fullscreen (daeuniverse#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
kunish authored Jun 24, 2023
1 parent 28acd26 commit 0bf6eb1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 41 deletions.
92 changes: 51 additions & 41 deletions src/components/PlainTextFormModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Input, Modal, Stack, TextInput } from '@mantine/core'
import { Box, Flex, Input, Modal, Stack, TextInput } from '@mantine/core'
import { UseFormReturnType, useForm, zodResolver } from '@mantine/form'
import { Editor } from '@monaco-editor/react'
import { useStore } from '@nanostores/react'
Expand Down Expand Up @@ -63,50 +63,60 @@ export const PlainTextFormModal = forwardRef(
}))

return (
<Modal title={title} opened={opened} onClose={onClose}>
<form
onSubmit={form.onSubmit((values) =>
handleSubmit(values).then(() => {
onClose()
form.reset()
})
)}
>
<Stack>
<TextInput label={t('name')} withAsterisk {...form.getInputProps('name')} disabled={!!editingID} />
<Modal.Root opened={opened} onClose={onClose} fullScreen>
<Modal.Overlay />

<Stack spacing={4}>
<Box
sx={{
overflow: 'hidden',
borderRadius: 4,
}}
<Modal.Content>
<Flex h="100%" direction="column">
<Modal.Header>
<Modal.Title>{title}</Modal.Title>
<Modal.CloseButton />
</Modal.Header>

<Modal.Body sx={{ flex: 1 }}>
<form
onSubmit={form.onSubmit((values) =>
handleSubmit(values).then(() => {
onClose()
form.reset()
})
)}
>
<Editor
height={320}
theme={colorScheme === 'dark' ? EDITOR_THEME_DARK : EDITOR_THEME_LIGHT}
options={EDITOR_OPTIONS}
language="routingA"
value={form.values.text}
onChange={(value) => form.setFieldValue('text', value || '')}
/>
</Box>
<Stack h="100%" pb={100} sx={{ display: 'flex', flexDirection: 'column', position: 'relative' }}>
<TextInput label={t('name')} withAsterisk {...form.getInputProps('name')} disabled={!!editingID} />

<Stack sx={{ flex: 1 }} spacing={4}>
<Box h="100%" sx={{ overflow: 'hidden', borderRadius: 4 }}>
<Editor
height="100%"
theme={colorScheme === 'dark' ? EDITOR_THEME_DARK : EDITOR_THEME_LIGHT}
options={EDITOR_OPTIONS}
language="routingA"
value={form.values.text}
onChange={(value) => form.setFieldValue('text', value || '')}
/>
</Box>

{form.errors['text'] && <Input.Error>{form.errors['text']}</Input.Error>}
</Stack>
{form.errors['text'] && <Input.Error>{form.errors['text']}</Input.Error>}
</Stack>

<FormActions
reset={() => {
if (editingID && origins) {
form.setValues(origins)
} else {
form.reset()
}
}}
/>
</Stack>
</form>
</Modal>
<Box sx={{ position: 'absolute', insetInline: 0, bottom: 50 }}>
<FormActions
reset={() => {
if (editingID && origins) {
form.setValues(origins)
} else {
form.reset()
}
}}
/>
</Box>
</Stack>
</form>
</Modal.Body>
</Flex>
</Modal.Content>
</Modal.Root>
)
}
)
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export const EDITOR_OPTIONS: EditorProps['options'] = {
minimap: {
enabled: false,
},
scrollBeyondLastLine: false,
renderWhitespace: 'selection',
cursorBlinking: 'solid',
formatOnPaste: true,
Expand Down

0 comments on commit 0bf6eb1

Please sign in to comment.