ywana-core8 0.0.943 → 0.0.945

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.943",
3
+ "version": "0.0.945",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
package/src/html/tab.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import React, { useState } from 'react'
2
2
  import { Fragment } from 'react'
3
- import { Icon, TEXTFORMATS, Text } from '../html'
3
+ import { Icon } from './icon'
4
+ import { Text, TEXTFORMATS } from './text'
4
5
  import './tab.css'
5
6
 
6
7
  /**
package/src/html/table.js CHANGED
@@ -13,7 +13,7 @@ const isFunction = value => value && (Object.prototype.toString.call(value) ===
13
13
  */
14
14
  export const DataTable = (props) => {
15
15
 
16
- const { columns = [], rows = [], onRowSelection, onSort, onCheckAll, editable, outlined, expanded = false, className, emptyMessage = "No Results Found", multisort = false, filterable = false } = props
16
+ const { columns = [], rows = [], onRowSelection, onSort, onCheckAll, editable, outlined, expanded = false, className, emptyMessage = "No Results Found", multisort = false, filterable = false, onClearFilters } = props
17
17
  const [sortDir, setSortDir] = useState({})
18
18
  const [allChecked, setAllChecked] = useState(false)
19
19
 
@@ -145,19 +145,41 @@ export const DataTable = (props) => {
145
145
  )
146
146
  }
147
147
 
148
+ /**
149
+ * DataTableFiltersRow
150
+ */
148
151
  const DataTableFiltersRow = ({ columns }) => {
152
+
153
+ const [form, setForm] = useState({})
154
+
155
+ function changeFilter(id, value, onFilter) {
156
+ setForm({ ...form, [id]: value })
157
+ if (onFilter) onFilter(value)
158
+ }
159
+
160
+ function clear() {
161
+ setForm({})
162
+ }
163
+
164
+ const dirty = Object.keys(form).length > 0 // dirty if there are filters set
165
+
149
166
  return (
150
167
  <tr className="filters-row">
151
168
  {columns.map(({ id, filterable, onFilter, options }) => {
152
169
 
153
- const field = options ? <DropDown id={id} options={options} onChange={onFilter} outlined /> : <TextField id={id} onChange={onFilter} outlined />
154
-
170
+ const field = options ?
171
+ <DropDown id={id} value={form[id]} options={options} onChange={(id,value) => changeFilter(id,value, onFilter)} outlined />
172
+ :
173
+ <TextField id={id} value={form[id]} onChange={(id,value) => changeFilter(id,value, onFilter)} outlined />
155
174
  return (
156
175
  <td className='filter-cell'>
157
176
  {filterable ? field : null}
158
177
  </td>
159
178
  )
160
179
  })}
180
+ <td>
181
+ <Icon icon="close" size="small" clickable action={clear} disabled={!dirty} />
182
+ </td>
161
183
  </tr>
162
184
  )
163
185
  }