From 3136da8e0b338dc01ef5e93922246d317029b934 Mon Sep 17 00:00:00 2001 From: Titani Date: Fri, 10 Apr 2026 10:58:00 -0400 Subject: [PATCH 1/2] chore(Label): Added enums for LabelColor and LabelStatus --- .../react-core/src/components/Label/Label.tsx | 60 +++- .../Label/examples/LabelCompact.tsx | 14 +- .../Label/examples/LabelCustomRender.tsx | 4 +- .../Label/examples/LabelEditable.tsx | 6 +- .../components/Label/examples/LabelFilled.tsx | 244 ++++++------- .../Label/examples/LabelGroupBasic.tsx | 6 +- .../Label/examples/LabelGroupCategory.tsx | 6 +- .../examples/LabelGroupCategoryRemovable.tsx | 4 +- .../Label/examples/LabelGroupEditableAdd.tsx | 4 +- .../LabelGroupEditableAddDropdown.tsx | 4 +- .../examples/LabelGroupEditableAddModal.tsx | 3 +- .../examples/LabelGroupEditableLabels.tsx | 10 +- .../Label/examples/LabelGroupOverflow.tsx | 12 +- ...GroupVerticalCategoryOverflowRemovable.tsx | 4 +- .../Label/examples/LabelOutline.tsx | 324 +++++++++++------- 15 files changed, 406 insertions(+), 299 deletions(-) diff --git a/packages/react-core/src/components/Label/Label.tsx b/packages/react-core/src/components/Label/Label.tsx index 71427cff802..90452034bde 100644 --- a/packages/react-core/src/components/Label/Label.tsx +++ b/packages/react-core/src/components/Label/Label.tsx @@ -13,17 +13,39 @@ 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; /** Additional classes added to the label. */ className?: string; /** Color of the label. */ - color?: 'blue' | 'teal' | 'green' | 'orange' | 'purple' | 'red' | 'orangered' | 'grey' | 'yellow'; + color?: LabelColor | 'blue' | 'teal' | 'green' | 'orange' | 'purple' | 'red' | 'orangered' | 'grey' | 'yellow'; /** Variant of the label. */ variant?: 'outline' | 'filled' | 'overflow' | 'add'; /** Status of the label with a respective icon and color. Overrides the color set by the color property. */ - status?: 'success' | 'warning' | 'danger' | 'info' | 'custom'; + status?: LabelStatus | 'success' | 'warning' | 'danger' | 'info' | 'custom'; /** Flag indicating the label is compact. */ isCompact?: boolean; /** 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 { }) => 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) -