mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
* new implementation/rich-text-editor * Ensure that Rich text editor exposes its default value on load Co-authored-by: Sherfin Shamsudeen <sherfin94@gmail.com>
31 lines
974 B
JavaScript
31 lines
974 B
JavaScript
import React, { useEffect } from 'react';
|
|
import 'draft-js/dist/Draft.css';
|
|
import { DraftEditor } from './DraftEditor';
|
|
|
|
export const RichTextEditor = function RichTextEditor({ width, height, properties, styles, setExposedVariable }) {
|
|
const { visibility, disabledState } = styles;
|
|
const placeholder = properties.placeholder;
|
|
const defaultValue = properties?.defaultValue ?? '';
|
|
|
|
// exposing the default value at first
|
|
useEffect(() => {
|
|
setExposedVariable('value', defaultValue);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
function handleChange(html) {
|
|
setExposedVariable('value', html);
|
|
}
|
|
|
|
return (
|
|
<div data-disabled={disabledState} style={{ height: `${height}px`, display: visibility ? '' : 'none' }}>
|
|
<DraftEditor
|
|
handleChange={handleChange}
|
|
height={height}
|
|
width={width}
|
|
placeholder={placeholder}
|
|
defaultValue={defaultValue}
|
|
></DraftEditor>
|
|
</div>
|
|
);
|
|
};
|