grommet 2.32.0 → 2.32.1

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 (45) hide show
  1. package/components/Chart/Chart.js +113 -57
  2. package/components/Chart/index.d.ts +3 -0
  3. package/components/Chart/propTypes.js +1 -0
  4. package/components/Chart/stories/Layout.js +6 -3
  5. package/components/Chart/stories/Pattern.js +1 -0
  6. package/components/Chart/stories/Vertical.js +41 -0
  7. package/components/Chart/utils.js +57 -10
  8. package/components/Data/Data.js +2 -1
  9. package/components/Data/filter.js +10 -7
  10. package/components/DataFilter/DataFilter.js +26 -21
  11. package/components/DataTable/GroupedBody.js +1 -1
  12. package/components/DataTable/buildState.js +1 -1
  13. package/components/Drop/DropContainer.js +3 -2
  14. package/components/RadioButtonGroup/RadioButtonGroup.js +19 -4
  15. package/components/RadioButtonGroup/stories/typescript/Simple.tsx +6 -4
  16. package/components/index.d.ts +2 -1
  17. package/contexts/DataContext.js +2 -1
  18. package/es6/components/Chart/Chart.js +113 -57
  19. package/es6/components/Chart/index.d.ts +3 -0
  20. package/es6/components/Chart/propTypes.js +1 -0
  21. package/es6/components/Chart/stories/Layout.js +6 -3
  22. package/es6/components/Chart/stories/Pattern.js +1 -0
  23. package/es6/components/Chart/stories/Vertical.js +35 -0
  24. package/es6/components/Chart/utils.js +57 -10
  25. package/es6/components/Data/Data.js +2 -1
  26. package/es6/components/Data/filter.js +10 -7
  27. package/es6/components/DataFilter/DataFilter.js +26 -21
  28. package/es6/components/DataTable/GroupedBody.js +1 -1
  29. package/es6/components/DataTable/buildState.js +1 -1
  30. package/es6/components/Drop/DropContainer.js +3 -2
  31. package/es6/components/RadioButtonGroup/RadioButtonGroup.js +19 -4
  32. package/es6/components/RadioButtonGroup/stories/typescript/Simple.tsx +6 -4
  33. package/es6/components/index.d.ts +2 -1
  34. package/es6/contexts/DataContext.js +2 -1
  35. package/es6/index.d.ts +11 -0
  36. package/es6/index.js +2 -0
  37. package/es6/utils/index.d.ts +1 -1
  38. package/es6/utils/refs.js +1 -1
  39. package/grommet.min.js +1 -1
  40. package/grommet.min.js.map +1 -1
  41. package/index.d.ts +11 -0
  42. package/index.js +1 -0
  43. package/package.json +32 -32
  44. package/utils/index.d.ts +1 -1
  45. package/utils/refs.js +1 -1
@@ -48,13 +48,16 @@ export var filter = function filter(data, view, properties) {
48
48
 
49
49
  // options case
50
50
  if (Array.isArray(filterValue)) {
51
- if (Array.isArray(value)) {
52
- return !filterValue.some(function (f) {
53
- return typeof f === 'object' ? value.includes(f == null ? void 0 : f.value) // from {label: ___, value: ___}
54
- : value.includes(f);
55
- });
56
- }
57
- return !filterValue.includes(value);
51
+ return !filterValue.some(function (f) {
52
+ // f may be an object with form {label: __, value: __}
53
+ var isObject = typeof f === 'object';
54
+ // match f within data value array using .includes()
55
+ if (Array.isArray(value)) {
56
+ return isObject ? value.includes(f == null ? void 0 : f.value) : value.includes(f);
57
+ }
58
+ // match f with data value using ===
59
+ return isObject ? (f == null ? void 0 : f.value) === value : f === value;
60
+ });
58
61
  }
59
62
 
60
63
  // presence case
@@ -65,9 +65,11 @@ export var DataFilter = function DataFilter(_ref) {
65
65
 
66
66
  // generate options from all values for property
67
67
  var uniqueValues = generateOptions(unfilteredData || data, property);
68
+ // if less than two values, nothing to filter
69
+ if (uniqueValues.length < 2) return [undefined, undefined];
68
70
  // if any values aren't numeric, treat as options
69
71
  if (uniqueValues.some(function (v) {
70
- return v && typeof v !== 'number';
72
+ return v !== undefined && typeof v !== 'number';
71
73
  })) return [uniqueValues, undefined];
72
74
  // all values are numeric, treat as range
73
75
  // normalize to make it friendler, so [1.3, 4.895] becomes [1, 5]
@@ -94,28 +96,31 @@ export var DataFilter = function DataFilter(_ref) {
94
96
  size: "full",
95
97
  round: "small"
96
98
  });
97
- } else if (options.length === 2 && options[1] === true && options[0] === false) {
98
- // special case boolean properties
99
- content = /*#__PURE__*/React.createElement(CheckBoxGroup, {
100
- id: id,
101
- name: property,
102
- options: booleanOptions
103
- });
104
- } else if (options.length < 7) {
105
- content = /*#__PURE__*/React.createElement(CheckBoxGroup, {
106
- id: id,
107
- name: property,
108
- options: options
109
- });
110
- } else {
111
- content = /*#__PURE__*/React.createElement(SelectMultiple, {
112
- id: id,
113
- name: property,
114
- showSelectedInline: true,
115
- options: options
116
- });
99
+ } else if (options) {
100
+ if (options.length === 2 && options[1] === true && options[0] === false) {
101
+ // special case boolean properties
102
+ content = /*#__PURE__*/React.createElement(CheckBoxGroup, {
103
+ id: id,
104
+ name: property,
105
+ options: booleanOptions
106
+ });
107
+ } else if (options.length < 7) {
108
+ content = /*#__PURE__*/React.createElement(CheckBoxGroup, {
109
+ id: id,
110
+ name: property,
111
+ options: options
112
+ });
113
+ } else {
114
+ content = /*#__PURE__*/React.createElement(SelectMultiple, {
115
+ id: id,
116
+ name: property,
117
+ showSelectedInline: true,
118
+ options: options
119
+ });
120
+ }
117
121
  }
118
122
  }
123
+ if (!content) return null;
119
124
  if (noForm)
120
125
  // likely in Toolbar
121
126
  content = /*#__PURE__*/React.createElement(DataForm, {
@@ -43,7 +43,7 @@ export var GroupedBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
43
43
  var isGroupSelected = false;
44
44
  var groupDisabled = [];
45
45
  var isGroupDisabled = false;
46
- if (memberCount > 1 || onUpdate && group.key) {
46
+ if (memberCount > 1 || onUpdate && group.key !== undefined) {
47
47
  // need a header
48
48
  var primaryKeys = group.data.map(function (datum) {
49
49
  return datum[primaryProperty];
@@ -224,7 +224,7 @@ export var buildGroupState = function buildGroupState(groups, groupBy) {
224
224
  if (groups) {
225
225
  groups.forEach(function (_ref) {
226
226
  var key = _ref.key;
227
- if (key) result[key] = {
227
+ if (key !== undefined) result[key] = {
228
228
  expanded: false
229
229
  };
230
230
  });
@@ -81,8 +81,9 @@ var DropContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
81
81
  }, [onClickOutside, containerTarget, portalContext]);
82
82
  useEffect(function () {
83
83
  var notifyAlign = function notifyAlign() {
84
- var styleCurrent = dropRef.current.style;
85
- var alignControl = styleCurrent.top !== '' ? 'top' : 'bottom';
84
+ var _dropRef$current;
85
+ var styleCurrent = dropRef == null ? void 0 : (_dropRef$current = dropRef.current) == null ? void 0 : _dropRef$current.style;
86
+ var alignControl = (styleCurrent == null ? void 0 : styleCurrent.top) !== '' ? 'top' : 'bottom';
86
87
  onAlign(alignControl);
87
88
  };
88
89
 
@@ -17,7 +17,7 @@ var RadioButtonGroup = /*#__PURE__*/forwardRef(function (_ref, ref) {
17
17
  _ref$focusIndicator = _ref.focusIndicator,
18
18
  focusIndicator = _ref$focusIndicator === void 0 ? true : _ref$focusIndicator,
19
19
  name = _ref.name,
20
- _onChange = _ref.onChange,
20
+ onChange = _ref.onChange,
21
21
  optionsProp = _ref.options,
22
22
  valueProp = _ref.value,
23
23
  gap = _ref.gap,
@@ -40,7 +40,7 @@ var RadioButtonGroup = /*#__PURE__*/forwardRef(function (_ref, ref) {
40
40
  var _formContext$useFormI = formContext.useFormInput({
41
41
  name: name,
42
42
  value: valueProp,
43
- initialValue: defaultValue || ''
43
+ initialValue: defaultValue != null ? defaultValue : ''
44
44
  }),
45
45
  value = _formContext$useFormI[0],
46
46
  setValue = _formContext$useFormI[1];
@@ -90,6 +90,18 @@ var RadioButtonGroup = /*#__PURE__*/forwardRef(function (_ref, ref) {
90
90
  setFocus(true);
91
91
  }, 1);
92
92
  };
93
+ var onRadioButtonChange = function onRadioButtonChange(event, optionValue) {
94
+ setValue(optionValue);
95
+ if (onChange) {
96
+ event.persist(); // extract from React synthetic event pool
97
+ // event.target.value gives value as a string which needs to be
98
+ // manually typecasted according to the type of original option value.
99
+ // return the original option value attached with the event.
100
+ var adjustedEvent = event;
101
+ adjustedEvent.value = optionValue;
102
+ onChange(adjustedEvent);
103
+ }
104
+ };
93
105
  var onBlur = function onBlur() {
94
106
  return setFocus(false);
95
107
  };
@@ -116,6 +128,10 @@ var RadioButtonGroup = /*#__PURE__*/forwardRef(function (_ref, ref) {
116
128
  // when nothing has been selected, show focus
117
129
  // on the first radiobutton
118
130
  value === '' && index === 0;
131
+ if (optionRest.checked) {
132
+ console.warn( // eslint-disable-next-line max-len
133
+ "'checked' prop of an individual RadioButton shouldn't be used in a RadioButtonGroup component. Use the RadioButtonGroup 'value' prop instead.");
134
+ }
119
135
  return /*#__PURE__*/React.createElement(RadioButton, _extends({
120
136
  ref: function ref(aRef) {
121
137
  optionRefs.current[index] = aRef;
@@ -138,8 +154,7 @@ var RadioButtonGroup = /*#__PURE__*/forwardRef(function (_ref, ref) {
138
154
  onFocus: onFocus,
139
155
  onBlur: onBlur,
140
156
  onChange: function onChange(event) {
141
- setValue(optionValue);
142
- if (_onChange) _onChange(event);
157
+ return onRadioButtonChange(event, optionValue);
143
158
  },
144
159
  tabIndex: focusable ? '0' : '-1' // necessary for Firefox
145
160
  }, optionRest), children ? function (state) {
@@ -1,7 +1,9 @@
1
- import React, { useState } from 'react';
1
+ import React, { ChangeEvent, useState } from 'react';
2
2
 
3
3
  import { Box, RadioButtonGroup } from 'grommet';
4
4
 
5
+ type EventWithValueProp = ChangeEvent<HTMLInputElement> & {value: string | number};
6
+
5
7
  export const Simple = () => {
6
8
  const postMethods = [
7
9
  { label: 'FTP', value: 'FTP' },
@@ -16,8 +18,8 @@ export const Simple = () => {
16
18
  ];
17
19
 
18
20
  // Type arguments can only be used in TypeScript files.
19
- // Remove <string | object> if you are not using Typescript.
20
- const [value, setValue] = useState<string | object>(postMethods[0]);
21
+ // Remove <string | number> if you are not using Typescript.
22
+ const [value, setValue] = useState<string | number>(postMethods[0].value);
21
23
 
22
24
  return (
23
25
  <Box align="center" pad="large">
@@ -25,7 +27,7 @@ export const Simple = () => {
25
27
  name="radio"
26
28
  options={postMethods}
27
29
  value={value}
28
- onChange={(event) => setValue(event.target.value)}
30
+ onChange={(event: EventWithValueProp) => setValue(event.value)}
29
31
  />
30
32
  </Box>
31
33
  );
@@ -85,7 +85,8 @@ export * from './Tag';
85
85
  export * from './Text';
86
86
  export * from './TextArea';
87
87
  export * from './TextInput';
88
- export * from './Tip';
89
88
  export * from './ThumbsRating';
89
+ export * from './Tip';
90
+ export * from './Toolbar';
90
91
  export * from './Video';
91
92
  export * from './WorldMap';
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
2
  export var DataContext = /*#__PURE__*/React.createContext({
3
- data: []
3
+ data: [],
4
+ addToolbarKey: function addToolbarKey() {}
4
5
  });
package/es6/index.d.ts CHANGED
@@ -10,13 +10,23 @@ export * from './components/Card';
10
10
  export * from './components/CardBody';
11
11
  export * from './components/CardFooter';
12
12
  export * from './components/CardHeader';
13
+ export * from './components/Cards';
13
14
  export * from './components/Chart';
14
15
  export * from './components/CheckBox';
15
16
  export * from './components/CheckBoxGroup';
16
17
  export * from './components/Clock';
17
18
  export * from './components/Collapsible';
19
+ export * from './components/Data';
18
20
  export * from './components/DataChart';
21
+ export * from './components/DataFilter';
22
+ export * from './components/DataFilters';
23
+ export * from './components/DataSearch';
24
+ export * from './components/DataSort';
25
+ export * from './components/DataSummary';
19
26
  export * from './components/DataTable';
27
+ export * from './components/DataTableColumns';
28
+ export * from './components/DataTableGroupBy';
29
+ export * from './components/DataView';
20
30
  export * from './components/DateInput';
21
31
  export * from './components/Diagram';
22
32
  export * from './components/Distribution';
@@ -79,6 +89,7 @@ export * from './components/TextArea';
79
89
  export * from './components/TextInput';
80
90
  export * from './components/ThumbsRating';
81
91
  export * from './components/Tip';
92
+ export * from './components/Toolbar';
82
93
  export * from './components/Video';
83
94
  export * from './components/WorldMap';
84
95
  export * from './contexts/AnnounceContext';
package/es6/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  export * from './components';
2
4
  export * from './contexts';
3
5
  export * from './default-props';
@@ -2,7 +2,7 @@
2
2
  declare const normalizeColor: (
3
3
  color: string | { dark?: string; light?: string },
4
4
  theme: object,
5
- required?: boolean,
5
+ dark?: boolean,
6
6
  ) => string;
7
7
 
8
8
  export { normalizeColor };
package/es6/utils/refs.js CHANGED
@@ -3,6 +3,6 @@ export var useForwardedRef = function useForwardedRef(ref) {
3
3
  var innerRef = useRef(null);
4
4
  useImperativeHandle(ref, function () {
5
5
  return innerRef.current;
6
- });
6
+ }, [innerRef]);
7
7
  return innerRef;
8
8
  };