-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tsx
80 lines (73 loc) · 2.05 KB
/
main.tsx
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
import './main.css'
import React, { useRef, useState } from 'react'
import ReactDOM from 'react-dom'
import MixInput from '../src/MixInput'
import type { MixInputRef, MixInputValues } from '../src/MixInputType'
function TestApp() {
const [value, setValue] = useState<MixInputValues>([])
const ref = useRef<MixInputRef>(null)
const handleOnChange = (value: MixInputValues) => {
console.log('on change', value)
setValue([value.flat()])
}
const handleControls = (type: string) => () => {
if (type === 'reset') {
setValue([])
}
if (type === 'insert-tag-by-arr') {
setValue((prv) => {
prv[0].push({
type: 'tag',
attrs: {
label: 'sss',
className: '----asd---',
id: 'sad',
ddd: 'dddd',
sss: 'tttt',
style: { color: 'red' },
},
})
return [...prv]
})
}
if (type === 'insert-tag-by-ref') {
ref.current?.insertContent({
type: 'tag',
attrs: { label: 'Tag', class: ['class-2', 's'] },
})
}
if (type === 'caret-pos') {
}
}
return (
<div>
<button onClick={handleControls('reset')} data-testId="reset">
Reset
</button>
<button onClick={handleControls('insert-tag-by-arr')} data-testId="insert-tag-by-arr">
Insert Tag 1
</button>
<button onClick={handleControls('insert-tag-by-ref')} data-testId="insert-tag-by-ref">
Insert Tag 2
</button>
<br />
<br />
<MixInput
ref={ref}
value={value}
onChange={handleOnChange}
placeholder="Write here..."
spellCheck={false}
tagAttrs={{ className: '' }}
// tagView={() => (
// <span data-id="a222" onMouseEnter={() => console.log(ref.current?.editor?.getJSON())}>
// Tag View
// </span>
// )}
// data-testId="input"
// tagAttrs={{ test-attr: '22', test: undefined }}
/>
</div>
)
}
ReactDOM.render(<TestApp />, document.getElementById('root'))