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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.1.45",
3
+ "version": "0.1.46",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -8,7 +8,7 @@
8
8
 
9
9
  .checkbox .checkmark {
10
10
  width: 1.5rem;
11
- height: 1.4rem;
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 > input {
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 ~ .checkmark:after {
44
- display: block;
45
- }
52
+ input:checked~.checkmark:after {
53
+ display: block;
54
+ }
46
55
 
47
- .checkbox > label {
48
- color: var(--text-color-light);
56
+ .checkbox>label {
57
+ color: var(--text-color);
49
58
  font-size: 1rem;
50
59
  font-weight: normal;
51
60
  }
52
61
 
53
- .checkbox .icon {
54
- position: absolute;
62
+ .checkbox.readonly>label {
63
+ color: var(--text-color-light);
55
64
  }
@@ -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, placeholder, value, readOnly=false, onChange } = props
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.preventDefault()
16
- const value = event.target.checked
17
- if (onChange) onChange(id, value)
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
- if (readOnly===true) {
25
- return value === true ? (
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" placeholder="Check 1" value={true} />
60
- <CheckBox id="check2" label="Check 2" placeholder="Check 2" value={false} />
61
- <CheckBox id="check3" label="Check 3" placeholder="Check 3" value={true} readOnly />
62
- <CheckBox id="check4" label="Check 4" placeholder="Check 4" value={false} readOnly />
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
  }
@@ -46,6 +46,10 @@
46
46
  color: rgba(150,150,150,1);
47
47
  }
48
48
 
49
+ .textfield-outlined.no-label > .icon {
50
+ top: .5rem;
51
+ }
52
+
49
53
  .textfield-date>.icon,
50
54
  .textfield-DATE>.icon {
51
55
  right: 2.5rem;