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
@@ -1,10 +1,10 @@
1
1
  // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import styled, { css } from 'styled-components';
4
- import { baseStyle, styledComponentsConfig } from '../../utils';
5
- var fullStyle = function fullStyle(full) {
4
+ import { baseStyle, overflowStyle, styledComponentsConfig } from '../../utils';
5
+ var fullStyle = function fullStyle(full, theme) {
6
6
  if (full === 'min') return css(["min-height:100vh;"]);
7
- return css(["width:100vw;height:100vh;overflow:auto;"]);
7
+ return css(["width:100vw;height:100vh;", ""], overflowStyle('auto', theme));
8
8
  };
9
9
  var StyledGrommet = styled.div.withConfig(styledComponentsConfig).withConfig({
10
10
  displayName: "StyledGrommet",
@@ -12,7 +12,7 @@ var StyledGrommet = styled.div.withConfig(styledComponentsConfig).withConfig({
12
12
  })(["", " ", " ", " ", " ", ""], function (props) {
13
13
  return !props.plain && baseStyle;
14
14
  }, function (props) {
15
- return props.full && fullStyle(props.full);
15
+ return props.full && fullStyle(props.full, props.theme);
16
16
  }, function (props) {
17
17
  return props.theme.global.font.face;
18
18
  }, function (props) {
@@ -11,6 +11,11 @@ export interface GrommetProps {
11
11
  dir?: 'rtl';
12
12
  full?: boolean | 'min';
13
13
  options?: {
14
+ /**
15
+ * Legacy compatibility fallback: restores the pre-WCAG color heuristic,
16
+ * which may select foreground colors that fail WCAG contrast requirements.
17
+ */
18
+ legacyColorIsDark?: boolean;
14
19
  button?: { childrenPlain?: boolean };
15
20
  box?: {
16
21
  cssGap?: boolean;
@@ -238,6 +243,7 @@ export interface GrommetProps {
238
243
  activeSectionValue?: string;
239
244
  chooseTime?: string;
240
245
  currentValue?: string;
246
+ currentValueWithoutSeconds?: string;
241
247
  inputLabel?: string;
242
248
  invalidTime?: string;
243
249
  openDrop?: string;
@@ -9,6 +9,7 @@ if (process.env.NODE_ENV !== 'production') {
9
9
  dir: PropTypes.oneOf(['rtl']),
10
10
  full: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['min'])]),
11
11
  options: PropTypes.shape({
12
+ legacyColorIsDark: PropTypes.bool,
12
13
  box: PropTypes.shape({
13
14
  cssGap: PropTypes.bool
14
15
  }),
@@ -251,6 +252,7 @@ if (process.env.NODE_ENV !== 'production') {
251
252
  activeSectionValue: PropTypes.string,
252
253
  chooseTime: PropTypes.string,
253
254
  currentValue: PropTypes.string,
255
+ currentValueWithoutSeconds: PropTypes.string,
254
256
  inputLabel: PropTypes.string,
255
257
  invalidTime: PropTypes.string,
256
258
  openDrop: PropTypes.string,
@@ -412,7 +412,7 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
412
412
  overflow: "auto",
413
413
  role: "menu",
414
414
  a11yTitle: a11y
415
- }, !grouped ? theme.menu.container : {}), menuContent), !initialAlignTop &&
415
+ }, !grouped ? theme.menu.container : {}, passThemeFlag), menuContent), !initialAlignTop &&
416
416
  // don't show controlMirror if caller is using
417
417
  // align.bottom === 'top'
418
418
  alignControlMirror === 'bottom' && align.bottom !== 'top' && align.top !== 'bottom' ? controlMirror : undefined))
@@ -344,7 +344,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref3, ref) {
344
344
  return setActiveIndex(-1);
345
345
  },
346
346
  theme: theme
347
- }), options.length > 0 ? /*#__PURE__*/React.createElement(OptionsContainer, {
347
+ }), options.length > 0 ? /*#__PURE__*/React.createElement(OptionsContainer, _extends({
348
348
  "aria-label": format({
349
349
  id: 'select.optionsA11y',
350
350
  messages: messages
@@ -356,7 +356,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref3, ref) {
356
356
  onMouseMove: function onMouseMove() {
357
357
  return setKeyboardNavigation(false);
358
358
  }
359
- }, /*#__PURE__*/React.createElement(InfiniteScroll, {
359
+ }, passThemeFlag), /*#__PURE__*/React.createElement(InfiniteScroll, {
360
360
  items: options,
361
361
  step: theme.select.step,
362
362
  onMore: onMore,
@@ -5,7 +5,7 @@ import { Box } from '../Box';
5
5
  import { Button } from '../Button';
6
6
  import { DropButton } from '../DropButton';
7
7
  import { TextInput } from '../TextInput';
8
- import { getHoverIndicatorStyle, selectedStyle, controlBorderStyle, sizeStyle, styledComponentsConfig } from '../../utils';
8
+ import { getHoverIndicatorStyle, selectedStyle, controlBorderStyle, overflowStyle, sizeStyle, styledComponentsConfig } from '../../utils';
9
9
  export var StyledContainer = styled(Box).withConfig({
10
10
  displayName: "StyledSelect__StyledContainer",
11
11
  componentId: "sc-znp66n-0"
@@ -19,7 +19,9 @@ export var StyledContainer = styled(Box).withConfig({
19
19
  export var OptionsContainer = styled.div.withConfig(styledComponentsConfig).withConfig({
20
20
  displayName: "StyledSelect__OptionsContainer",
21
21
  componentId: "sc-znp66n-1"
22
- })(["position:relative;scroll-behavior:smooth;overflow:auto;outline:none;", ";"], function (props) {
22
+ })(["position:relative;scroll-behavior:smooth;", " outline:none;", ";"], function (props) {
23
+ return overflowStyle('auto', props.theme);
24
+ }, function (props) {
23
25
  if (props.selectMultiple) return props.theme.selectMultiple.listbox && props.theme.selectMultiple.listbox.extend;
24
26
  return props.theme.select.listbox && props.theme.select.listbox.extend;
25
27
  });
@@ -1,7 +1,7 @@
1
1
  // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import styled, { css } from 'styled-components';
4
- import { disabledStyle, inputStyle, styledComponentsConfig } from '../../utils';
4
+ import { disabledStyle, inputStyle, scrollbarStyle, styledComponentsConfig } from '../../utils';
5
5
  var plainStyle = css(["outline:none;border:none;width:100%;-webkit-appearance:none;"]);
6
6
  var resizeStyle = function resizeStyle(resize) {
7
7
  if (resize === 'horizontal') {
@@ -18,7 +18,7 @@ var resizeStyle = function resizeStyle(resize) {
18
18
  var StyledTextArea = styled.textarea.withConfig(styledComponentsConfig).withConfig({
19
19
  displayName: "StyledTextArea",
20
20
  componentId: "sc-17i3mwp-0"
21
- })(["", " ", " ", " ", " ", " ", ";max-width:100%;"], inputStyle, function (props) {
21
+ })(["", " ", " ", " ", " ", " ", ";", " max-width:100%;"], inputStyle, function (props) {
22
22
  return props.resize !== undefined && resizeStyle(props.resize);
23
23
  }, function (props) {
24
24
  return props.fillArg && 'height: 100%;';
@@ -28,5 +28,7 @@ var StyledTextArea = styled.textarea.withConfig(styledComponentsConfig).withConf
28
28
  return props.disabled && disabledStyle(props.theme.textArea.disabled && props.theme.textArea.disabled.opacity);
29
29
  }, function (props) {
30
30
  return props.theme.textArea && props.theme.textArea.extend;
31
+ }, function (props) {
32
+ return scrollbarStyle(props.theme);
31
33
  });
32
34
  export { StyledTextArea };
@@ -1,13 +1,14 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
2
  // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
3
3
  // SPDX-License-Identifier: Apache-2.0
4
- import React from 'react';
4
+ import React, { useContext } from 'react';
5
5
  import styled from 'styled-components';
6
6
  import { Copy } from 'grommet-icons/icons/Copy';
7
7
  import { Button } from '../Button';
8
8
  import { Tip } from '../Tip';
9
9
  import { edgeStyle } from '../../utils/styles';
10
10
  import { useThemeValue } from '../../utils/useThemeValue';
11
+ import { MessageContext } from '../../contexts/MessageContext';
11
12
 
12
13
  // to overcome `plain` styling due to (icon && !label) condition
13
14
  // in buttons without theme.button.default, apply the padding here
@@ -21,16 +22,31 @@ var StyledButton = styled(Button).withConfig({
21
22
  });
22
23
  export var CopyButton = function CopyButton(_ref) {
23
24
  var _theme$textInput, _theme$global$input$p, _theme$global$input$p2, _theme$global$input$p3;
24
- var disabled = _ref.disabled,
25
- onClickCopy = _ref.onClickCopy,
25
+ var ariaLabel = _ref.ariaLabel,
26
+ authoredType = _ref.authoredType,
27
+ disabled = _ref.disabled,
28
+ messages = _ref.messages,
29
+ onCopy = _ref.onCopy,
26
30
  onBlurCopy = _ref.onBlurCopy,
27
- readOnlyCopyPrompt = _ref.readOnlyCopyPrompt,
28
31
  tip = _ref.tip,
29
32
  value = _ref.value;
30
33
  var _useThemeValue = useThemeValue(),
31
34
  theme = _useThemeValue.theme,
32
35
  passThemeFlag = _useThemeValue.passThemeFlag;
36
+ var _useContext = useContext(MessageContext),
37
+ format = _useContext.format;
33
38
  var CopyIcon = ((_theme$textInput = theme.textInput) == null || (_theme$textInput = _theme$textInput.icons) == null ? void 0 : _theme$textInput.copy) || Copy;
39
+ // never expose the masked value via the accessible name
40
+ var buttonAriaLabel = ariaLabel || ((authoredType == null ? void 0 : authoredType.toLowerCase()) !== 'password' && (value || value === 0) ? format({
41
+ id: 'input.readOnlyCopy.promptWithValue',
42
+ messages: messages,
43
+ values: {
44
+ value: value
45
+ }
46
+ }) : format({
47
+ id: 'input.readOnlyCopy.prompt',
48
+ messages: messages
49
+ }));
34
50
  return /*#__PURE__*/React.createElement(Tip, {
35
51
  dropProps: {
36
52
  align: {
@@ -40,7 +56,7 @@ export var CopyButton = function CopyButton(_ref) {
40
56
  content: tip
41
57
  }, /*#__PURE__*/React.createElement(StyledButton, _extends({
42
58
  disabled: disabled,
43
- onClick: onClickCopy,
59
+ onClick: onCopy,
44
60
  icon: /*#__PURE__*/React.createElement(CopyIcon, null),
45
61
  pad: {
46
62
  horizontal: (_theme$global$input$p = theme.global.input.padding) == null ? void 0 : _theme$global$input$p.horizontal,
@@ -53,6 +69,6 @@ export var CopyButton = function CopyButton(_ref) {
53
69
  },
54
70
  onBlur: onBlurCopy,
55
71
  onMouseOut: onBlurCopy,
56
- "aria-label": readOnlyCopyPrompt + " " + value
72
+ "aria-label": buttonAriaLabel
57
73
  }, passThemeFlag)));
58
74
  };
@@ -2,39 +2,30 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import styled, { css } from 'styled-components';
4
4
  import { controlBorderStyle, disabledStyle, getInputPadBySide, inputStyle, parseMetricToNum, plainInputStyle, textAlignStyle, widthStyle, styledComponentsConfig } from '../../utils';
5
- import { getInputIconPad, inputPadForIcon } from '../../utils/styles';
5
+ import { inputPadForIcon } from '../../utils/styles';
6
6
  import { readOnlyStyle } from '../../utils/readOnly';
7
- var getInlineButtonPad = function getInlineButtonPad(props) {
8
- var rightInset = Number.parseFloat(getInputPadBySide(props, 'right'));
9
- var iconPad = Number.parseFloat(getInputIconPad(props));
10
- var trailingIconPad = props.hasTrailingIcon ? iconPad : 0;
11
- // Reserve both the icon space and the control's edge inset so text clears
12
- // the flush-right password toggle, and the reversed icon when both coexist.
13
- return iconPad + trailingIconPad + rightInset + "px";
14
- };
15
7
  var getPlainStyle = function getPlainStyle(plain) {
16
8
  if (plain === 'full') {
17
- return css(["", " padding:0;"], plainInputStyle);
9
+ return css(["", ";padding:0;"], plainInputStyle);
18
10
  }
19
11
  return plain && plainInputStyle;
20
12
  };
21
13
  var StyledTextInput = styled.input.withConfig(styledComponentsConfig).withConfig({
22
14
  displayName: "StyledTextInput",
23
15
  componentId: "sc-1x30a0s-0"
24
- })(["", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", ";"], inputStyle, function (props) {
16
+ })(["", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", ";"], inputStyle, function (props) {
25
17
  return (props.hasButton || props.readOnlyCopy) && 'flex: 1 1 auto;';
26
18
  }, function (props) {
27
19
  return (props.hasButton || props.readOnlyCopy) && 'min-width: 0;';
28
20
  }, function (props) {
29
- return props.readOnlyCopy || props.hasButton ? "padding-" + (props.reverse ? 'left' : 'right') + ": 0px;" : '';
21
+ if (!(props.readOnlyCopy || props.hasButton)) return '';
22
+ return 'padding-right: 0px;';
30
23
  }, function (props) {
31
- return props.readOnly && "border: none;";
24
+ return (props.readOnly || props.hasButton) && "border: none;";
32
25
  }, function (props) {
33
26
  return getPlainStyle(props.plain);
34
27
  }, function (props) {
35
- return props.icon && inputPadForIcon;
36
- }, function (props) {
37
- return props.hasInlineButton && "padding-right: " + getInlineButtonPad(props) + ";";
28
+ return props.icon && !props.hasActionsGroup && inputPadForIcon;
38
29
  }, function (props) {
39
30
  return props.disabled && disabledStyle(props.theme.textInput.disabled && props.theme.textInput.disabled.opacity);
40
31
  }, function (props) {
@@ -50,7 +41,11 @@ var StyledTextInputContainer = styled.div.withConfig(styledComponentsConfig).wit
50
41
  })(["position:relative;width:100%;", " ", ";", ";", " ", ";"], function (props) {
51
42
  return props.widthProp && props.readOnlyProp && widthStyle(props.widthProp, props.theme);
52
43
  }, function (props) {
53
- return props.readOnlyProp && !props.plain && controlBorderStyle;
44
+ return (
45
+ // The container owns the border so the actions group remains inside
46
+ // the field.
47
+ (props.readOnlyProp || props.hasButton) && !props.plain && controlBorderStyle
48
+ );
54
49
  }, function (props) {
55
50
  return (props.readOnlyCopy || props.hasButton) && "\n box-sizing: border-box;\n flex-direction: row;\n display: flex;\n align-items: stretch;\n ";
56
51
  }, function (props) {
@@ -70,20 +65,19 @@ var StyledIcon = styled.div.withConfig(styledComponentsConfig).withConfig({
70
65
  displayName: "StyledTextInput__StyledIcon",
71
66
  componentId: "sc-1x30a0s-3"
72
67
  })(["position:absolute;display:flex;justify:center;top:50%;transform:translateY(-50%);pointer-events:none;", ""], function (props) {
68
+ if (props.hasActionsGroup) {
69
+ return "\n position: static;\n align-items: center;\n transform: none;\n padding-left: " + getInputPadBySide(props, 'left') + ";\n padding-right: " + getInputPadBySide(props, 'right') + ";\n ";
70
+ }
73
71
  return props.reverse ? "right: " + getInputPadBySide(props, 'right') + ";" : "left: " + getInputPadBySide(props, 'left') + ";";
74
72
  });
75
- var StyledInlineButton = styled.div.withConfig(styledComponentsConfig).withConfig({
76
- displayName: "StyledTextInput__StyledInlineButton",
73
+ var StyledActionsGroup = styled.div.withConfig(styledComponentsConfig).withConfig({
74
+ displayName: "StyledTextInput__StyledActionsGroup",
77
75
  componentId: "sc-1x30a0s-4"
78
- })(["position:absolute;display:flex;align-items:stretch;top:0;right:0;bottom:0;z-index:1;"]);
79
- var StyledInlineIcon = styled.div.withConfig(styledComponentsConfig).withConfig({
80
- displayName: "StyledTextInput__StyledInlineIcon",
81
- componentId: "sc-1x30a0s-5"
82
- })(["display:flex;align-items:center;justify-content:center;pointer-events:none;"]);
76
+ })(["display:flex;align-items:stretch;z-index:1;"]);
83
77
  var StyledSuggestions = styled.ol.withConfig(styledComponentsConfig).withConfig({
84
78
  displayName: "StyledTextInput__StyledSuggestions",
85
- componentId: "sc-1x30a0s-6"
79
+ componentId: "sc-1x30a0s-5"
86
80
  })(["border-top-left-radius:0;border-top-right-radius:0;margin:0;padding:0;list-style-type:none;", ";"], function (props) {
87
81
  return props.theme.textInput && props.theme.textInput.suggestions && props.theme.textInput.suggestions.extend;
88
82
  });
89
- export { StyledTextInput, StyledTextInputContainer, StyledPlaceholder, StyledIcon, StyledInlineButton, StyledInlineIcon, StyledSuggestions };
83
+ export { StyledTextInput, StyledTextInputContainer, StyledPlaceholder, StyledIcon, StyledActionsGroup, StyledSuggestions };
@@ -1,5 +1,9 @@
1
- var _excluded = ["a11yTitle", "defaultSuggestion", "defaultValue", "disabled", "dropAlign", "dropHeight", "dropTarget", "dropProps", "focusIndicator", "icon", "id", "messages", "name", "onBlur", "onChange", "onFocus", "onKeyDown", "onSelect", "onSuggestionSelect", "onSuggestionsClose", "onSuggestionsOpen", "password", "placeholder", "plain", "readOnly", "readOnlyCopy", "reverse", "suggestions", "textAlign", "type", "value", "width"];
1
+ var _excluded = ["a11yTitle", "copy", "defaultSuggestion", "defaultValue", "disabled", "dropAlign", "dropHeight", "dropProps", "dropTarget", "focusIndicator", "icon", "id", "messages", "name", "onBlur", "onChange", "onClickCopy", "onFocus", "onKeyDown", "onSelect", "onSuggestionSelect", "onSuggestionsClose", "onSuggestionsOpen", "password", "placeholder", "plain", "readOnly", "readOnlyCopy", "reverse", "suggestions", "textAlign", "type", "value", "width"];
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
4
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
5
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
6
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
3
7
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
8
  // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
5
9
  // SPDX-License-Identifier: Apache-2.0
@@ -13,7 +17,7 @@ import { Keyboard } from '../Keyboard';
13
17
  import { FormContext } from '../Form/FormContext';
14
18
  import { AnnounceContext } from '../../contexts';
15
19
  import { isNodeAfterScroll, isNodeBeforeScroll, sizeStyle, useForwardedRef, useSizedIcon } from '../../utils';
16
- import { StyledTextInput, StyledTextInputContainer, StyledPlaceholder, StyledIcon, StyledInlineButton, StyledInlineIcon, StyledSuggestions } from './StyledTextInput';
20
+ import { StyledTextInput, StyledTextInputContainer, StyledPlaceholder, StyledIcon, StyledActionsGroup, StyledSuggestions } from './StyledTextInput';
17
21
  import { MessageContext } from '../../contexts/MessageContext';
18
22
  import { TextInputPropTypes } from './propTypes';
19
23
  import { CopyButton } from './CopyButton';
@@ -44,21 +48,26 @@ var ContainerBox = styled(Box).withConfig({
44
48
  })(["", ";@media screen and (-ms-high-contrast:active),(-ms-high-contrast:none){width:100%;}"], function (props) {
45
49
  return props.dropHeight ? sizeStyle('max-height', props.dropHeight, props.theme) : 'max-height: inherit;';
46
50
  });
51
+ var StyledPasswordToggleButton = styled(Button).withConfig({
52
+ displayName: "TextInput__StyledPasswordToggleButton",
53
+ componentId: "sc-1ai0c08-1"
54
+ })(["padding-top:0;padding-bottom:0;"]);
47
55
  var defaultDropAlign = {
48
56
  top: 'bottom',
49
57
  left: 'left'
50
58
  };
51
59
  var TextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
52
- var _inputRef$current, _inputRef$current2, _theme$textInput, _theme$textInput2;
60
+ var _inputRef$current2, _inputRef$current3, _theme$textInput, _theme$textInput2;
53
61
  var a11yTitle = _ref.a11yTitle,
62
+ copy = _ref.copy,
54
63
  defaultSuggestion = _ref.defaultSuggestion,
55
64
  defaultValue = _ref.defaultValue,
56
65
  disabled = _ref.disabled,
57
66
  _ref$dropAlign = _ref.dropAlign,
58
67
  dropAlign = _ref$dropAlign === void 0 ? defaultDropAlign : _ref$dropAlign,
59
68
  dropHeight = _ref.dropHeight,
60
- dropTarget = _ref.dropTarget,
61
69
  dropProps = _ref.dropProps,
70
+ dropTarget = _ref.dropTarget,
62
71
  _ref$focusIndicator = _ref.focusIndicator,
63
72
  focusIndicator = _ref$focusIndicator === void 0 ? true : _ref$focusIndicator,
64
73
  icon = _ref.icon,
@@ -67,6 +76,7 @@ var TextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
67
76
  name = _ref.name,
68
77
  _onBlur = _ref.onBlur,
69
78
  onChange = _ref.onChange,
79
+ onClickCopy = _ref.onClickCopy,
70
80
  _onFocus = _ref.onFocus,
71
81
  onKeyDown = _ref.onKeyDown,
72
82
  onSelect = _ref.onSelect,
@@ -141,11 +151,40 @@ var TextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
141
151
  id: 'textInput.hidePassword',
142
152
  messages: messages
143
153
  });
144
- var onClickCopy = function onClickCopy() {
145
- navigator.clipboard.writeText(value);
146
- announce(readOnlyCopyValidation, 'assertive');
147
- setTip(readOnlyCopyValidation);
148
- };
154
+ var handleCopyClick = /*#__PURE__*/function () {
155
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(event) {
156
+ var _ref3, _inputRef$current$val, _inputRef$current;
157
+ var currentValue;
158
+ return _regenerator().w(function (_context) {
159
+ while (1) switch (_context.n) {
160
+ case 0:
161
+ // uncontrolled inputs keep their current text on the DOM node, not
162
+ // in `value`, which stays undefined outside a Form
163
+ currentValue = (_ref3 = (_inputRef$current$val = (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.value) != null ? _inputRef$current$val : value) != null ? _ref3 : '';
164
+ if (!onClickCopy) {
165
+ _context.n = 2;
166
+ break;
167
+ }
168
+ _context.n = 1;
169
+ return onClickCopy(event, currentValue);
170
+ case 1:
171
+ _context.n = 3;
172
+ break;
173
+ case 2:
174
+ _context.n = 3;
175
+ return navigator.clipboard.writeText(currentValue);
176
+ case 3:
177
+ announce(readOnlyCopyValidation, 'assertive');
178
+ setTip(readOnlyCopyValidation);
179
+ case 4:
180
+ return _context.a(2);
181
+ }
182
+ }, _callee);
183
+ }));
184
+ return function handleCopyClick(_x) {
185
+ return _ref2.apply(this, arguments);
186
+ };
187
+ }();
149
188
  var onBlurCopy = function onBlurCopy() {
150
189
  if (tip === readOnlyCopyValidation) setTip(readOnlyCopyPrompt);
151
190
  };
@@ -262,7 +301,7 @@ var TextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
262
301
  if (readOnly && inputRef != null && inputRef.current && inputRef.current.scrollLeft > 0) {
263
302
  inputRef.current.scrollLeft = 0;
264
303
  }
265
- }, [readOnly, inputRef, inputRef == null || (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.scrollLeft]);
304
+ }, [readOnly, inputRef, inputRef == null || (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.scrollLeft]);
266
305
  var setValueFromSuggestion = function setValueFromSuggestion(event, suggestion) {
267
306
  // if we stole the focus in the drop, perhaps by interacting with
268
307
  // a suggestion button or the scrollbar, give it back
@@ -291,7 +330,7 @@ var TextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
291
330
  }, [activeSuggestionIndex]);
292
331
 
293
332
  // account for input value in both controlled and uncontrolled scenarios
294
- var hasValue = value || ((_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.value);
333
+ var hasValue = value || ((_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.value);
295
334
  var showStyledPlaceholder = useMemo(function () {
296
335
  return placeholder && typeof placeholder !== 'string' && !hasValue;
297
336
  }, [hasValue, placeholder]);
@@ -418,17 +457,16 @@ var TextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
418
457
  inputType = passwordRevealed ? 'text' : 'password';
419
458
  }
420
459
  var showTextInputIcon = !!textInputIcon && !readOnlyCopy;
421
- var showLeadingIcon = showTextInputIcon && !reverse;
422
- var showTrailingIcon = showTextInputIcon && reverse;
423
- var ReadOnlyCopyButton = /*#__PURE__*/React.createElement(CopyButton, {
460
+ var copyButtonElement = /*#__PURE__*/React.createElement(CopyButton, {
461
+ authoredType: authoredType,
424
462
  disabled: disabled,
463
+ messages: messages,
425
464
  onBlurCopy: onBlurCopy,
426
- onClickCopy: onClickCopy,
427
- readOnlyCopyPrompt: readOnlyCopyPrompt,
465
+ onCopy: handleCopyClick,
428
466
  tip: tip,
429
467
  value: value
430
468
  });
431
- var PasswordToggleButton = passwordToggle ? /*#__PURE__*/React.createElement(Button, {
469
+ var passwordToggleButton = passwordToggle ? /*#__PURE__*/React.createElement(StyledPasswordToggleButton, _extends({
432
470
  disabled: disabled,
433
471
  kind: "toolbar",
434
472
  icon: passwordRevealed ? renderIcon(hidePasswordIcon, {
@@ -442,10 +480,17 @@ var TextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
442
480
  });
443
481
  },
444
482
  "aria-label": passwordRevealed ? hidePasswordMessage : showPasswordMessage
445
- }) : undefined;
446
- var textInputButton = readOnlyCopy ? ReadOnlyCopyButton : undefined;
483
+ }, passThemeFlag)) : undefined;
484
+ var copyButton = readOnlyCopy || copy ? copyButtonElement : undefined;
485
+ // Keep state-changing password visibility before the non-destructive
486
+ // copy action.
487
+ var actionsGroup = passwordToggleButton || copyButton ? /*#__PURE__*/React.createElement(StyledActionsGroup, passThemeFlag, passwordToggleButton, copyButton) : undefined;
488
+ var hasActionsGroup = !!actionsGroup;
489
+ var iconOnRight = reverse;
490
+ var showLeadingIcon = showTextInputIcon && !iconOnRight;
491
+ var showTrailingIcon = showTextInputIcon && iconOnRight;
447
492
  return /*#__PURE__*/React.createElement(StyledTextInputContainer, _extends({
448
- hasButton: !!textInputButton,
493
+ hasButton: !!actionsGroup,
449
494
  readOnlyProp: readOnly // readOnlyProp to avoid passing to DOM
450
495
  ,
451
496
  readOnlyCopy: readOnlyCopy,
@@ -455,8 +500,9 @@ var TextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
455
500
  onMouseMove: function onMouseMove() {
456
501
  return setMouseMovedSinceLastKey(true);
457
502
  }
458
- }, passThemeFlag), reverse && textInputButton, showStyledPlaceholder && /*#__PURE__*/React.createElement(StyledPlaceholder, passThemeFlag, placeholder), showLeadingIcon && /*#__PURE__*/React.createElement(StyledIcon, {
459
- reverse: reverse,
503
+ }, passThemeFlag), showStyledPlaceholder && /*#__PURE__*/React.createElement(StyledPlaceholder, passThemeFlag, placeholder), showLeadingIcon && /*#__PURE__*/React.createElement(StyledIcon, {
504
+ reverse: iconOnRight,
505
+ hasActionsGroup: hasActionsGroup,
460
506
  theme: theme
461
507
  }, textInputIcon), /*#__PURE__*/React.createElement(Keyboard, _extends({
462
508
  target: focus ? 'document' : undefined
@@ -469,11 +515,11 @@ var TextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
469
515
  disabled: disabled,
470
516
  plain: plain,
471
517
  placeholder: typeof placeholder === 'string' ? placeholder : undefined,
472
- icon: showTextInputIcon ? icon : undefined,
473
- reverse: reverse,
518
+ icon: showTextInputIcon && !hasActionsGroup ? icon : undefined,
519
+ reverse: iconOnRight,
474
520
  focus: focus,
475
- hasButton: !!textInputButton,
476
- hasInlineButton: passwordToggle,
521
+ hasButton: hasActionsGroup,
522
+ hasActionsGroup: hasActionsGroup,
477
523
  hasTrailingIcon: showTrailingIcon,
478
524
  focusIndicator: focusIndicator,
479
525
  textAlign: textAlign,
@@ -522,10 +568,11 @@ var TextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
522
568
  setActiveSuggestionIndex(resetSuggestionIndex);
523
569
  if (onChange) onChange(event);
524
570
  }
525
- }))), PasswordToggleButton && !readOnlyCopy && /*#__PURE__*/React.createElement(StyledInlineButton, passThemeFlag, showTrailingIcon && /*#__PURE__*/React.createElement(StyledInlineIcon, passThemeFlag, textInputIcon), PasswordToggleButton), showTrailingIcon && !PasswordToggleButton && /*#__PURE__*/React.createElement(StyledIcon, {
526
- reverse: reverse,
571
+ }))), showTrailingIcon && /*#__PURE__*/React.createElement(StyledIcon, {
572
+ reverse: iconOnRight,
573
+ hasActionsGroup: hasActionsGroup,
527
574
  theme: theme
528
- }, textInputIcon), !reverse && textInputButton, !readOnly && drop);
575
+ }, textInputIcon), actionsGroup, !readOnly && drop);
529
576
  });
530
577
  TextInput.displayName = 'TextInput';
531
578
  TextInput.propTypes = TextInputPropTypes;
@@ -13,6 +13,8 @@ export interface TextInputProps
13
13
  'onSelect' | 'size' | 'placeholder' | 'width'
14
14
  > {
15
15
  a11yTitle?: A11yTitleType;
16
+ copy?: boolean;
17
+ defaultSuggestion?: number;
16
18
  dropAlign?: {
17
19
  top?: 'top' | 'bottom';
18
20
  bottom?: 'top' | 'bottom';
@@ -20,10 +22,9 @@ export interface TextInputProps
20
22
  left?: 'left' | 'right';
21
23
  };
22
24
  dropHeight?: 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | string;
23
- dropTarget?: object;
24
25
  dropProps?: DropType;
26
+ dropTarget?: object;
25
27
  focusIndicator?: boolean;
26
- defaultSuggestion?: number;
27
28
  icon?: React.ReactNode;
28
29
  id?: string;
29
30
  messages?: {
@@ -35,6 +36,14 @@ export interface TextInputProps
35
36
  suggestionIsOpen?: string;
36
37
  };
37
38
  name?: string;
39
+ /**
40
+ * Called when the copy button is activated. The value is unmasked; do not
41
+ * log, persist, or transmit it unless explicitly required.
42
+ */
43
+ onClickCopy?: (
44
+ event: React.MouseEvent<HTMLButtonElement>,
45
+ value: string,
46
+ ) => void | Promise<void>;
38
47
  onSelect?: (x: {
39
48
  target: React.RefObject<HTMLElement | null>['current'];
40
49
  suggestion: any;
@@ -43,8 +52,8 @@ export interface TextInputProps
43
52
  target: React.RefObject<HTMLElement | null>['current'];
44
53
  suggestion: any;
45
54
  }) => void;
46
- onSuggestionsOpen?: () => void;
47
55
  onSuggestionsClose?: () => void;
56
+ onSuggestionsOpen?: () => void;
48
57
  password?: boolean;
49
58
  placeholder?: string | React.ReactNode;
50
59
  plain?: boolean | 'full';
@@ -29,6 +29,7 @@ if (process.env.NODE_ENV !== 'production') {
29
29
  }),
30
30
  name: PropTypes.string,
31
31
  onChange: PropTypes.func,
32
+ onClickCopy: PropTypes.func,
32
33
  onSelect: PropTypes.func,
33
34
  onSuggestionSelect: PropTypes.func,
34
35
  onSuggestionsOpen: PropTypes.func,
@@ -36,6 +37,7 @@ if (process.env.NODE_ENV !== 'production') {
36
37
  password: PropTypes.bool,
37
38
  placeholder: PropTypes.node,
38
39
  plain: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['full'])]),
40
+ copy: PropTypes.bool,
39
41
  readOnlyCopy: PropTypes.bool,
40
42
  reverse: PropTypes.bool,
41
43
  size: PropTypes.oneOfType([PropTypes.oneOf(['xsmall', 'small', 'medium', 'large', 'xlarge', 'xxlarge', '2xl', '3xl', '4xl', '5xl', '6xl']), PropTypes.string]),
@@ -0,0 +1,42 @@
1
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import React from 'react';
4
+
5
+ import { Box, Text, TextInput } from 'grommet';
6
+
7
+ export const Copy = () => {
8
+ const [value, setValue] = React.useState<string>('Editable value');
9
+ const [status, setStatus] = React.useState<string>('');
10
+
11
+ return (
12
+ // Uncomment <Grommet> lines when using outside of storybook
13
+ // <Grommet theme={...}>
14
+ <Box fill align="center" justify="start" pad="large" gap="medium">
15
+ <Box width="medium" gap="small">
16
+ <TextInput
17
+ value={value}
18
+ onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
19
+ setValue(event.target.value)
20
+ }
21
+ copy
22
+ aria-label="Editable value"
23
+ />
24
+ <TextInput
25
+ value="Custom copy handler"
26
+ copy
27
+ onClickCopy={(
28
+ _event: React.MouseEvent<HTMLButtonElement>,
29
+ copiedValue: string,
30
+ ) => setStatus(`Custom copy handler called with "${copiedValue}"`)}
31
+ aria-label="Custom copy handler"
32
+ />
33
+ {status && <Text>{status}</Text>}
34
+ </Box>
35
+ </Box>
36
+ // </Grommet>
37
+ );
38
+ };
39
+
40
+ export default {
41
+ title: 'Input/TextInput/Copy',
42
+ };