-
Notifications
You must be signed in to change notification settings - Fork 460
feat(ui): add Mosaic Badge component #9221
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
Changes from all commits
2f24dfe
d0a3fcd
ba4d13a
dfb8912
5406ee6
8e4e83b
49c80c2
890fc06
3401708
d9eb41d
c07c514
3a910e0
4ba9759
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import * as BadgeStories from './badge.stories'; | ||
|
|
||
| # Badge | ||
|
|
||
| Badge labels the status or category of the thing next to it. It renders a `span` by default and forwards a ref to the underlying element; use the `render` prop when the badge belongs in a different element, such as a link. Its `color` carries meaning, so keep the label itself self-describing for anyone who can't see it. | ||
|
|
||
| ## Playground | ||
|
|
||
| <Preview | ||
| name='Primary' | ||
| storyModule={BadgeStories} | ||
| /> | ||
|
|
||
| ## Props | ||
|
|
||
| <PropTable | ||
| meta={BadgeStories.meta} | ||
| extra={[{ name: 'render', type: '(props) => ReactNode' }]} | ||
| sx={false} | ||
| /> | ||
|
|
||
| ## Usage | ||
|
|
||
| <Usage | ||
| component='Badge' | ||
| module='@clerk/ui/mosaic/components/badge' | ||
| > | ||
| Badge Label | ||
| </Usage> | ||
|
|
||
| --- | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Colors | ||
|
|
||
| <Story | ||
| name='Colors' | ||
| storyModule={BadgeStories} | ||
| /> | ||
|
|
||
| ### With an icon | ||
|
|
||
| <Story | ||
| name='WithIcon' | ||
| storyModule={BadgeStories} | ||
| /> |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,95 @@ | ||||||||||||||
| import type { BadgeProps } from '@clerk/ui/mosaic/components/badge'; | ||||||||||||||
| import { Badge } from '@clerk/ui/mosaic/components/badge'; | ||||||||||||||
|
Comment on lines
+1
to
+2
Contributor
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. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Add the required Emotion JSX pragma. This story renders a styled Mosaic component but lacks the required top-level +/** `@jsxImportSource` `@emotion/react` */
+
import type { BadgeProps } from '`@clerk/ui/mosaic/components/badge`';As per coding guidelines, “Use Emotion pragma 📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||||||
|
|
||||||||||||||
| import type { StoryMeta } from '@/lib/types'; | ||||||||||||||
|
|
||||||||||||||
| // Exposes this file's own source (via the `?raw` webpack rule) so each `<Story>` example | ||||||||||||||
| // renders a code footer with its function's source. See `StoryModule.__source`. | ||||||||||||||
| export { default as __source } from './badge.stories?raw'; | ||||||||||||||
|
|
||||||||||||||
| // StyleX has no runtime recipe to derive knobs from, so the variant surface is described | ||||||||||||||
| // here to drive the playground + prop table. Keys mirror `BadgeProps`. | ||||||||||||||
| export const meta: StoryMeta = { | ||||||||||||||
| group: 'Components', | ||||||||||||||
| title: 'Badge', | ||||||||||||||
| source: 'packages/ui/src/mosaic/components/badge/badge.tsx', | ||||||||||||||
| styles: { | ||||||||||||||
| _variants: { | ||||||||||||||
| color: { primary: {}, neutral: {}, warning: {}, negative: {}, positive: {} }, | ||||||||||||||
| }, | ||||||||||||||
| _defaultVariants: { | ||||||||||||||
| color: 'primary', | ||||||||||||||
| }, | ||||||||||||||
| }, | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| // Story functions accept Record<string,unknown> (knob values) and cast to BadgeProps. | ||||||||||||||
| // The cast is unavoidable: knobs are dynamically typed; Badge has a strict prop interface. | ||||||||||||||
| function knobsAsProps(props: Record<string, unknown>) { | ||||||||||||||
| return props as unknown as BadgeProps; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export function Primary(props: Record<string, unknown>) { | ||||||||||||||
| return <Badge {...knobsAsProps(props)}>Badge Label</Badge>; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export function Colors(props: Record<string, unknown>) { | ||||||||||||||
| return ( | ||||||||||||||
| <div style={{ display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' }}> | ||||||||||||||
| <Badge | ||||||||||||||
| {...knobsAsProps(props)} | ||||||||||||||
| color='primary' | ||||||||||||||
| > | ||||||||||||||
| Primary | ||||||||||||||
| </Badge> | ||||||||||||||
| <Badge | ||||||||||||||
| {...knobsAsProps(props)} | ||||||||||||||
| color='neutral' | ||||||||||||||
| > | ||||||||||||||
| Neutral | ||||||||||||||
| </Badge> | ||||||||||||||
| <Badge | ||||||||||||||
| {...knobsAsProps(props)} | ||||||||||||||
| color='warning' | ||||||||||||||
| > | ||||||||||||||
| Warning | ||||||||||||||
| </Badge> | ||||||||||||||
| <Badge | ||||||||||||||
| {...knobsAsProps(props)} | ||||||||||||||
| color='negative' | ||||||||||||||
| > | ||||||||||||||
| Negative | ||||||||||||||
| </Badge> | ||||||||||||||
| <Badge | ||||||||||||||
| {...knobsAsProps(props)} | ||||||||||||||
| color='positive' | ||||||||||||||
| > | ||||||||||||||
| Positive | ||||||||||||||
| </Badge> | ||||||||||||||
| </div> | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export function WithIcon(props: Record<string, unknown>) { | ||||||||||||||
| return ( | ||||||||||||||
| <Badge | ||||||||||||||
| {...knobsAsProps(props)} | ||||||||||||||
| color='positive' | ||||||||||||||
| > | ||||||||||||||
| <svg | ||||||||||||||
| width='10' | ||||||||||||||
| height='10' | ||||||||||||||
| viewBox='0 0 24 24' | ||||||||||||||
| fill='none' | ||||||||||||||
| stroke='currentColor' | ||||||||||||||
| strokeWidth='3' | ||||||||||||||
| strokeLinecap='round' | ||||||||||||||
| strokeLinejoin='round' | ||||||||||||||
| style={{ flexShrink: 0 }} | ||||||||||||||
| > | ||||||||||||||
| <path d='M20 6 9 17l-5-5' /> | ||||||||||||||
| </svg> | ||||||||||||||
| Verified | ||||||||||||||
| </Badge> | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
|
|
||
| import { colorVars, radiusVars, space, typeScaleVars } from '../../tokens.stylex'; | ||
|
|
||
| // warning/negative/positive tint a faded fill and use the saturated token as text; | ||
| // primary/neutral fill with the solid token and use its `-foreground` for text. | ||
| export const styles = stylex.create({ | ||
| base: { | ||
| borderRadius: radiusVars['--cl-radius-full'], | ||
| gap: space['1'], | ||
| paddingInline: space['2'], | ||
| alignItems: 'center', | ||
| boxSizing: 'border-box', | ||
| display: 'inline-flex', | ||
| fontFamily: 'inherit', | ||
| fontSize: typeScaleVars['--cl-text-label-sm-size'], | ||
| fontWeight: typeScaleVars['--cl-text-label-sm-weight'], | ||
| justifyContent: 'center', | ||
| lineHeight: typeScaleVars['--cl-text-label-sm-leading'], | ||
| whiteSpace: 'nowrap', | ||
| height: space['5'], | ||
| }, | ||
| }); | ||
|
|
||
| export const colors = stylex.create({ | ||
| primary: { | ||
| backgroundColor: colorVars['--cl-color-primary'], | ||
| color: colorVars['--cl-color-primary-foreground'], | ||
| }, | ||
| neutral: { | ||
| backgroundColor: colorVars['--cl-color-neutral'], | ||
| color: colorVars['--cl-color-neutral-foreground'], | ||
| }, | ||
| warning: { | ||
| backgroundColor: colorVars['--cl-color-warning-faded'], | ||
| color: colorVars['--cl-color-warning'], | ||
| }, | ||
| negative: { | ||
| backgroundColor: colorVars['--cl-color-negative-faded'], | ||
| color: colorVars['--cl-color-negative'], | ||
| }, | ||
| positive: { | ||
| backgroundColor: colorVars['--cl-color-positive-faded'], | ||
| color: colorVars['--cl-color-positive'], | ||
| }, | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.