Skip to content

Commit 3136da8

Browse files
committed
chore(Label): Added enums for LabelColor and LabelStatus
1 parent 911223a commit 3136da8

15 files changed

+406
-299
lines changed

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

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,39 @@ import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-erro
1313
import RhUiWarningFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-warning-fill-icon';
1414
import RhUiInformationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-information-fill-icon';
1515

16+
/** Semantic status for labels (default icon and status styling). */
17+
export enum LabelStatus {
18+
success = 'success',
19+
warning = 'warning',
20+
danger = 'danger',
21+
info = 'info',
22+
custom = 'custom'
23+
}
24+
25+
/** Label palette color when not using the `status` prop. */
26+
export enum LabelColor {
27+
blue = 'blue',
28+
teal = 'teal',
29+
green = 'green',
30+
orange = 'orange',
31+
purple = 'purple',
32+
red = 'red',
33+
orangered = 'orangered',
34+
grey = 'grey',
35+
yellow = 'yellow'
36+
}
37+
1638
export interface LabelProps extends React.HTMLProps<HTMLSpanElement> {
1739
/** Content rendered inside the label. */
1840
children?: React.ReactNode;
1941
/** Additional classes added to the label. */
2042
className?: string;
2143
/** Color of the label. */
22-
color?: 'blue' | 'teal' | 'green' | 'orange' | 'purple' | 'red' | 'orangered' | 'grey' | 'yellow';
44+
color?: LabelColor | 'blue' | 'teal' | 'green' | 'orange' | 'purple' | 'red' | 'orangered' | 'grey' | 'yellow';
2345
/** Variant of the label. */
2446
variant?: 'outline' | 'filled' | 'overflow' | 'add';
2547
/** Status of the label with a respective icon and color. Overrides the color set by the color property. */
26-
status?: 'success' | 'warning' | 'danger' | 'info' | 'custom';
48+
status?: LabelStatus | 'success' | 'warning' | 'danger' | 'info' | 'custom';
2749
/** Flag indicating the label is compact. */
2850
isCompact?: boolean;
2951
/** Flag indicating the label is disabled. Works only on clickable labels, so either href or onClick props must be passed in. */
@@ -82,30 +104,30 @@ export interface LabelProps extends React.HTMLProps<HTMLSpanElement> {
82104
}) => React.ReactNode;
83105
}
84106

85-
const colorStyles = {
86-
blue: styles.modifiers.blue,
87-
teal: styles.modifiers.teal,
88-
green: styles.modifiers.green,
89-
orange: styles.modifiers.orange,
90-
purple: styles.modifiers.purple,
91-
red: styles.modifiers.red,
92-
orangered: styles.modifiers.orangered,
93-
yellow: styles.modifiers.yellow,
94-
grey: ''
107+
const colorStyles: Record<LabelColor, string> = {
108+
[LabelColor.blue]: styles.modifiers.blue,
109+
[LabelColor.teal]: styles.modifiers.teal,
110+
[LabelColor.green]: styles.modifiers.green,
111+
[LabelColor.orange]: styles.modifiers.orange,
112+
[LabelColor.purple]: styles.modifiers.purple,
113+
[LabelColor.red]: styles.modifiers.red,
114+
[LabelColor.orangered]: styles.modifiers.orangered,
115+
[LabelColor.yellow]: styles.modifiers.yellow,
116+
[LabelColor.grey]: ''
95117
};
96118

97-
const statusIcons = {
98-
success: <RhUiCheckCircleFillIcon />,
99-
warning: <RhUiWarningFillIcon />,
100-
danger: <RhUiErrorFillIcon />,
101-
info: <RhUiInformationFillIcon />,
102-
custom: <RhUiNotificationFillIcon />
119+
const statusIcons: Record<LabelStatus, React.ReactNode> = {
120+
[LabelStatus.success]: <RhUiCheckCircleFillIcon />,
121+
[LabelStatus.warning]: <RhUiWarningFillIcon />,
122+
[LabelStatus.danger]: <RhUiErrorFillIcon />,
123+
[LabelStatus.info]: <RhUiInformationFillIcon />,
124+
[LabelStatus.custom]: <RhUiNotificationFillIcon />
103125
};
104126

105127
export const Label: React.FunctionComponent<LabelProps> = ({
106128
children,
107129
className = '',
108-
color = 'grey',
130+
color = LabelColor.grey,
109131
variant = 'filled',
110132
status,
111133
isCompact = false,

packages/react-core/src/components/Label/examples/LabelCompact.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Fragment } from 'react';
2-
import { Label } from '@patternfly/react-core';
2+
import { Label, LabelColor } from '@patternfly/react-core';
33
import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
44
import RhUiInformationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-information-fill-icon';
55

@@ -42,24 +42,24 @@ export const LabelCompact: React.FunctionComponent = () => (
4242
>
4343
Compact clickable removable (disabled)
4444
</Label>
45-
<Label variant="outline" color="blue" isCompact icon={<CubeIcon />}>
45+
<Label variant="outline" color={LabelColor.blue} isCompact icon={<CubeIcon />}>
4646
Compact icon
4747
</Label>
48-
<Label variant="outline" color="blue" isCompact onClose={() => Function.prototype}>
48+
<Label variant="outline" color={LabelColor.blue} isCompact onClose={() => Function.prototype}>
4949
Compact removable
5050
</Label>
51-
<Label variant="outline" color="blue" isCompact icon={<CubeIcon />} onClose={() => Function.prototype}>
51+
<Label variant="outline" color={LabelColor.blue} isCompact icon={<CubeIcon />} onClose={() => Function.prototype}>
5252
Compact icon removable
5353
</Label>
54-
<Label variant="outline" color="blue" isCompact href="#compact">
54+
<Label variant="outline" color={LabelColor.blue} isCompact href="#compact">
5555
Compact link
5656
</Label>
57-
<Label variant="outline" color="blue" isCompact href="#compact" onClose={() => Function.prototype}>
57+
<Label variant="outline" color={LabelColor.blue} isCompact href="#compact" onClose={() => Function.prototype}>
5858
Compact link removable
5959
</Label>
6060
<Label
6161
variant="outline"
62-
color="blue"
62+
color={LabelColor.blue}
6363
isCompact
6464
icon={<CubeIcon />}
6565
onClose={() => Function.prototype}

packages/react-core/src/components/Label/examples/LabelCustomRender.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Label } from '@patternfly/react-core';
1+
import { Label, LabelColor } from '@patternfly/react-core';
22
import RhUiInformationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-information-fill-icon';
33

44
export const LabelCustomRender: React.FunctionComponent = () => (
55
<Label
6-
color="blue"
6+
color={LabelColor.blue}
77
icon={<RhUiInformationFillIcon />}
88
onClose={() => Function.prototype}
99
render={({ className, content, componentRef }) => (

packages/react-core/src/components/Label/examples/LabelEditable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Fragment, useState } from 'react';
2-
import { Label } from '@patternfly/react-core';
2+
import { Label, LabelColor } from '@patternfly/react-core';
33

44
export const LabelEditable: React.FunctionComponent = () => {
55
const [labelText, setLabelText] = useState('Editable label');
@@ -24,7 +24,7 @@ export const LabelEditable: React.FunctionComponent = () => {
2424
return (
2525
<Fragment>
2626
<Label
27-
color="blue"
27+
color={LabelColor.blue}
2828
onClose={() => {}}
2929
closeBtnAriaLabel="Custom close button for editable label"
3030
onEditCancel={onEditCancel}
@@ -38,7 +38,7 @@ export const LabelEditable: React.FunctionComponent = () => {
3838
{labelText}
3939
</Label>
4040
<Label
41-
color="grey"
41+
color={LabelColor.grey}
4242
isCompact
4343
onClose={() => {}}
4444
closeBtnAriaLabel="Custom close button for compact editable label"

0 commit comments

Comments
 (0)