ywana-core8 0.0.138 → 0.0.142

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.138",
3
+ "version": "0.0.142",
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>
@@ -59,7 +59,6 @@ export const DropDown = (props) => {
59
59
  const { id, options = [], value, onChange, canFilter = false } = props
60
60
  const [open, setOpen] = useState(false)
61
61
  const [label, setLabel] = useState()
62
- const [filter, srtFilter] = useState()
63
62
 
64
63
  useEffect(() => {
65
64
  if (Array.isArray(options)) {
@@ -69,8 +68,9 @@ export const DropDown = (props) => {
69
68
  }, [value])
70
69
 
71
70
  function change(id, value) {
71
+ console.log('dropdown change > canFilter:', canFilter, id, value)
72
72
  if (canFilter) {
73
- setFilter(value)
73
+ setLabel(value)
74
74
  } else {
75
75
  if (onChange) onChange(id, value)
76
76
  }
@@ -95,23 +95,24 @@ export const DropDown = (props) => {
95
95
  setOpen(false)
96
96
  }
97
97
 
98
- const items = (open == true && Array.isArray(options)) ?
99
- options
100
- .filter(option => canFilter === false || filter.toUpperCase().indexOf(option.label.toUpperCase()) >= 0 )
101
- .map(option => <li key={option.value} value={option.value}>{option.label}</li>)
102
- : null
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 => label.toUpperCase().indexOf(option.label.toUpperCase()) >= 0) : options
103
+ console.log('filterActive: ',filterActive, label, items.length)
104
+ const lis = items.map(option => <li key={option.value} value={option.value}>{option.label}</li>)
105
+ return <menu><ul onClick={select}>{lis}</ul></menu>
106
+ } else {
107
+ return null
108
+ }
109
+ }
103
110
 
104
111
  return (
105
112
  <div className="dropdown">
106
113
  <TextField {...props} onClick={toggle} value={label} onChange={change} />
107
114
  <Icon icon="expand_more" clickable size="small" action={toggle} />
108
- {open == true ? (
109
- <menu>
110
- <ul onClick={select}>
111
- {items}
112
- </ul>
113
- </menu>
114
- ) : null}
115
+ {renderOptions()}
115
116
  </div>
116
117
  )
117
118
  }