@patternfly/react-core 5.3.0-prerelease.17 → 5.3.0-prerelease.18

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 (140) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/components/package.json +1 -1
  3. package/deprecated/package.json +1 -1
  4. package/dist/dynamic/components/AboutModal/package.json +1 -1
  5. package/dist/dynamic/components/Accordion/package.json +1 -1
  6. package/dist/dynamic/components/ActionList/package.json +1 -1
  7. package/dist/dynamic/components/Alert/package.json +1 -1
  8. package/dist/dynamic/components/Avatar/package.json +1 -1
  9. package/dist/dynamic/components/BackToTop/package.json +1 -1
  10. package/dist/dynamic/components/Backdrop/package.json +1 -1
  11. package/dist/dynamic/components/BackgroundImage/package.json +1 -1
  12. package/dist/dynamic/components/Badge/package.json +1 -1
  13. package/dist/dynamic/components/Banner/package.json +1 -1
  14. package/dist/dynamic/components/Brand/package.json +1 -1
  15. package/dist/dynamic/components/Breadcrumb/package.json +1 -1
  16. package/dist/dynamic/components/Button/package.json +1 -1
  17. package/dist/dynamic/components/CalendarMonth/package.json +1 -1
  18. package/dist/dynamic/components/Card/package.json +1 -1
  19. package/dist/dynamic/components/Checkbox/package.json +1 -1
  20. package/dist/dynamic/components/Chip/package.json +1 -1
  21. package/dist/dynamic/components/ClipboardCopy/package.json +1 -1
  22. package/dist/dynamic/components/CodeBlock/package.json +1 -1
  23. package/dist/dynamic/components/DataList/package.json +1 -1
  24. package/dist/dynamic/components/DatePicker/package.json +1 -1
  25. package/dist/dynamic/components/DescriptionList/package.json +1 -1
  26. package/dist/dynamic/components/Divider/package.json +1 -1
  27. package/dist/dynamic/components/DragDrop/package.json +1 -1
  28. package/dist/dynamic/components/Drawer/package.json +1 -1
  29. package/dist/dynamic/components/Dropdown/package.json +1 -1
  30. package/dist/dynamic/components/DualListSelector/package.json +1 -1
  31. package/dist/dynamic/components/EmptyState/package.json +1 -1
  32. package/dist/dynamic/components/ExpandableSection/package.json +1 -1
  33. package/dist/dynamic/components/FileUpload/package.json +1 -1
  34. package/dist/dynamic/components/Form/package.json +1 -1
  35. package/dist/dynamic/components/FormSelect/package.json +1 -1
  36. package/dist/dynamic/components/HelperText/package.json +1 -1
  37. package/dist/dynamic/components/Hint/package.json +1 -1
  38. package/dist/dynamic/components/Icon/package.json +1 -1
  39. package/dist/dynamic/components/InputGroup/package.json +1 -1
  40. package/dist/dynamic/components/JumpLinks/package.json +1 -1
  41. package/dist/dynamic/components/Label/package.json +1 -1
  42. package/dist/dynamic/components/List/package.json +1 -1
  43. package/dist/dynamic/components/LoginPage/package.json +1 -1
  44. package/dist/dynamic/components/Masthead/package.json +1 -1
  45. package/dist/dynamic/components/Menu/package.json +1 -1
  46. package/dist/dynamic/components/MenuToggle/package.json +1 -1
  47. package/dist/dynamic/components/Modal/package.json +1 -1
  48. package/dist/dynamic/components/MultipleFileUpload/package.json +1 -1
  49. package/dist/dynamic/components/Nav/package.json +1 -1
  50. package/dist/dynamic/components/NotificationBadge/package.json +1 -1
  51. package/dist/dynamic/components/NotificationDrawer/package.json +1 -1
  52. package/dist/dynamic/components/NumberInput/package.json +1 -1
  53. package/dist/dynamic/components/OverflowMenu/package.json +1 -1
  54. package/dist/dynamic/components/Page/package.json +1 -1
  55. package/dist/dynamic/components/Pagination/package.json +1 -1
  56. package/dist/dynamic/components/Panel/package.json +1 -1
  57. package/dist/dynamic/components/Popover/package.json +1 -1
  58. package/dist/dynamic/components/Progress/package.json +1 -1
  59. package/dist/dynamic/components/ProgressStepper/package.json +1 -1
  60. package/dist/dynamic/components/Radio/package.json +1 -1
  61. package/dist/dynamic/components/SearchInput/package.json +1 -1
  62. package/dist/dynamic/components/Select/package.json +1 -1
  63. package/dist/dynamic/components/Sidebar/package.json +1 -1
  64. package/dist/dynamic/components/SimpleList/package.json +1 -1
  65. package/dist/dynamic/components/Skeleton/package.json +1 -1
  66. package/dist/dynamic/components/SkipToContent/package.json +1 -1
  67. package/dist/dynamic/components/Slider/package.json +1 -1
  68. package/dist/dynamic/components/Spinner/package.json +1 -1
  69. package/dist/dynamic/components/Switch/package.json +1 -1
  70. package/dist/dynamic/components/Tabs/package.json +1 -1
  71. package/dist/dynamic/components/Text/package.json +1 -1
  72. package/dist/dynamic/components/TextArea/package.json +1 -1
  73. package/dist/dynamic/components/TextInput/package.json +1 -1
  74. package/dist/dynamic/components/TextInputGroup/package.json +1 -1
  75. package/dist/dynamic/components/Tile/package.json +1 -1
  76. package/dist/dynamic/components/TimePicker/package.json +1 -1
  77. package/dist/dynamic/components/Timestamp/package.json +1 -1
  78. package/dist/dynamic/components/Title/package.json +1 -1
  79. package/dist/dynamic/components/ToggleGroup/package.json +1 -1
  80. package/dist/dynamic/components/Toolbar/package.json +1 -1
  81. package/dist/dynamic/components/Tooltip/package.json +1 -1
  82. package/dist/dynamic/components/TreeView/package.json +1 -1
  83. package/dist/dynamic/components/Truncate/package.json +1 -1
  84. package/dist/dynamic/components/Wizard/hooks/package.json +1 -1
  85. package/dist/dynamic/components/Wizard/package.json +1 -1
  86. package/dist/dynamic/deprecated/components/ApplicationLauncher/package.json +1 -1
  87. package/dist/dynamic/deprecated/components/ContextSelector/package.json +1 -1
  88. package/dist/dynamic/deprecated/components/Dropdown/package.json +1 -1
  89. package/dist/dynamic/deprecated/components/OptionsMenu/package.json +1 -1
  90. package/dist/dynamic/deprecated/components/PageHeader/package.json +1 -1
  91. package/dist/dynamic/deprecated/components/Select/package.json +1 -1
  92. package/dist/dynamic/deprecated/components/Wizard/package.json +1 -1
  93. package/dist/dynamic/deprecated/components/package.json +1 -1
  94. package/dist/dynamic/helpers/FocusTrap/FocusTrap/package.json +1 -1
  95. package/dist/dynamic/helpers/GenerateId/GenerateId/package.json +1 -1
  96. package/dist/dynamic/helpers/KeyboardHandler/package.json +1 -1
  97. package/dist/dynamic/helpers/OUIA/ouia/package.json +1 -1
  98. package/dist/dynamic/helpers/Popper/Popper/package.json +1 -1
  99. package/dist/dynamic/helpers/constants/package.json +1 -1
  100. package/dist/dynamic/helpers/datetimeUtils/package.json +1 -1
  101. package/dist/dynamic/helpers/favorites/package.json +1 -1
  102. package/dist/dynamic/helpers/fileUtils/package.json +1 -1
  103. package/dist/dynamic/helpers/htmlConstants/package.json +1 -1
  104. package/dist/dynamic/helpers/package.json +1 -1
  105. package/dist/dynamic/helpers/resizeObserver/package.json +1 -1
  106. package/dist/dynamic/helpers/typeUtils/package.json +1 -1
  107. package/dist/dynamic/helpers/useInterval/package.json +1 -1
  108. package/dist/dynamic/helpers/useIsomorphicLayout/package.json +1 -1
  109. package/dist/dynamic/helpers/useUnmountEffect/package.json +1 -1
  110. package/dist/dynamic/helpers/util/package.json +1 -1
  111. package/dist/dynamic/layouts/Bullseye/package.json +1 -1
  112. package/dist/dynamic/layouts/Flex/package.json +1 -1
  113. package/dist/dynamic/layouts/Gallery/package.json +1 -1
  114. package/dist/dynamic/layouts/Grid/package.json +1 -1
  115. package/dist/dynamic/layouts/Level/package.json +1 -1
  116. package/dist/dynamic/layouts/Split/package.json +1 -1
  117. package/dist/dynamic/layouts/Stack/package.json +1 -1
  118. package/dist/dynamic/next/components/DualListSelector/package.json +1 -1
  119. package/dist/dynamic/next/components/Modal/package.json +1 -1
  120. package/dist/dynamic/next/components/package.json +1 -1
  121. package/dist/dynamic/styles/package.json +1 -1
  122. package/dist/esm/components/MenuToggle/MenuToggle.d.ts +9 -0
  123. package/dist/esm/components/MenuToggle/MenuToggle.d.ts.map +1 -1
  124. package/dist/esm/components/MenuToggle/MenuToggle.js +26 -2
  125. package/dist/esm/components/MenuToggle/MenuToggle.js.map +1 -1
  126. package/dist/js/components/MenuToggle/MenuToggle.d.ts +9 -0
  127. package/dist/js/components/MenuToggle/MenuToggle.d.ts.map +1 -1
  128. package/dist/js/components/MenuToggle/MenuToggle.js +27 -3
  129. package/dist/js/components/MenuToggle/MenuToggle.js.map +1 -1
  130. package/dist/umd/react-core.min.js +2 -2
  131. package/helpers/package.json +1 -1
  132. package/layouts/package.json +1 -1
  133. package/next/package.json +1 -1
  134. package/package.json +2 -2
  135. package/src/components/MenuToggle/MenuToggle.tsx +33 -0
  136. package/src/components/MenuToggle/__tests__/MenuToggle.test.tsx +15 -0
  137. package/src/components/MenuToggle/examples/MenuToggle.md +28 -13
  138. package/src/components/MenuToggle/examples/MenuToggleStatus.tsx +20 -0
  139. package/src/components/Select/examples/Select.md +30 -11
  140. package/src/components/Select/examples/SelectValidated.tsx +74 -0
@@ -1 +1 @@
1
- {"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"5.3.0-prerelease.16","private":true}
1
+ {"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"5.3.0-prerelease.17","private":true}
@@ -1 +1 @@
1
- {"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"5.3.0-prerelease.16","private":true}
1
+ {"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"5.3.0-prerelease.17","private":true}
package/next/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"5.3.0-prerelease.16","private":true}
1
+ {"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"5.3.0-prerelease.17","private":true}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "5.3.0-prerelease.17",
3
+ "version": "5.3.0-prerelease.18",
4
4
  "description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -72,5 +72,5 @@
72
72
  "react": "^17 || ^18",
73
73
  "react-dom": "^17 || ^18"
74
74
  },
75
- "gitHead": "c2b801e346348cb0d522244c1764c3d1f47a48a8"
75
+ "gitHead": "c440812aaa961f95f2c3bd38f42faf93cef14807"
76
76
  }
@@ -3,6 +3,15 @@ import styles from '@patternfly/react-styles/css/components/MenuToggle/menu-togg
3
3
  import { css } from '@patternfly/react-styles';
4
4
  import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
5
5
  import { BadgeProps } from '../Badge';
6
+ import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
7
+ import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
8
+ import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon';
9
+
10
+ export enum MenuToggleStatus {
11
+ success = 'success',
12
+ danger = 'danger',
13
+ warning = 'warning'
14
+ }
6
15
 
7
16
  export type MenuToggleElement = HTMLDivElement | HTMLButtonElement;
8
17
 
@@ -37,6 +46,10 @@ export interface MenuToggleProps
37
46
  splitButtonOptions?: SplitButtonOptions;
38
47
  /** Variant styles of the menu toggle */
39
48
  variant?: 'default' | 'plain' | 'primary' | 'plainText' | 'secondary' | 'typeahead';
49
+ /** @beta Status styles of the menu toggle */
50
+ status?: 'success' | 'warning' | 'danger';
51
+ /** Overrides the status icon */
52
+ statusIcon?: React.ReactNode;
40
53
  /** Optional icon or image rendered inside the toggle, before the children content. It is
41
54
  * recommended to wrap most basic icons in our icon component.
42
55
  */
@@ -69,6 +82,8 @@ class MenuToggleBase extends React.Component<MenuToggleProps> {
69
82
  isFullWidth,
70
83
  splitButtonOptions,
71
84
  variant,
85
+ status,
86
+ statusIcon,
72
87
  innerRef,
73
88
  onClick,
74
89
  'aria-label': ariaLabel,
@@ -77,8 +92,25 @@ class MenuToggleBase extends React.Component<MenuToggleProps> {
77
92
  const isPlain = variant === 'plain';
78
93
  const isPlainText = variant === 'plainText';
79
94
  const isTypeahead = variant === 'typeahead';
95
+
96
+ let _statusIcon = statusIcon;
97
+ if (!statusIcon) {
98
+ switch (status) {
99
+ case MenuToggleStatus.success:
100
+ _statusIcon = <CheckCircleIcon aria-hidden="true" />;
101
+ break;
102
+ case MenuToggleStatus.warning:
103
+ _statusIcon = <ExclamationTriangleIcon aria-hidden="true" />;
104
+ break;
105
+ case MenuToggleStatus.danger:
106
+ _statusIcon = <ExclamationCircleIcon aria-hidden="true" />;
107
+ break;
108
+ }
109
+ }
110
+
80
111
  const toggleControls = (
81
112
  <span className={css(styles.menuToggleControls)}>
113
+ {status !== undefined && <span className={css(styles.menuToggleStatusIcon)}>{_statusIcon}</span>}
82
114
  <span className={css(styles.menuToggleToggleIcon)}>
83
115
  <CaretDownIcon aria-hidden />
84
116
  </span>
@@ -111,6 +143,7 @@ class MenuToggleBase extends React.Component<MenuToggleProps> {
111
143
  isExpanded && styles.modifiers.expanded,
112
144
  variant === 'primary' && styles.modifiers.primary,
113
145
  variant === 'secondary' && styles.modifiers.secondary,
146
+ status && styles.modifiers[status],
114
147
  (isPlain || isPlainText) && styles.modifiers.plain,
115
148
  isPlainText && styles.modifiers.text,
116
149
  isFullHeight && styles.modifiers.fullHeight,
@@ -57,6 +57,21 @@ describe('menu toggle', () => {
57
57
  expect(asFragment()).toMatchSnapshot();
58
58
  });
59
59
 
60
+ test('shows success status', () => {
61
+ render(<MenuToggle status="success">Toggle</MenuToggle>);
62
+ expect(screen.getByRole('button')).toHaveClass('pf-m-success');
63
+ });
64
+
65
+ test('shows warning status', () => {
66
+ render(<MenuToggle status="warning">Toggle</MenuToggle>);
67
+ expect(screen.getByRole('button')).toHaveClass('pf-m-warning');
68
+ });
69
+
70
+ test('shows danger status', () => {
71
+ render(<MenuToggle status="danger">Toggle</MenuToggle>);
72
+ expect(screen.getByRole('button')).toHaveClass('pf-m-danger');
73
+ });
74
+
60
75
  test('split toggle passes onClick', async () => {
61
76
  const mockClick = jest.fn();
62
77
  const user = userEvent.setup();
@@ -17,7 +17,7 @@ import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
17
17
 
18
18
  ### Collapsed toggle
19
19
 
20
- A toggle is collapsed until it is selected by a user.
20
+ A toggle is collapsed until it is selected by a user.
21
21
 
22
22
  ```ts
23
23
  import React from 'react';
@@ -29,7 +29,7 @@ import { MenuToggle } from '@patternfly/react-core';
29
29
 
30
30
  ### Expanded toggle
31
31
 
32
- When a user selects a toggle, it becomes expanded and is styled with a blue underline. To flag expanded toggles, and apply expanded styling, use the `isExpanded` property .
32
+ When a user selects a toggle, it becomes expanded and is styled with a blue underline. To flag expanded toggles, and apply expanded styling, use the `isExpanded` property .
33
33
 
34
34
  ```ts
35
35
  import React from 'react';
@@ -41,7 +41,7 @@ import { MenuToggle } from '@patternfly/react-core';
41
41
 
42
42
  ### Disabled toggle
43
43
 
44
- To disable the selection and expansion of a toggle, use the `isDisabled` property.
44
+ To disable the selection and expansion of a toggle, use the `isDisabled` property.
45
45
 
46
46
  ```ts
47
47
  import React from 'react';
@@ -65,7 +65,7 @@ import { MenuToggle, Badge } from '@patternfly/react-core';
65
65
 
66
66
  ### With icons
67
67
 
68
- To add a recognizable icon to a menu toggle, use the `icon` property. The following example adds a `CogIcon` to the toggle.
68
+ To add a recognizable icon to a menu toggle, use the `icon` property. The following example adds a `CogIcon` to the toggle.
69
69
 
70
70
  For most basic icons, it is recommended to wrap it inside our [icon component](/components/icon).
71
71
 
@@ -111,7 +111,7 @@ import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
111
111
 
112
112
  ### With avatar and text
113
113
 
114
- You can also pass images into the `icon` property. The following example passes in an `<Avatar>` component with an `imgAvatar`.
114
+ You can also pass images into the `icon` property. The following example passes in an `<Avatar>` component with an `imgAvatar`.
115
115
 
116
116
  This can be used alongside a text label that provides more context for the image.
117
117
 
@@ -150,9 +150,9 @@ import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
150
150
 
151
151
  ### Plain toggle with icon
152
152
 
153
- To apply plain styling to a menu toggle with an icon, pass in `variant="plain"`. This will remove the default bottom border and caret. You may pass in an `icon` to serve as the menu toggle. The following example passes in an `EllipsisVIcon`.
153
+ To apply plain styling to a menu toggle with an icon, pass in `variant="plain"`. This will remove the default bottom border and caret. You may pass in an `icon` to serve as the menu toggle. The following example passes in an `EllipsisVIcon`.
154
154
 
155
- If the toggle does not have any visible text content, use the `aria-label` property to provide an accessible name.
155
+ If the toggle does not have any visible text content, use the `aria-label` property to provide an accessible name.
156
156
 
157
157
  ```ts
158
158
  import React from 'react';
@@ -171,6 +171,7 @@ import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-ico
171
171
  </MenuToggle>
172
172
  </React.Fragment>
173
173
  ```
174
+
174
175
  ### Plain toggle with text label
175
176
 
176
177
  To apply plain styling to a menu toggle with a text label, pass in `variant="plainText"`. Unlike the “plain” variant, “plainText” adds a caret pointing down in the toggle.
@@ -201,27 +202,30 @@ The following example shows a split button with a `<MenuToggleCheckbox>`.
201
202
  Variant styling can be applied to split button toggles to adjust their appearance for different scenarios. Both "primary" and "secondary" variants can be used with split button toggles.
202
203
 
203
204
  ```ts file='MenuToggleSplitButtonCheckbox.tsx'
205
+
204
206
  ```
205
207
 
206
208
  ### Split button toggle with text label
207
209
 
208
- To display text in a split button menu toggle, add a label to the `items` property of `splitButtonOptions`.
210
+ To display text in a split button menu toggle, add a label to the `items` property of `splitButtonOptions`.
209
211
 
210
212
  ```ts file='MenuToggleSplitButtonCheckboxWithText.tsx'
213
+
211
214
  ```
212
215
 
213
216
  ### Split button toggle with action
214
217
 
215
- To add an action to a split button, pass `variant='action'` into `splitButtonOptions` and add a `<MenuToggleAction>` to the `items` property of `splitButtonOptions`.
218
+ To add an action to a split button, pass `variant='action'` into `splitButtonOptions` and add a `<MenuToggleAction>` to the `items` property of `splitButtonOptions`.
216
219
 
217
220
  Actions may be used with primary and secondary toggle variants.
218
-
221
+
219
222
  ```ts file='MenuToggleSplitButtonAction.tsx'
223
+
220
224
  ```
221
225
 
222
226
  ### Full height toggle
223
227
 
224
- A full height toggle fills the height of its parent. To flag a full height toggle, use the `isFullHeight` property.
228
+ A full height toggle fills the height of its parent. To flag a full height toggle, use the `isFullHeight` property.
225
229
 
226
230
  In the following example, the toggle fills the size of the "80px" `<div>` element that it is within.
227
231
 
@@ -238,7 +242,7 @@ import { MenuToggle } from '@patternfly/react-core';
238
242
 
239
243
  ### Full width toggle
240
244
 
241
- A full width toggle fills the width of its parent. To flag a full width toggle, use the `isFullWidth` property.
245
+ A full width toggle fills the width of its parent. To flag a full width toggle, use the `isFullWidth` property.
242
246
 
243
247
  In the following example, the toggle fills the width of its parent as the window size changes.
244
248
 
@@ -249,7 +253,7 @@ import { MenuToggle } from '@patternfly/react-core';
249
253
  const fullWidth: React.FunctionComponent = () => {
250
254
  return (
251
255
  <MenuToggle isFullWidth aria-label="Full width menu toggle" >
252
- Full width
256
+ Full width
253
257
  </MenuToggle>
254
258
  );
255
259
  }
@@ -262,4 +266,15 @@ To create a typeahead toggle, pass in `variant="typeahead"` to the `<MenuToggle>
262
266
  To create a multiple typeahead toggle, pass a `<TextInputGroup>` component implemented like the [text input group's filter example](/components/text-input-group#filters) as a child of `<MenuToggle>`.
263
267
 
264
268
  ```ts file='MenuToggleTypeahead.tsx'
269
+
270
+ ```
271
+
272
+ ### Status toggle
273
+
274
+ To create a toggle with a status, pass in the `status` property to the `MenuToggle`. The default icon associated with each status may be overridden by using the `statusIcon` property.
275
+
276
+ When the status value is "warning" or "danger", you must include helper text that conveys what is causing the warning/error.
277
+
278
+ ```ts isBeta file='MenuToggleStatus.tsx'
279
+
265
280
  ```
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { MenuToggle, HelperText, HelperTextItem } from '@patternfly/react-core';
3
+
4
+ export const MenuToggleStatus: React.FunctionComponent = () => (
5
+ <React.Fragment>
6
+ <MenuToggle status="success">Success</MenuToggle>
7
+ <br />
8
+ <br />
9
+ <MenuToggle status="warning">Warning</MenuToggle>
10
+ <HelperText>
11
+ <HelperTextItem variant="warning">Warning text that explains the issue.</HelperTextItem>
12
+ </HelperText>
13
+ <br />
14
+ <br />
15
+ <MenuToggle status="danger">Danger</MenuToggle>
16
+ <HelperText>
17
+ <HelperTextItem variant="error">Danger text that explains the issue.</HelperTextItem>
18
+ </HelperText>
19
+ </React.Fragment>
20
+ );
@@ -15,7 +15,10 @@ import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
15
15
 
16
16
  Select builds off of the menu component suite to adapt commonly used properties and functions to create a select menu. See the [menu documentation](/components/menus/menu) for a full list of properties that may be used to further customize a select menu. View the [custom menu examples](/components/menus/custom-menus) to see examples of fully functional select menus.
17
17
 
18
+ For use cases that do not require a lot of customization, there are various template components available to use in the `@react-templates` package. These templates have a streamlined API and logic, making them easier to set up and use, but are limited in scope and flexibility. See the [templates page](/components/menus/select/react-templates) for details.
19
+
18
20
  ### Single select
21
+
19
22
  To let users select a single item from a list, use a single select menu.
20
23
 
21
24
  You can add multiple `<SelectOption>` components to build out a list of menu items. For each select option, pass a relevant option label to the `value` property.
@@ -28,30 +31,42 @@ To disable the select menu toggle, use the `isDisabled` property. In the followi
28
31
 
29
32
  ### Select option variants
30
33
 
31
- The following example showcases different option variants and customizations that are commonly used in a select menu.
34
+ The following example showcases different option variants and customizations that are commonly used in a select menu.
32
35
 
33
- To create these variants, you can pass different properties into a `<SelectOption>` component.
36
+ To create these variants, you can pass different properties into a `<SelectOption>` component.
34
37
 
35
- This example provides examples of:
38
+ This example provides examples of:
36
39
 
37
40
  - An option with a description, which is created by using the `description` property.
38
- - An option with a link, which is created by passing a URL into the `to` property. For external links, use the `isExternalLink` property so that the option is styled with an outbound link icon.
39
- - An option with an icon, which is created by using the `icon` property.
40
- - An option that is disabled by using the `isDisabled` property.
41
+ - An option with a link, which is created by passing a URL into the `to` property. For external links, use the `isExternalLink` property so that the option is styled with an outbound link icon.
42
+ - An option with an icon, which is created by using the `icon` property.
43
+ - An option that is disabled by using the `isDisabled` property.
41
44
 
42
45
  ```ts file="./SelectOptionVariations.tsx"
43
46
 
44
47
  ```
45
48
 
46
49
  ### With grouped items
50
+
47
51
  To group related select options together, use 1 or more `<SelectGroup>` components and title each group using the `label` property.
48
52
 
49
53
  ```ts file="./SelectGrouped.tsx"
50
54
 
51
55
  ```
52
56
 
57
+ ### With validation
58
+
59
+ To create a toggle with a status, pass in `status` to the `MenuToggle`. The default icon associated with each status may be overridden by using the `statusIcon` property.
60
+
61
+ When the status value is "warning" or "danger", you must include helper text that conveys what is causing the warning/error.
62
+
63
+ ```ts isBeta file="./SelectValidated.tsx"
64
+
65
+ ```
66
+
53
67
  ### Checkbox select
54
- To let users select multiple list options via checkbox input, use a checkbox select.
68
+
69
+ To let users select multiple list options via checkbox input, use a checkbox select.
55
70
 
56
71
  To create a checkbox select, pass `role="menu"` to the `<Select>`, and `hasCheckbox` into each `<SelectOption>` component. To indicate that an option is selected, use the `isSelected` property.
57
72
 
@@ -62,6 +77,7 @@ By default, the menu toggle will display a badge to indicate the number of items
62
77
  ```
63
78
 
64
79
  ### Typeahead
80
+
65
81
  Typeahead is a select variant that replaces the typical button toggle for opening the select menu with a text input and button toggle combo. As a user enters characters into the text input, the menu options will be filtered to match.
66
82
 
67
83
  To make a typeahead, pass `variant=typeahead` into the `<MenuToggle>` component and link an `onClick` function to the `<TextInputGroupMain>` component.
@@ -71,7 +87,8 @@ To make a typeahead, pass `variant=typeahead` into the `<MenuToggle>` component
71
87
  ```
72
88
 
73
89
  ### Typeahead with create option
74
- If a user enters a value into a typeahead select menu that does not exist, you can allow them to create an option of that value.
90
+
91
+ If a user enters a value into a typeahead select menu that does not exist, you can allow them to create an option of that value.
75
92
 
76
93
  To enable the creation ability, pass a predetermined `value` into a `<SelectOption>` component. You can use the `placeholder` property to change the default text shown in the text input.
77
94
 
@@ -82,6 +99,7 @@ The following example outlines the code implementation required to create a work
82
99
  ```
83
100
 
84
101
  ### Multiple typeahead with chips
102
+
85
103
  A multiple typeahead can be used to allow users to select multiple options from a list. Additionally, you can render a chip group to be placed in the select toggle.
86
104
 
87
105
  When more items than the allowed limit are selected, overflowing items will be hidden under a "more" button. The following example hides items after more than 3 are selected. To show hidden items, select the “more” button. Select "show less" to hide extra items again.
@@ -91,6 +109,7 @@ When more items than the allowed limit are selected, overflowing items will be h
91
109
  ```
92
110
 
93
111
  ### Multiple typeahead with create option
112
+
94
113
  If the text that is entered into a typeahead doesn't match a menu item, users can choose to create a new option that matches the text input. You can also combine this create functionality with a chip group to display created items as chips."
95
114
 
96
115
  ```ts file="./SelectMultiTypeaheadCreatable.tsx"
@@ -98,13 +117,14 @@ If the text that is entered into a typeahead doesn't match a menu item, users ca
98
117
  ```
99
118
 
100
119
  ### Multiple typeahead with checkboxes
120
+
101
121
  By default, a multiple typeahead select allows you to select multiple menu items, placing a checkmark beside selected items. Like basic checkbox select menus, you can add checkboxes to your menu items. This approach may be more accurate and comprehensive for more complex menu scenarios like filtering.
102
122
 
103
123
  ```ts file="./SelectMultiTypeaheadCheckbox.tsx"
104
124
 
105
125
  ```
106
126
 
107
- ### With view more
127
+ ### With view more
108
128
 
109
129
  To reduce the processing load for long select lists, you can add a "View more" action to load additional items.
110
130
 
@@ -118,7 +138,6 @@ The following example shows 3 items before the "View more" link, but you can adj
118
138
 
119
139
  You can add a `<MenuFooter>` component to a select menu to hold additional actions that users can take on menu items, through elements such as link buttons. A footer will be placed beneath a divider at the end of the select menu.
120
140
 
121
-
122
141
  ```ts file="./SelectFooter.tsx"
123
142
 
124
- ```
143
+ ```
@@ -0,0 +1,74 @@
1
+ import React from 'react';
2
+ import {
3
+ Select,
4
+ SelectOption,
5
+ SelectList,
6
+ MenuToggle,
7
+ MenuToggleElement,
8
+ MenuToggleStatus,
9
+ HelperText,
10
+ HelperTextItem
11
+ } from '@patternfly/react-core';
12
+
13
+ export const SelectValidated: React.FunctionComponent = () => {
14
+ const [isOpen, setIsOpen] = React.useState(false);
15
+ const [selected, setSelected] = React.useState<string>('Select a value');
16
+ const [status, setStatus] = React.useState<MenuToggleStatus>();
17
+
18
+ const onToggleClick = () => {
19
+ setIsOpen(!isOpen);
20
+ };
21
+
22
+ const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
23
+ // eslint-disable-next-line no-console
24
+ console.log('selected', value);
25
+
26
+ setSelected(value as string);
27
+ setStatus((value as string).toLowerCase() as MenuToggleStatus);
28
+ setIsOpen(false);
29
+ };
30
+
31
+ const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
32
+ <MenuToggle
33
+ ref={toggleRef}
34
+ onClick={onToggleClick}
35
+ isExpanded={isOpen}
36
+ style={
37
+ {
38
+ width: '200px'
39
+ } as React.CSSProperties
40
+ }
41
+ status={status}
42
+ >
43
+ {selected}
44
+ </MenuToggle>
45
+ );
46
+
47
+ return (
48
+ <React.Fragment>
49
+ <Select
50
+ id="single-select"
51
+ isOpen={isOpen}
52
+ selected={selected}
53
+ onSelect={onSelect}
54
+ onOpenChange={(isOpen) => setIsOpen(isOpen)}
55
+ toggle={toggle}
56
+ shouldFocusToggleOnSelect
57
+ >
58
+ <SelectList>
59
+ <SelectOption value="Success">Success</SelectOption>
60
+ <SelectOption value="Warning">Warning</SelectOption>
61
+ <SelectOption value="Danger">Danger</SelectOption>
62
+ </SelectList>
63
+ </Select>
64
+ {(status === MenuToggleStatus.warning || status === MenuToggleStatus.danger) && (
65
+ <HelperText isLiveRegion>
66
+ <HelperTextItem variant={status === MenuToggleStatus.warning ? 'warning' : 'error'}>
67
+ {status === MenuToggleStatus.warning && 'Warning text that explains the issue.'}
68
+ {status === MenuToggleStatus.danger && 'Danger text that explains the issue.'}
69
+ </HelperTextItem>
70
+ </HelperText>
71
+ )}
72
+ </React.Fragment>
73
+ );
74
+ };