Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3471 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3452 stevensc 1
import React from 'react';
2
import { Controller, useFormContext } from 'react-hook-form';
3
import { FormControl, FormLabel, Typography } from '@mui/material';
4
import { CKEditor } from '@ckeditor/ckeditor5-react';
5
import { ClassicEditor } from 'ckeditor5';
6
 
7
export function FormRichEditor({
8
  id = '',
9
  label = '',
10
  name = '',
11
  disabled,
12
  rules,
13
  style = {},
14
  onReady = () => {}
15
}) {
16
  const { control } = useFormContext();
17
 
18
  return (
19
    <Controller
20
      name={name}
21
      control={control}
22
      disabled={disabled}
23
      rules={rules}
24
      render={({ field: { value, onChange, disabled }, fieldState: { error } }) => (
25
        <FormControl variant='standard' fullWidth sx={style}>
26
          {label && <FormLabel htmlFor={id}>{label}</FormLabel>}
27
          <CKEditor
28
            editor={ClassicEditor}
29
            onReady={onReady}
30
            data={value}
31
            onChange={(event, editor) => onChange(editor.getData())}
32
            id={id}
33
            disabled={disabled}
34
          />
35
 
36
          {error && (
37
            <Typography sx={{ color: 'red', fontSize: '0.75rem' }}>{error.message}</Typography>
38
          )}
39
        </FormControl>
40
      )}
41
    />
42
  );
43
}