ywana-core8 0.1.45 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +17 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +22 -9
- package/dist/index.css.map +1 -1
- package/dist/index.modern.js +17 -48
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +17 -48
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/html/checkbox.css +18 -9
- package/src/html/checkbox.js +30 -38
- package/src/html/textfield.css +4 -0
package/package.json
CHANGED
package/src/html/checkbox.css
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
.checkbox .checkmark {
|
10
10
|
width: 1.5rem;
|
11
|
-
height: 1.
|
11
|
+
height: 1.5rem;
|
12
12
|
display: flex;
|
13
13
|
align-items: center;
|
14
14
|
justify-content: center;
|
@@ -18,6 +18,10 @@
|
|
18
18
|
padding-bottom: .1rem;
|
19
19
|
}
|
20
20
|
|
21
|
+
.checkbox.readonly>.checkmark {
|
22
|
+
border: solid 1px var(--text-color-light);
|
23
|
+
}
|
24
|
+
|
21
25
|
.checkbox .checkmark:after {
|
22
26
|
content: "";
|
23
27
|
width: 0.3rem;
|
@@ -31,7 +35,12 @@
|
|
31
35
|
z-index: 0;
|
32
36
|
}
|
33
37
|
|
34
|
-
.checkbox
|
38
|
+
.checkbox.readonly .checkmark:after {
|
39
|
+
border-color: var(--text-color-lighter);
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
.checkbox>input {
|
35
44
|
position: absolute;
|
36
45
|
flex: 1;
|
37
46
|
width: 2rem;
|
@@ -40,16 +49,16 @@
|
|
40
49
|
z-index: 1;
|
41
50
|
}
|
42
51
|
|
43
|
-
input:checked
|
44
|
-
|
45
|
-
|
52
|
+
input:checked~.checkmark:after {
|
53
|
+
display: block;
|
54
|
+
}
|
46
55
|
|
47
|
-
.checkbox
|
48
|
-
color: var(--text-color
|
56
|
+
.checkbox>label {
|
57
|
+
color: var(--text-color);
|
49
58
|
font-size: 1rem;
|
50
59
|
font-weight: normal;
|
51
60
|
}
|
52
61
|
|
53
|
-
.checkbox
|
54
|
-
|
62
|
+
.checkbox.readonly>label {
|
63
|
+
color: var(--text-color-light);
|
55
64
|
}
|
package/src/html/checkbox.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
import React from 'react'
|
1
|
+
import React, { useEffect } from 'react'
|
2
2
|
import { Text } from './text'
|
3
|
-
import { Icon } from './icon'
|
4
3
|
import './checkbox.css'
|
5
4
|
|
6
5
|
/**
|
@@ -8,58 +7,51 @@ import './checkbox.css'
|
|
8
7
|
*/
|
9
8
|
export const CheckBox = (props) => {
|
10
9
|
|
11
|
-
const { id, label,
|
10
|
+
const { id, label, value = false, readOnly = false, onChange } = props
|
11
|
+
|
12
|
+
const [checked, setChecked] = React.useState(value)
|
13
|
+
|
14
|
+
useEffect(() => {
|
15
|
+
setChecked(value)
|
16
|
+
}, [value])
|
12
17
|
|
13
18
|
function change(event) {
|
14
19
|
event.stopPropagation()
|
15
|
-
event.
|
16
|
-
|
17
|
-
if (onChange) onChange(id,
|
20
|
+
const nextValue = event.target.checked
|
21
|
+
setChecked(nextValue)
|
22
|
+
if (onChange) onChange(id, nextValue)
|
18
23
|
}
|
19
24
|
|
20
|
-
const labelTxt = <Text>{label}</Text>
|
21
|
-
const placeholderTxt = <Text>{placeholder}</Text>
|
25
|
+
const labelTxt = label && <Text>{label}</Text>
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
<div className="checkbox" key={`${id}1`}>
|
27
|
-
<Icon id={id} icon="check" size="small" />
|
28
|
-
<span className="checkmark" />
|
29
|
-
<label htmlFor={id}>{labelTxt}</label>
|
30
|
-
</div>
|
31
|
-
) : (
|
32
|
-
<div className="checkbox" key={`${id}0`}>
|
33
|
-
<span className="checkmark" />
|
34
|
-
<label htmlFor={id}>{labelTxt}</label>
|
35
|
-
</div>
|
36
|
-
)
|
37
|
-
}
|
38
|
-
|
39
|
-
return value === true ? (
|
40
|
-
<div className="checkbox" key={`${id}1`}>
|
41
|
-
<input id={id} type="checkbox" placeholder={placeholderTxt} checked value={value} onChange={change} readOnly />
|
42
|
-
<span className="checkmark" />
|
43
|
-
<label htmlFor={id}>{labelTxt}</label>
|
44
|
-
</div>
|
45
|
-
) : (
|
46
|
-
<div className="checkbox" key={`${id}0`}>
|
47
|
-
<input id={id} type="checkbox" placeholder={placeholderTxt} value={value} onChange={change} readOnly />
|
27
|
+
return (
|
28
|
+
<div className={`checkbox ${readOnly ? "readonly" : ""}`} key={`${id}1`}>
|
29
|
+
<input id={id} key={`${id}_${checked}`} type="checkbox" checked={checked} onChange={change} disabled={readOnly} />
|
48
30
|
<span className="checkmark" />
|
49
31
|
<label htmlFor={id}>{labelTxt}</label>
|
50
32
|
</div>
|
51
33
|
)
|
52
34
|
}
|
53
35
|
|
54
|
-
|
55
36
|
const CheckBoxTest = (props) => {
|
56
37
|
|
38
|
+
const [checked, setChecked] = React.useState({
|
39
|
+
check1: true,
|
40
|
+
check2: false,
|
41
|
+
check3: true,
|
42
|
+
check4: false
|
43
|
+
})
|
44
|
+
|
45
|
+
function change(id, value) {
|
46
|
+
setChecked({ ...checked, [id]: value })
|
47
|
+
}
|
48
|
+
|
57
49
|
return (
|
58
50
|
<div>
|
59
|
-
<CheckBox id="check1" label="Check 1"
|
60
|
-
<CheckBox id="check2" label="Check 2"
|
61
|
-
<CheckBox id="check3" label="Check 3"
|
62
|
-
<CheckBox id="check4" label="Check 4"
|
51
|
+
<CheckBox id="check1" label="Check 1" value={checked.check1} onChange={change} />
|
52
|
+
<CheckBox id="check2" label="Check 2" value={checked.check2} onChange={change} />
|
53
|
+
<CheckBox id="check3" label="Check 3" value={checked.check3} onChange={change} readOnly/>
|
54
|
+
<CheckBox id="check4" label="Check 4" value={checked.check4} onChange={change} readOnly/>
|
63
55
|
</div>
|
64
56
|
)
|
65
57
|
}
|