Skip to content

Commit

Permalink
Merge pull request #2279 from adevinta/2243-component-tag-new-intent-…
Browse files Browse the repository at this point in the history
…surface

feat(tag): add "surface" intent
  • Loading branch information
acd02 authored Jun 28, 2024
2 parents 8bd3855 + d79192d commit 6dcf4de
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
17 changes: 12 additions & 5 deletions packages/components/tag/src/Tag.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const intents: TagProps['intent'][] = [
'danger',
'info',
'neutral',
'surface',
]
const designs: TagProps['design'][] = ['filled', 'outlined', 'tinted']

Expand All @@ -43,11 +44,17 @@ export const Intent: StoryFn = _args => (
<div className="flex flex-col gap-md">
{designs.map(design => (
<div key={design} className="flex flex-row gap-md">
{intents.map(intent => (
<Tag key={intent} design={design} intent={intent}>
{intent} tag
</Tag>
))}
{intents.map(intent => {
if (design !== 'filled' && intent === 'surface') {
return <span className="self-center text-small">N/A</span>
}

return (
<Tag key={intent} design={design} intent={intent as any}>
{intent} tag
</Tag>
)
})}
</div>
))}
</div>
Expand Down
14 changes: 13 additions & 1 deletion packages/components/tag/src/Tag.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ export const tagStyles = cva(
*/
intent: makeVariants<
'intent',
['main', 'support', 'accent', 'basic', 'success', 'alert', 'info', 'neutral', 'danger']
[
'main',
'support',
'accent',
'basic',
'success',
'alert',
'info',
'neutral',
'danger',
'surface',
]
>({
main: [],
support: [],
Expand All @@ -39,6 +50,7 @@ export const tagStyles = cva(
danger: [],
info: [],
neutral: [],
surface: [],
}),
},
compoundVariants: [...filledVariants, ...outlinedVariants, ...tintedVariants],
Expand Down
17 changes: 16 additions & 1 deletion packages/components/tag/src/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { forwardRef, type PropsWithChildren } from 'react'

import { tagStyles, type TagStylesProps } from './Tag.styles'

export interface TagProps
interface BaseTagProps
extends PropsWithChildren<React.ButtonHTMLAttributes<HTMLSpanElement>>,
TagStylesProps {
/**
Expand All @@ -12,6 +12,21 @@ export interface TagProps
asChild?: boolean
}

interface FilteredDesignIntent<
Design extends TagProps['design'],
K extends TagStylesProps['intent'] | never = never,
> {
design?: Design
intent?: Exclude<TagStylesProps['intent'], K>
}

type ValidTagDesignIntent =
| FilteredDesignIntent<'tinted', 'surface'>
| FilteredDesignIntent<'outlined', 'surface'>
| FilteredDesignIntent<'filled'>

export type TagProps = BaseTagProps & ValidTagDesignIntent

export const Tag = forwardRef<HTMLButtonElement, TagProps>(
({ design = 'filled', intent = 'basic', asChild, className, ...others }, ref) => {
const Component = asChild ? Slot : 'span'
Expand Down
5 changes: 5 additions & 0 deletions packages/components/tag/src/variants/filled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ export const filledVariants = [
design: 'filled',
class: tw(['bg-neutral', 'text-on-neutral']),
},
{
intent: 'surface',
design: 'filled',
class: tw(['bg-surface', 'text-on-surface']),
},
] as const

0 comments on commit 6dcf4de

Please sign in to comment.