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
@@ -4,13 +4,14 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
4
4
 
5
5
  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; }
6
6
 
7
- import React, { cloneElement, forwardRef, useContext, useEffect, useState } from 'react';
7
+ import React, { cloneElement, forwardRef, useCallback, useContext, useEffect, useState } from 'react';
8
8
  import { ThemeContext } from 'styled-components';
9
9
  import { defaultProps } from '../../default-props';
10
- import { normalizeColor } from '../../utils';
10
+ import { findButtonParent, normalizeColor } from '../../utils';
11
11
  import { Box } from '../Box';
12
12
  import { StyledAnchor } from './StyledAnchor';
13
13
  import { AnchorPropTypes } from './propTypes';
14
+ import { useAnalytics } from '../../contexts/AnalyticsContext';
14
15
  var Anchor = /*#__PURE__*/forwardRef(function (_ref, ref) {
15
16
  var a11yTitle = _ref.a11yTitle,
16
17
  ariaLabel = _ref['aria-label'],
@@ -22,7 +23,7 @@ var Anchor = /*#__PURE__*/forwardRef(function (_ref, ref) {
22
23
  icon = _ref.icon,
23
24
  label = _ref.label,
24
25
  _onBlur = _ref.onBlur,
25
- onClick = _ref.onClick,
26
+ onClickProp = _ref.onClick,
26
27
  _onFocus = _ref.onFocus,
27
28
  reverse = _ref.reverse,
28
29
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
@@ -33,6 +34,17 @@ var Anchor = /*#__PURE__*/forwardRef(function (_ref, ref) {
33
34
  focus = _useState[0],
34
35
  setFocus = _useState[1];
35
36
 
37
+ var sendAnalytics = useAnalytics();
38
+ var onClick = useCallback(function (event) {
39
+ sendAnalytics({
40
+ type: 'anchorClick',
41
+ element: findButtonParent(event.target),
42
+ event: event,
43
+ href: href,
44
+ label: typeof label === 'string' ? label : undefined
45
+ });
46
+ if (onClickProp) onClickProp(event);
47
+ }, [onClickProp, sendAnalytics, label, href]);
36
48
  useEffect(function () {
37
49
  if ((icon || label) && children) {
38
50
  console.warn('Anchor should not have children if icon or label is provided');
@@ -4,16 +4,17 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
4
4
 
5
5
  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; }
6
6
 
7
- import React, { cloneElement, Children, forwardRef, useContext, useMemo, useState } from 'react';
7
+ import React, { cloneElement, Children, forwardRef, useContext, useMemo, useState, useCallback } from 'react';
8
8
  import { ThemeContext } from 'styled-components';
9
- import { backgroundAndTextColors, colorIsDark, normalizeBackground, normalizeColor } from '../../utils';
9
+ import { backgroundAndTextColors, colorIsDark, findButtonParent, normalizeBackground, normalizeColor } from '../../utils';
10
10
  import { defaultProps } from '../../default-props';
11
11
  import { ButtonPropTypes } from './propTypes';
12
12
  import { Box } from '../Box';
13
13
  import { Tip } from '../Tip';
14
14
  import { Badge } from './Badge';
15
15
  import { StyledButton } from './StyledButton';
16
- import { StyledButtonKind } from './StyledButtonKind'; // We have two Styled* components to separate
16
+ import { StyledButtonKind } from './StyledButtonKind';
17
+ import { useAnalytics } from '../../contexts/AnalyticsContext'; // We have two Styled* components to separate
17
18
  // the newer default|primary|secondary approach,
18
19
  // which we use the term "kind" to refer to,
19
20
  // from the previous approach. Hopefully, when we get to grommet v3,
@@ -48,7 +49,8 @@ var getIconColor = function getIconColor(paths, theme, colorProp, kind) {
48
49
  if (typeof kind === 'object') index = 0; // stop when we have a color or no more paths
49
50
 
50
51
  while (index >= 0 && !result[1]) {
51
- var obj = typeof kind === 'object' && kind || theme.button; // find the sub-object under the button them that corresponds with this path
52
+ var baseObj = typeof kind === 'object' && kind || theme.button;
53
+ var obj = baseObj; // find sub-object under the button theme that corresponds with this path
52
54
  // for example: 'active.primary'
53
55
 
54
56
  if (paths[index]) {
@@ -60,14 +62,30 @@ var getIconColor = function getIconColor(paths, theme, colorProp, kind) {
60
62
  }
61
63
 
62
64
  if (obj) {
65
+ var _obj, _obj$icon, _obj$icon$props;
66
+
63
67
  // use passed in color for background if the theme has a background color
64
68
  var background = colorProp && obj.background && obj.background.color ? colorProp : obj.background; // if theme object explicitly sets the color to undefined, pass false
65
69
  // to indicate that the theme doesn't want any text color
66
70
 
67
- 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
71
+ var objColor = obj.color || (Object.prototype.hasOwnProperty.call(obj, 'color') && obj.color === undefined ? false : undefined);
72
+ var color = void 0;
73
+ 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
74
+ // with color defined at one higher level
75
+ else if (paths[index + 1]) {
76
+ var _obj2, _obj2$icon, _obj2$icon$props;
77
+
78
+ var _parts = paths[index + 1].split('.');
79
+
80
+ while (baseObj && _parts.length) {
81
+ obj = baseObj[_parts.shift()];
82
+ }
83
+
84
+ 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;
85
+ } // use passed in color for text if the theme doesn't have
68
86
  // background or border color
69
87
 
70
- var color = colorProp && (!obj.background || !obj.background.color) && (!obj.border || !obj.border.color) ? colorProp : objColor;
88
+ if (!color) color = colorProp && (!obj.background || !obj.background.color) && (!obj.border || !obj.border.color) ? colorProp : objColor;
71
89
  result = backgroundAndTextColors(background, color, theme);
72
90
  }
73
91
 
@@ -75,6 +93,39 @@ var getIconColor = function getIconColor(paths, theme, colorProp, kind) {
75
93
  }
76
94
 
77
95
  return result[1] || undefined;
96
+ }; // get the icon for the current button state
97
+
98
+
99
+ var getKindIcon = function getKindIcon(paths, theme, kind) {
100
+ if (paths === void 0) {
101
+ paths = [];
102
+ }
103
+
104
+ var result;
105
+ var index = paths.length - 1; // caller has specified a themeObj to use for styling
106
+ // relevant for cases like pagination which looks to theme.pagination.button
107
+
108
+ if (typeof kind === 'object') index = 0; // stop when we have a color or no more paths
109
+
110
+ while (index >= 0 && !result) {
111
+ var _obj3;
112
+
113
+ var obj = typeof kind === 'object' && kind || theme.button; // find sub-object under the button theme that corresponds with this path
114
+ // for example: 'active.primary'
115
+
116
+ if (paths[index]) {
117
+ var parts = paths[index].split('.');
118
+
119
+ while (obj && parts.length) {
120
+ obj = obj[parts.shift()];
121
+ }
122
+ }
123
+
124
+ if ((_obj3 = obj) != null && _obj3.icon) result = obj.icon;
125
+ index -= 1;
126
+ }
127
+
128
+ return result || undefined;
78
129
  };
79
130
 
80
131
  var getPropertyColor = function getPropertyColor(property, paths, theme, kind, primary) {
@@ -108,6 +159,8 @@ var getPropertyColor = function getPropertyColor(property, paths, theme, kind, p
108
159
  };
109
160
 
110
161
  var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
162
+ var _theme$button$kind;
163
+
111
164
  var active = _ref.active,
112
165
  _ref$align = _ref.align,
113
166
  align = _ref$align === void 0 ? 'center' : _ref$align,
@@ -126,13 +179,13 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
126
179
  kindArg = _ref.kind,
127
180
  label = _ref.label,
128
181
  _onBlur = _ref.onBlur,
129
- onClick = _ref.onClick,
182
+ onClickProp = _ref.onClick,
130
183
  _onFocus = _ref.onFocus,
131
184
  onMouseOut = _ref.onMouseOut,
132
185
  onMouseOver = _ref.onMouseOver,
133
186
  plain = _ref.plain,
134
187
  primary = _ref.primary,
135
- reverse = _ref.reverse,
188
+ reverseProp = _ref.reverse,
136
189
  secondary = _ref.secondary,
137
190
  selected = _ref.selected,
138
191
  size = _ref.size,
@@ -156,9 +209,20 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
156
209
 
157
210
  if ((icon || label) && children) {
158
211
  console.warn('Button should not have children if icon or label is provided');
159
- } // kindArg is object if we are referencing a theme object
160
- // outside of theme.button
212
+ }
161
213
 
214
+ var sendAnalytics = useAnalytics();
215
+ var onClick = useCallback(function (event) {
216
+ sendAnalytics({
217
+ type: 'buttonClick',
218
+ element: findButtonParent(event.target),
219
+ event: event,
220
+ href: href,
221
+ label: typeof label === 'string' ? label : undefined
222
+ });
223
+ if (onClickProp) onClickProp(event);
224
+ }, [onClickProp, sendAnalytics, href, label]); // kindArg is object if we are referencing a theme object
225
+ // outside of theme.button
162
226
 
163
227
  var kindObj = useMemo(function () {
164
228
  return typeof kindArg === 'object';
@@ -236,7 +300,8 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
236
300
  }
237
301
  };
238
302
 
239
- var buttonIcon = icon; // only change color if user did not specify the color themselves...
303
+ var kindIcon = hover && getKindIcon(themePaths == null ? void 0 : themePaths.hover, theme, kind) || getKindIcon(themePaths == null ? void 0 : themePaths.base, theme, kind);
304
+ var buttonIcon = icon || kindIcon; // only change color if user did not specify the color themselves...
240
305
 
241
306
  if (icon && !icon.props.color) {
242
307
  if (kind) {
@@ -252,8 +317,15 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
252
317
  color: theme.global.colors.text[isDarkBackground() ? 'dark' : 'light']
253
318
  });
254
319
  }
320
+ } else if (kindIcon && !plain) {
321
+ var _iconColor = hover && getIconColor(themePaths.hover, theme) || getIconColor(themePaths.base, theme, color, kind);
322
+
323
+ if (_iconColor) buttonIcon = /*#__PURE__*/cloneElement(kindIcon, {
324
+ color: _iconColor
325
+ });
255
326
  }
256
327
 
328
+ var reverse = reverseProp != null ? reverseProp : (_theme$button$kind = theme.button[kind]) == null ? void 0 : _theme$button$kind.reverse;
257
329
  var domTag = !as && href ? 'a' : as;
258
330
  var first = reverse ? label : buttonIcon;
259
331
  var second = reverse ? buttonIcon : label;
@@ -18,11 +18,17 @@ var fontStyle = function fontStyle(props) {
18
18
  return css(["font-size:", ";line-height:", ";"], data.size, data.height);
19
19
  };
20
20
 
21
- var padFromTheme = function padFromTheme(size, theme, themeObj) {
21
+ var padFromTheme = function padFromTheme(size, theme, themeObj, kind) {
22
+ var _themeObj$size, _themeObj$size$size, _themeObj$size$size$k;
23
+
22
24
  if (size === void 0) {
23
25
  size = 'medium';
24
26
  }
25
27
 
28
+ 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) {
29
+ return themeObj.size[size][kind].pad;
30
+ }
31
+
26
32
  if (size && themeObj.size && themeObj.size[size] && themeObj.size[size].pad) {
27
33
  return {
28
34
  vertical: themeObj.size[size].pad.vertical,
@@ -47,7 +53,7 @@ var padStyle = function padStyle(_ref) {
47
53
  // caller has specified a themeObj to use for styling
48
54
  // relevant for cases like pagination which looks to theme.pagination.button
49
55
  var themeObj = typeof kind === 'object' ? kind : theme.button;
50
- var pad = padFromTheme(size, theme, themeObj);
56
+ var pad = padFromTheme(size, theme, themeObj, kind);
51
57
  return pad ? css(["padding:", " ", ";"], pad.vertical, pad.horizontal) : '';
52
58
  };
53
59
 
@@ -86,7 +92,7 @@ var kindStyle = function kindStyle(_ref2) {
86
92
  // relevant for cases like pagination which looks to theme.pagination.button
87
93
 
88
94
  var themeObj = typeof kind === 'object' ? kind : theme.button;
89
- var pad = padFromTheme(size, theme, themeObj);
95
+ var pad = padFromTheme(size, theme, themeObj, kind);
90
96
  themePaths.base.forEach(function (themePath) {
91
97
  var obj = getPath(themeObj, themePath);
92
98
 
@@ -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;
@@ -29,7 +29,7 @@ if (process.env.NODE_ENV !== 'production') {
29
29
  primary: PropTypes.bool,
30
30
  reverse: PropTypes.bool,
31
31
  secondary: PropTypes.bool,
32
- size: PropTypes.oneOf(['small', 'medium', 'large']),
32
+ size: PropTypes.oneOfType([PropTypes.oneOf(['small', 'medium', 'large']), PropTypes.string]),
33
33
  target: PropTypes.oneOfType([PropTypes.oneOf(['_self', '_blank', '_parent', '_top']), PropTypes.string]),
34
34
  tip: PropTypes.oneOfType([PropTypes.shape({
35
35
  content: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),