diff --git a/packages/react/jest.config.js b/packages/react/jest.config.js index 16932e82195..dd30f1d0925 100644 --- a/packages/react/jest.config.js +++ b/packages/react/jest.config.js @@ -69,6 +69,7 @@ module.exports = { '/src/__tests__/theme.test.ts', '/src/__tests__/themeGet.test.ts', '/src/__tests__/useSafeTimeout.test.ts', + '/src/experimental/IssueLabel', '/src/experimental/Skeleton', '/src/hooks/', '/src/internal/utils/', diff --git a/packages/react/src/experimental/IssueLabel/IssueLabel.features.stories.tsx b/packages/react/src/experimental/IssueLabel/IssueLabel.features.stories.tsx index 10291eb5154..d9151f188ae 100644 --- a/packages/react/src/experimental/IssueLabel/IssueLabel.features.stories.tsx +++ b/packages/react/src/experimental/IssueLabel/IssueLabel.features.stories.tsx @@ -9,46 +9,46 @@ const meta = { export default meta -export const VariantPink = () => +export const VariantPink = () => Issue label -export const VariantPlum = () => +export const VariantPlum = () => Issue label -export const VariantPurple = () => +export const VariantPurple = () => Issue label -export const VariantIndigo = () => +export const VariantIndigo = () => Issue label -export const VariantBlue = () => +export const VariantBlue = () => Issue label -export const VariantCyan = () => +export const VariantCyan = () => Issue label -export const VariantTeal = () => +export const VariantTeal = () => Issue label -export const VariantPine = () => +export const VariantPine = () => Issue label -export const VariantGreen = () => +export const VariantGreen = () => Issue label -export const VariantLime = () => +export const VariantLime = () => Issue label -export const VariantOlive = () => +export const VariantOlive = () => Issue label -export const VariantLemon = () => +export const VariantLemon = () => Issue label -export const VariantYellow = () => +export const VariantYellow = () => Issue label -export const VariantOrange = () => +export const VariantOrange = () => Issue label -export const VariantRed = () => +export const VariantRed = () => Issue label -export const VariantCoral = () => +export const VariantCoral = () => Issue label -export const VariantGray = () => +export const VariantGray = () => Issue label -export const VariantBrown = () => +export const VariantBrown = () => Issue label -export const VariantAuburn = () => +export const VariantAuburn = () => Issue label export const HexColor = (args: {fillColor: `#${string}`}) => ( - + Issue label ) HexColor.args = { fillColor: '#59B200', @@ -56,7 +56,7 @@ HexColor.args = { HexColor.argTypes = { fillColor: {control: {type: 'color'}}, variant: {table: {disable: true}}, - text: {table: {disable: true}}, + children: {table: {disable: true}}, id: {table: {disable: true}}, className: {table: {disable: true}}, onClick: {table: {disable: true}}, @@ -65,19 +65,19 @@ HexColor.argTypes = { href: {table: {disable: true}}, } -export const AsLink = () => +export const AsLink = () => Issue label -export const AsButton = () => +export const AsButton = () => Issue label -export const OnClick = () => alert('clicked')} /> +export const OnClick = () => alert('clicked')}>Issue label export const GroupOfLabels = () => ( - - - - - - + Issue label + Another label + A third label + Issue label + Another label + A third label ) diff --git a/packages/react/src/experimental/IssueLabel/IssueLabel.stories.tsx b/packages/react/src/experimental/IssueLabel/IssueLabel.stories.tsx index f4ab7006ba6..a47ca33b6fb 100644 --- a/packages/react/src/experimental/IssueLabel/IssueLabel.stories.tsx +++ b/packages/react/src/experimental/IssueLabel/IssueLabel.stories.tsx @@ -8,12 +8,12 @@ const meta = { export default meta -export const Default = () => +export const Default = () => Issue label export const Playground: StoryObj = { render: args => , args: { - text: 'Issue label', + children: 'Issue label', as: 'span', }, argTypes: { @@ -45,9 +45,6 @@ export const Playground: StoryObj = { 'auburn', ], }, - text: { - control: 'text', - }, as: { control: 'inline-radio', options: ['span', 'button', 'a'], diff --git a/packages/react/src/experimental/IssueLabel/IssueLabel.test.tsx b/packages/react/src/experimental/IssueLabel/IssueLabel.test.tsx new file mode 100644 index 00000000000..0a904c2fa37 --- /dev/null +++ b/packages/react/src/experimental/IssueLabel/IssueLabel.test.tsx @@ -0,0 +1,19 @@ +import {describe, expect, it, vi} from 'vitest' +import {render, screen} from '@testing-library/react' +import userEvent from '@testing-library/user-event' +import {IssueLabel} from '../IssueLabel' + +describe('IssueLabel', () => { + it('should support `className` on outermost element', () => { + const {container} = render(Label) + expect(container.firstChild).toHaveClass('custom-class') + }) + + it('should support merging `style` on outermost element', () => { + const {container} = render(Label) + expect(container.firstChild).toHaveStyle({ + color: 'red', + backgroundColor: 'blue', + }) + }) +}) diff --git a/packages/react/src/experimental/IssueLabel/IssueLabel.tsx b/packages/react/src/experimental/IssueLabel/IssueLabel.tsx index 343b4d29f0a..be03b4f20f7 100644 --- a/packages/react/src/experimental/IssueLabel/IssueLabel.tsx +++ b/packages/react/src/experimental/IssueLabel/IssueLabel.tsx @@ -3,7 +3,8 @@ import {getColorsFromHex} from './getColorFromHex' import {useTheme} from '../../ThemeProvider' import {clsx} from 'clsx' import classes from './IssueLabel.module.css' -export type Hex = `#${string}` + +type Hex = `#${string}` type LabelColorVariant = | 'pink' @@ -26,35 +27,15 @@ type LabelColorVariant = | 'brown' | 'auburn' -export interface IssueLabelProps { +type IssueLabelProps = { + as?: As fillColor?: Hex variant?: LabelColorVariant - href?: string - as?: 'button' | 'a' | 'span' - text: React.ReactNode - id?: number | string className?: string - onClick?: React.MouseEventHandler - onFocus?: React.FocusEventHandler -} - -export function IssueLabel({ - className, - fillColor, - variant = 'gray', - href, - onClick, - onFocus, - text, - as, - id, - ...rest -}: IssueLabelProps) { - // Error handling: `href` and `onClick` should not be set simultaneously - if (href && onClick) { - throw new Error('`href` and `onClick` cannot both be set. Choose either a link (``) or a button (`