-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tag): add "surface" intent #2279
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
/** | ||
|
@@ -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'> | ||
Comment on lines
+23
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is being done here is to prevent unwanted combinations. <Tag design="tinted" intent="surface"> // ❌ TS will raise an error
<Tag design="outlined" intent="surface"> // ❌ TS will raise an error
<Tag design="filled" intent="surface"> // ✅ |
||
|
||
export type TagProps = BaseTagProps & ValidTagDesignIntent | ||
|
||
export const Tag = forwardRef<HTMLButtonElement, TagProps>( | ||
({ design = 'filled', intent = 'basic', asChild, className, ...others }, ref) => { | ||
const Component = asChild ? Slot : 'span' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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']), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, yes. Otherwise, we lose the autocompletion / intellisense. This is due to a limitation of the Tailwind ESLint plugin's typings, which cannot handle very large objects, if I recall correctly |
||
}, | ||
] as const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the
any
😅, but without it, TS will complain because it can't infer that due to my previousif
block, we cannot have a surface of intent, with a design of outlined or tinted when we end up hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be ashamed!