grommet 2.57.0 → 2.58.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 (124) hide show
  1. package/components/Box/StyledBox.js +1 -1
  2. package/components/Box/stories/ColorContrast.stories.js +36 -0
  3. package/components/Button/BusyAnimation.js +7 -1
  4. package/components/Button/Button.js +12 -3
  5. package/components/DataTable/StyledDataTable.js +1 -1
  6. package/components/DateInput/DateInput.js +3 -3
  7. package/components/DateTimeInput/DateTimeInput.js +17 -11
  8. package/components/FocusedContainer.js +2 -1
  9. package/components/FormField/FormField.js +31 -10
  10. package/components/FormField/FormFieldContext.js +12 -0
  11. package/components/Grommet/Grommet.js +4 -1
  12. package/components/Grommet/StyledGrommet.js +3 -3
  13. package/components/Grommet/index.d.ts +6 -0
  14. package/components/Grommet/propTypes.js +2 -0
  15. package/components/Menu/Menu.js +1 -1
  16. package/components/Select/SelectContainer.js +2 -2
  17. package/components/Select/StyledSelect.js +3 -1
  18. package/components/TextArea/StyledTextArea.js +3 -1
  19. package/components/TextInput/CopyButton.js +23 -6
  20. package/components/TextInput/StyledTextInput.js +19 -25
  21. package/components/TextInput/TextInput.js +75 -28
  22. package/components/TextInput/index.d.ts +12 -3
  23. package/components/TextInput/propTypes.js +2 -0
  24. package/components/TextInput/stories/Copy.stories.tsx +42 -0
  25. package/components/TextInput/stories/CopySecret.stories.tsx +44 -0
  26. package/components/TimeInput/README.md +24 -1
  27. package/components/TimeInput/StyledTimeInput.js +91 -27
  28. package/components/TimeInput/TimeInput.js +185 -120
  29. package/components/TimeInput/TimeInputPopup.js +114 -117
  30. package/components/TimeInput/index.d.ts +2 -0
  31. package/components/TimeInput/propTypes.js +2 -0
  32. package/components/TimeInput/stories/Controlled.stories.tsx +2 -2
  33. package/components/TimeInput/stories/CustomThemed.stories.tsx +79 -0
  34. package/components/TimeInput/stories/CustomThemedHpe.stories.tsx +115 -0
  35. package/components/TimeInput/stories/Form.stories.tsx +1 -0
  36. package/components/TimeInput/stories/ShowSeconds.stories.tsx +28 -0
  37. package/components/TimeInput/useSectionedTimeField.js +2 -2
  38. package/components/TimeInput/utils.js +13 -62
  39. package/components/Wizard/Wizard.js +396 -210
  40. package/components/Wizard/WizardContent.js +61 -35
  41. package/components/Wizard/WizardContext.js +3 -0
  42. package/components/Wizard/WizardFooter.js +14 -15
  43. package/components/Wizard/WizardHeader.js +12 -7
  44. package/components/Wizard/WizardProgress.js +27 -2
  45. package/components/Wizard/index.d.ts +35 -4
  46. package/components/Wizard/propTypes.js +6 -1
  47. package/components/Wizard/stories/BasicLinear.stories.js +12 -10
  48. package/components/Wizard/stories/ClickableSteps.stories.js +104 -0
  49. package/components/Wizard/stories/ExternalForm.stories.js +114 -0
  50. package/components/Wizard/stories/NonClosableHeader.stories.js +68 -0
  51. package/components/Wizard/stories/Validation.stories.js +18 -8
  52. package/es6/components/Box/StyledBox.js +1 -1
  53. package/es6/components/Box/stories/ColorContrast.stories.js +31 -0
  54. package/es6/components/Button/BusyAnimation.js +7 -1
  55. package/es6/components/Button/Button.js +12 -3
  56. package/es6/components/DataTable/StyledDataTable.js +2 -2
  57. package/es6/components/DateInput/DateInput.js +3 -3
  58. package/es6/components/DateTimeInput/DateTimeInput.js +17 -11
  59. package/es6/components/FocusedContainer.js +2 -1
  60. package/es6/components/FormField/FormField.js +31 -10
  61. package/es6/components/FormField/FormFieldContext.js +7 -0
  62. package/es6/components/Grommet/Grommet.js +4 -1
  63. package/es6/components/Grommet/StyledGrommet.js +4 -4
  64. package/es6/components/Grommet/index.d.ts +6 -0
  65. package/es6/components/Grommet/propTypes.js +2 -0
  66. package/es6/components/Menu/Menu.js +1 -1
  67. package/es6/components/Select/SelectContainer.js +2 -2
  68. package/es6/components/Select/StyledSelect.js +4 -2
  69. package/es6/components/TextArea/StyledTextArea.js +4 -2
  70. package/es6/components/TextInput/CopyButton.js +22 -6
  71. package/es6/components/TextInput/StyledTextInput.js +20 -26
  72. package/es6/components/TextInput/TextInput.js +76 -29
  73. package/es6/components/TextInput/index.d.ts +12 -3
  74. package/es6/components/TextInput/propTypes.js +2 -0
  75. package/es6/components/TextInput/stories/Copy.stories.tsx +42 -0
  76. package/es6/components/TextInput/stories/CopySecret.stories.tsx +44 -0
  77. package/es6/components/TimeInput/README.md +24 -1
  78. package/es6/components/TimeInput/StyledTimeInput.js +92 -28
  79. package/es6/components/TimeInput/TimeInput.js +187 -122
  80. package/es6/components/TimeInput/TimeInputPopup.js +115 -118
  81. package/es6/components/TimeInput/index.d.ts +2 -0
  82. package/es6/components/TimeInput/propTypes.js +2 -0
  83. package/es6/components/TimeInput/stories/Controlled.stories.tsx +2 -2
  84. package/es6/components/TimeInput/stories/CustomThemed.stories.tsx +79 -0
  85. package/es6/components/TimeInput/stories/CustomThemedHpe.stories.tsx +115 -0
  86. package/es6/components/TimeInput/stories/Form.stories.tsx +1 -0
  87. package/es6/components/TimeInput/stories/ShowSeconds.stories.tsx +28 -0
  88. package/es6/components/TimeInput/useSectionedTimeField.js +2 -2
  89. package/es6/components/TimeInput/utils.js +12 -61
  90. package/es6/components/Wizard/Wizard.js +397 -211
  91. package/es6/components/Wizard/WizardContent.js +62 -36
  92. package/es6/components/Wizard/WizardContext.js +3 -0
  93. package/es6/components/Wizard/WizardFooter.js +14 -15
  94. package/es6/components/Wizard/WizardHeader.js +12 -7
  95. package/es6/components/Wizard/WizardProgress.js +27 -2
  96. package/es6/components/Wizard/index.d.ts +35 -4
  97. package/es6/components/Wizard/propTypes.js +6 -1
  98. package/es6/components/Wizard/stories/BasicLinear.stories.js +11 -11
  99. package/es6/components/Wizard/stories/ClickableSteps.stories.js +99 -0
  100. package/es6/components/Wizard/stories/ExternalForm.stories.js +111 -0
  101. package/es6/components/Wizard/stories/NonClosableHeader.stories.js +63 -0
  102. package/es6/components/Wizard/stories/Validation.stories.js +18 -9
  103. package/es6/languages/default.json +2 -0
  104. package/es6/themes/base.d.ts +79 -59
  105. package/es6/themes/base.js +65 -34
  106. package/es6/utils/DOM.js +10 -7
  107. package/es6/utils/background.js +9 -7
  108. package/es6/utils/colors.js +84 -12
  109. package/es6/utils/legacyColorIsDark.js +17 -0
  110. package/es6/utils/styles.js +13 -5
  111. package/grommet.min.js +1 -1
  112. package/grommet.min.js.map +1 -1
  113. package/languages/default.json +2 -0
  114. package/package.json +3 -3
  115. package/themes/base.d.ts +79 -59
  116. package/themes/base.js +65 -34
  117. package/tools/draft-release-version-pr.js +1 -0
  118. package/tools/generate-release-notes.js +1 -1
  119. package/tools/release-notes-utils.js +1 -0
  120. package/utils/DOM.js +10 -7
  121. package/utils/background.js +9 -7
  122. package/utils/colors.js +84 -12
  123. package/utils/legacyColorIsDark.js +21 -0
  124. package/utils/styles.js +14 -6
package/utils/colors.js CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.normalizeColor = exports.getRGBArray = exports.getRGBA = exports.colorIsDark = exports.canExtractRGBArray = void 0;
5
+ var _legacyColorIsDark = require("./legacyColorIsDark");
5
6
  // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
6
7
  // SPDX-License-Identifier: Apache-2.0
8
+
7
9
  // Track which deprecated colors have already been warned about
8
10
  var warnedColors = new Set();
9
11
  var checkColorDeprecation = function checkColorDeprecation(color, theme, dark) {
@@ -139,29 +141,99 @@ var getRGBArray = exports.getRGBArray = function getRGBArray(color) {
139
141
  }
140
142
  return color;
141
143
  };
142
- var colorIsDark = exports.colorIsDark = function colorIsDark(color) {
143
- if (color && canExtractRGBArray(color)) {
144
- var _getRGBArray = getRGBArray(color),
144
+
145
+ // sRGB-to-linear conversion constants.
146
+ // https://www.w3.org/TR/WCAG22/#dfn-relative-luminance
147
+ var SRGB_LINEAR_THRESHOLD = 0.04045;
148
+ var SRGB_LINEAR_DIVISOR = 12.92;
149
+ var SRGB_GAMMA_OFFSET = 0.055;
150
+ var SRGB_GAMMA_DIVISOR = 1.055;
151
+ var SRGB_GAMMA_EXPONENT = 2.4;
152
+
153
+ // Linearizes an sRGB channel (0-255) per the WCAG relative luminance spec.
154
+ // https://www.w3.org/TR/WCAG22/#dfn-relative-luminance
155
+ var linearizeChannel = function linearizeChannel(value) {
156
+ var c = value / 255;
157
+ return c <= SRGB_LINEAR_THRESHOLD ? c / SRGB_LINEAR_DIVISOR : Math.pow((c + SRGB_GAMMA_OFFSET) / SRGB_GAMMA_DIVISOR, SRGB_GAMMA_EXPONENT);
158
+ };
159
+
160
+ // WCAG relative luminance coefficients for linearized sRGB channels.
161
+ // https://www.w3.org/TR/WCAG22/#dfn-relative-luminance
162
+ var RED_LUMINANCE_COEFFICIENT = 0.2126;
163
+ var GREEN_LUMINANCE_COEFFICIENT = 0.7152;
164
+ var BLUE_LUMINANCE_COEFFICIENT = 0.0722;
165
+ var relativeLuminance = function relativeLuminance(red, green, blue) {
166
+ return RED_LUMINANCE_COEFFICIENT * linearizeChannel(red) + GREEN_LUMINANCE_COEFFICIENT * linearizeChannel(green) + BLUE_LUMINANCE_COEFFICIENT * linearizeChannel(blue);
167
+ };
168
+
169
+ // Offset added to luminance values in the WCAG contrast ratio formula:
170
+ // (L1 + 0.05) / (L2 + 0.05). https://www.w3.org/TR/WCAG22/#dfn-contrast-ratio
171
+ var WCAG_CONTRAST_OFFSET = 0.05;
172
+
173
+ // Luminance at which black and white text have equal WCAG contrast ratios
174
+ // against the background: solving (1.05 / (L+0.05)) = ((L+0.05) / 0.05).
175
+ var EQUAL_CONTRAST_LUMINANCE = 0.179;
176
+ var luminanceOf = function luminanceOf(color, theme, dark) {
177
+ var resolved = theme && _normalizeColor(color, theme, dark) || color;
178
+ if (resolved && canExtractRGBArray(resolved)) {
179
+ var _getRGBArray = getRGBArray(resolved),
145
180
  red = _getRGBArray[0],
146
181
  green = _getRGBArray[1],
147
- blue = _getRGBArray[2],
148
- alpha = _getRGBArray[3];
149
- // if there is an alpha and it's greater than 50%, we can't really tell
150
- if (alpha < 0.5) return undefined;
151
- var brightness = (299 * red + 587 * green + 114 * blue) / 1000;
152
- // From: http://www.had2know.com/technology/color-contrast-calculator-web-design.html
153
- // Above domain is no longer registered.
154
- return brightness < 125;
182
+ blue = _getRGBArray[2];
183
+ return relativeLuminance(red, green, blue);
155
184
  }
156
185
  return undefined;
157
186
  };
158
- var getRGBA = exports.getRGBA = function getRGBA(color, opacity) {
187
+
188
+ // Luminance at which a pair of light/dark text colors have equal WCAG
189
+ // contrast against the background. text.light is the (typically darker)
190
+ // text used against light backgrounds and text.dark is the (typically
191
+ // lighter) text used against dark backgrounds. text defaults to
192
+ // theme.global.colors.text so callers that select an alternate text color
193
+ // pair (e.g. Button's explicit color prop) can pass it in and get a
194
+ // threshold that matches what will actually be selected. Falls back to the
195
+ // black/white derived EQUAL_CONTRAST_LUMINANCE when no usable text colors
196
+ // are available, preserving prior behavior for callers that don't pass one.
197
+ var equalContrastLuminance = function equalContrastLuminance(theme, text) {
198
+ if (text === void 0) {
199
+ var _theme$global;
200
+ text = theme == null || (_theme$global = theme.global) == null || (_theme$global = _theme$global.colors) == null ? void 0 : _theme$global.text;
201
+ }
202
+ if (!text) return EQUAL_CONTRAST_LUMINANCE;
203
+ // resolve both sides directly from text (a color name, a raw color, or a
204
+ // { dark, light } pair) with explicit dark args, so named theme colors
205
+ // (e.g. 'text') and aliases (e.g. text.dark: 'text-strong') resolve to
206
+ // the intended side rather than the theme's current mode
207
+ var darkTextLuminance = luminanceOf(text, theme, false);
208
+ var lightTextLuminance = luminanceOf(text, theme, true);
209
+ if (darkTextLuminance === undefined || lightTextLuminance === undefined) {
210
+ return EQUAL_CONTRAST_LUMINANCE;
211
+ }
212
+ return Math.sqrt((darkTextLuminance + WCAG_CONTRAST_OFFSET) * (lightTextLuminance + WCAG_CONTRAST_OFFSET)) - WCAG_CONTRAST_OFFSET;
213
+ };
214
+ var colorIsDark = exports.colorIsDark = function colorIsDark(color, theme, text) {
159
215
  if (color && canExtractRGBArray(color)) {
160
216
  var _getRGBArray2 = getRGBArray(color),
161
217
  red = _getRGBArray2[0],
162
218
  green = _getRGBArray2[1],
163
219
  blue = _getRGBArray2[2],
164
220
  alpha = _getRGBArray2[3];
221
+ // if there is an alpha and it's greater than 50%, we can't really tell
222
+ if (alpha < 0.5) return undefined;
223
+ if (theme != null && theme[_legacyColorIsDark.LEGACY_COLOR_IS_DARK]) {
224
+ return (0, _legacyColorIsDark.legacyColorIsDark)(red, green, blue);
225
+ }
226
+ return relativeLuminance(red, green, blue) < equalContrastLuminance(theme, text);
227
+ }
228
+ return undefined;
229
+ };
230
+ var getRGBA = exports.getRGBA = function getRGBA(color, opacity) {
231
+ if (color && canExtractRGBArray(color)) {
232
+ var _getRGBArray3 = getRGBArray(color),
233
+ red = _getRGBArray3[0],
234
+ green = _getRGBArray3[1],
235
+ blue = _getRGBArray3[2],
236
+ alpha = _getRGBArray3[3];
165
237
  var normalizedAlpha;
166
238
  if (opacity !== undefined) {
167
239
  normalizedAlpha = opacity;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.legacyColorIsDark = exports.LEGACY_COLOR_IS_DARK = void 0;
5
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
6
+ // SPDX-License-Identifier: Apache-2.0
7
+ var LEGACY_COLOR_IS_DARK = exports.LEGACY_COLOR_IS_DARK = Symbol('legacyColorIsDark');
8
+
9
+ // Brightness weights documented by Had2Know's legacy contrast calculator.
10
+ // https://www.had2know.org/technology/color-contrast-calculator-web-design.html
11
+ var RED_BRIGHTNESS_COEFFICIENT = 299;
12
+ var GREEN_BRIGHTNESS_COEFFICIENT = 587;
13
+ var BLUE_BRIGHTNESS_COEFFICIENT = 114;
14
+ var BRIGHTNESS_COEFFICIENT_DIVISOR = 1000;
15
+
16
+ // Legacy cutoff; the source's 125 threshold is for color-pair difference.
17
+ var DARK_BRIGHTNESS_THRESHOLD = 125;
18
+ var legacyColorIsDark = exports.legacyColorIsDark = function legacyColorIsDark(red, green, blue) {
19
+ var brightness = (RED_BRIGHTNESS_COEFFICIENT * red + GREEN_BRIGHTNESS_COEFFICIENT * green + BLUE_BRIGHTNESS_COEFFICIENT * blue) / BRIGHTNESS_COEFFICIENT_DIVISOR;
20
+ return brightness < DARK_BRIGHTNESS_THRESHOLD;
21
+ };
package/utils/styles.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.widthStyle = exports.unfocusStyle = exports.textAlignStyle = exports.styledComponentsConfig = exports.sizeStyle = exports.roundStyle = exports.plainInputStyle = exports.overflowStyle = exports.kindPartStyles = exports.inputStyle = exports.inputPadForIcon = exports.heightStyle = exports.getInputPadBySide = exports.getInputIconPad = exports.genericStyles = exports.focusStyle = exports.fillStyle = exports.elevationStyle = exports.edgeStyle = exports.disabledStyle = exports.controlBorderStyle = exports.baseStyle = exports.alignStyle = exports.alignContentStyle = void 0;
4
+ exports.widthStyle = exports.unfocusStyle = exports.textAlignStyle = exports.styledComponentsConfig = exports.sizeStyle = exports.scrollbarStyle = exports.roundStyle = exports.plainInputStyle = exports.overflowStyle = exports.kindPartStyles = exports.inputStyle = exports.inputPadForIcon = exports.heightStyle = exports.getInputPadBySide = exports.getInputIconPad = exports.genericStyles = exports.focusStyle = exports.fillStyle = exports.elevationStyle = exports.edgeStyle = exports.disabledStyle = exports.controlBorderStyle = exports.baseStyle = exports.alignStyle = exports.alignContentStyle = void 0;
5
5
  var _styledComponents = require("styled-components");
6
6
  var _isPropValid = _interopRequireDefault(require("@emotion/is-prop-valid"));
7
7
  var _background = require("./background");
@@ -322,11 +322,19 @@ var inputPadForIcon = exports.inputPadForIcon = (0, _styledComponents.css)(["",
322
322
  var pad = getInputIconPad(props);
323
323
  return props.reverse ? "padding-right: " + pad + ";" : "padding-left: " + pad + ";";
324
324
  });
325
- var overflowStyle = exports.overflowStyle = function overflowStyle(overflowProp) {
326
- if (typeof overflowProp === 'string') {
327
- return (0, _styledComponents.css)(["overflow:", ";"], overflowProp);
328
- }
329
- return (0, _styledComponents.css)(["", " ", ";"], overflowProp.horizontal && "overflow-x: " + overflowProp.horizontal + ";", overflowProp.vertical && "overflow-y: " + overflowProp.vertical + ";");
325
+ var scrollbarStyle = exports.scrollbarStyle = function scrollbarStyle(theme) {
326
+ var _theme$global$scrollb;
327
+ var width = theme.global && ((_theme$global$scrollb = theme.global.scrollbar) == null ? void 0 : _theme$global$scrollb.width);
328
+ var color = (0, _colors.normalizeColor)('scrollbar', theme);
329
+ if (!color && !width) return undefined;
330
+ return (0, _styledComponents.css)(["", " ", ""], color && "scrollbar-color: " + color + " transparent;", width !== undefined && "scrollbar-width: " + width + ";");
331
+ };
332
+ var overflowStyle = exports.overflowStyle = function overflowStyle(overflowProp, theme) {
333
+ var overflow = typeof overflowProp === 'string' ? "overflow: " + overflowProp + ";" : [overflowProp.horizontal && "overflow-x: " + overflowProp.horizontal + ";", overflowProp.vertical && "overflow-y: " + overflowProp.vertical + ";"].filter(Boolean).join(' ');
334
+ var scrollable = ['auto', 'scroll', 'overlay'].some(function (value) {
335
+ return overflow.includes(": " + value + ";");
336
+ });
337
+ return (0, _styledComponents.css)(["", " ", ""], overflow, scrollable && scrollbarStyle(theme));
330
338
  };
331
339
  var ALIGN_SELF_MAP = {
332
340
  center: 'center',