Repository navigation
feat(mosaic): export Card, Field, the Switcher's parts, and more glyphs #10854
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
6281834
f401656
077c24b
668ef78
37e1ec6
7cc3ace
31376a8
50243c3
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,11 @@ | ||
| --- | ||
| '@clerk/mosaic': patch | ||
| --- | ||
|
|
||
| Add component entry points: | ||
|
|
||
| - `Card` from `@clerk/mosaic/components/card` and `Field` from `@clerk/mosaic/components/field` | ||
| - `Popover` from `@clerk/mosaic/components/popover` | ||
| - `ProviderButton` and `ProviderButtonGroup` from `@clerk/mosaic/components/provider-button` | ||
| - `Switcher` from `@clerk/mosaic/components/switcher`: `Switcher.Root`, `Switcher.Trigger` and `Switcher.Popup`, and the content parts `Switcher.Header`, `Switcher.Separator`, `Switcher.Group`, `Switcher.Item` (with `ItemMedia`, `ItemContent`, `ItemLabel`, `ItemDescription` and `ItemTrailing`), `Switcher.Avatar` and `Switcher.BadgedAvatar`. `UserButton` and `OrganizationSwitcher` are built from them | ||
| - The `Building`, `Checkmark`, `ChevronDown`, `ChevronRight`, `Cog6Teeth`, `EllipsisHorizontal`, `Key`, `SecurityLockSquare`, `SecurityPhone`, `SignOut`, `SwitchAccount` and `UsersAddRight` glyphs from `@clerk/mosaic/icons/glyphs/<name>` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| 'use client'; | ||
|
|
||
| /** | ||
| * The account and organization switcher. `Switcher.Root` holds the open state, `Switcher.Trigger` | ||
| * opens it, and `Switcher.Popup` positions a card holding `Switcher.Header` and `Switcher.Group`s | ||
| * of `Switcher.Item`s. `UserButton`, `OrganizationSwitcher` and `Switcher` from `@clerk/mosaic` | ||
| * compose these parts with Clerk's session and organization state. | ||
| * | ||
| * ```tsx | ||
| * <Switcher.Root> | ||
| * <Switcher.Trigger | ||
| * aria-label='Open account menu' | ||
| * avatar={<Switcher.BadgedAvatar name='Acme' badge={{ name: 'Alice Smith' }} size='sm' />} | ||
| * name='Acme' | ||
| * badge='Pro' | ||
| * variant='full' | ||
| * /> | ||
| * <Switcher.Popup aria-label='Account menu'> | ||
| * <Switcher.Header | ||
| * avatar={<Switcher.BadgedAvatar name='Acme' badge={{ name: 'Alice Smith' }} size='md' />} | ||
| * title='Acme' | ||
| * description='alice@example.com' | ||
| * /> | ||
| * <Switcher.Separator /> | ||
| * <Switcher.Group> | ||
| * <Switcher.Item render={<button type='button' />}> | ||
| * <Switcher.ItemMedia> | ||
| * <Switcher.Avatar name='Globex' shape='square' size='sm' /> | ||
| * </Switcher.ItemMedia> | ||
| * <Switcher.ItemContent> | ||
| * <Switcher.ItemLabel>Globex</Switcher.ItemLabel> | ||
| * <Switcher.ItemDescription>Member</Switcher.ItemDescription> | ||
| * </Switcher.ItemContent> | ||
| * <Switcher.ItemTrailing>…</Switcher.ItemTrailing> | ||
| * </Switcher.Item> | ||
| * </Switcher.Group> | ||
| * </Switcher.Popup> | ||
| * </Switcher.Root> | ||
| * ``` | ||
| */ | ||
| export * as Switcher from './switcher.parts'; | ||
| export type { SwitcherAvatarProps, SwitcherBadgedAvatarProps } from './switcher-avatar'; | ||
| export type { SwitcherHeaderProps } from './switcher-header'; | ||
| export type { | ||
| SwitcherGroupProps, | ||
| SwitcherItemContentProps, | ||
| SwitcherItemDescriptionProps, | ||
| SwitcherItemLabelProps, | ||
| SwitcherItemMediaProps, | ||
| SwitcherItemProps, | ||
| SwitcherItemTrailingProps, | ||
| SwitcherSeparatorProps, | ||
| } from './switcher-item'; | ||
| export type { SwitcherPopupProps } from './switcher-popup'; | ||
| export type { SwitcherRootProps } from './switcher-root'; | ||
| export type { SwitcherTriggerProps, SwitcherTriggerVariant } from './switcher-trigger'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| 'use client'; | ||
|
|
||
| import * as stylex from '@stylexjs/stylex'; | ||
| import React from 'react'; | ||
|
|
||
|
|
@@ -7,10 +9,18 @@ import { mergeStyleProps, themeProps } from '../../props'; | |
| import { focusOutline } from '../../styles/focus-outline.styles'; | ||
| import { reset } from '../../styles/reset.styles'; | ||
| import { truncationStyles } from '../../styles/typography.styles'; | ||
| import { useSlot } from './switcher.context'; | ||
| import { styles } from './switcher-item.styles'; | ||
| import { useSlot } from './switcher-surface'; | ||
|
|
||
| export const SwitcherItem = React.forwardRef<HTMLDivElement, MosaicComponentProps<'div'>>(function SwitcherItem( | ||
| export type SwitcherItemProps = MosaicComponentProps<'div'>; | ||
| export type SwitcherItemMediaProps = MosaicElementProps<'div'>; | ||
| export type SwitcherItemContentProps = MosaicElementProps<'div'>; | ||
| export type SwitcherItemDescriptionProps = MosaicElementProps<'div'>; | ||
| export type SwitcherItemTrailingProps = MosaicElementProps<'div'>; | ||
| export type SwitcherGroupProps = MosaicElementProps<'div'>; | ||
| export type SwitcherSeparatorProps = MosaicElementProps<'hr'>; | ||
|
|
||
| export const SwitcherItem = React.forwardRef<HTMLDivElement, SwitcherItemProps>(function SwitcherItem( | ||
| { render, xstyle, ...rest }, | ||
| ref, | ||
| ) { | ||
|
|
@@ -28,14 +38,14 @@ export const SwitcherItem = React.forwardRef<HTMLDivElement, MosaicComponentProp | |
| }); | ||
| }); | ||
|
|
||
| export function SwitcherItemMedia({ xstyle, ...rest }: MosaicElementProps<'div'>) { | ||
| export function SwitcherItemMedia({ xstyle, ...rest }: SwitcherItemMediaProps) { | ||
|
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. Forward refs from the newly exported element parts.
Use
|
||
| const slot = useSlot(); | ||
| return ( | ||
| <div {...mergeStyleProps(themeProps(slot('item-media')), stylex.props(reset.base, styles.media, xstyle), rest)} /> | ||
| ); | ||
| } | ||
|
|
||
| export function SwitcherItemContent({ xstyle, ...rest }: MosaicElementProps<'div'>) { | ||
| export function SwitcherItemContent({ xstyle, ...rest }: SwitcherItemContentProps) { | ||
| const slot = useSlot(); | ||
| return ( | ||
| <div | ||
|
|
@@ -74,7 +84,7 @@ export function SwitcherItemLabel({ variant = 'default', xstyle, ...rest }: Swit | |
| ); | ||
| } | ||
|
|
||
| export function SwitcherItemDescription({ xstyle, ...rest }: MosaicElementProps<'div'>) { | ||
| export function SwitcherItemDescription({ xstyle, ...rest }: SwitcherItemDescriptionProps) { | ||
| const slot = useSlot(); | ||
| return ( | ||
| <div | ||
|
|
@@ -87,7 +97,7 @@ export function SwitcherItemDescription({ xstyle, ...rest }: MosaicElementProps< | |
| ); | ||
| } | ||
|
|
||
| export function SwitcherItemTrailing({ xstyle, ...rest }: MosaicElementProps<'div'>) { | ||
| export function SwitcherItemTrailing({ xstyle, ...rest }: SwitcherItemTrailingProps) { | ||
| const slot = useSlot(); | ||
| return ( | ||
| <div | ||
|
|
@@ -96,12 +106,12 @@ export function SwitcherItemTrailing({ xstyle, ...rest }: MosaicElementProps<'di | |
| ); | ||
| } | ||
|
|
||
| export function SwitcherGroup({ xstyle, ...rest }: MosaicElementProps<'div'>) { | ||
| export function SwitcherGroup({ xstyle, ...rest }: SwitcherGroupProps) { | ||
| const slot = useSlot(); | ||
| return <div {...mergeStyleProps(themeProps(slot('group')), stylex.props(reset.base, styles.group, xstyle), rest)} />; | ||
| } | ||
|
|
||
| export function SwitcherSeparator({ xstyle, ...rest }: MosaicElementProps<'hr'>) { | ||
| export function SwitcherSeparator({ xstyle, ...rest }: SwitcherSeparatorProps) { | ||
| const slot = useSlot(); | ||
| return ( | ||
| <hr {...mergeStyleProps(themeProps(slot('separator')), stylex.props(reset.base, styles.separator, xstyle), rest)} /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
|
|
||
| export const styles = stylex.create({ | ||
| popup: { | ||
| width: 'min(21.875rem, calc(100vw - 2rem))', | ||
| }, | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.
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.
CardandFieldfail in Server Components because their barrels are client modules.The
'use client'directive incard/index.tsandfield/index.tsmakes each barrel a client module.export * as Cardthen becomes a client reference. A Server Component that renders<Card.Root>or<Field.Root>dot-accesses that reference, and React throws error#591.Removing the barrel directive does not fix this. The leaf modules
card.tsxandfield.tsxdo not keep the client boundary in the published output. The build uses tsdown, which runs on rolldown. Rolldown drops a'use client'directive from a non-entry module that is merged into an entry chunk. Without the barrel directive,dist/components/card.jsanddist/components/field.jslose their top-level directive.scripts/check-bundle.mjsrejects entries without it, and the entries would evaluate on the server.Make the
CardandFieldnamespaces usable from Server Components, and keep the publishedcomponents/cardandcomponents/fieldentries marked as client modules. Choose how the directive survives the bundle, or how the parts are exposed. Then confirm thatcheck-bundlepasses and that a Server Component can render<Card.Root>without error.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.
Confirmed this is real for direct use in a Server Component: each export of a
'use client'module becomes a client reference, soCard.Rootis undefined on the server. It's pre-existing, though: main already publishescomponents/table,panel,section, andprofilewith the same'use client'+export * as Xshape, and Card/Field follow it so they passcheck-bundle. Removing the directive doesn't fix it (the entry loses its boundary and check-bundle fails). The real fix applies to every namespace entry (flat named client exports alongside the namespace, or per-part client references through an unbundled build), so I'll take it in a follow-up rather than diverge from the existing entries here.