-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
128 lines (120 loc) · 3.01 KB
/
Copy pathApp.tsx
File metadata and controls
128 lines (120 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import {useState} from 'react';
import './App.css';
import { CKEditor } from '@ckeditor/ckeditor5-react';
import Editor from 'ckeditor5-custom-build';
const editorConfig = {
toolbar: {
items: [
'undo',
'redo',
'|',
'heading',
'|',
'textPartLanguage',
'|',
'blockQuote',
'specialCharacters',
'insertTable',
'horizontalLine',
'imageUpload',
'imageInsert',
'pageBreak',
'|',
'-',
'bold',
'italic',
'underline',
'|',
'alignment',
'bulletedList',
'numberedList',
'outdent',
'indent',
'|',
'fontFamily',
'fontSize',
'fontColor',
'fontBackgroundColor',
'highlight',
'|',
'link',
'removeFormat'
],
shouldNotGroupWhenFull: true
},
language: 'pt-br',
image: {
toolbar: [
'imageTextAlternative',
'toggleImageCaption',
'imageStyle:inline',
'imageStyle:block',
'imageStyle:side'
]
},
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells',
'tableCellProperties',
'tableProperties'
]
}
};
function App() {
const [addTexto, setaValor] = useState('');
const [textoAdicionado, mostraTexto] = useState(false);
const alteraTexto = ( event: any , editor: any) => {
const texto = editor.data.get();
setaValor(texto);
}
const setaFocoNoEditor = (editor: any) => {
editor.editing.view.focus();
};
const carregaTexto = (editor: any = []) => {
setaValor('<p>Exemplo de Texto Completo!</p>');
}
const objComTexto = {__html:addTexto};
return (
<div className="App">
<h1>TESTE do CKEditor</h1>
<CKEditor
editor={ Editor }
config={ editorConfig }
data={ addTexto }
onReady={ editor => {
// You can store the "editor" and use when it is needed.
console.log( 'Editor pronto para uso!', editor );
setaFocoNoEditor( editor );
} }
onChange={ ( event, editor ) => {
alteraTexto(event, editor);
console.log(editor.data.get());
} }
onBlur={ ( event, editor ) => {
console.log( 'Editor desfocado.', editor );
} }
onFocus={ ( event, editor ) => {
console.log( 'Editor Focado.', editor );
} }
/>
<div>
<button
style={{background: 'black' , color: 'white '}}
onClick={ ()=> mostraTexto(!textoAdicionado) }
>
{textoAdicionado ? 'Esconde Texto' : 'Mostra Texto'}
</button>
<button
style={{background: 'black' , color: 'white '}}
onClick={ ()=> carregaTexto() }
>
Carrega Texto Completo
</button>
</div>
{textoAdicionado ? <div dangerouslySetInnerHTML={objComTexto}/> : ''}
</div>
);
}
export default App;