ywana-core8 0.0.137 → 0.0.141

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.0.137",
3
+ "version": "0.0.141",
4
4
  "description": "ywana-core8",
5
5
  "author": "Ernesto Roldan Garcia",
6
6
  "license": "MIT",
@@ -244,7 +244,7 @@ export const StringEditor = ({ field, value = '', onChange, content, outlined })
244
244
  <div className='field-editor string-editor'>
245
245
  {
246
246
  format === FORMATS.DATE ? <TextField outlined={outlined} id={id} type="date" label={label} value={value} onChange={change} readOnly={!editable} /> :
247
- options ? <DropDown outlined={outlined} id={id} label={label} value={value} onChange={change} options={buildOptions()} readOnly={!editable} /> :
247
+ options ? <DropDown outlined={outlined} id={id} label={label} value={value} onChange={change} options={buildOptions()} readOnly={!editable} canFilter={true}/> :
248
248
  <TextField outlined={outlined} id={id} label={label} value={value} onChange={change} readOnly={!editable} />
249
249
  }
250
250
  </div>
@@ -39,6 +39,12 @@
39
39
  -webkit-transition: 0.2s ease all;
40
40
  }
41
41
 
42
+ .textfield-outlined input[type="date"] ~ label {
43
+ top: .3rem;
44
+ font-size: .8rem;
45
+ color: var(--primary-color);
46
+ }
47
+
42
48
  /* active state */
43
49
  .textfield-outlined > input:focus ~ label,
44
50
  .textfield-outlined > input:valid ~ label {
@@ -47,6 +47,12 @@ input:read-only {
47
47
  border: 0px !important;
48
48
  }
49
49
 
50
+ .textfield input[type="date"] ~ label {
51
+ top: .3rem;
52
+ font-size: .8rem;
53
+ color: var(--primary-color);
54
+ }
55
+
50
56
  /* active state */
51
57
  input:read-only ~ label,
52
58
  .textfield > input:focus ~ label,
@@ -11,7 +11,7 @@ import './textfield.css'
11
11
  export const TextField = (props) => {
12
12
 
13
13
  const site = useContext(SiteContext)
14
- const { id, type = 'text', label, placeholder, value, outlined, readOnly=false, onChange, onEnter, onClick } = props
14
+ const { id, type = 'text', label, placeholder, value, outlined, readOnly = false, onChange, onEnter, onClick } = props
15
15
 
16
16
  function onKeyPress(event) {
17
17
  var key = event.charCode ? event.charCode : event.keyCode ? event.keyCode : 0;
@@ -29,9 +29,11 @@ export const TextField = (props) => {
29
29
 
30
30
  function focus() {
31
31
  if (site) {
32
- site.changeFocus({ lose: () => {
33
- // DO NOTHING
34
- }})
32
+ site.changeFocus({
33
+ lose: () => {
34
+ // DO NOTHING
35
+ }
36
+ })
35
37
  }
36
38
  }
37
39
 
@@ -41,9 +43,9 @@ export const TextField = (props) => {
41
43
  const labelTxt = <Text>{label}</Text>
42
44
  return (
43
45
  <div className={`${style}`} onClick={onClick}>
44
- <input id={id} type={type} placeholder={placeholder} value={value} required onChange={change} onKeyDown={onKeyPress} onFocus={focus} readOnly={readOnly} onfocus="(this.type='date')" onfocusout="(this.type='text')"/>
46
+ <input id={id} type={type} placeholder={placeholder} value={value} required onChange={change} onKeyDown={onKeyPress} onFocus={focus} readOnly={readOnly} onfocus="(this.type='date')" onfocusout="(this.type='text')" />
45
47
  <span className="bar"></span>
46
- { label ? <label>{labelTxt}</label> : null }
48
+ {label ? <label>{labelTxt}</label> : null}
47
49
  </div>
48
50
  )
49
51
  }
@@ -54,7 +56,7 @@ export const TextField = (props) => {
54
56
  export const DropDown = (props) => {
55
57
 
56
58
  const site = useContext(SiteContext)
57
- const { id, options = [], value, onChange } = props
59
+ const { id, options = [], value, onChange, canFilter = false } = props
58
60
  const [open, setOpen] = useState(false)
59
61
  const [label, setLabel] = useState()
60
62
 
@@ -65,13 +67,23 @@ export const DropDown = (props) => {
65
67
  }
66
68
  }, [value])
67
69
 
70
+ function change(id, value) {
71
+ console.log('dropdown change > canFilter:', canFilter, id, value)
72
+ if (canFilter) {
73
+ setLabel(value)
74
+ } else {
75
+ if (onChange) onChange(id, value)
76
+ }
77
+ }
68
78
 
69
79
  function toggle() {
70
80
  if (site) {
71
- site.changeFocus({ lose: () => {
72
- setOpen(false)
73
- }})
74
- }
81
+ site.changeFocus({
82
+ lose: () => {
83
+ setOpen(false)
84
+ }
85
+ })
86
+ }
75
87
  setOpen(!open)
76
88
  }
77
89
 
@@ -83,17 +95,23 @@ export const DropDown = (props) => {
83
95
  setOpen(false)
84
96
  }
85
97
 
98
+ function renderOptions() {
99
+ const canShow = open == true && Array.isArray(options)
100
+ if (canShow) {
101
+ const filterActive = canFilter && label && label.length > 0
102
+ const items = filterActive ? options.filter(option => canFilter === false || label.toUpperCase().indexOf(option.label.toUpperCase()) >= 0) : options
103
+ const lis = items.map(option => <li key={option.value} value={option.value}>{option.label}</li>)
104
+ return <menu><ul onClick={select}>{lis}</ul></menu>
105
+ } else {
106
+ return null
107
+ }
108
+ }
109
+
86
110
  return (
87
111
  <div className="dropdown">
88
- <TextField {...props} onClick={toggle} value={label} />
112
+ <TextField {...props} onClick={toggle} value={label} onChange={change} />
89
113
  <Icon icon="expand_more" clickable size="small" action={toggle} />
90
- {open == true ? (
91
- <menu>
92
- <ul onClick={select}>
93
- {Array.isArray(options) ? options.map(option => <li key={option.value} value={option.value}>{option.label}</li>) : null}
94
- </ul>
95
- </menu>
96
- ) : null}
114
+ {renderOptions()}
97
115
  </div>
98
116
  )
99
117
  }