@@ -13,17 +13,39 @@ import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-erro
1313import RhUiWarningFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-warning-fill-icon' ;
1414import 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+
1638export 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
105127export const Label : React . FunctionComponent < LabelProps > = ( {
106128 children,
107129 className = '' ,
108- color = ' grey' ,
130+ color = LabelColor . grey ,
109131 variant = 'filled' ,
110132 status,
111133 isCompact = false ,
0 commit comments