-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
32 deletions.
There are no files selected for viewing
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,45 @@ | ||
import { CKEditor } from '@ckeditor/ckeditor5-react'; | ||
import ClassicEditor from '@ckeditor/ckeditor5-build-classic'; | ||
import {useState} from "react"; | ||
|
||
export interface EditorProps { | ||
name?: string; | ||
id?: string; | ||
label?: string; | ||
type?: string; | ||
value?: string; | ||
class?: string; | ||
} | ||
|
||
export default function Editor(props: EditorProps) { | ||
const [data, setData] = useState(props.value); | ||
|
||
const handleChange = (event: any, editor: any) => { | ||
const data = editor.getData(); | ||
|
||
console.log( { event, editor, data } ); | ||
|
||
setData(data); | ||
} | ||
|
||
return <div className={'form-group'}> | ||
<label className="col-form-label" htmlFor={props.id}>{props.label}</label> | ||
<textarea className={'box-hidden'+ (props.class ? ' ' + props.class : '')} name={props.name}>{data}</textarea> | ||
|
||
<CKEditor | ||
editor={ ClassicEditor } | ||
id={props.id} | ||
data={data} | ||
onReady={ editor => { | ||
console.log( 'Editor is ready to use!', editor ); | ||
} } | ||
onChange={ handleChange } | ||
onBlur={ ( event, editor ) => { | ||
console.log( 'Blur.', editor ); | ||
} } | ||
onFocus={ ( event, editor ) => { | ||
console.log( 'Focus.', editor ); | ||
} } | ||
/> | ||
</div> | ||
} |
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