Skip to content

Commit f5df2ac

Browse files
author
Eric Olkowski
committed
feat(HelperText): consumed Penta updates
1 parent 0dfe65d commit f5df2ac

11 files changed

+61
-178
lines changed

packages/react-core/src/components/HelperText/HelperTextItem.tsx

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,72 +13,52 @@ export interface HelperTextItemProps extends React.HTMLProps<HTMLDivElement | HT
1313
className?: string;
1414
/** Sets the component type of the helper text item. */
1515
component?: 'div' | 'li';
16-
/** Variant styling of the helper text item. */
17-
variant?: 'default' | 'indeterminate' | 'warning' | 'success' | 'error';
18-
/** Custom icon prefixing the helper text. This property will override the default icon paired with each helper text variant. */
19-
icon?: React.ReactNode;
20-
/** Flag indicating the helper text item is dynamic. This prop should be used when the
21-
* text content of the helper text item will never change, but the icon and styling will
22-
* be dynamically updated via the `variant` prop.
16+
/** Status styling of the helper text item. Will also render a default icon, which can be overridden
17+
* with the icon prop.
2318
*/
24-
isDynamic?: boolean;
25-
/** Flag indicating the helper text should have an icon. Dynamic helper texts include icons by default while static helper texts do not. */
26-
hasIcon?: boolean;
19+
status?: 'indeterminate' | 'warning' | 'success' | 'error';
20+
/** Custom icon prefixing the helper text. This property will override the default icon when the status property is passed in. */
21+
icon?: React.ReactNode;
2722
/** ID for the helper text item. The value of this prop can be passed into a form component's
2823
* aria-describedby prop when you intend for only specific helper text items to be announced to
2924
* assistive technologies.
3025
*/
3126
id?: string;
3227
/** Text that is only accessible to screen readers in order to announce the status of a helper text item.
33-
* This prop can only be used when the isDynamic prop is also passed in.
28+
* This prop can only be used when the status prop is also passed in.
3429
*/
3530
screenReaderText?: string;
3631
}
3732

38-
const variantStyle = {
39-
default: '',
40-
indeterminate: styles.modifiers.indeterminate,
41-
warning: styles.modifiers.warning,
42-
success: styles.modifiers.success,
43-
error: styles.modifiers.error
33+
const defaultStatusIcons = {
34+
indeterminate: <MinusIcon />,
35+
warning: <ExclamationTriangleIcon />,
36+
success: <CheckCircleIcon />,
37+
error: <ExclamationCircleIcon />
4438
};
4539

4640
export const HelperTextItem: React.FunctionComponent<HelperTextItemProps> = ({
4741
children,
4842
className,
4943
component = 'div',
50-
variant = 'default',
44+
status,
5145
icon,
52-
isDynamic = false,
53-
hasIcon = isDynamic,
5446
id,
55-
screenReaderText = `${variant} status`,
47+
screenReaderText = `${status} status`,
5648
...props
5749
}: HelperTextItemProps) => {
5850
const Component = component as any;
5951
return (
60-
<Component
61-
className={css(styles.helperTextItem, variantStyle[variant], isDynamic && styles.modifiers.dynamic, className)}
62-
id={id}
63-
{...props}
64-
>
65-
{icon && (
66-
<span className={css(styles.helperTextItemIcon)} aria-hidden>
67-
{icon}
68-
</span>
69-
)}
70-
{hasIcon && !icon && (
52+
<Component className={css(styles.helperTextItem, styles.modifiers[status], className)} id={id} {...props}>
53+
{(status || icon) && (
7154
<span className={css(styles.helperTextItemIcon)} aria-hidden>
72-
{(variant === 'default' || variant === 'indeterminate') && <MinusIcon />}
73-
{variant === 'warning' && <ExclamationTriangleIcon />}
74-
{variant === 'success' && <CheckCircleIcon />}
75-
{variant === 'error' && <ExclamationCircleIcon />}
55+
{icon || defaultStatusIcons[status]}
7656
</span>
7757
)}
7858

7959
<span className={css(styles.helperTextItemText)}>
8060
{children}
81-
{isDynamic && <span className="pf-v5-screen-reader">: {screenReaderText};</span>}
61+
{status && <span className="pf-v5-screen-reader">: {screenReaderText};</span>}
8262
</span>
8363
</Component>
8464
);

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,22 @@ import ExclamationIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-
1313

1414
## Examples
1515

16-
### Static
16+
### Basic
1717

1818
```ts file="HelperTextStatic.tsx"
19-
```
20-
21-
### Static with default icons
2219

23-
```ts file="HelperTextStaticWithDefaultIcon.tsx"
2420
```
2521

26-
### Static with custom icons
22+
### With custom icons
2723

2824
```ts file="HelperTextStaticWithCustomIcon.tsx"
29-
```
30-
31-
### Multiple static
3225

33-
```ts file="HelperTextMultipleStatic.tsx"
3426
```
3527

36-
### Dynamic
28+
### Multiple items
3729

38-
```ts file="HelperTextDynamic.tsx"
39-
```
30+
You can pass multiple `<HelperTextItem>` components inside a single `<Helpertext>` container.
4031

41-
### Dynamic list
32+
```ts file="HelperTextMultipleStatic.tsx"
4233

43-
```ts file="HelperTextDynamicList.tsx"
4434
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import { HelperText, HelperTextItem } from '@patternfly/react-core';
3+
4+
export const HelperTextBasic: React.FunctionComponent = () => (
5+
<React.Fragment>
6+
<HelperText>
7+
<HelperTextItem>This is default helper text</HelperTextItem>
8+
</HelperText>
9+
<HelperText>
10+
<HelperTextItem status="indeterminate">This is indeterminate helper text</HelperTextItem>
11+
</HelperText>
12+
<HelperText>
13+
<HelperTextItem status="warning">This is warning helper text</HelperTextItem>
14+
</HelperText>
15+
<HelperText>
16+
<HelperTextItem status="success">This is success helper text</HelperTextItem>
17+
</HelperText>
18+
<HelperText>
19+
<HelperTextItem status="error">This is error helper text</HelperTextItem>
20+
</HelperText>
21+
</React.Fragment>
22+
);

packages/react-core/src/components/HelperText/examples/HelperTextDynamic.tsx

Lines changed: 0 additions & 41 deletions
This file was deleted.

packages/react-core/src/components/HelperText/examples/HelperTextDynamicList.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import { HelperText, HelperTextItem } from '@patternfly/react-core';
3+
4+
export const HelperTextMultipleItems: React.FunctionComponent = () => (
5+
<HelperText component="ul">
6+
<HelperTextItem component="li">This is default helper text</HelperTextItem>
7+
<HelperTextItem component="li">This is another default helper text in the same HelperText block</HelperTextItem>
8+
<HelperTextItem component="li">And this is more default text in the same HelperText block</HelperTextItem>
9+
</HelperText>
10+
);

packages/react-core/src/components/HelperText/examples/HelperTextMultipleStatic.tsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/react-core/src/components/HelperText/examples/HelperTextStatic.tsx

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/react-core/src/components/HelperText/examples/HelperTextStaticWithDefaultIcon.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ import ExclamationIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-
66
import CheckIcon from '@patternfly/react-icons/dist/esm/icons/check-icon';
77
import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
88

9-
export const HelperTextStaticWithCustomIcon: React.FunctionComponent = () => (
9+
export const HelperTextWithCustomIcon: React.FunctionComponent = () => (
1010
<React.Fragment>
1111
<HelperText>
1212
<HelperTextItem icon={<InfoIcon />}>This is default helper text</HelperTextItem>
1313
</HelperText>
1414
<HelperText>
15-
<HelperTextItem variant="indeterminate" icon={<QuestionIcon />}>
15+
<HelperTextItem status="indeterminate" icon={<QuestionIcon />}>
1616
This is indeterminate helper text
1717
</HelperTextItem>
1818
</HelperText>
1919
<HelperText>
20-
<HelperTextItem variant="warning" icon={<ExclamationIcon />}>
20+
<HelperTextItem status="warning" icon={<ExclamationIcon />}>
2121
This is warning helper text
2222
</HelperTextItem>
2323
</HelperText>
2424
<HelperText>
25-
<HelperTextItem variant="success" icon={<CheckIcon />}>
25+
<HelperTextItem status="success" icon={<CheckIcon />}>
2626
This is success helper text
2727
</HelperTextItem>
2828
</HelperText>
2929
<HelperText>
30-
<HelperTextItem variant="error" icon={<TimesIcon />}>
30+
<HelperTextItem status="error" icon={<TimesIcon />}>
3131
This is error helper text
3232
</HelperTextItem>
3333
</HelperText>

0 commit comments

Comments
 (0)