From 6787c5d4b95d303aa853fc7f1764dadbbe61e7c6 Mon Sep 17 00:00:00 2001 From: Isa Stettler Date: Wed, 6 Dec 2023 09:49:37 -0500 Subject: [PATCH] update StatusBadge type and theme --- src/components/StatusBadge/StatusBadge.tsx | 11 +++- src/theme/components/statusBadge.ts | 74 ++++++++++++---------- 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/components/StatusBadge/StatusBadge.tsx b/src/components/StatusBadge/StatusBadge.tsx index 9e3b1759dc..3b8f5bc393 100644 --- a/src/components/StatusBadge/StatusBadge.tsx +++ b/src/components/StatusBadge/StatusBadge.tsx @@ -1,4 +1,4 @@ -import { Box, chakra, useStyleConfig } from "@chakra-ui/react"; +import { Box, chakra, ChakraComponent, useStyleConfig } from "@chakra-ui/react"; import React, { forwardRef } from "react"; export const statusBadgeTypeArray = ["low", "medium", "high"] as const; @@ -16,7 +16,14 @@ export interface StatusBadgeProps { * The `StatusBadge` component is used to display a visual badge for three * different status levels. */ -export const StatusBadge: React.FC = chakra( +export const StatusBadge: ChakraComponent< + React.ForwardRefExoticComponent< + StatusBadgeProps & { + children?: React.ReactNode; + } & React.RefAttributes + >, + StatusBadgeProps +> = chakra( forwardRef>( (props, ref?) => { const { children, className, id, level = "low", ...rest } = props; diff --git a/src/theme/components/statusBadge.ts b/src/theme/components/statusBadge.ts index ab52b3ad00..9afe91c440 100644 --- a/src/theme/components/statusBadge.ts +++ b/src/theme/components/statusBadge.ts @@ -1,38 +1,46 @@ -const StatusBadge = { - baseStyle: { - borderRadius: "base", - color: "ui.typography.heading", - display: "block", - fontSize: "desktop.body.body2", // slightly smaller than the default size - fontStyle: "italic", - py: "inset.extranarrow", - px: "inset.narrow", - textAlign: "center", - width: "fit-content", - _dark: { - backgroundColor: "dark.ui.bg.active", - borderLeft: "4px solid", - borderColor: "dark.ui.border.default", - color: "dark.ui.typography.heading", - }, +import { defineStyleConfig } from "@chakra-ui/react"; +import { defineStyle } from "@chakra-ui/system"; + +const baseStyle = defineStyle({ + borderRadius: "base", + color: "ui.typography.heading", + display: "block", + fontSize: "desktop.body.body2", // slightly smaller than the default size + fontStyle: "italic", + py: "inset.extranarrow", + px: "inset.narrow", + textAlign: "center", + width: "fit-content", + _dark: { + backgroundColor: "dark.ui.bg.active", + borderLeft: "4px solid", + borderColor: "dark.ui.border.default", + color: "dark.ui.typography.heading", + }, +}); + +// Variants +const low = defineStyle({ bg: "ui.gray.light-cool" }); +const medium = defineStyle({ + bg: "ui.status.primary", + _dark: { + borderColor: "ui.status.primary", }, +}); +const high = defineStyle({ + bg: "ui.status.secondary", + _dark: { + borderColor: "dark.ui.error.primary", + }, +}); + +const StatusBadge = defineStyleConfig({ + baseStyle, variants: { - low: { - bg: "ui.gray.light-cool", - }, - medium: { - bg: "ui.status.primary", - _dark: { - borderColor: "ui.status.primary", - }, - }, - high: { - bg: "ui.status.secondary", - _dark: { - borderColor: "dark.ui.error.primary", - }, - }, + low, + medium, + high, }, -}; +}); export default StatusBadge;