grommet 2.34.2 → 2.35.0

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.
Files changed (93) hide show
  1. package/components/CheckBox/CheckBox.js +1 -1
  2. package/components/CheckBox/StyledCheckBox.js +1 -1
  3. package/components/Data/Data.js +26 -8
  4. package/components/Data/DataForm.js +42 -83
  5. package/components/Data/index.d.ts +27 -3
  6. package/components/Data/propTypes.js +53 -2
  7. package/components/DataClearFilters/stories/Simple.js +45 -9
  8. package/components/DataFilter/DataFilter.js +1 -1
  9. package/components/DataFilters/DataFilters.js +22 -24
  10. package/components/DataFilters/index.d.ts +1 -1
  11. package/components/DataFilters/propTypes.js +1 -1
  12. package/components/DataSearch/DataSearch.js +54 -9
  13. package/components/DataSearch/index.d.ts +1 -0
  14. package/components/DataSearch/propTypes.js +2 -1
  15. package/components/DataSearch/stories/UpdateOnSubmit.js +42 -0
  16. package/components/DataSort/DataSort.js +6 -4
  17. package/components/DataSummary/DataSummary.js +12 -1
  18. package/components/DataSummary/index.d.ts +9 -1
  19. package/components/DataSummary/propTypes.js +7 -2
  20. package/components/DataTable/DataTable.js +14 -2
  21. package/components/DataTable/GroupedBody.js +1 -1
  22. package/components/DataTable/buildState.js +1 -1
  23. package/components/DataTableColumns/DataTableColumns.js +4 -3
  24. package/components/FormField/FormField.js +5 -20
  25. package/components/Grommet/index.d.ts +20 -1
  26. package/components/Grommet/propTypes.js +21 -2
  27. package/components/Image/stories/Fill.js +2 -1
  28. package/components/Image/stories/Fit.js +4 -2
  29. package/components/Image/stories/Opacity.js +14 -7
  30. package/components/Image/stories/Simple.js +2 -1
  31. package/components/RangeSelector/RangeSelector.js +15 -1
  32. package/components/SelectMultiple/SelectMultiple.js +48 -8
  33. package/components/SelectMultiple/SelectMultipleContainer.js +20 -3
  34. package/components/SelectMultiple/SelectMultipleValue.js +23 -4
  35. package/components/SelectMultiple/SelectionSummary.js +30 -3
  36. package/components/SelectMultiple/index.d.ts +17 -0
  37. package/components/SelectMultiple/propTypes.js +21 -2
  38. package/components/SelectMultiple/stories/CustomMessages.js +71 -0
  39. package/components/StarRating/StarRating.js +17 -6
  40. package/components/StarRating/index.d.ts +2 -2
  41. package/components/Tag/index.d.ts +2 -11
  42. package/components/Tag/propTypes.js +2 -5
  43. package/es6/components/CheckBox/CheckBox.js +1 -1
  44. package/es6/components/CheckBox/StyledCheckBox.js +1 -1
  45. package/es6/components/Data/Data.js +26 -8
  46. package/es6/components/Data/DataForm.js +43 -84
  47. package/es6/components/Data/index.d.ts +27 -3
  48. package/es6/components/Data/propTypes.js +53 -2
  49. package/es6/components/DataClearFilters/stories/Simple.js +46 -10
  50. package/es6/components/DataFilter/DataFilter.js +1 -1
  51. package/es6/components/DataFilters/DataFilters.js +22 -24
  52. package/es6/components/DataFilters/index.d.ts +1 -1
  53. package/es6/components/DataFilters/propTypes.js +1 -1
  54. package/es6/components/DataSearch/DataSearch.js +54 -9
  55. package/es6/components/DataSearch/index.d.ts +1 -0
  56. package/es6/components/DataSearch/propTypes.js +2 -1
  57. package/es6/components/DataSearch/stories/UpdateOnSubmit.js +37 -0
  58. package/es6/components/DataSort/DataSort.js +6 -4
  59. package/es6/components/DataSummary/DataSummary.js +12 -1
  60. package/es6/components/DataSummary/index.d.ts +9 -1
  61. package/es6/components/DataSummary/propTypes.js +7 -2
  62. package/es6/components/DataTable/DataTable.js +14 -2
  63. package/es6/components/DataTable/GroupedBody.js +1 -1
  64. package/es6/components/DataTable/buildState.js +1 -1
  65. package/es6/components/DataTableColumns/DataTableColumns.js +4 -3
  66. package/es6/components/FormField/FormField.js +5 -20
  67. package/es6/components/Grommet/index.d.ts +20 -1
  68. package/es6/components/Grommet/propTypes.js +21 -2
  69. package/es6/components/Image/stories/Fill.js +2 -1
  70. package/es6/components/Image/stories/Fit.js +4 -2
  71. package/es6/components/Image/stories/Opacity.js +14 -7
  72. package/es6/components/Image/stories/Simple.js +2 -1
  73. package/es6/components/RangeSelector/RangeSelector.js +15 -1
  74. package/es6/components/SelectMultiple/SelectMultiple.js +48 -8
  75. package/es6/components/SelectMultiple/SelectMultipleContainer.js +20 -3
  76. package/es6/components/SelectMultiple/SelectMultipleValue.js +24 -5
  77. package/es6/components/SelectMultiple/SelectionSummary.js +31 -4
  78. package/es6/components/SelectMultiple/index.d.ts +17 -0
  79. package/es6/components/SelectMultiple/propTypes.js +21 -2
  80. package/es6/components/SelectMultiple/stories/CustomMessages.js +65 -0
  81. package/es6/components/StarRating/StarRating.js +18 -7
  82. package/es6/components/StarRating/index.d.ts +2 -2
  83. package/es6/components/Tag/index.d.ts +2 -11
  84. package/es6/components/Tag/propTypes.js +2 -5
  85. package/es6/languages/default.json +17 -1
  86. package/es6/themes/base.js +3 -12
  87. package/es6/utils/use-debounce.js +21 -0
  88. package/grommet.min.js +1 -1
  89. package/grommet.min.js.map +1 -1
  90. package/languages/default.json +17 -1
  91. package/package.json +10 -10
  92. package/themes/base.js +3 -12
  93. package/utils/use-debounce.js +25 -0
@@ -1,7 +1,7 @@
1
- var _excluded = ["children", "footer", "onDone", "onTouched", "pad", "updateOn"];
1
+ var _excluded = ["children", "footer", "onDone", "pad", "updateOn"];
2
2
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
3
3
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
- import React, { useMemo, useCallback, useContext, useEffect, useState } from 'react';
4
+ import React, { useMemo, useCallback, useContext, useEffect, useRef, useState } from 'react';
5
5
  import styled from 'styled-components';
6
6
  import { Box } from '../Box';
7
7
  import { Button } from '../Button';
@@ -10,23 +10,13 @@ import { Form } from '../Form';
10
10
  import { DataContext } from '../../contexts/DataContext';
11
11
  import { DataFormContext } from '../../contexts/DataFormContext';
12
12
  import { MessageContext } from '../../contexts/MessageContext';
13
- var HideableButton = styled(Button).withConfig({
14
- displayName: "DataForm__HideableButton",
15
- componentId: "sc-v64e1r-0"
16
- })(["", ""], function (props) {
17
- return props.disabled && "\n opacity: 0;";
18
- });
13
+ import { useDebounce } from '../../utils/use-debounce';
19
14
  var MaxForm = styled(Form).withConfig({
20
15
  displayName: "DataForm__MaxForm",
21
- componentId: "sc-v64e1r-1"
16
+ componentId: "sc-v64e1r-0"
22
17
  })(["max-width:100%;", ""], function (props) {
23
18
  return props.fill && 'max-height: 100%;';
24
19
  });
25
- var hideButtonProps = {
26
- 'aria-hidden': true,
27
- disabled: true,
28
- tabIndex: -1
29
- };
30
20
 
31
21
  // We convert the view structure to something more flat to work better
32
22
  // with the Form inputs. These keys are how we flatten the Form value object
@@ -151,10 +141,23 @@ var formValueToView = function formValueToView(value, views) {
151
141
 
152
142
  // remove any empty arrays of property values by deleting the key for
153
143
  // that property in the view properties
154
- var clearEmpty = function clearEmpty(formValue) {
144
+ var clearEmpty = function clearEmpty(formValue, pendingReset) {
155
145
  var value = formValue;
156
146
  Object.keys(value).forEach(function (k) {
157
147
  if (Array.isArray(value[k]) && value[k].length === 0) delete value[k];
148
+ // special case for when range selector returns to its min/max
149
+ // flat format with full: true needed to match filter name structure
150
+ // { a: b: { _range: [0, 100] } } ==> a.b._range: [0, 100]
151
+ if (typeof value[k] === 'object' && !Array.isArray(value[k])) {
152
+ var _pendingReset$current;
153
+ var filterName = k + "." + Object.keys(flatten(value[k], {
154
+ full: true
155
+ }))[0];
156
+ if (pendingReset != null && (_pendingReset$current = pendingReset.current) != null && _pendingReset$current.has(filterName)) {
157
+ delete value[k];
158
+ pendingReset.current["delete"](filterName);
159
+ }
160
+ }
158
161
  });
159
162
  return value;
160
163
  };
@@ -165,28 +168,10 @@ var resetPage = function resetPage(nextFormValue, prevFormValue) {
165
168
  // eslint-disable-next-line no-param-reassign
166
169
  nextFormValue[formPageKey] = 1;
167
170
  };
168
- var transformTouched = function transformTouched(touched, value) {
169
- // DataFilters expects values for keys touched to evaluate to falsey to
170
- // not cause a badge. However any property value that is set back to its
171
- // default/initial value that isn't undefined/null/false/0 will cause a
172
- // badge this is particulary true for a 'range' which will always have
173
- // a value.
174
- //
175
- // Should this instead determine touched by comparing against
176
- // initial/default values?
177
- //
178
- var result = {};
179
- Object.keys(touched).forEach(function (key) {
180
- result[key] = flatten(value, {
181
- full: true
182
- })[key];
183
- });
184
- return result;
185
- };
186
171
 
187
172
  // function shared by onSubmit and onChange to coordinate view
188
173
  // name changes
189
- var normalizeValue = function normalizeValue(nextValue, prevValue, views) {
174
+ var normalizeValue = function normalizeValue(nextValue, prevValue, views, pendingReset) {
190
175
  if (nextValue[formViewNameKey] && nextValue[formViewNameKey] !== prevValue[formViewNameKey]) {
191
176
  // view name changed, reset view contents from named view
192
177
  return viewToFormValue(views.find(function (v) {
@@ -196,16 +181,18 @@ var normalizeValue = function normalizeValue(nextValue, prevValue, views) {
196
181
  // something else changed
197
182
 
198
183
  // clear empty properties
199
- var result = clearEmpty(nextValue);
184
+ var result = clearEmpty(nextValue, pendingReset);
200
185
 
201
- // if we have a view and something related to it changed, clear the view
186
+ // if we have a view and something changed, clear the view
202
187
  if (result[formViewNameKey]) {
203
188
  var view = views.find(function (v) {
204
189
  return v.name === result[formViewNameKey];
205
190
  });
206
191
  var viewValue = viewToFormValue(view);
207
- clearEmpty(viewValue);
208
- if (Object.keys(viewValue).some(function (k) {
192
+ clearEmpty(viewValue, pendingReset);
193
+ if (Object.keys(viewValue).length !== Object.keys(result).length) {
194
+ delete result[formViewNameKey];
195
+ } else if (Object.keys(viewValue).some(function (k) {
209
196
  return (
210
197
  // allow mismatch between empty and set strings
211
198
  viewValue[k] && result[k] && JSON.stringify(result[k]) !== JSON.stringify(viewValue[k])
@@ -219,29 +206,10 @@ var normalizeValue = function normalizeValue(nextValue, prevValue, views) {
219
206
 
220
207
  // 300ms was chosen empirically as a reasonable default
221
208
  var DEBOUNCE_TIMEOUT = 300;
222
- var debounce = function debounce(func, timeout) {
223
- if (timeout === void 0) {
224
- timeout = DEBOUNCE_TIMEOUT;
225
- }
226
- var timer;
227
- return function () {
228
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
229
- args[_key] = arguments[_key];
230
- }
231
- clearTimeout(timer);
232
- timer = setTimeout(function () {
233
- func.apply(void 0, args);
234
- }, timeout);
235
- };
236
- };
237
- var debounceSearch = debounce(function (onView, nextValue, views) {
238
- return onView(formValueToView(nextValue, views));
239
- });
240
209
  export var DataForm = function DataForm(_ref) {
241
210
  var children = _ref.children,
242
211
  footer = _ref.footer,
243
212
  onDone = _ref.onDone,
244
- onTouched = _ref.onTouched,
245
213
  pad = _ref.pad,
246
214
  _ref$updateOn = _ref.updateOn,
247
215
  updateOn = _ref$updateOn === void 0 ? 'submit' : _ref$updateOn,
@@ -256,45 +224,43 @@ export var DataForm = function DataForm(_ref) {
256
224
  var _useState = useState(viewToFormValue(view)),
257
225
  formValue = _useState[0],
258
226
  setFormValue = _useState[1];
259
- var _useState2 = useState(),
260
- changed = _useState2[0],
261
- setChanged = _useState2[1];
227
+ // special case for range selectors which always have a value.
228
+ // when value returns to its min/max, remove it from view
229
+ // like other properties
230
+ var pendingReset = useRef(new Set());
262
231
  var contextValue = useMemo(function () {
263
232
  return {
264
- inDataForm: true
233
+ inDataForm: true,
234
+ pendingReset: pendingReset
265
235
  };
266
236
  }, []);
237
+ var debounce = useDebounce(DEBOUNCE_TIMEOUT);
267
238
  var onSubmit = useCallback(function (_ref2) {
268
- var value = _ref2.value,
269
- touched = _ref2.touched;
270
- var nextValue = normalizeValue(value, formValue, views);
239
+ var value = _ref2.value;
240
+ var nextValue = normalizeValue(value, formValue, views, pendingReset);
271
241
  resetPage(nextValue, formValue);
272
242
  setFormValue(nextValue);
273
- setChanged(false);
274
- if (onTouched) onTouched(transformTouched(touched, nextValue));
275
243
  onView(formValueToView(nextValue, views));
276
244
  if (onDone) onDone();
277
- }, [formValue, onDone, onTouched, onView, views]);
245
+ }, [formValue, onDone, onView, views]);
278
246
  var onChange = useCallback(function (value, _ref3) {
279
247
  var touched = _ref3.touched;
280
- var nextValue = normalizeValue(value, formValue, views);
248
+ var nextValue = normalizeValue(value, formValue, views, pendingReset);
281
249
  resetPage(nextValue, formValue);
282
250
  setFormValue(nextValue);
283
- setChanged(true);
284
251
  if (updateOn === 'change') {
285
- if (onTouched) onTouched(transformTouched(touched, nextValue));
286
252
  // debounce search
287
253
  if (touched[formSearchKey]) {
288
- debounceSearch(onView, nextValue, views);
254
+ debounce(function () {
255
+ return function () {
256
+ return onView(formValueToView(nextValue, views));
257
+ };
258
+ });
289
259
  } else {
290
260
  onView(formValueToView(nextValue, views));
291
261
  }
292
262
  }
293
- }, [formValue, onTouched, onView, updateOn, views]);
294
- var onReset = useCallback(function () {
295
- setFormValue(viewToFormValue(view));
296
- setChanged(false);
297
- }, [view]);
263
+ }, [debounce, formValue, onView, updateOn, views]);
298
264
  useEffect(function () {
299
265
  return setFormValue(viewToFormValue(view));
300
266
  }, [view]);
@@ -328,14 +294,7 @@ export var DataForm = function DataForm(_ref) {
328
294
  }),
329
295
  type: "submit",
330
296
  primary: true
331
- }), /*#__PURE__*/React.createElement(HideableButton, _extends({
332
- label: format({
333
- id: 'dataForm.reset',
334
- messages: messages == null ? void 0 : messages.dataForm
335
- }),
336
- type: "reset",
337
- onClick: onReset
338
- }, !changed ? hideButtonProps : {}))));
297
+ })));
339
298
  }
340
299
  return /*#__PURE__*/React.createElement(MaxForm, _extends({}, rest, {
341
300
  value: formValue,
@@ -37,12 +37,13 @@ export interface DataProps {
37
37
  onView?: (view: View) => void;
38
38
 
39
39
  // whether to render a Toolbar
40
- toolbar?: boolean | 'search' | 'filters';
40
+ toolbar?: boolean | 'search' | 'filters' | 'view';
41
41
 
42
42
  properties?:
43
43
  | string[]
44
44
  | {
45
45
  [key: string]: {
46
+ badge?: boolean;
46
47
  filter?: boolean;
47
48
  // for DataTable column header, DataFilter label, DataTableColumns label
48
49
  label?: string | React.ReactNode;
@@ -72,23 +73,46 @@ export interface DataProps {
72
73
  clear?: string;
73
74
  heading?: string;
74
75
  open?: string;
76
+ openSet?: {
77
+ singular?: string;
78
+ plural?: string;
79
+ };
75
80
  };
76
81
  dataForm?: {
77
- reset?: string;
78
82
  submit?: string;
79
83
  };
80
84
  dataSearch?: {
81
85
  label?: string;
86
+ open?: string;
82
87
  };
83
88
  dataSort?: {
84
89
  ascending?: string;
85
90
  by?: string;
86
91
  descending?: string;
87
92
  direction?: string;
93
+ open?: string;
88
94
  };
89
95
  dataSummary?: {
90
- filteredTotal?: string;
96
+ filtered?: string;
97
+ filteredSingle?: string;
98
+ items?: string;
99
+ itemsSingle?: string;
100
+ selected?: string;
91
101
  total?: string;
102
+ totalSingle?: string;
103
+ };
104
+ dataTableColumns?: {
105
+ open?: string;
106
+ order?: string;
107
+ select?: string;
108
+ tip?: string;
109
+ };
110
+ dataTableGroupBy?: {
111
+ clear?: string;
112
+ label?: string;
113
+ };
114
+ dataView?: {
115
+ label?: string;
92
116
  };
93
117
  };
94
118
 
@@ -12,8 +12,58 @@ if (process.env.NODE_ENV !== 'production') {
12
12
  PropType = {
13
13
  data: PropTypes.arrayOf(PropTypes.shape({})),
14
14
  defaultView: viewType,
15
+ filteredTotal: PropTypes.number,
16
+ id: PropTypes.string,
17
+ messages: PropTypes.shape({
18
+ dataFilters: PropTypes.shape({
19
+ clear: PropTypes.string,
20
+ heading: PropTypes.string,
21
+ open: PropTypes.string,
22
+ openSet: PropTypes.shape({
23
+ singular: PropTypes.string,
24
+ plural: PropTypes.string
25
+ })
26
+ }),
27
+ dataForm: PropTypes.shape({
28
+ submit: PropTypes.string
29
+ }),
30
+ dataSearch: PropTypes.shape({
31
+ label: PropTypes.string,
32
+ open: PropTypes.string
33
+ }),
34
+ dataSort: PropTypes.shape({
35
+ ascending: PropTypes.string,
36
+ by: PropTypes.string,
37
+ descending: PropTypes.string,
38
+ direction: PropTypes.string,
39
+ open: PropTypes.string
40
+ }),
41
+ dataSummary: PropTypes.shape({
42
+ filtered: PropTypes.string,
43
+ filteredSingle: PropTypes.string,
44
+ items: PropTypes.string,
45
+ itemsSingle: PropTypes.string,
46
+ selected: PropTypes.string,
47
+ total: PropTypes.string,
48
+ totalSingle: PropTypes.string
49
+ }),
50
+ dataTableColumns: PropTypes.shape({
51
+ open: PropTypes.string,
52
+ order: PropTypes.string,
53
+ select: PropTypes.string,
54
+ tip: PropTypes.string
55
+ }),
56
+ dataTableGroupBy: PropTypes.shape({
57
+ clear: PropTypes.string,
58
+ label: PropTypes.string
59
+ }),
60
+ dataView: PropTypes.shape({
61
+ label: PropTypes.string
62
+ })
63
+ }),
15
64
  onView: PropTypes.func,
16
65
  properties: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.objectOf(PropTypes.shape({
66
+ badge: PropTypes.bool,
17
67
  filter: PropTypes.bool,
18
68
  label: PropTypes.string,
19
69
  options: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.shape({})])),
@@ -25,9 +75,10 @@ if (process.env.NODE_ENV !== 'production') {
25
75
  search: PropTypes.bool,
26
76
  sort: PropTypes.bool
27
77
  }))]),
28
- toolbar: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['search', 'filters'])]),
78
+ toolbar: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['search', 'filters', 'view'])]),
29
79
  total: PropTypes.number,
30
- view: PropTypes.oneOfType([PropTypes.string, viewType])
80
+ view: PropTypes.oneOfType([PropTypes.string, viewType]),
81
+ views: PropTypes.arrayOf(viewType)
31
82
  };
32
83
  }
33
84
  export var DataPropTypes = PropType;
@@ -1,5 +1,5 @@
1
1
  import React, { useContext } from 'react';
2
- import { Box, Data, DataClearFilters, DataContext, DataFilter, DataFilters, DataSearch, DataSummary, DataTable, SelectMultiple, Toolbar } from 'grommet';
2
+ import { Box, Data, DataClearFilters, DataContext, DataFilter, DataFilters, DataSearch, DataSummary, DataView, DataTable, SelectMultiple, Toolbar } from 'grommet';
3
3
  import { columns, DATA } from '../../DataTable/stories/data';
4
4
  export var Simple = function Simple() {
5
5
  return (
@@ -13,9 +13,35 @@ export var Simple = function Simple() {
13
13
  total: DATA.length,
14
14
  properties: {
15
15
  location: {
16
- label: 'Location'
16
+ label: 'Location',
17
+ badge: false
18
+ },
19
+ percent: {
20
+ label: 'Percent'
21
+ },
22
+ date: {
23
+ label: 'date'
24
+ },
25
+ name: {
26
+ label: 'Name'
17
27
  }
18
- }
28
+ },
29
+ views: [{
30
+ name: 'latest',
31
+ sort: {
32
+ property: 'date',
33
+ direction: 'desc'
34
+ }
35
+ }, {
36
+ name: 'Bay Area behind',
37
+ properties: {
38
+ percent: {
39
+ min: 0,
40
+ max: 50
41
+ },
42
+ location: ['San Francisco']
43
+ }
44
+ }]
19
45
  }, /*#__PURE__*/React.createElement(DataToolbar, null), /*#__PURE__*/React.createElement(DataSummary, null), /*#__PURE__*/React.createElement(DataTable, {
20
46
  columns: columns
21
47
  })))
@@ -24,14 +50,15 @@ export var Simple = function Simple() {
24
50
  };
25
51
  var DataToolbar = function DataToolbar() {
26
52
  var _useContext = useContext(DataContext),
27
- filteredTotal = _useContext.filteredTotal,
28
- total = _useContext.total;
53
+ view = _useContext.view;
29
54
  return /*#__PURE__*/React.createElement(Toolbar, {
55
+ gap: "medium",
30
56
  align: "end"
31
- }, /*#__PURE__*/React.createElement(DataSearch, {
32
- placeholder: "Search"
33
- }), /*#__PURE__*/React.createElement(DataFilters, {
34
- updateOn: "change"
57
+ }, /*#__PURE__*/React.createElement(Toolbar, {
58
+ align: "end"
59
+ }, /*#__PURE__*/React.createElement(DataSearch, null), /*#__PURE__*/React.createElement(DataFilters, {
60
+ updateOn: "change",
61
+ clearFilters: false
35
62
  }, /*#__PURE__*/React.createElement(DataFilter, {
36
63
  property: "location"
37
64
  // override HPE theme margin to align with search + filter
@@ -49,7 +76,16 @@ var DataToolbar = function DataToolbar() {
49
76
  placeholder: "Select location",
50
77
  options: ['Boise', 'Fort Collins', 'Palo Alto', 'San Francisco'],
51
78
  name: "location"
52
- }))), filteredTotal !== total ? /*#__PURE__*/React.createElement(DataClearFilters, null) : null);
79
+ }))), /*#__PURE__*/React.createElement(DataFilters, {
80
+ layer: true,
81
+ clearFilters: false
82
+ }, /*#__PURE__*/React.createElement(DataFilter, {
83
+ property: "name"
84
+ }), /*#__PURE__*/React.createElement(DataFilter, {
85
+ property: "percent"
86
+ }), /*#__PURE__*/React.createElement(DataFilter, {
87
+ property: "paid"
88
+ })), (view == null ? void 0 : view.properties) !== undefined && Object.keys(view == null ? void 0 : view.properties).length !== 0 ? /*#__PURE__*/React.createElement(DataClearFilters, null) : null), /*#__PURE__*/React.createElement(DataView, null));
53
89
  };
54
90
  Simple.storyName = 'Simple';
55
91
  export default {
@@ -17,7 +17,7 @@ var maxCheckBoxGroupOptions = 4;
17
17
  var minSelectSearchOptions = 10;
18
18
  var defaultRangeSteps = 20;
19
19
  var getValueAt = function getValueAt(valueObject, pathArg) {
20
- if (valueObject === undefined) return undefined;
20
+ if (!pathArg || valueObject === undefined) return undefined;
21
21
  var path = Array.isArray(pathArg) ? pathArg : pathArg.split('.');
22
22
  if (path.length === 1) return valueObject[path];
23
23
  return getValueAt(valueObject[path.shift()], path);
@@ -10,7 +10,6 @@ import { Button } from '../Button';
10
10
  import { DataClearFilters } from '../DataClearFilters';
11
11
  import { DataFilter } from '../DataFilter';
12
12
  import { DataForm } from '../Data/DataForm';
13
- import { DataSort } from '../DataSort';
14
13
  import { DropButton } from '../DropButton';
15
14
  import { Header } from '../Header';
16
15
  import { Heading } from '../Heading';
@@ -52,10 +51,8 @@ export var DataFilters = function DataFilters(_ref) {
52
51
  var _useState = useState(),
53
52
  showContent = _useState[0],
54
53
  setShowContent = _useState[1];
55
- // touched is a map of form field name to its value, it only has fields that
56
- // were changed as part of the DataForm here. This is so we can track based
57
- // on what's inside DataFilters as opposed to trying to track from the view
58
- // object, since touched is used as logic for whether to show badge or not
54
+ // touched is a map of property to its value based on if user interacts
55
+ // with a filter or a view applies of set of filters
59
56
  var _useState2 = useState(defaultTouched),
60
57
  touched = _useState2[0],
61
58
  setTouched = _useState2[1];
@@ -76,6 +73,21 @@ export var DataFilters = function DataFilters(_ref) {
76
73
  var controlled = useMemo(function () {
77
74
  return drop || layer;
78
75
  }, [drop, layer]);
76
+ var configured = Children.count(children) === 0;
77
+ useEffect(function () {
78
+ // when view changes via DataView or user interacting with filters,
79
+ // adjust badge to reflect that
80
+ if (controlled && view.properties) {
81
+ var nextTouched = _extends({}, view.properties);
82
+ Object.keys(nextTouched).forEach(function (k) {
83
+ var _properties$k;
84
+ if ((properties == null || (_properties$k = properties[k]) == null ? void 0 : _properties$k.badge) === false || configured && properties && !(properties != null && properties[k])) {
85
+ delete nextTouched[k];
86
+ }
87
+ });
88
+ setTouched(nextTouched);
89
+ }
90
+ }, [configured, controlled, properties, view]);
79
91
 
80
92
  // generate the badge value based on touched fields that have a value.
81
93
  // only show the badge based off of what's included in this DataFilters
@@ -110,27 +122,12 @@ export var DataFilters = function DataFilters(_ref) {
110
122
  property: property
111
123
  });
112
124
  });
113
- if (view != null && view.sort) {
114
- content.push( /*#__PURE__*/React.createElement(DataSort, {
115
- key: "_sort"
116
- }));
117
- }
118
125
  }
119
126
  content = /*#__PURE__*/React.createElement(DataForm, _extends({
120
127
  pad: controlled ? 'medium' : undefined,
121
128
  onDone: function onDone() {
122
129
  return setShowContent(false);
123
130
  },
124
- onTouched: controlled ? function (currentTouched) {
125
- return (
126
- // we merge this with our prior state to handle the case where the
127
- // user opens and closes the drop multiple times and we want to
128
- // track both new changes and prior changes.
129
- setTouched(function (prevTouched) {
130
- return _extends({}, prevTouched, currentTouched);
131
- })
132
- );
133
- } : undefined,
134
131
  updateOn: updateOn
135
132
  }, !controlled ? rest : {
136
133
  fill: 'vertical'
@@ -142,7 +139,6 @@ export var DataFilters = function DataFilters(_ref) {
142
139
  messages: messages == null ? void 0 : messages.dataFilters
143
140
  })), !controlled && clearControl, /*#__PURE__*/React.createElement(Button, {
144
141
  icon: /*#__PURE__*/React.createElement(Close, null),
145
- hoverIndicator: true,
146
142
  onClick: function onClick() {
147
143
  return setShowContent(undefined);
148
144
  }
@@ -164,7 +160,6 @@ export var DataFilters = function DataFilters(_ref) {
164
160
  "aria-label": tip,
165
161
  kind: (_theme$data$button = theme.data.button) == null ? void 0 : _theme$data$button.kind,
166
162
  icon: /*#__PURE__*/React.createElement(Filter, null),
167
- hoverIndicator: true,
168
163
  dropProps: dropProps,
169
164
  dropContent: content,
170
165
  badge: badge,
@@ -183,7 +178,6 @@ export var DataFilters = function DataFilters(_ref) {
183
178
  tip: tip,
184
179
  "aria-label": tip,
185
180
  kind: (_theme$data$button2 = theme.data.button) == null ? void 0 : _theme$data$button2.kind,
186
- hoverIndicator: true,
187
181
  icon: /*#__PURE__*/React.createElement(Filter, null),
188
182
  badge: badge,
189
183
  onClick: function onClick() {
@@ -203,6 +197,10 @@ export var DataFilters = function DataFilters(_ref) {
203
197
  onEsc: function onEsc() {
204
198
  return setShowContent(undefined);
205
199
  }
206
- }), content));
200
+ }), /*#__PURE__*/React.createElement(Box, {
201
+ width: {
202
+ min: 'medium'
203
+ }
204
+ }, content)));
207
205
  };
208
206
  DataFilters.propTypes = DataFiltersPropTypes;
@@ -2,10 +2,10 @@ import * as React from 'react';
2
2
  import { BoxProps } from '../Box/index';
3
3
 
4
4
  export interface DataFiltersProps {
5
+ clearFilters?: boolean;
5
6
  drop?: boolean;
6
7
  heading?: string | React.ReactNode;
7
8
  layer?: boolean;
8
- clearFilters?: boolean;
9
9
  // when view changes should be delivered
10
10
  updateOn?: 'change' | 'submit';
11
11
  }
@@ -2,10 +2,10 @@ import PropTypes from 'prop-types';
2
2
  var PropType = {};
3
3
  if (process.env.NODE_ENV !== 'production') {
4
4
  PropType = {
5
+ clearFilters: PropTypes.bool,
5
6
  drop: PropTypes.bool,
6
7
  heading: PropTypes.string,
7
8
  layer: PropTypes.bool,
8
- clearFilters: PropTypes.bool,
9
9
  updateOn: PropTypes.oneOf(['change', 'submit'])
10
10
  };
11
11
  }