forked from JetBrains/kotlin-wrappers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quill.kt
57 lines (46 loc) · 1.22 KB
/
Quill.kt
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
package example
/**
* An example of using an external React component by Scott_Huang@qq.com (Zhiliang.Huang@gmail.com)
*
* Run `npm install react-quill --save`
* Add `require ("react-quill/dist/quill.snow.css")` to index.kt to include the CSS
*/
import react.*
import react.dom.*
@JsModule("react-quill")
@JsNonModule
external val reactQuill: RClass<ReactQuillProps>
external interface ReactQuillProps : RProps {
var value: String
var onChange: (String) -> Unit
}
interface QuillProps : RProps {
var initialText: String
}
interface QuillState : RState {
var text: String
}
class Quill(props: QuillProps) : RComponent<QuillProps, QuillState>(props) {
override fun QuillState.init(props: QuillProps) {
text = props.initialText
}
private fun handleChange(value: String) {
setState {
text = value
}
console.log(value)
}
override fun RBuilder.render() {
div {
reactQuill {
attrs {
value = state.text
onChange = { handleChange(it) }
}
}
}
}
}
fun RBuilder.quill(quillValue: String) = child(Quill::class) {
attrs.initialText = quillValue
}