grommet 2.25.2 → 2.26.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 (111) hide show
  1. package/components/Anchor/Anchor.js +1 -1
  2. package/components/Box/stories/BackgroundThemed.js +54 -0
  3. package/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
  4. package/components/Button/Button.js +2 -2
  5. package/components/Calendar/Calendar.js +2 -1
  6. package/components/CheckBoxGroup/CheckBoxGroup.js +3 -2
  7. package/components/CheckBoxGroup/index.d.ts +2 -1
  8. package/components/CheckBoxGroup/propTypes.js +1 -0
  9. package/components/FormField/FormField.js +1 -1
  10. package/components/Heading/Heading.js +31 -2
  11. package/components/Heading/StyledHeading.js +1 -1
  12. package/components/Heading/index.d.ts +1 -0
  13. package/components/Heading/propTypes.js +1 -0
  14. package/components/Heading/stories/All.js +4 -1
  15. package/components/Layer/LayerContainer.js +16 -9
  16. package/components/List/List.js +131 -33
  17. package/components/List/index.d.ts +1 -0
  18. package/components/List/propTypes.js +1 -0
  19. package/components/List/stories/Pinned.js +36 -0
  20. package/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
  21. package/components/Select/DefaultSelectTextInput.js +43 -0
  22. package/components/Select/EmptySearchOption.js +34 -0
  23. package/components/Select/Select.js +30 -95
  24. package/components/Select/SelectContainer.js +19 -59
  25. package/components/Select/StyledSelect.js +58 -2
  26. package/components/Select/index.d.ts +11 -9
  27. package/components/Select/propTypes.js +44 -40
  28. package/components/Select/utils.js +103 -3
  29. package/components/SelectMultiple/README.md +2 -0
  30. package/components/SelectMultiple/SelectMultiple.js +476 -0
  31. package/components/SelectMultiple/SelectMultipleContainer.js +481 -0
  32. package/components/SelectMultiple/SelectMultipleValue.js +166 -0
  33. package/components/SelectMultiple/SelectionSummary.js +104 -0
  34. package/components/SelectMultiple/index.d.ts +21 -0
  35. package/components/SelectMultiple/index.js +8 -0
  36. package/components/SelectMultiple/propTypes.js +28 -0
  37. package/components/SelectMultiple/stories/Default.js +76 -0
  38. package/components/SelectMultiple/stories/Disabled.js +84 -0
  39. package/components/SelectMultiple/stories/FormField.js +66 -0
  40. package/components/SelectMultiple/stories/Limited.js +68 -0
  41. package/components/SelectMultiple/stories/LongList.js +76 -0
  42. package/components/SelectMultiple/stories/ObjectOptions.js +80 -0
  43. package/components/SelectMultiple/stories/ShowSelectedInline.js +76 -0
  44. package/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
  45. package/components/index.d.ts +1 -0
  46. package/components/index.js +8 -0
  47. package/es6/components/Anchor/Anchor.js +2 -2
  48. package/es6/components/Box/stories/BackgroundThemed.js +39 -0
  49. package/es6/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
  50. package/es6/components/Button/Button.js +3 -3
  51. package/es6/components/Calendar/Calendar.js +2 -1
  52. package/es6/components/CheckBoxGroup/CheckBoxGroup.js +3 -2
  53. package/es6/components/CheckBoxGroup/index.d.ts +2 -1
  54. package/es6/components/CheckBoxGroup/propTypes.js +1 -0
  55. package/es6/components/FormField/FormField.js +1 -1
  56. package/es6/components/Heading/Heading.js +30 -3
  57. package/es6/components/Heading/StyledHeading.js +1 -1
  58. package/es6/components/Heading/index.d.ts +1 -0
  59. package/es6/components/Heading/propTypes.js +1 -0
  60. package/es6/components/Heading/stories/All.js +4 -1
  61. package/es6/components/Layer/LayerContainer.js +16 -9
  62. package/es6/components/List/List.js +131 -34
  63. package/es6/components/List/index.d.ts +1 -0
  64. package/es6/components/List/propTypes.js +1 -0
  65. package/es6/components/List/stories/Pinned.js +21 -0
  66. package/es6/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
  67. package/es6/components/Select/DefaultSelectTextInput.js +31 -0
  68. package/es6/components/Select/EmptySearchOption.js +21 -0
  69. package/es6/components/Select/Select.js +26 -89
  70. package/es6/components/Select/SelectContainer.js +19 -58
  71. package/es6/components/Select/StyledSelect.js +45 -1
  72. package/es6/components/Select/index.d.ts +11 -9
  73. package/es6/components/Select/propTypes.js +41 -39
  74. package/es6/components/Select/utils.js +75 -1
  75. package/es6/components/SelectMultiple/README.md +2 -0
  76. package/es6/components/SelectMultiple/SelectMultiple.js +447 -0
  77. package/es6/components/SelectMultiple/SelectMultipleContainer.js +453 -0
  78. package/es6/components/SelectMultiple/SelectMultipleValue.js +152 -0
  79. package/es6/components/SelectMultiple/SelectionSummary.js +91 -0
  80. package/es6/components/SelectMultiple/index.d.ts +21 -0
  81. package/es6/components/SelectMultiple/index.js +1 -0
  82. package/es6/components/SelectMultiple/propTypes.js +18 -0
  83. package/es6/components/SelectMultiple/stories/Default.js +60 -0
  84. package/es6/components/SelectMultiple/stories/Disabled.js +68 -0
  85. package/es6/components/SelectMultiple/stories/FormField.js +50 -0
  86. package/es6/components/SelectMultiple/stories/Limited.js +53 -0
  87. package/es6/components/SelectMultiple/stories/LongList.js +63 -0
  88. package/es6/components/SelectMultiple/stories/ObjectOptions.js +64 -0
  89. package/es6/components/SelectMultiple/stories/ShowSelectedInline.js +61 -0
  90. package/es6/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
  91. package/es6/components/index.d.ts +1 -0
  92. package/es6/components/index.js +1 -0
  93. package/es6/index.d.ts +1 -0
  94. package/es6/themes/base.d.ts +8 -2
  95. package/es6/themes/base.js +54 -38
  96. package/es6/themes/grommet.js +15 -0
  97. package/es6/utils/DOM.js +4 -0
  98. package/es6/utils/background.js +65 -12
  99. package/es6/utils/general-prop-types.js +2 -0
  100. package/es6/utils/index.d.ts +2 -0
  101. package/grommet.min.js +1 -1
  102. package/grommet.min.js.map +1 -1
  103. package/index.d.ts +1 -0
  104. package/package.json +7 -6
  105. package/themes/base.d.ts +8 -2
  106. package/themes/base.js +55 -38
  107. package/themes/grommet.js +15 -0
  108. package/utils/DOM.js +9 -2
  109. package/utils/background.js +64 -12
  110. package/utils/general-prop-types.js +2 -0
  111. package/utils/index.d.ts +2 -0
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports["default"] = exports.ShowSelectedInline = void 0;
5
+
6
+ var _react = _interopRequireWildcard(require("react"));
7
+
8
+ var _grommet = require("grommet");
9
+
10
+ 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); }
11
+
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
+
14
+ var defaultOptions = ['Apple', 'Orange', 'Banana', 'Grape', 'Melon', 'Strawberry', 'Kiwi', 'Mango', 'Raspberry', 'Rhubarb'];
15
+
16
+ var ShowSelectedInline = function ShowSelectedInline() {
17
+ var _useState = (0, _react.useState)(defaultOptions),
18
+ options = _useState[0],
19
+ setOptions = _useState[1];
20
+
21
+ var _useState2 = (0, _react.useState)([]),
22
+ valueMultiple = _useState2[0],
23
+ setValueMultiple = _useState2[1];
24
+
25
+ return (
26
+ /*#__PURE__*/
27
+ // Uncomment <Grommet> lines when using outside of storybook
28
+ // <Grommet theme={...}>
29
+ _react["default"].createElement(_grommet.Box, {
30
+ fill: true,
31
+ align: "center",
32
+ pad: "large",
33
+ gap: "large"
34
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.Text, null, "SelectMultiple showSelectedInline"), /*#__PURE__*/_react["default"].createElement(_grommet.SelectMultiple, {
35
+ showSelectedInline: true,
36
+ placeholder: "Select",
37
+ options: options,
38
+ onSearch: function onSearch(text) {
39
+ // The line below escapes regular expression special characters:
40
+ // [ \ ^ $ . | ? * + ( )
41
+ var escapedText = text.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); // Create the regular expression with modified value which
42
+ // handles escaping special characters. Without escaping special
43
+ // characters, errors will appear in the console
44
+
45
+ var exp = new RegExp(escapedText, 'i');
46
+ setOptions(defaultOptions.filter(function (o) {
47
+ return exp.test(o);
48
+ }));
49
+ },
50
+ onClose: function onClose() {
51
+ return setOptions(defaultOptions);
52
+ },
53
+ value: valueMultiple,
54
+ onChange: function onChange(_ref) {
55
+ var value = _ref.value;
56
+ setValueMultiple(value);
57
+ }
58
+ })) // </Grommet>
59
+
60
+ );
61
+ };
62
+
63
+ exports.ShowSelectedInline = ShowSelectedInline;
64
+ ShowSelectedInline.storyName = 'showSelectedInline';
65
+ ShowSelectedInline.parameters = {
66
+ chromatic: {
67
+ disable: true
68
+ }
69
+ };
70
+ ShowSelectedInline.args = {
71
+ full: true
72
+ };
73
+ var _default = {
74
+ title: 'Input/SelectMultiple/showSelectedInline'
75
+ };
76
+ exports["default"] = _default;
@@ -0,0 +1,106 @@
1
+ import React, { useState } from 'react';
2
+
3
+ import { FormClose } from 'grommet-icons';
4
+ import { Box, Button, Text } from 'grommet';
5
+ import { SelectMultiple } from '../../SelectMultiple.js';
6
+
7
+ const allSeasons = [
8
+ 'S01',
9
+ 'S02',
10
+ 'S03',
11
+ 'S04',
12
+ 'S05',
13
+ 'S06',
14
+ 'S07',
15
+ 'S08',
16
+ 'S09',
17
+ 'S10',
18
+ ];
19
+
20
+ export const Children = () => {
21
+ const [selected, setSelected] = useState([]);
22
+
23
+ const onRemoveSeason = (season) => {
24
+ setSelected(selected.filter((selectedSeason) => selectedSeason !== season));
25
+ };
26
+
27
+ const renderSeason = (season) => (
28
+ <Button
29
+ key={`season_tag_${season}`}
30
+ onClick={(event) => {
31
+ event.preventDefault();
32
+ event.stopPropagation();
33
+ onRemoveSeason(season);
34
+ }}
35
+ onFocus={(event) => event.stopPropagation()}
36
+ a11yTitle={season}
37
+ >
38
+ <Box
39
+ align="center"
40
+ direction="row"
41
+ gap="xsmall"
42
+ pad={{ vertical: 'xsmall', horizontal: 'small' }}
43
+ margin="xsmall"
44
+ background="light-3"
45
+ round="large"
46
+ >
47
+ <Text size="small">{season}</Text>
48
+ <Box round="full" margin={{ left: 'xsmall' }}>
49
+ <FormClose size="small" style={{ width: '12px', height: '12px' }} />
50
+ </Box>
51
+ </Box>
52
+ </Button>
53
+ );
54
+
55
+ const renderOption = (option, state) => (
56
+ <Box pad="small" background={state.active ? 'active' : undefined}>
57
+ {option}
58
+ </Box>
59
+ );
60
+
61
+ return (
62
+ // Uncomment <Grommet> lines when using outside of storybook
63
+ // <Grommet theme={...}>
64
+ <Box fill align="center" pad="large" gap="large">
65
+ <Text>SelectMultiple with custom children</Text>
66
+ <SelectMultiple
67
+ sortSelectedOnClose={false}
68
+ showSelectedInline
69
+ valueLabel={(option) => (
70
+ <Box wrap direction="row" width="small">
71
+ {option && option.length ? (
72
+ <>
73
+ {option.map((i) => {
74
+ console.log(option);
75
+ return renderSeason(i);
76
+ })}
77
+ </>
78
+ ) : (
79
+ <Text color="text-weak">Select Season</Text>
80
+ )}
81
+ </Box>
82
+ )}
83
+ options={allSeasons}
84
+ value={selected}
85
+ onChange={({ value }) => {
86
+ setSelected([...value]);
87
+ }}
88
+ >
89
+ {renderOption}
90
+ </SelectMultiple>
91
+ </Box>
92
+ // </Grommet>
93
+ );
94
+ };
95
+
96
+ Children.parameters = {
97
+ chromatic: { disable: true },
98
+ };
99
+
100
+ Children.args = {
101
+ full: true,
102
+ };
103
+
104
+ export default {
105
+ title: 'Input/SelectMultiple/Children',
106
+ };
@@ -54,6 +54,7 @@ export * from './RangeSelector';
54
54
  export * from './RoutedAnchor';
55
55
  export * from './RoutedButton';
56
56
  export * from './Select';
57
+ export * from './SelectMultiple';
57
58
  export * from './Sidebar';
58
59
  export * from './SkipLink';
59
60
  export * from './SkipLinks';
@@ -466,6 +466,14 @@ Object.keys(_Select).forEach(function (key) {
466
466
  exports[key] = _Select[key];
467
467
  });
468
468
 
469
+ var _SelectMultiple = require("./SelectMultiple");
470
+
471
+ Object.keys(_SelectMultiple).forEach(function (key) {
472
+ if (key === "default" || key === "__esModule") return;
473
+ if (key in exports && exports[key] === _SelectMultiple[key]) return;
474
+ exports[key] = _SelectMultiple[key];
475
+ });
476
+
469
477
  var _Sidebar = require("./Sidebar");
470
478
 
471
479
  Object.keys(_Sidebar).forEach(function (key) {
@@ -7,7 +7,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
7
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';
@@ -38,7 +38,7 @@ var Anchor = /*#__PURE__*/forwardRef(function (_ref, ref) {
38
38
  var onClick = useCallback(function (event) {
39
39
  sendAnalytics({
40
40
  type: 'anchorClick',
41
- element: event.target,
41
+ element: findButtonParent(event.target),
42
42
  event: event,
43
43
  href: href,
44
44
  label: typeof label === 'string' ? label : undefined
@@ -0,0 +1,39 @@
1
+ import React, { useContext } from 'react';
2
+ import { Box, Paragraph, Text, ThemeContext } from 'grommet';
3
+ import { Grid } from '../../Grid';
4
+ export var BackgroundThemed = function BackgroundThemed() {
5
+ var theme = useContext(ThemeContext);
6
+ var backgrounds = theme.global.backgrounds;
7
+ return (// Uncomment <Grommet> lines when using outside of storybook
8
+ // <Grommet>
9
+ backgrounds ? /*#__PURE__*/React.createElement(Grid, {
10
+ columns: "small",
11
+ rows: "small",
12
+ gap: "small",
13
+ pad: "large"
14
+ }, Object.entries(backgrounds).map(function (_ref) {
15
+ var key = _ref[0],
16
+ background = _ref[1];
17
+ return /*#__PURE__*/React.createElement(Box, {
18
+ key: key,
19
+ background: background,
20
+ fill: true,
21
+ pad: "medium",
22
+ justify: "center",
23
+ round: "small"
24
+ }, /*#__PURE__*/React.createElement(Text, {
25
+ weight: "bold",
26
+ size: "large"
27
+ }, key));
28
+ })) : /*#__PURE__*/React.createElement(Box, {
29
+ pad: "large"
30
+ }, /*#__PURE__*/React.createElement(Paragraph, {
31
+ size: "large"
32
+ }, "There are no backgrounds defined at `theme.global.backgrounds` for the currently selected theme. Selecting \"grommet\" from the Theme menu above is a good place to start.")) // </Grommet>
33
+
34
+ );
35
+ };
36
+ BackgroundThemed.storyName = 'Background from theme';
37
+ export default {
38
+ title: 'Layout/Box/Background from theme'
39
+ };
@@ -0,0 +1,176 @@
1
+ import React from 'react';
2
+
3
+ import { Grommet, Box, Grid, Text } from 'grommet';
4
+ import { ThemeType } from 'grommet/themes';
5
+
6
+ const myTheme: ThemeType = {
7
+ global: {
8
+ backgrounds: {
9
+ hex: '#555555',
10
+ themeColor: 'accent-1',
11
+ image: `url(https://images.unsplash.com/photo-1583530015497-6cf9ef9c6f0f?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80)`,
12
+ 'dark-light-image': {
13
+ dark: `url(https://images.unsplash.com/photo-1620744209976-74accdabd814?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=687&q=80)`,
14
+ light: `url(https://images.unsplash.com/photo-1646723504943-4b55a30ed655?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1471&q=80)`,
15
+ },
16
+ gradient: `linear-gradient(
17
+ 80deg,
18
+ hsl(41deg 100% 67%) 0%,
19
+ hsl(333deg 100% 70%) 33%,
20
+ hsl(257deg 99% 73%) 67%,
21
+ hsl(173deg 95% 75%) 100%
22
+ );`,
23
+ object: {
24
+ color: 'white',
25
+ image: `url(https://images.unsplash.com/photo-1464820453369-31d2c0b651af?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=80&q=80)`,
26
+ repeat: 'repeat',
27
+ size: '24px',
28
+ opacity: true,
29
+ },
30
+ stack: {
31
+ color: 'light-1',
32
+ image: `url(https://v2.grommet.io/img/stak-hurrah.svg)`,
33
+ },
34
+ },
35
+ },
36
+ };
37
+
38
+ const backgroundSamples = [
39
+ {
40
+ background: '#F8F8F8',
41
+ label: { value: 'hex value', context: 'prop string' },
42
+ },
43
+ { background: 'hex', label: { value: 'hex value', context: 'theme string' } },
44
+ {
45
+ background: 'accent-4',
46
+ label: { value: 'color name', context: 'prop string' },
47
+ },
48
+ {
49
+ background: 'themeColor',
50
+ label: { value: 'color name', context: 'theme string' },
51
+ },
52
+ {
53
+ background: `url(https://images.unsplash.com/photo-1493552832879-f61d5dce6c9e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80)`,
54
+ label: { value: 'image', context: 'prop string' },
55
+ },
56
+ {
57
+ background: 'image',
58
+ label: { value: 'image', context: 'theme string' },
59
+ },
60
+ {
61
+ background: {
62
+ color: 'light-1',
63
+ },
64
+ label: { value: 'hover', context: 'over me' },
65
+ onClick: () => {},
66
+ hoverIndicator: 'stack',
67
+ },
68
+ {
69
+ background: `linear-gradient(
70
+ 155deg,
71
+ hsl(147deg 100% 72%) 0%,
72
+ hsl(223deg 100% 72%) 50%,
73
+ hsl(299deg 100% 72%) 100%
74
+ );`,
75
+ label: { value: 'gradient', context: 'prop string' },
76
+ },
77
+ {
78
+ background: 'gradient',
79
+ label: { value: 'gradient', context: 'theme string' },
80
+ },
81
+ {
82
+ background: { dark: 'accent-2', light: 'accent-3' },
83
+ label: { value: 'dark-light object', context: 'prop object' },
84
+ },
85
+ {
86
+ background: 'dark-light-image',
87
+ label: { value: 'dark-light object', context: 'theme object' },
88
+ },
89
+ {
90
+ background: {
91
+ image: 'dark-light-image',
92
+ dark: true,
93
+ color: { dark: 'black', light: 'gold' },
94
+ },
95
+ label: { value: 'dark-light object force dark', context: 'theme object' },
96
+ },
97
+ {
98
+ background: {
99
+ color: 'neutral-2',
100
+ image: `url(https://images.unsplash.com/photo-1653023500770-3a3b64a1b4c4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1632&q=80)`,
101
+ position: 'top-left',
102
+ },
103
+ label: { value: 'object', context: 'prop object' },
104
+ },
105
+ {
106
+ background: 'object',
107
+ label: { value: 'object', context: 'theme object' },
108
+ },
109
+ {
110
+ background: { image: 'gradient', rotate: 180 },
111
+ label: { value: 'rotate', context: 'prop object' },
112
+ },
113
+ {
114
+ background: {
115
+ image: 'gradient',
116
+ rotate: -90,
117
+ clip: 'text',
118
+ },
119
+ label: {
120
+ value: <Text size="xxlarge">clip text</Text>,
121
+ context: <Text size="medium">prop object</Text>,
122
+ },
123
+ },
124
+ {
125
+ background: {
126
+ image: 'image',
127
+ rotate: -90,
128
+ clip: 'text',
129
+ },
130
+ label: {
131
+ value: <Text size="xxlarge">clip text</Text>,
132
+ context: <Text size="medium">prop object</Text>,
133
+ },
134
+ },
135
+ ];
136
+
137
+ const Swatch = ({ label, ...rest }) => (
138
+ <Box fill pad="medium" justify="center" round="small" {...rest}>
139
+ <Text weight="bold" size="large">
140
+ {label.value}
141
+ </Text>
142
+ <Text size="small">{label.context}</Text>
143
+ </Box>
144
+ );
145
+
146
+ export const ThemedBackgrounds = () => (
147
+ // Uncomment <Grommet> lines when using outside of storybook
148
+ <Grommet
149
+ theme={myTheme}
150
+ full
151
+ background={`linear-gradient(
152
+ 155deg,
153
+ hsl(0deg 0% 51%) 0%,
154
+ hsl(0deg 0% 76%) 50%,
155
+ hsl(0deg 0% 100%) 100%
156
+ )`}
157
+ >
158
+ <Grid columns="small" rows="small" gap="small" pad="large">
159
+ {backgroundSamples.map((sample, index) => (
160
+ <Swatch
161
+ // eslint-disable-next-line react/no-array-index-key
162
+ key={index}
163
+ background={sample.background}
164
+ label={sample.label}
165
+ {...sample}
166
+ />
167
+ ))}
168
+ </Grid>
169
+ </Grommet>
170
+ );
171
+
172
+ ThemedBackgrounds.storyName = 'Themed Background';
173
+
174
+ export default {
175
+ title: 'Layout/Box/Custom Themed/Themed Background',
176
+ };
@@ -6,7 +6,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
6
6
 
7
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';
@@ -215,7 +215,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
215
215
  var onClick = useCallback(function (event) {
216
216
  sendAnalytics({
217
217
  type: 'buttonClick',
218
- element: event.target,
218
+ element: findButtonParent(event.target),
219
219
  event: event,
220
220
  href: href,
221
221
  label: typeof label === 'string' ? label : undefined
@@ -420,7 +420,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
420
420
  href: href,
421
421
  kind: kind,
422
422
  themePaths: themePaths,
423
- onClick: onClickProp ? onClick : undefined,
423
+ onClick: onClick,
424
424
  onFocus: function onFocus(event) {
425
425
  setFocus(true);
426
426
  if (_onFocus) _onFocus(event);
@@ -545,7 +545,8 @@ var Calendar = /*#__PURE__*/forwardRef(function (_ref3, ref) {
545
545
  }, /*#__PURE__*/React.createElement(Heading, {
546
546
  level: size === 'small' ? theme.calendar.heading && theme.calendar.heading.level || 4 : (theme.calendar.heading && theme.calendar.heading.level || 4) - 1,
547
547
  size: size,
548
- margin: "none"
548
+ margin: "none",
549
+ overflowWrap: "normal"
549
550
  }, reference.toLocaleDateString(locale, {
550
551
  month: 'long',
551
552
  year: 'numeric'
@@ -1,4 +1,4 @@
1
- var _excluded = ["children", "value", "disabled", "focusIndicator", "gap", "labelKey", "valueKey", "onChange", "options", "name"],
1
+ var _excluded = ["children", "defaultValue", "value", "disabled", "focusIndicator", "gap", "labelKey", "valueKey", "onChange", "options", "name"],
2
2
  _excluded2 = ["value"];
3
3
 
4
4
  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); }
@@ -13,6 +13,7 @@ import { StyledCheckBoxGroup } from './StyledCheckBoxGroup';
13
13
  import { CheckBoxGroupPropTypes } from './propTypes';
14
14
  var CheckBoxGroup = /*#__PURE__*/forwardRef(function (_ref, ref) {
15
15
  var children = _ref.children,
16
+ defaultValue = _ref.defaultValue,
16
17
  valueProp = _ref.value,
17
18
  disabledProp = _ref.disabled,
18
19
  _ref$focusIndicator = _ref.focusIndicator,
@@ -39,7 +40,7 @@ var CheckBoxGroup = /*#__PURE__*/forwardRef(function (_ref, ref) {
39
40
  var _formContext$useFormI = formContext.useFormInput({
40
41
  name: name,
41
42
  value: valueProp,
42
- initialValue: []
43
+ initialValue: defaultValue || []
43
44
  }),
44
45
  value = _formContext$useFormI[0],
45
46
  setValue = _formContext$useFormI[1]; // Logic is necessary to maintain a proper data structure for Form logic
@@ -15,6 +15,7 @@ export interface CheckBoxType
15
15
 
16
16
  export interface CheckBoxGroupProps {
17
17
  value?: (number | string)[];
18
+ defaultValue?: (number | string)[];
18
19
  disabled?: boolean;
19
20
  labelKey?: string;
20
21
  name?: string;
@@ -26,7 +27,7 @@ export interface CheckBoxGroupProps {
26
27
  export interface CheckBoxGroupExtendedProps
27
28
  extends CheckBoxGroupProps,
28
29
  BoxProps,
29
- Omit<JSX.IntrinsicElements['div'], 'onClick' | 'onChange'> {}
30
+ Omit<JSX.IntrinsicElements['div'], 'onClick' | keyof CheckBoxGroupProps> {}
30
31
 
31
32
  declare const CheckBoxGroup: React.FC<CheckBoxGroupExtendedProps>;
32
33
 
@@ -4,6 +4,7 @@ var PropType = {};
4
4
  if (process.env.NODE_ENV !== 'production') {
5
5
  PropType = {
6
6
  value: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])),
7
+ defaultValue: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
7
8
  disabled: PropTypes.bool,
8
9
  labelKey: PropTypes.string,
9
10
  name: PropTypes.string,
@@ -21,7 +21,7 @@ import { Text } from '../Text';
21
21
  import { TextInput } from '../TextInput';
22
22
  import { FormContext } from '../Form/FormContext';
23
23
  import { FormFieldPropTypes } from './propTypes';
24
- var grommetInputNames = ['CheckBox', 'CheckBoxGroup', 'TextInput', 'Select', 'MaskedInput', 'TextArea', 'DateInput', 'FileInput', 'RadioButtonGroup', 'RangeInput'];
24
+ var grommetInputNames = ['CheckBox', 'CheckBoxGroup', 'TextInput', 'Select', 'MaskedInput', 'SelectMultiple', 'TextArea', 'DateInput', 'FileInput', 'RadioButtonGroup', 'RangeInput'];
25
25
  var grommetInputPadNames = ['CheckBox', 'CheckBoxGroup', 'RadioButtonGroup', 'RangeInput'];
26
26
 
27
27
  var isGrommetInput = function isGrommetInput(comp) {
@@ -1,20 +1,46 @@
1
- var _excluded = ["color", "fill", "level", "weight"];
1
+ var _excluded = ["color", "fill", "level", "overflowWrap", "weight"];
2
2
 
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
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, { forwardRef } from 'react';
7
+ import React, { forwardRef, useState } from 'react';
8
+ import { useLayoutEffect } from '../../utils/use-isomorphic-layout-effect';
8
9
  import { StyledHeading } from './StyledHeading';
9
10
  import { HeadingPropTypes } from './propTypes';
11
+ import { useForwardedRef } from '../../utils';
10
12
  var Heading = /*#__PURE__*/forwardRef(function (_ref, ref // munged to avoid styled-components putting it in the DOM
11
13
  ) {
12
14
  var color = _ref.color,
13
15
  fill = _ref.fill,
14
16
  level = _ref.level,
17
+ overflowWrapProp = _ref.overflowWrap,
15
18
  weight = _ref.weight,
16
19
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
17
20
 
21
+ var headingRef = useForwardedRef(ref);
22
+
23
+ var _useState = useState(overflowWrapProp || 'break-word'),
24
+ overflowWrap = _useState[0],
25
+ setOverflowWrap = _useState[1]; // handle overflowWrap of heading
26
+
27
+
28
+ useLayoutEffect(function () {
29
+ var updateOverflowWrap = function updateOverflowWrap() {
30
+ var wrap;
31
+
32
+ if (!overflowWrapProp && headingRef.current) {
33
+ wrap = headingRef.current.scrollWidth > headingRef.current.offsetWidth ? 'anywhere' : 'break-word';
34
+ setOverflowWrap(wrap);
35
+ }
36
+ };
37
+
38
+ window.addEventListener('resize', updateOverflowWrap);
39
+ updateOverflowWrap();
40
+ return function () {
41
+ return window.removeEventListener('resize', updateOverflowWrap);
42
+ };
43
+ }, [headingRef, overflowWrapProp]);
18
44
  return (
19
45
  /*#__PURE__*/
20
46
  // enforce level to be a number
@@ -23,9 +49,10 @@ var Heading = /*#__PURE__*/forwardRef(function (_ref, ref // munged to avoid sty
23
49
  colorProp: color,
24
50
  fillProp: fill,
25
51
  level: +level,
52
+ overflowWrap: overflowWrap,
26
53
  weight: weight
27
54
  }, rest, {
28
- ref: ref
55
+ ref: headingRef
29
56
  }))
30
57
  );
31
58
  });
@@ -10,7 +10,7 @@ var sizeStyle = function sizeStyle(props) {
10
10
 
11
11
  if (levelStyle) {
12
12
  var data = levelStyle[size];
13
- var styles = [css(["font-size:", ";line-height:", ";max-width:", ";font-weight:", ";"], data ? data.size : size, data ? data.height : 'normal', props.fillProp && 'none' || data && data.maxWidth || levelStyle.medium.maxWidth, props.weight || levelStyle.font.weight || headingTheme.weight)];
13
+ var styles = [css(["font-size:", ";line-height:", ";max-width:", ";font-weight:", ";overflow-wrap:", ";"], data ? data.size : size, data ? data.height : 'normal', props.fillProp && 'none' || data && data.maxWidth || levelStyle.medium.maxWidth, props.weight || levelStyle.font.weight || headingTheme.weight, props.overflowWrap)];
14
14
 
15
15
  if (props.responsive && headingTheme.responsiveBreakpoint) {
16
16
  var breakpoint = props.theme.global.breakpoints[headingTheme.responsiveBreakpoint];
@@ -19,6 +19,7 @@ export interface HeadingProps {
19
19
  fill?: boolean;
20
20
  level?: '1' | '2' | '3' | '4' | '5' | '6' | 1 | 2 | 3 | 4 | 5 | 6;
21
21
  margin?: MarginType;
22
+ overflowWrap?: 'normal' | 'break-word' | 'anywhere' | string;
22
23
  responsive?: boolean;
23
24
  size?: 'small' | 'medium' | 'large' | 'xlarge' | string;
24
25
  textAlign?: TextAlignType;
@@ -9,6 +9,7 @@ if (process.env.NODE_ENV !== 'production') {
9
9
  color: colorPropType,
10
10
  fill: PropTypes.bool,
11
11
  level: PropTypes.oneOf([1, 2, 3, 4, 5, 6, '1', '2', '3', '4', '5', '6']),
12
+ overflowWrap: PropTypes.oneOfType([PropTypes.oneOf(['normal', 'break-word', 'anywhere']), PropTypes.string]),
12
13
  responsive: PropTypes.bool,
13
14
  size: PropTypes.oneOfType([PropTypes.oneOf(['small', 'medium', 'large', 'xlarge']), PropTypes.string]),
14
15
  textAlign: PropTypes.oneOf(['start', 'center', 'end', 'justify']),
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Grid, Heading } from 'grommet';
4
4
  var headingFiller = "\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\ntempor incididunt ut labore et dolore magna aliqua.\n";
5
+ var longWord = 'Supercalifragilisticexpialidocious';
5
6
 
6
7
  var H = function H(_ref) {
7
8
  var level = _ref.level,
@@ -49,7 +50,9 @@ export var All = function All() {
49
50
  size: "xlarge"
50
51
  })), /*#__PURE__*/React.createElement(Heading, {
51
52
  fill: true
52
- }, headingFiller)) // </Grommet>
53
+ }, headingFiller), /*#__PURE__*/React.createElement(Heading, {
54
+ fill: true
55
+ }, longWord)) // </Grommet>
53
56
 
54
57
  );
55
58
  };