grommet 2.25.0 → 2.25.3

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 (123) hide show
  1. package/components/Anchor/Anchor.js +14 -1
  2. package/components/Button/Button.js +81 -8
  3. package/components/Button/StyledButtonKind.js +9 -3
  4. package/components/Button/index.d.ts +1 -1
  5. package/components/Button/propTypes.js +1 -1
  6. package/components/Calendar/Calendar.js +232 -292
  7. package/components/Calendar/utils.js +16 -129
  8. package/components/Chart/calcs.js +44 -27
  9. package/components/Chart/stories/Scan.js +11 -9
  10. package/components/Chart/stories/data.js +16 -17
  11. package/components/CheckBox/CheckBox.js +3 -2
  12. package/components/DataChart/DataChart.js +14 -28
  13. package/components/DataChart/Detail.js +18 -11
  14. package/components/DataChart/XAxis.js +29 -18
  15. package/components/DataChart/stories/Pad.js +54 -0
  16. package/components/DataTable/DataTable.js +13 -9
  17. package/components/DataTable/buildState.js +2 -2
  18. package/components/DataTable/index.d.ts +4 -1
  19. package/components/DataTable/stories/SpaceX.js +3 -1
  20. package/components/DataTable/stories/SpaceXUngrouped.js +6 -2
  21. package/components/DateInput/DateInput.js +60 -68
  22. package/components/DateInput/utils.js +30 -5
  23. package/components/FileInput/FileInput.js +2 -1
  24. package/components/FileInput/StyledFileInput.js +1 -1
  25. package/components/Form/Form.js +78 -5
  26. package/components/FormField/FormField.js +29 -29
  27. package/components/Grommet/Grommet.js +7 -2
  28. package/components/Grommet/index.d.ts +1 -0
  29. package/components/Grommet/propTypes.js +2 -1
  30. package/components/Heading/Heading.js +4 -2
  31. package/components/Heading/StyledHeading.js +1 -1
  32. package/components/Heading/index.d.ts +1 -0
  33. package/components/Heading/propTypes.js +2 -1
  34. package/components/Image/Image.js +4 -2
  35. package/components/Layer/LayerContainer.js +25 -0
  36. package/components/List/List.js +17 -0
  37. package/components/Menu/Menu.js +7 -4
  38. package/components/Menu/index.d.ts +2 -2
  39. package/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
  40. package/components/Meter/Circle.js +5 -1
  41. package/components/PageHeader/PageHeader.js +22 -13
  42. package/components/PageHeader/index.d.ts +10 -1
  43. package/components/PageHeader/propTypes.js +1 -0
  44. package/components/PageHeader/stories/Size.js +55 -0
  45. package/components/Select/SelectContainer.js +96 -75
  46. package/components/Select/stories/Clear.js +7 -1
  47. package/components/Select/utils.js +1 -0
  48. package/components/Spinner/Spinner.js +1 -0
  49. package/components/Tab/Tab.js +1 -1
  50. package/components/Tabs/Tabs.js +11 -2
  51. package/components/Video/StyledVideo.js +2 -2
  52. package/contexts/AnalyticsContext/AnalyticsContext.js +65 -0
  53. package/contexts/AnalyticsContext/index.d.ts +7 -0
  54. package/contexts/AnalyticsContext/index.js +11 -0
  55. package/contexts/index.js +8 -0
  56. package/es6/components/Anchor/Anchor.js +15 -3
  57. package/es6/components/Button/Button.js +83 -11
  58. package/es6/components/Button/StyledButtonKind.js +9 -3
  59. package/es6/components/Button/index.d.ts +1 -1
  60. package/es6/components/Button/propTypes.js +1 -1
  61. package/es6/components/Calendar/Calendar.js +230 -292
  62. package/es6/components/Calendar/utils.js +13 -114
  63. package/es6/components/Chart/calcs.js +44 -27
  64. package/es6/components/Chart/stories/Scan.js +10 -9
  65. package/es6/components/Chart/stories/data.js +16 -17
  66. package/es6/components/CheckBox/CheckBox.js +3 -2
  67. package/es6/components/DataChart/DataChart.js +15 -28
  68. package/es6/components/DataChart/Detail.js +20 -10
  69. package/es6/components/DataChart/XAxis.js +29 -19
  70. package/es6/components/DataChart/stories/Pad.js +42 -0
  71. package/es6/components/DataTable/DataTable.js +13 -9
  72. package/es6/components/DataTable/buildState.js +2 -2
  73. package/es6/components/DataTable/index.d.ts +4 -1
  74. package/es6/components/DataTable/stories/SpaceX.js +3 -1
  75. package/es6/components/DataTable/stories/SpaceXUngrouped.js +6 -2
  76. package/es6/components/DateInput/DateInput.js +57 -64
  77. package/es6/components/DateInput/utils.js +29 -7
  78. package/es6/components/FileInput/FileInput.js +2 -1
  79. package/es6/components/FileInput/StyledFileInput.js +1 -1
  80. package/es6/components/Form/Form.js +76 -5
  81. package/es6/components/FormField/FormField.js +29 -30
  82. package/es6/components/Grommet/Grommet.js +6 -2
  83. package/es6/components/Grommet/index.d.ts +1 -0
  84. package/es6/components/Grommet/propTypes.js +2 -1
  85. package/es6/components/Heading/Heading.js +4 -2
  86. package/es6/components/Heading/StyledHeading.js +1 -1
  87. package/es6/components/Heading/index.d.ts +1 -0
  88. package/es6/components/Heading/propTypes.js +2 -1
  89. package/es6/components/Image/Image.js +4 -2
  90. package/es6/components/Layer/LayerContainer.js +24 -0
  91. package/es6/components/List/List.js +16 -0
  92. package/es6/components/Menu/Menu.js +7 -4
  93. package/es6/components/Menu/index.d.ts +2 -2
  94. package/es6/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
  95. package/es6/components/Meter/Circle.js +5 -1
  96. package/es6/components/PageHeader/PageHeader.js +24 -14
  97. package/es6/components/PageHeader/index.d.ts +10 -1
  98. package/es6/components/PageHeader/propTypes.js +1 -0
  99. package/es6/components/PageHeader/stories/Size.js +43 -0
  100. package/es6/components/Select/SelectContainer.js +96 -77
  101. package/es6/components/Select/stories/Clear.js +7 -1
  102. package/es6/components/Select/utils.js +1 -0
  103. package/es6/components/Spinner/Spinner.js +1 -0
  104. package/es6/components/Tab/Tab.js +1 -1
  105. package/es6/components/Tabs/Tabs.js +10 -2
  106. package/es6/components/Video/StyledVideo.js +2 -2
  107. package/es6/contexts/AnalyticsContext/AnalyticsContext.js +47 -0
  108. package/es6/contexts/AnalyticsContext/index.d.ts +7 -0
  109. package/es6/contexts/AnalyticsContext/index.js +1 -0
  110. package/es6/contexts/index.js +1 -0
  111. package/es6/themes/base.d.ts +51 -33
  112. package/es6/themes/base.js +49 -1
  113. package/es6/utils/DOM.js +4 -0
  114. package/es6/utils/mixins.js +3 -0
  115. package/grommet.min.js +1 -1
  116. package/grommet.min.js.map +1 -1
  117. package/package.json +56 -48
  118. package/themes/base.d.ts +51 -33
  119. package/themes/base.js +49 -1
  120. package/tools/pack.js +20 -13
  121. package/tools/release-stable.js +2 -4
  122. package/utils/DOM.js +9 -2
  123. package/utils/mixins.js +7 -1
@@ -17,6 +17,8 @@ var _StyledAnchor = require("./StyledAnchor");
17
17
 
18
18
  var _propTypes = require("./propTypes");
19
19
 
20
+ var _AnalyticsContext = require("../../contexts/AnalyticsContext");
21
+
20
22
  var _excluded = ["a11yTitle", "aria-label", "children", "color", "disabled", "gap", "href", "icon", "label", "onBlur", "onClick", "onFocus", "reverse"];
21
23
 
22
24
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -38,7 +40,7 @@ var Anchor = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
38
40
  icon = _ref.icon,
39
41
  label = _ref.label,
40
42
  _onBlur = _ref.onBlur,
41
- onClick = _ref.onClick,
43
+ onClickProp = _ref.onClick,
42
44
  _onFocus = _ref.onFocus,
43
45
  reverse = _ref.reverse,
44
46
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
@@ -49,6 +51,17 @@ var Anchor = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
49
51
  focus = _useState[0],
50
52
  setFocus = _useState[1];
51
53
 
54
+ var sendAnalytics = (0, _AnalyticsContext.useAnalytics)();
55
+ var onClick = (0, _react.useCallback)(function (event) {
56
+ sendAnalytics({
57
+ type: 'anchorClick',
58
+ element: (0, _utils.findButtonParent)(event.target),
59
+ event: event,
60
+ href: href,
61
+ label: typeof label === 'string' ? label : undefined
62
+ });
63
+ if (onClickProp) onClickProp(event);
64
+ }, [onClickProp, sendAnalytics, label, href]);
52
65
  (0, _react.useEffect)(function () {
53
66
  if ((icon || label) && children) {
54
67
  console.warn('Anchor should not have children if icon or label is provided');
@@ -23,6 +23,8 @@ var _StyledButton = require("./StyledButton");
23
23
 
24
24
  var _StyledButtonKind = require("./StyledButtonKind");
25
25
 
26
+ var _AnalyticsContext = require("../../contexts/AnalyticsContext");
27
+
26
28
  var _excluded = ["active", "align", "aria-label", "badge", "color", "children", "disabled", "icon", "focusIndicator", "gap", "fill", "href", "justify", "kind", "label", "onBlur", "onClick", "onFocus", "onMouseOut", "onMouseOver", "plain", "primary", "reverse", "secondary", "selected", "size", "tip", "type", "a11yTitle", "as"];
27
29
 
28
30
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -67,7 +69,8 @@ var getIconColor = function getIconColor(paths, theme, colorProp, kind) {
67
69
  if (typeof kind === 'object') index = 0; // stop when we have a color or no more paths
68
70
 
69
71
  while (index >= 0 && !result[1]) {
70
- var obj = typeof kind === 'object' && kind || theme.button; // find the sub-object under the button them that corresponds with this path
72
+ var baseObj = typeof kind === 'object' && kind || theme.button;
73
+ var obj = baseObj; // find sub-object under the button theme that corresponds with this path
71
74
  // for example: 'active.primary'
72
75
 
73
76
  if (paths[index]) {
@@ -79,14 +82,30 @@ var getIconColor = function getIconColor(paths, theme, colorProp, kind) {
79
82
  }
80
83
 
81
84
  if (obj) {
85
+ var _obj, _obj$icon, _obj$icon$props;
86
+
82
87
  // use passed in color for background if the theme has a background color
83
88
  var background = colorProp && obj.background && obj.background.color ? colorProp : obj.background; // if theme object explicitly sets the color to undefined, pass false
84
89
  // to indicate that the theme doesn't want any text color
85
90
 
86
- var objColor = obj.color || (Object.prototype.hasOwnProperty.call(obj, 'color') && obj.color === undefined ? false : undefined); // use passed in color for text if the theme doesn't have
91
+ var objColor = obj.color || (Object.prototype.hasOwnProperty.call(obj, 'color') && obj.color === undefined ? false : undefined);
92
+ var color = void 0;
93
+ if ((_obj = obj) != null && (_obj$icon = _obj.icon) != null && (_obj$icon$props = _obj$icon.props) != null && _obj$icon$props.color) color = obj.icon.props.color; // if no icon defined for this state, see if there is an icon
94
+ // with color defined at one higher level
95
+ else if (paths[index + 1]) {
96
+ var _obj2, _obj2$icon, _obj2$icon$props;
97
+
98
+ var _parts = paths[index + 1].split('.');
99
+
100
+ while (baseObj && _parts.length) {
101
+ obj = baseObj[_parts.shift()];
102
+ }
103
+
104
+ if ((_obj2 = obj) != null && (_obj2$icon = _obj2.icon) != null && (_obj2$icon$props = _obj2$icon.props) != null && _obj2$icon$props.color) color = obj.icon.props.color;
105
+ } // use passed in color for text if the theme doesn't have
87
106
  // background or border color
88
107
 
89
- var color = colorProp && (!obj.background || !obj.background.color) && (!obj.border || !obj.border.color) ? colorProp : objColor;
108
+ if (!color) color = colorProp && (!obj.background || !obj.background.color) && (!obj.border || !obj.border.color) ? colorProp : objColor;
90
109
  result = (0, _utils.backgroundAndTextColors)(background, color, theme);
91
110
  }
92
111
 
@@ -94,6 +113,39 @@ var getIconColor = function getIconColor(paths, theme, colorProp, kind) {
94
113
  }
95
114
 
96
115
  return result[1] || undefined;
116
+ }; // get the icon for the current button state
117
+
118
+
119
+ var getKindIcon = function getKindIcon(paths, theme, kind) {
120
+ if (paths === void 0) {
121
+ paths = [];
122
+ }
123
+
124
+ var result;
125
+ var index = paths.length - 1; // caller has specified a themeObj to use for styling
126
+ // relevant for cases like pagination which looks to theme.pagination.button
127
+
128
+ if (typeof kind === 'object') index = 0; // stop when we have a color or no more paths
129
+
130
+ while (index >= 0 && !result) {
131
+ var _obj3;
132
+
133
+ var obj = typeof kind === 'object' && kind || theme.button; // find sub-object under the button theme that corresponds with this path
134
+ // for example: 'active.primary'
135
+
136
+ if (paths[index]) {
137
+ var parts = paths[index].split('.');
138
+
139
+ while (obj && parts.length) {
140
+ obj = obj[parts.shift()];
141
+ }
142
+ }
143
+
144
+ if ((_obj3 = obj) != null && _obj3.icon) result = obj.icon;
145
+ index -= 1;
146
+ }
147
+
148
+ return result || undefined;
97
149
  };
98
150
 
99
151
  var getPropertyColor = function getPropertyColor(property, paths, theme, kind, primary) {
@@ -127,6 +179,8 @@ var getPropertyColor = function getPropertyColor(property, paths, theme, kind, p
127
179
  };
128
180
 
129
181
  var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
182
+ var _theme$button$kind;
183
+
130
184
  var active = _ref.active,
131
185
  _ref$align = _ref.align,
132
186
  align = _ref$align === void 0 ? 'center' : _ref$align,
@@ -145,13 +199,13 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
145
199
  kindArg = _ref.kind,
146
200
  label = _ref.label,
147
201
  _onBlur = _ref.onBlur,
148
- onClick = _ref.onClick,
202
+ onClickProp = _ref.onClick,
149
203
  _onFocus = _ref.onFocus,
150
204
  onMouseOut = _ref.onMouseOut,
151
205
  onMouseOver = _ref.onMouseOver,
152
206
  plain = _ref.plain,
153
207
  primary = _ref.primary,
154
- reverse = _ref.reverse,
208
+ reverseProp = _ref.reverse,
155
209
  secondary = _ref.secondary,
156
210
  selected = _ref.selected,
157
211
  size = _ref.size,
@@ -175,9 +229,20 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
175
229
 
176
230
  if ((icon || label) && children) {
177
231
  console.warn('Button should not have children if icon or label is provided');
178
- } // kindArg is object if we are referencing a theme object
179
- // outside of theme.button
232
+ }
180
233
 
234
+ var sendAnalytics = (0, _AnalyticsContext.useAnalytics)();
235
+ var onClick = (0, _react.useCallback)(function (event) {
236
+ sendAnalytics({
237
+ type: 'buttonClick',
238
+ element: (0, _utils.findButtonParent)(event.target),
239
+ event: event,
240
+ href: href,
241
+ label: typeof label === 'string' ? label : undefined
242
+ });
243
+ if (onClickProp) onClickProp(event);
244
+ }, [onClickProp, sendAnalytics, href, label]); // kindArg is object if we are referencing a theme object
245
+ // outside of theme.button
181
246
 
182
247
  var kindObj = (0, _react.useMemo)(function () {
183
248
  return typeof kindArg === 'object';
@@ -255,7 +320,8 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
255
320
  }
256
321
  };
257
322
 
258
- var buttonIcon = icon; // only change color if user did not specify the color themselves...
323
+ var kindIcon = hover && getKindIcon(themePaths == null ? void 0 : themePaths.hover, theme, kind) || getKindIcon(themePaths == null ? void 0 : themePaths.base, theme, kind);
324
+ var buttonIcon = icon || kindIcon; // only change color if user did not specify the color themselves...
259
325
 
260
326
  if (icon && !icon.props.color) {
261
327
  if (kind) {
@@ -271,8 +337,15 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
271
337
  color: theme.global.colors.text[isDarkBackground() ? 'dark' : 'light']
272
338
  });
273
339
  }
340
+ } else if (kindIcon && !plain) {
341
+ var _iconColor = hover && getIconColor(themePaths.hover, theme) || getIconColor(themePaths.base, theme, color, kind);
342
+
343
+ if (_iconColor) buttonIcon = /*#__PURE__*/(0, _react.cloneElement)(kindIcon, {
344
+ color: _iconColor
345
+ });
274
346
  }
275
347
 
348
+ var reverse = reverseProp != null ? reverseProp : (_theme$button$kind = theme.button[kind]) == null ? void 0 : _theme$button$kind.reverse;
276
349
  var domTag = !as && href ? 'a' : as;
277
350
  var first = reverse ? label : buttonIcon;
278
351
  var second = reverse ? buttonIcon : label;
@@ -29,11 +29,17 @@ var fontStyle = function fontStyle(props) {
29
29
  return (0, _styledComponents.css)(["font-size:", ";line-height:", ";"], data.size, data.height);
30
30
  };
31
31
 
32
- var padFromTheme = function padFromTheme(size, theme, themeObj) {
32
+ var padFromTheme = function padFromTheme(size, theme, themeObj, kind) {
33
+ var _themeObj$size, _themeObj$size$size, _themeObj$size$size$k;
34
+
33
35
  if (size === void 0) {
34
36
  size = 'medium';
35
37
  }
36
38
 
39
+ if (size && themeObj != null && (_themeObj$size = themeObj.size) != null && (_themeObj$size$size = _themeObj$size[size]) != null && (_themeObj$size$size$k = _themeObj$size$size[kind]) != null && _themeObj$size$size$k.pad) {
40
+ return themeObj.size[size][kind].pad;
41
+ }
42
+
37
43
  if (size && themeObj.size && themeObj.size[size] && themeObj.size[size].pad) {
38
44
  return {
39
45
  vertical: themeObj.size[size].pad.vertical,
@@ -58,7 +64,7 @@ var padStyle = function padStyle(_ref) {
58
64
  // caller has specified a themeObj to use for styling
59
65
  // relevant for cases like pagination which looks to theme.pagination.button
60
66
  var themeObj = typeof kind === 'object' ? kind : theme.button;
61
- var pad = padFromTheme(size, theme, themeObj);
67
+ var pad = padFromTheme(size, theme, themeObj, kind);
62
68
  return pad ? (0, _styledComponents.css)(["padding:", " ", ";"], pad.vertical, pad.horizontal) : '';
63
69
  };
64
70
 
@@ -97,7 +103,7 @@ var kindStyle = function kindStyle(_ref2) {
97
103
  // relevant for cases like pagination which looks to theme.pagination.button
98
104
 
99
105
  var themeObj = typeof kind === 'object' ? kind : theme.button;
100
- var pad = padFromTheme(size, theme, themeObj);
106
+ var pad = padFromTheme(size, theme, themeObj, kind);
101
107
  themePaths.base.forEach(function (themePath) {
102
108
  var obj = getPath(themeObj, themePath);
103
109
 
@@ -64,7 +64,7 @@ export interface ButtonProps {
64
64
  primary?: boolean;
65
65
  reverse?: boolean;
66
66
  secondary?: boolean;
67
- size?: 'small' | 'medium' | 'large';
67
+ size?: 'small' | 'medium' | 'large' | string;
68
68
  tip?: TipProps | string;
69
69
  type?: 'button' | 'reset' | 'submit';
70
70
  as?: PolymorphicType;
@@ -38,7 +38,7 @@ if (process.env.NODE_ENV !== 'production') {
38
38
  primary: _propTypes["default"].bool,
39
39
  reverse: _propTypes["default"].bool,
40
40
  secondary: _propTypes["default"].bool,
41
- size: _propTypes["default"].oneOf(['small', 'medium', 'large']),
41
+ size: _propTypes["default"].oneOfType([_propTypes["default"].oneOf(['small', 'medium', 'large']), _propTypes["default"].string]),
42
42
  target: _propTypes["default"].oneOfType([_propTypes["default"].oneOf(['_self', '_blank', '_parent', '_top']), _propTypes["default"].string]),
43
43
  tip: _propTypes["default"].oneOfType([_propTypes["default"].shape({
44
44
  content: _propTypes["default"].oneOfType([_propTypes["default"].node, _propTypes["default"].string]),