Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions frontend/documentation/components/Chip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export const Accent: Story = {
args: { children: '"hello"', variant: 'accent' },
}

export const Success: Story = {
args: { children: 'View feature', variant: 'success' },
}

export const Warning: Story = {
args: { children: '1/2', variant: 'warning' },
}

export const Sizes: Story = {
render: () => (
<div className='d-flex align-items-center gap-2'>
Expand Down Expand Up @@ -56,6 +64,8 @@ export const Group: Story = {
<div className='d-flex flex-wrap gap-2'>
<Chip>Development</Chip>
<Chip variant='accent'>Staging</Chip>
<Chip variant='success'>Live</Chip>
<Chip variant='warning'>Paused</Chip>
<Chip onRemove={() => undefined}>Production</Chip>
</div>
),
Expand Down
8 changes: 8 additions & 0 deletions frontend/web/components/base/Chip/Chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
border-color: var(--color-border-action);
}

&--success {
border-color: var(--color-border-success);
}

&--warning {
border-color: var(--color-border-warning);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Comment thread
talissoncosta marked this conversation as resolved.
Resolved
}

// Sizes (default is the base above).
&--sm {
padding: 3px 8px;
Expand Down
13 changes: 11 additions & 2 deletions frontend/web/components/base/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { toHexColour } from 'common/utils/hexColour'
import './Chip.scss'

export type ChipSize = 'default' | 'sm' | 'xs'
export type ChipVariant = 'neutral' | 'accent' | 'tinted'
export type ChipVariant =
| 'neutral'
| 'accent'
| 'success'
| 'warning'
| 'tinted'
type TokenVariant = Exclude<ChipVariant, 'tinted'>

// 'tinted' takes a 6-digit hex colour; the token variants take none.
Expand Down Expand Up @@ -37,6 +42,8 @@ export type ChipProps = ChipVariantProps & {
const VARIANT_UTILITIES: Record<TokenVariant, string> = {
accent: 'bg-surface-action-subtle text-action',
neutral: 'bg-surface-subtle text-default',
success: 'bg-surface-success text-success',
warning: 'bg-surface-warning text-warning',
}

// Token-based chip primitive. Uses `ds-chip` rather than the legacy `.chip`
Expand Down Expand Up @@ -78,9 +85,11 @@ const Chip = ({
{
'ds-chip--accent': !tint && tokenVariant === 'accent',
'ds-chip--clickable': interactive,
'ds-chip--success': !tint && tokenVariant === 'success',
'ds-chip--tinted': !!tint,
[`ds-chip--${size}`]: size !== 'default',
'ds-chip--truncate': truncate,
[`ds-chip--${size}`]: size !== 'default',
'ds-chip--warning': !tint && tokenVariant === 'warning',
},
className,
)}
Expand Down
Loading