Skip to content

Commit

Permalink
Extract reusable variable for badge colors
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentSmedinga committed Jan 24, 2024
1 parent 129ee6d commit 334eef8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 79 deletions.
86 changes: 8 additions & 78 deletions packages/react/src/Badge/Badge.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render } from '@testing-library/react'
import { createRef } from 'react'
import { Badge } from './Badge'
import { Badge, badgeColors } from './Badge'
import '@testing-library/jest-dom'

describe('Badge', () => {
Expand Down Expand Up @@ -55,83 +55,13 @@ describe('Badge', () => {
expect(component).toHaveClass('amsterdam-badge--dark-green')
})

it('renders with black color', () => {
const { container } = render(<Badge label="test" color="black" />)
badgeColors.map((color) =>
it(`renders with ${color} color`, () => {
const { container } = render(<Badge label="test" color={color} />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-badge--black')
})

it('renders with blue color', () => {
const { container } = render(<Badge label="test" color="blue" />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-badge--blue')
})

it('renders with dark-blue color', () => {
const { container } = render(<Badge label="test" color="dark-blue" />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-badge--dark-blue')
})

it('renders with dark-green color', () => {
const { container } = render(<Badge label="test" color="dark-green" />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-badge--dark-green')
})

it('renders with green color', () => {
const { container } = render(<Badge label="test" color="green" />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-badge--green')
})
const component = container.querySelector(':only-child')

it('renders with magenta color', () => {
const { container } = render(<Badge label="test" color="magenta" />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-badge--magenta')
})

it('renders with orange color', () => {
const { container } = render(<Badge label="test" color="orange" />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-badge--orange')
})

it('renders with purple color', () => {
const { container } = render(<Badge label="test" color="purple" />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-badge--purple')
})

it('renders with white color', () => {
const { container } = render(<Badge label="test" color="white" />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-badge--white')
})

it('renders with yellow color', () => {
const { container } = render(<Badge label="test" color="yellow" />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('amsterdam-badge--yellow')
})
expect(component).toHaveClass(`amsterdam-badge--${color}`)
}),
)
})
17 changes: 16 additions & 1 deletion packages/react/src/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,23 @@ import clsx from 'clsx'
import { forwardRef } from 'react'
import type { ForwardedRef, HTMLAttributes } from 'react'

export const badgeColors = [
'black',
'blue',
'dark-blue',
'dark-green',
'green',
'magenta',
'orange',
'purple',
'white',
'yellow',
] as const

type BadgeColor = (typeof badgeColors)[number]

export interface BadgeProps extends HTMLAttributes<HTMLElement> {
color?: 'black' | 'blue' | 'dark-blue' | 'dark-green' | 'green' | 'magenta' | 'orange' | 'purple' | 'white' | 'yellow'
color?: BadgeColor
label: string | number
}

Expand Down

0 comments on commit 334eef8

Please sign in to comment.