index.tsx
32 lines
| 1 | import {ClassicEditor} from '@givewp/form-builder-library'; |
| 2 | import {Controller, useFormContext} from 'react-hook-form'; |
| 3 | |
| 4 | type Props = { |
| 5 | name: string; |
| 6 | rows?: number; |
| 7 | }; |
| 8 | |
| 9 | /** |
| 10 | * @since 4.0.0 |
| 11 | */ |
| 12 | export default ({name, rows = 4, ...rest}: Props) => { |
| 13 | |
| 14 | const {control} = useFormContext(); |
| 15 | |
| 16 | return ( |
| 17 | <Controller |
| 18 | name={name} |
| 19 | control={control} |
| 20 | render={({field}) => ( |
| 21 | <ClassicEditor |
| 22 | id={name} |
| 23 | content={field.value} |
| 24 | setContent={(value) => field.onChange(value)} |
| 25 | rows={rows} |
| 26 | {...rest} |
| 27 | /> |
| 28 | )} |
| 29 | /> |
| 30 | ); |
| 31 | } |
| 32 |