import React from 'react'; import {ExtractProps, cornerShapeStencil, createComponent} from '@workday/canvas-kit-react/common'; import {systemIconStencil} from '@workday/canvas-kit-react/icon'; import {Flex, mergeStyles} from '@workday/canvas-kit-react/layout'; import {ExtractStencilProps, createStencil, px2rem} from '@workday/canvas-kit-styling'; import {system} from '@workday/canvas-tokens-web'; import {StatusIndicatorIcon} from './StatusIndicatorIcon'; import {StatusIndicatorLabel} from './StatusIndicatorLabel'; /** * @deprecated This is being deprecated and will be removed in a future release. Use * `StatusIndicatorProps['variant']` instead. */ export type StatusIndicatorVariant = | 'info' | 'neutral' | 'caution' | 'positive' | 'critical' | 'transparent' | 'blue' | 'green' | 'orange' | 'red' | 'gray'; export interface StatusIndicatorProps extends ExtractProps, Omit, 'variant'> { /** * Defines the color of the `StatusIndicator`. * * `info` | `blue` - Uses the info system color and is used for informational status indications * * `positive` | `green` - Uses the positive system color and is used for positive status indications * * `caution` | `orange` - Uses the caution system color and is used for warnings or required actions * * `critical` | `red` - Uses the error system color and is used for critical or negative status indications * * `neutral` | `gray` - Uses the neutral system color and generally doesn't have positive or negative connotations * * `illuminate` - Uses the AI system color and is used for AI generated content * * `transparent` - Uses the transparent system color and is used for overlays on top of images or videos * * @default 'neutral' */ variant?: StatusIndicatorVariant; /** * Children of the `StatusIndicator`. Can contain a `StatusIndicator.Label` and optionally a `StatusIndicator.Icon`. */ children: React.ReactNode; } // TODO: Remove this in a future release const deprecatedVariantsMap = { blue: 'info', green: 'positive', orange: 'caution', red: 'critical', gray: 'neutral', } as const; const statusIndicatorStencil = createStencil({ extends: cornerShapeStencil, base: { display: 'inline-flex', gap: system.legacy.gap.xs, maxWidth: px2rem(200), alignItems: 'center', [cornerShapeStencil.vars.shape]: system.legacy.shape.md, height: system.legacy.size.xs, padding: `${system.legacy.padding.xxs} ${system.legacy.padding.xs}`, outline: `${px2rem(1)} solid transparent`, [systemIconStencil.vars.color]: 'currentColor', }, modifiers: { /** * Defines the color of the `StatusIndicator`. * * `info` | `blue` - Uses the info system color and is used for informational status indications * * `positive` | `green` - Uses the positive system color and is used for positive status indications * * `caution` | `orange` - Uses the caution system color and is used for warnings or required actions * * `critical` | `red` - Uses the error system color and is used for critical or negative status indications * * `neutral` | `gray` - Uses the neutral system color and generally doesn't have positive or negative connotations * * `illuminate` - Uses the AI system color and is used for AI generated content * * `transparent` - Uses the transparent system color and is used for overlays on top of images or videos * * @default 'neutral' */ variant: { info: { color: system.legacy.color.fg.info.strong, backgroundColor: system.legacy.color.surface.info.strong, }, positive: { color: system.legacy.color.fg.success.strong, backgroundColor: system.legacy.color.surface.success.strong, }, caution: { color: system.legacy.color.fg.warning.strong, backgroundColor: system.legacy.color.surface.warning.strong, }, critical: { color: system.legacy.color.fg.danger.strong, backgroundColor: system.legacy.color.surface.danger.strong, }, neutral: { color: system.color.fg.muted.strong, backgroundColor: system.legacy.color.surface.alt.strong, }, transparent: { color: system.color.fg.inverse, backgroundColor: system.legacy.color.surface.contrast.default, }, }, /** * Defines the emphasis of the `StatusIndicator`. `low` should be used in almost all cases. * `high` is being deprecated and will be removed in a future release. * * `low` - Normal emphasis and will visually fit in with other components. * * `high` - High emphasis has been used to make the `StatusIndicator` stand out more, but * tends to overpower other components. It will be removed and should not be used. * * @default 'low' * */ emphasis: { low: {}, high: {}, }, }, compound: [ { modifiers: { variant: 'info', emphasis: 'high', }, styles: { backgroundColor: system.legacy.color.accent.info, color: system.color.fg.inverse, }, }, { modifiers: { variant: 'positive', emphasis: 'high', }, styles: { backgroundColor: system.legacy.color.accent.success, color: system.color.fg.inverse, }, }, { modifiers: { variant: 'caution', emphasis: 'high', }, styles: { backgroundColor: system.legacy.color.accent.warning, color: system.color.fg.contrast.default, }, }, { modifiers: { variant: 'critical', emphasis: 'high', }, styles: { backgroundColor: system.legacy.color.accent.danger, color: system.color.fg.inverse, }, }, { modifiers: { variant: 'neutral', emphasis: 'high', }, styles: { backgroundColor: system.legacy.color.accent.muted.default, color: system.color.fg.inverse, }, }, ], defaultModifiers: { variant: 'neutral', emphasis: 'low', }, }); /** * `StatusIndicator` is a container component has a default maximum width of `200px`. * * ```tsx * * {Child components} * * ``` */ export const StatusIndicator = createComponent('div')({ displayName: 'StatusIndicator', subComponents: { /** * `StatusIndicator.Label` will apply an ellipsis if its contents exceed the component's maximum * width. * * ```tsx * {The text to be rendered} * ``` */ Label: StatusIndicatorLabel, /** * `StatusIndicator.Icon` renders {@link SystemIcon} under the hood. It's used as a decorative * element to visually support the {@link StatusIndicatorLabel StatusIndicator.Label} text. * * ```tsx * * ``` */ Icon: StatusIndicatorIcon, }, Component: ({variant, emphasis, children, ...elemProps}: StatusIndicatorProps, ref, Element) => { return ( {children} ); }, });