diff --git a/packages/react-core/src/components/Label/Label.tsx b/packages/react-core/src/components/Label/Label.tsx index 71427cff802..b2569d84490 100644 --- a/packages/react-core/src/components/Label/Label.tsx +++ b/packages/react-core/src/components/Label/Label.tsx @@ -13,6 +13,28 @@ import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-erro import RhUiWarningFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-warning-fill-icon'; import RhUiInformationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-information-fill-icon'; +/** Semantic status for labels (default icon and status styling). */ +export enum LabelStatus { + success = 'success', + warning = 'warning', + danger = 'danger', + info = 'info', + custom = 'custom' +} + +/** Label palette color when not using the `status` prop. */ +export enum LabelColor { + blue = 'blue', + teal = 'teal', + green = 'green', + orange = 'orange', + purple = 'purple', + red = 'red', + orangered = 'orangered', + grey = 'grey', + yellow = 'yellow' +} + export interface LabelProps extends React.HTMLProps { /** Content rendered inside the label. */ children?: React.ReactNode; @@ -82,30 +104,30 @@ export interface LabelProps extends React.HTMLProps { }) => React.ReactNode; } -const colorStyles = { - blue: styles.modifiers.blue, - teal: styles.modifiers.teal, - green: styles.modifiers.green, - orange: styles.modifiers.orange, - purple: styles.modifiers.purple, - red: styles.modifiers.red, - orangered: styles.modifiers.orangered, - yellow: styles.modifiers.yellow, - grey: '' +const colorStyles: Record = { + [LabelColor.blue]: styles.modifiers.blue, + [LabelColor.teal]: styles.modifiers.teal, + [LabelColor.green]: styles.modifiers.green, + [LabelColor.orange]: styles.modifiers.orange, + [LabelColor.purple]: styles.modifiers.purple, + [LabelColor.red]: styles.modifiers.red, + [LabelColor.orangered]: styles.modifiers.orangered, + [LabelColor.yellow]: styles.modifiers.yellow, + [LabelColor.grey]: '' }; -const statusIcons = { - success: , - warning: , - danger: , - info: , - custom: +const statusIcons: Record = { + [LabelStatus.success]: , + [LabelStatus.warning]: , + [LabelStatus.danger]: , + [LabelStatus.info]: , + [LabelStatus.custom]: }; export const Label: React.FunctionComponent = ({ children, className = '', - color = 'grey', + color = LabelColor.grey, variant = 'filled', status, isCompact = false, diff --git a/packages/react-core/src/components/Label/examples/LabelCompact.tsx b/packages/react-core/src/components/Label/examples/LabelCompact.tsx index fea1a0bdb84..de8adfe859a 100644 --- a/packages/react-core/src/components/Label/examples/LabelCompact.tsx +++ b/packages/react-core/src/components/Label/examples/LabelCompact.tsx @@ -1,5 +1,5 @@ import { Fragment } from 'react'; -import { Label } from '@patternfly/react-core'; +import { Label, LabelColor } from '@patternfly/react-core'; import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon'; import RhUiInformationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-information-fill-icon'; @@ -42,24 +42,24 @@ export const LabelCompact: React.FunctionComponent = () => ( > Compact clickable removable (disabled) -