-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(canary): add field to persist value CKEditor5 on form
- Loading branch information
1 parent
f64cc8c
commit 2895540
Showing
2 changed files
with
69 additions
and
27 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
clients/packages/canary-client/src/scenes/WidgetActions/Settings/Autofire/CKEditor5Field.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from "react"; | ||
import { FormControl, FormLabel, Flex, Tooltip, Stack } from "bonde-components/chakra"; | ||
import { Hint } from "bonde-components"; | ||
import { InfoIcon } from "bonde-components/icons"; | ||
import { useField } from "bonde-components/form"; | ||
|
||
import { CKEditor } from "@ckeditor/ckeditor5-react"; | ||
import ClassicEditor from "ckeditor5-custom-build"; | ||
|
||
|
||
const CKEditor5Field = ({ | ||
name, | ||
helpText, | ||
label, | ||
...config | ||
}: any) => { | ||
const { input, meta } = useField(name, config); | ||
const editorConfig: any = { | ||
s3Upload: { | ||
signingUrl: process.env.REACT_APP_UPLOADS_URL | ||
} | ||
} | ||
|
||
return ( | ||
<FormControl | ||
isInvalid={(meta.error || meta.submitError) && meta.touched} | ||
mb={4} | ||
> | ||
<Flex direction="row" justify="space-between"> | ||
<Stack direction="row" spacing={2} align="center"> | ||
<FormLabel>{label}</FormLabel> | ||
{helpText && ( | ||
<Tooltip label={helpText}> | ||
<InfoIcon color="gray.300" boxSize={3} /> | ||
</Tooltip> | ||
)} | ||
</Stack> | ||
{(meta.error || meta.submitError) && meta.touched && ( | ||
<Hint color="error">{meta.error || meta.submitError}</Hint> | ||
)} | ||
</Flex> | ||
<CKEditor | ||
data={input.value} | ||
editor={ClassicEditor} | ||
config={editorConfig} | ||
onChange={(event, editor) => { | ||
const data = editor.getData(); | ||
console.log("event, editor, data", { event, editor, data }); | ||
input.onChange(data); | ||
}} | ||
/> | ||
</FormControl> | ||
) | ||
} | ||
|
||
export default CKEditor5Field; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters