Skip to content

Commit ce8c198

Browse files
committed
pr feedback
1 parent 1ad13ad commit ce8c198

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

packages/react-core/src/components/MenuToggle/MenuToggle.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle
77
import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
88
import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon';
99

10+
export enum MenuToggleStatus {
11+
success = 'success',
12+
danger = 'danger',
13+
warning = 'warning'
14+
}
15+
1016
export type MenuToggleElement = HTMLDivElement | HTMLButtonElement;
1117

1218
export interface SplitButtonOptions {
@@ -90,13 +96,13 @@ class MenuToggleBase extends React.Component<MenuToggleProps> {
9096
let _statusIcon = statusIcon;
9197
if (!statusIcon) {
9298
switch (status) {
93-
case 'success':
99+
case MenuToggleStatus.success:
94100
_statusIcon = <CheckCircleIcon aria-hidden="true" />;
95101
break;
96-
case 'warning':
102+
case MenuToggleStatus.warning:
97103
_statusIcon = <ExclamationTriangleIcon aria-hidden="true" />;
98104
break;
99-
case 'danger':
105+
case MenuToggleStatus.danger:
100106
_statusIcon = <ExclamationCircleIcon aria-hidden="true" />;
101107
break;
102108
}
@@ -137,9 +143,7 @@ class MenuToggleBase extends React.Component<MenuToggleProps> {
137143
isExpanded && styles.modifiers.expanded,
138144
variant === 'primary' && styles.modifiers.primary,
139145
variant === 'secondary' && styles.modifiers.secondary,
140-
status === 'success' && styles.modifiers.success,
141-
status === 'warning' && styles.modifiers.warning,
142-
status === 'danger' && styles.modifiers.danger,
146+
status && styles.modifiers[status],
143147
(isPlain || isPlainText) && styles.modifiers.plain,
144148
isPlainText && styles.modifiers.text,
145149
isFullHeight && styles.modifiers.fullHeight,

packages/react-core/src/components/MenuToggle/examples/MenuToggle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,6 @@ To create a multiple typeahead toggle, pass a `<TextInputGroup>` component imple
273273

274274
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.
275275

276-
```ts file='MenuToggleStatus.tsx'
276+
```ts isBeta file='MenuToggleStatus.tsx'
277277

278278
```

packages/react-core/src/components/Select/examples/Select.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ To group related select options together, use 1 or more `<SelectGroup>` componen
5454

5555
### With validation
5656

57-
To validate selections that users make, pass the `status` property to the `MenuToggle`. Validating selections can let users know if the selections they make would cause issues or errors.
57+
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.
5858

59-
```ts file="./SelectValidated.tsx"
59+
When the status value is "warning" or "danger", you must include helper text that conveys what is causing the warning/error.
60+
61+
```ts isBeta file="./SelectValidated.tsx"
6062

6163
```
6264

packages/react-core/src/components/Select/examples/SelectValidated.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import React from 'react';
2-
import { Select, SelectOption, SelectList, MenuToggle, MenuToggleElement, HelperText } from '@patternfly/react-core';
2+
import {
3+
Select,
4+
SelectOption,
5+
SelectList,
6+
MenuToggle,
7+
MenuToggleElement,
8+
MenuToggleStatus,
9+
HelperText,
10+
HelperTextItem
11+
} from '@patternfly/react-core';
312

413
export const SelectValidated: React.FunctionComponent = () => {
514
const [isOpen, setIsOpen] = React.useState(false);
615
const [selected, setSelected] = React.useState<string>('Select a value');
7-
const [status, setStatus] = React.useState<'success' | 'warning' | 'danger'>();
16+
const [status, setStatus] = React.useState<MenuToggleStatus>();
817

918
const onToggleClick = () => {
1019
setIsOpen(!isOpen);
@@ -15,7 +24,7 @@ export const SelectValidated: React.FunctionComponent = () => {
1524
console.log('selected', value);
1625

1726
setSelected(value as string);
18-
setStatus((value as string).toLowerCase() as 'success' | 'warning' | 'danger');
27+
setStatus((value as string).toLowerCase() as MenuToggleStatus);
1928
setIsOpen(false);
2029
};
2130

@@ -52,10 +61,12 @@ export const SelectValidated: React.FunctionComponent = () => {
5261
<SelectOption value="Danger">Danger</SelectOption>
5362
</SelectList>
5463
</Select>
55-
{(status === 'warning' || status === 'danger') && (
64+
{(status === MenuToggleStatus.warning || status === MenuToggleStatus.danger) && (
5665
<HelperText isLiveRegion>
57-
Helper text may be used to convery additional information to the user about the status, and to inform
58-
screenreaders a {status} status occured.
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>
5970
</HelperText>
6071
)}
6172
</React.Fragment>

0 commit comments

Comments
 (0)