From 62818348c933485fc3a4b67ba729370e9f77f52a Mon Sep 17 00:00:00 2001 From: Max Yinger Date: Mon, 16 Nov 2026 22:56:18 -0700 Subject: [PATCH 1/8] feat(mosaic): export Card, Field, the Switcher's parts, and more glyphs So a page can rebuild these components on static data from the same parts Mosaic draws them with, the way the clerk.com /ui figure rebuilds the profile. `SwitcherTriggerButton` carries the trigger's look on a plain button; the popover trigger now shares its content and styles. Co-Authored-By: Claude Opus 5.5 --- .changeset/mosaic-card-field-entry-points.md | 5 + packages/mosaic/package.json | 75 ++++++++++++++ .../mosaic/src/components/switcher/index.ts | 21 ++++ .../src/features/switcher/switcher.view.tsx | 98 ++++++++++++++++--- packages/mosaic/tsdown.config.mts | 15 +++ 5 files changed, 200 insertions(+), 14 deletions(-) create mode 100644 .changeset/mosaic-card-field-entry-points.md create mode 100644 packages/mosaic/src/components/switcher/index.ts diff --git a/.changeset/mosaic-card-field-entry-points.md b/.changeset/mosaic-card-field-entry-points.md new file mode 100644 index 00000000000..fd716d8c5ee --- /dev/null +++ b/.changeset/mosaic-card-field-entry-points.md @@ -0,0 +1,5 @@ +--- +'@clerk/mosaic': patch +--- + +Export `Card` and `Field` from `@clerk/mosaic/components/card` and `@clerk/mosaic/components/field`, the Switcher's presentational parts (`SwitcherItem` and its slots, `SwitcherGroup`, `SwitcherSeparator`, `SwitcherHeader`, `RowAvatar`, `BadgedAvatar`, and `SwitcherTriggerButton`, the trigger's look on a plain button) from `@clerk/mosaic/components/switcher`, and the `Building`, `Checkmark`, `ChevronDown`, `ChevronRight`, `Cog6Teeth`, `EllipsisHorizontal`, `Key`, `SecurityLockSquare`, `SecurityPhone`, `SignOut`, `SwitchAccount` and `UsersAddRight` glyphs from `@clerk/mosaic/icons/glyphs/`, so a page can rebuild these components on static data. diff --git a/packages/mosaic/package.json b/packages/mosaic/package.json index b73407d8ff9..b61d38b9d19 100644 --- a/packages/mosaic/package.json +++ b/packages/mosaic/package.json @@ -56,6 +56,11 @@ "import": "./dist/components/button.js", "default": "./dist/components/button.js" }, + "./components/card": { + "types": "./dist/components/card.d.ts", + "import": "./dist/components/card.js", + "default": "./dist/components/card.js" + }, "./components/data-list": { "types": "./dist/components/data-list.d.ts", "import": "./dist/components/data-list.js", @@ -71,6 +76,11 @@ "import": "./dist/components/entity.js", "default": "./dist/components/entity.js" }, + "./components/field": { + "types": "./dist/components/field.d.ts", + "import": "./dist/components/field.js", + "default": "./dist/components/field.js" + }, "./components/heading": { "types": "./dist/components/heading.d.ts", "import": "./dist/components/heading.js", @@ -121,6 +131,11 @@ "import": "./dist/components/skeleton.js", "default": "./dist/components/skeleton.js" }, + "./components/switcher": { + "types": "./dist/components/switcher.d.ts", + "import": "./dist/components/switcher.js", + "default": "./dist/components/switcher.js" + }, "./components/table": { "types": "./dist/components/table.d.ts", "import": "./dist/components/table.js", @@ -136,31 +151,91 @@ "import": "./dist/icons/glyphs/arrow-up-right.js", "default": "./dist/icons/glyphs/arrow-up-right.js" }, + "./icons/glyphs/building": { + "types": "./dist/icons/glyphs/building.d.ts", + "import": "./dist/icons/glyphs/building.js", + "default": "./dist/icons/glyphs/building.js" + }, + "./icons/glyphs/checkmark": { + "types": "./dist/icons/glyphs/checkmark.d.ts", + "import": "./dist/icons/glyphs/checkmark.js", + "default": "./dist/icons/glyphs/checkmark.js" + }, + "./icons/glyphs/chevron-down": { + "types": "./dist/icons/glyphs/chevron-down.d.ts", + "import": "./dist/icons/glyphs/chevron-down.js", + "default": "./dist/icons/glyphs/chevron-down.js" + }, + "./icons/glyphs/chevron-right": { + "types": "./dist/icons/glyphs/chevron-right.d.ts", + "import": "./dist/icons/glyphs/chevron-right.js", + "default": "./dist/icons/glyphs/chevron-right.js" + }, "./icons/glyphs/code": { "types": "./dist/icons/glyphs/code.d.ts", "import": "./dist/icons/glyphs/code.js", "default": "./dist/icons/glyphs/code.js" }, + "./icons/glyphs/cog-6-teeth": { + "types": "./dist/icons/glyphs/cog-6-teeth.d.ts", + "import": "./dist/icons/glyphs/cog-6-teeth.js", + "default": "./dist/icons/glyphs/cog-6-teeth.js" + }, + "./icons/glyphs/ellipsis-horizontal": { + "types": "./dist/icons/glyphs/ellipsis-horizontal.d.ts", + "import": "./dist/icons/glyphs/ellipsis-horizontal.js", + "default": "./dist/icons/glyphs/ellipsis-horizontal.js" + }, "./icons/glyphs/external": { "types": "./dist/icons/glyphs/external.d.ts", "import": "./dist/icons/glyphs/external.js", "default": "./dist/icons/glyphs/external.js" }, + "./icons/glyphs/key": { + "types": "./dist/icons/glyphs/key.d.ts", + "import": "./dist/icons/glyphs/key.js", + "default": "./dist/icons/glyphs/key.js" + }, "./icons/glyphs/plus": { "types": "./dist/icons/glyphs/plus.d.ts", "import": "./dist/icons/glyphs/plus.js", "default": "./dist/icons/glyphs/plus.js" }, + "./icons/glyphs/security-lock-square": { + "types": "./dist/icons/glyphs/security-lock-square.d.ts", + "import": "./dist/icons/glyphs/security-lock-square.js", + "default": "./dist/icons/glyphs/security-lock-square.js" + }, + "./icons/glyphs/security-phone": { + "types": "./dist/icons/glyphs/security-phone.d.ts", + "import": "./dist/icons/glyphs/security-phone.js", + "default": "./dist/icons/glyphs/security-phone.js" + }, "./icons/glyphs/shield-check": { "types": "./dist/icons/glyphs/shield-check.d.ts", "import": "./dist/icons/glyphs/shield-check.js", "default": "./dist/icons/glyphs/shield-check.js" }, + "./icons/glyphs/sign-out": { + "types": "./dist/icons/glyphs/sign-out.d.ts", + "import": "./dist/icons/glyphs/sign-out.js", + "default": "./dist/icons/glyphs/sign-out.js" + }, + "./icons/glyphs/switch-account": { + "types": "./dist/icons/glyphs/switch-account.d.ts", + "import": "./dist/icons/glyphs/switch-account.js", + "default": "./dist/icons/glyphs/switch-account.js" + }, "./icons/glyphs/user-circle": { "types": "./dist/icons/glyphs/user-circle.d.ts", "import": "./dist/icons/glyphs/user-circle.js", "default": "./dist/icons/glyphs/user-circle.js" }, + "./icons/glyphs/users-add-right": { + "types": "./dist/icons/glyphs/users-add-right.d.ts", + "import": "./dist/icons/glyphs/users-add-right.js", + "default": "./dist/icons/glyphs/users-add-right.js" + }, "./styles.css": { "types": "./styles.css.d.ts", "default": "./dist/styles.css" diff --git a/packages/mosaic/src/components/switcher/index.ts b/packages/mosaic/src/components/switcher/index.ts new file mode 100644 index 00000000000..b2c26950bb1 --- /dev/null +++ b/packages/mosaic/src/components/switcher/index.ts @@ -0,0 +1,21 @@ +'use client'; + +// The Switcher's presentational parts, for rebuilding the switcher on static data (a marketing figure or +// a docs illustration). The working component is `UserButton` / `OrganizationSwitcher`. +export type { BadgedAvatarProps, RowAvatarProps } from '../../features/switcher/switcher-avatar.view'; +export { BadgedAvatar, RowAvatar } from '../../features/switcher/switcher-avatar.view'; +export type { SwitcherHeaderProps } from '../../features/switcher/switcher-header.view'; +export { SwitcherHeader } from '../../features/switcher/switcher-header.view'; +export type { SwitcherItemLabelProps } from '../../features/switcher/switcher-item.view'; +export { + SwitcherGroup, + SwitcherItem, + SwitcherItemContent, + SwitcherItemDescription, + SwitcherItemLabel, + SwitcherItemMedia, + SwitcherItemTrailing, + SwitcherSeparator, +} from '../../features/switcher/switcher-item.view'; +export type { SwitcherTriggerButtonProps } from '../../features/switcher/switcher.view'; +export { SwitcherTriggerButton } from '../../features/switcher/switcher.view'; diff --git a/packages/mosaic/src/features/switcher/switcher.view.tsx b/packages/mosaic/src/features/switcher/switcher.view.tsx index 0c6ab1e0d49..f2b233e3cde 100644 --- a/packages/mosaic/src/features/switcher/switcher.view.tsx +++ b/packages/mosaic/src/features/switcher/switcher.view.tsx @@ -26,9 +26,11 @@ import { UsersAddRight } from '../../icons/glyphs/users-add-right'; import { fill, plural, useLocale, useMessages } from '../../localization'; import { Button as HeadlessButton } from '../../primitives/button'; import type { PopoverProps } from '../../primitives/popover'; +import type { MosaicElementProps } from '../../props'; import { mergeStyleProps, themeProps } from '../../props'; import { focusOutline } from '../../styles/focus-outline.styles'; import { rtl } from '../../styles/rtl.styles'; +import { reset } from '../../styles/reset.styles'; import { truncationStyles } from '../../styles/typography.styles'; import { applyOrder } from '../../utils/apply-order'; import type { SwitcherLayout } from './switcher.layout'; @@ -1062,18 +1064,48 @@ export function SwitcherTrigger({ - + } + name={showTriggerLabel ? name : undefined} + badge={typeof planLabel === 'string' ? planLabel : undefined} + badgeId={badge?.id} /> - {showTriggerLabel ? ( + + ); +} + +function triggerStyles(showLabel: boolean, shape: 'circle' | 'square') { + return [ + focusOutline.visible, + styles.trigger, + showLabel ? styles.triggerLabelled : styles.triggerAvatarOnly, + !showLabel && shape === 'circle' ? styles.triggerRound : null, + ]; +} + +function SwitcherTriggerContent({ + avatar, + name, + badge, + badgeId, +}: { + avatar: ReactNode; + name?: string; + badge?: string; + badgeId?: string; +}): ReactElement { + const slot = useSlot(); + return ( + <> + {avatar} + {name ? ( <> {name} - {typeof planLabel === 'string' ? ( + {badge ? ( - {planLabel} + {badge} ) : null} ) : null} - + + ); +} + +export interface SwitcherTriggerButtonProps extends Omit, 'children'> { + /** The lead's mark, such as a `BadgedAvatar`. */ + avatar: ReactNode; + /** The lead's name. Leave it out for the avatar-only trigger. */ + name?: string; + /** A plan or status label beside the name. */ + badge?: string; + shape?: 'circle' | 'square'; +} + +/** The trigger's look on a plain button, without the popover it opens: for showing the trigger on its own. */ +export function SwitcherTriggerButton({ + avatar, + name, + badge, + shape = 'square', + xstyle, + ...rest +}: SwitcherTriggerButtonProps): ReactElement { + const slot = useSlot(); + return ( + ); } diff --git a/packages/mosaic/tsdown.config.mts b/packages/mosaic/tsdown.config.mts index a9d87fc30e0..3f50d8eac4f 100644 --- a/packages/mosaic/tsdown.config.mts +++ b/packages/mosaic/tsdown.config.mts @@ -18,11 +18,13 @@ export default defineConfig({ 'components/action-menu': './src/components/action-menu/index.ts', 'components/avatar': './src/components/avatar/index.ts', 'components/badge': './src/components/badge/index.ts', + 'components/card': './src/components/card/index.ts', 'components/banner': './src/components/banner/index.ts', 'components/button': './src/components/button/index.ts', 'components/data-list': './src/components/data-list/index.ts', 'components/empty-state': './src/components/empty-state/index.ts', 'components/entity': './src/components/entity/index.ts', + 'components/field': './src/components/field/index.ts', 'components/heading': './src/components/heading/index.ts', 'components/icon': './src/components/icon/index.ts', 'components/input': './src/components/input/index.ts', @@ -33,14 +35,27 @@ export default defineConfig({ 'components/section': './src/components/section/index.ts', 'components/segmented-control': './src/components/segmented-control/index.ts', 'components/skeleton': './src/components/skeleton/index.ts', + 'components/switcher': './src/components/switcher/index.ts', 'components/table': './src/components/table/index.ts', 'components/text': './src/components/text/index.ts', 'icons/glyphs/arrow-up-right': './src/icons/glyphs/arrow-up-right.tsx', + 'icons/glyphs/building': './src/icons/glyphs/building.tsx', + 'icons/glyphs/checkmark': './src/icons/glyphs/checkmark.tsx', + 'icons/glyphs/chevron-down': './src/icons/glyphs/chevron-down.tsx', + 'icons/glyphs/chevron-right': './src/icons/glyphs/chevron-right.tsx', 'icons/glyphs/code': './src/icons/glyphs/code.tsx', + 'icons/glyphs/cog-6-teeth': './src/icons/glyphs/cog-6-teeth.tsx', + 'icons/glyphs/ellipsis-horizontal': './src/icons/glyphs/ellipsis-horizontal.tsx', 'icons/glyphs/external': './src/icons/glyphs/external.tsx', + 'icons/glyphs/key': './src/icons/glyphs/key.tsx', 'icons/glyphs/plus': './src/icons/glyphs/plus.tsx', + 'icons/glyphs/security-lock-square': './src/icons/glyphs/security-lock-square.tsx', + 'icons/glyphs/security-phone': './src/icons/glyphs/security-phone.tsx', 'icons/glyphs/shield-check': './src/icons/glyphs/shield-check.tsx', + 'icons/glyphs/sign-out': './src/icons/glyphs/sign-out.tsx', + 'icons/glyphs/switch-account': './src/icons/glyphs/switch-account.tsx', 'icons/glyphs/user-circle': './src/icons/glyphs/user-circle.tsx', + 'icons/glyphs/users-add-right': './src/icons/glyphs/users-add-right.tsx', }, outDir: './dist', format: ['esm'], From f401656a63c92d60fdd638cc9f6601ee55736874 Mon Sep 17 00:00:00 2001 From: Max Yinger Date: Tue, 17 Nov 2026 12:05:18 -0700 Subject: [PATCH 2/8] feat(mosaic): export ProviderButton and ProviderButtonGroup Co-Authored-By: Claude Opus 5.5 --- .changeset/mosaic-card-field-entry-points.md | 2 +- packages/mosaic/package.json | 5 +++++ packages/mosaic/src/components/provider-button/index.ts | 2 ++ packages/mosaic/tsdown.config.mts | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.changeset/mosaic-card-field-entry-points.md b/.changeset/mosaic-card-field-entry-points.md index fd716d8c5ee..bca890fe55e 100644 --- a/.changeset/mosaic-card-field-entry-points.md +++ b/.changeset/mosaic-card-field-entry-points.md @@ -2,4 +2,4 @@ '@clerk/mosaic': patch --- -Export `Card` and `Field` from `@clerk/mosaic/components/card` and `@clerk/mosaic/components/field`, the Switcher's presentational parts (`SwitcherItem` and its slots, `SwitcherGroup`, `SwitcherSeparator`, `SwitcherHeader`, `RowAvatar`, `BadgedAvatar`, and `SwitcherTriggerButton`, the trigger's look on a plain button) from `@clerk/mosaic/components/switcher`, and the `Building`, `Checkmark`, `ChevronDown`, `ChevronRight`, `Cog6Teeth`, `EllipsisHorizontal`, `Key`, `SecurityLockSquare`, `SecurityPhone`, `SignOut`, `SwitchAccount` and `UsersAddRight` glyphs from `@clerk/mosaic/icons/glyphs/`, so a page can rebuild these components on static data. +Export `Card` and `Field` from `@clerk/mosaic/components/card` and `@clerk/mosaic/components/field`, `ProviderButton` and `ProviderButtonGroup` from `@clerk/mosaic/components/provider-button`, the Switcher's presentational parts (`SwitcherItem` and its slots, `SwitcherGroup`, `SwitcherSeparator`, `SwitcherHeader`, `RowAvatar`, `BadgedAvatar`, and `SwitcherTriggerButton`, the trigger's look on a plain button) from `@clerk/mosaic/components/switcher`, and the `Building`, `Checkmark`, `ChevronDown`, `ChevronRight`, `Cog6Teeth`, `EllipsisHorizontal`, `Key`, `SecurityLockSquare`, `SecurityPhone`, `SignOut`, `SwitchAccount` and `UsersAddRight` glyphs from `@clerk/mosaic/icons/glyphs/`, so a page can rebuild these components on static data. diff --git a/packages/mosaic/package.json b/packages/mosaic/package.json index b61d38b9d19..4747aab8698 100644 --- a/packages/mosaic/package.json +++ b/packages/mosaic/package.json @@ -111,6 +111,11 @@ "import": "./dist/components/profile.js", "default": "./dist/components/profile.js" }, + "./components/provider-button": { + "types": "./dist/components/provider-button.d.ts", + "import": "./dist/components/provider-button.js", + "default": "./dist/components/provider-button.js" + }, "./components/radio": { "types": "./dist/components/radio.d.ts", "import": "./dist/components/radio.js", diff --git a/packages/mosaic/src/components/provider-button/index.ts b/packages/mosaic/src/components/provider-button/index.ts index 39f99711aa9..ce5b679537e 100644 --- a/packages/mosaic/src/components/provider-button/index.ts +++ b/packages/mosaic/src/components/provider-button/index.ts @@ -1,3 +1,5 @@ +'use client'; + export { ProviderButton } from './provider-button'; export type { ProviderButtonProps } from './provider-button'; export { ProviderButtonGroup } from './provider-button-group'; diff --git a/packages/mosaic/tsdown.config.mts b/packages/mosaic/tsdown.config.mts index 3f50d8eac4f..4ebe76e7baa 100644 --- a/packages/mosaic/tsdown.config.mts +++ b/packages/mosaic/tsdown.config.mts @@ -31,6 +31,7 @@ export default defineConfig({ 'components/item': './src/components/item/index.ts', 'components/panel': './src/components/panel/index.ts', 'components/profile': './src/components/profile/index.ts', + 'components/provider-button': './src/components/provider-button/index.ts', 'components/radio': './src/components/radio/index.ts', 'components/section': './src/components/section/index.ts', 'components/segmented-control': './src/components/segmented-control/index.ts', From 077c24b755c0659a4316fb735c1f3a1aae59a70e Mon Sep 17 00:00:00 2001 From: Max Yinger Date: Tue, 17 Nov 2026 13:43:20 -0700 Subject: [PATCH 3/8] fix(mosaic): mark the Card and Field entries as client boundaries Published entries must start with 'use client' (scripts/check-bundle.mjs), as Table, Panel, and Section do. Co-Authored-By: Claude Opus 5.5 --- packages/mosaic/src/components/card/index.ts | 2 ++ packages/mosaic/src/components/field/index.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/mosaic/src/components/card/index.ts b/packages/mosaic/src/components/card/index.ts index b78516bb3e4..0c0d86c8722 100644 --- a/packages/mosaic/src/components/card/index.ts +++ b/packages/mosaic/src/components/card/index.ts @@ -1,3 +1,5 @@ +'use client'; + /** * A styled surface composed through `Card.Root`, `Card.Header`, `Card.Media`, `Card.Title`, * `Card.Description`, `Card.Banner`, `Card.Content`, and `Card.Footer`. Every part accepts the Mosaic diff --git a/packages/mosaic/src/components/field/index.ts b/packages/mosaic/src/components/field/index.ts index 8eff98a34ad..fab7c85e755 100644 --- a/packages/mosaic/src/components/field/index.ts +++ b/packages/mosaic/src/components/field/index.ts @@ -1,3 +1,5 @@ +'use client'; + /** Styled parts for composing an automatically associated single-control field. */ export * as Field from './field.parts'; export type { From 668ef7836a2c43934c7367a5ef4c86dbd34f17d6 Mon Sep 17 00:00:00 2001 From: Max Yinger Date: Tue, 17 Nov 2026 13:54:00 -0700 Subject: [PATCH 4/8] refactor(mosaic): make Switcher a component the switcher feature uses Move the switcher's presentational parts (rows, group, separator, header, avatars, and the trigger's look) from features/switcher into a real components/switcher namespace, and have the feature compose them. The public entry now exports a `Switcher` namespace instead of reaching into feature internals. Slots and StyleX output are unchanged. Co-Authored-By: Claude Opus 5.5 --- .changeset/mosaic-card-field-entry-points.md | 2 +- .../mosaic/src/components/switcher/index.ts | 49 +++--- .../switcher/switcher-avatar.styles.ts | 0 .../switcher/switcher-avatar.tsx} | 16 +- .../switcher/switcher-header.styles.ts | 0 .../switcher/switcher-header.tsx} | 4 +- .../switcher/switcher-item.styles.ts | 0 .../switcher/switcher-item.tsx} | 26 ++- .../switcher/switcher-trigger.styles.ts | 68 ++++++++ .../components/switcher/switcher-trigger.tsx | 106 ++++++++++++ .../components/switcher/switcher.context.ts | 17 ++ .../src/components/switcher/switcher.doc.ts | 161 ++++++++++++++++++ .../src/components/switcher/switcher.parts.ts | 13 ++ .../src/components/switcher/switcher.test.tsx | 121 +++++++++++++ .../oauth-consent/oauth-consent.view.tsx | 2 +- .../organization-list.skeleton.tsx | 2 +- .../organization-list.view.tsx | 2 +- .../sign-in/steps/sign-in-accounts.tsx | 2 +- .../features/switcher/switcher-surface.tsx | 17 +- .../src/features/switcher/switcher.styles.ts | 64 +------ .../src/features/switcher/switcher.view.tsx | 128 ++------------ .../task-choose-organization.skeleton.tsx | 2 +- .../swingset/src/stories/switcher.stories.tsx | 4 +- 23 files changed, 574 insertions(+), 232 deletions(-) rename packages/mosaic/src/{features => components}/switcher/switcher-avatar.styles.ts (100%) rename packages/mosaic/src/{features/switcher/switcher-avatar.view.tsx => components/switcher/switcher-avatar.tsx} (83%) rename packages/mosaic/src/{features => components}/switcher/switcher-header.styles.ts (100%) rename packages/mosaic/src/{features/switcher/switcher-header.view.tsx => components/switcher/switcher-header.tsx} (95%) rename packages/mosaic/src/{features => components}/switcher/switcher-item.styles.ts (100%) rename packages/mosaic/src/{features/switcher/switcher-item.view.tsx => components/switcher/switcher-item.tsx} (71%) create mode 100644 packages/mosaic/src/components/switcher/switcher-trigger.styles.ts create mode 100644 packages/mosaic/src/components/switcher/switcher-trigger.tsx create mode 100644 packages/mosaic/src/components/switcher/switcher.context.ts create mode 100644 packages/mosaic/src/components/switcher/switcher.doc.ts create mode 100644 packages/mosaic/src/components/switcher/switcher.parts.ts create mode 100644 packages/mosaic/src/components/switcher/switcher.test.tsx diff --git a/.changeset/mosaic-card-field-entry-points.md b/.changeset/mosaic-card-field-entry-points.md index bca890fe55e..e8dfcdcb17a 100644 --- a/.changeset/mosaic-card-field-entry-points.md +++ b/.changeset/mosaic-card-field-entry-points.md @@ -2,4 +2,4 @@ '@clerk/mosaic': patch --- -Export `Card` and `Field` from `@clerk/mosaic/components/card` and `@clerk/mosaic/components/field`, `ProviderButton` and `ProviderButtonGroup` from `@clerk/mosaic/components/provider-button`, the Switcher's presentational parts (`SwitcherItem` and its slots, `SwitcherGroup`, `SwitcherSeparator`, `SwitcherHeader`, `RowAvatar`, `BadgedAvatar`, and `SwitcherTriggerButton`, the trigger's look on a plain button) from `@clerk/mosaic/components/switcher`, and the `Building`, `Checkmark`, `ChevronDown`, `ChevronRight`, `Cog6Teeth`, `EllipsisHorizontal`, `Key`, `SecurityLockSquare`, `SecurityPhone`, `SignOut`, `SwitchAccount` and `UsersAddRight` glyphs from `@clerk/mosaic/icons/glyphs/`, so a page can rebuild these components on static data. +Export `Card` and `Field` from `@clerk/mosaic/components/card` and `@clerk/mosaic/components/field`, `ProviderButton` and `ProviderButtonGroup` from `@clerk/mosaic/components/provider-button`, a `Switcher` component namespace from `@clerk/mosaic/components/switcher` (`Switcher.Trigger`, the trigger's look on a plain button; `Switcher.Header`; `Switcher.Avatar` and `Switcher.BadgedAvatar`; `Switcher.Group` and `Switcher.Separator`; and `Switcher.Item` with its `ItemMedia`, `ItemContent`, `ItemLabel`, `ItemDescription` and `ItemTrailing` parts), the presentational parts `UserButton` and `OrganizationSwitcher` are built from, and the `Building`, `Checkmark`, `ChevronDown`, `ChevronRight`, `Cog6Teeth`, `EllipsisHorizontal`, `Key`, `SecurityLockSquare`, `SecurityPhone`, `SignOut`, `SwitchAccount` and `UsersAddRight` glyphs from `@clerk/mosaic/icons/glyphs/`, so a page can rebuild these components on static data. diff --git a/packages/mosaic/src/components/switcher/index.ts b/packages/mosaic/src/components/switcher/index.ts index b2c26950bb1..c6e9a5fd091 100644 --- a/packages/mosaic/src/components/switcher/index.ts +++ b/packages/mosaic/src/components/switcher/index.ts @@ -1,21 +1,32 @@ 'use client'; -// The Switcher's presentational parts, for rebuilding the switcher on static data (a marketing figure or -// a docs illustration). The working component is `UserButton` / `OrganizationSwitcher`. -export type { BadgedAvatarProps, RowAvatarProps } from '../../features/switcher/switcher-avatar.view'; -export { BadgedAvatar, RowAvatar } from '../../features/switcher/switcher-avatar.view'; -export type { SwitcherHeaderProps } from '../../features/switcher/switcher-header.view'; -export { SwitcherHeader } from '../../features/switcher/switcher-header.view'; -export type { SwitcherItemLabelProps } from '../../features/switcher/switcher-item.view'; -export { - SwitcherGroup, - SwitcherItem, - SwitcherItemContent, - SwitcherItemDescription, - SwitcherItemLabel, - SwitcherItemMedia, - SwitcherItemTrailing, - SwitcherSeparator, -} from '../../features/switcher/switcher-item.view'; -export type { SwitcherTriggerButtonProps } from '../../features/switcher/switcher.view'; -export { SwitcherTriggerButton } from '../../features/switcher/switcher.view'; +/** + * The account and organization switcher's look, as parts to compose on static data, such as a + * marketing figure or a docs illustration. The working components are `UserButton`, + * `OrganizationSwitcher` and `Switcher`, which build their trigger and popover from these parts. + * + * ```tsx + * } title='Acme' /> + * + * + * + * + * Globex + * + * + * ``` + */ +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 { SwitcherTriggerProps } from './switcher-trigger'; diff --git a/packages/mosaic/src/features/switcher/switcher-avatar.styles.ts b/packages/mosaic/src/components/switcher/switcher-avatar.styles.ts similarity index 100% rename from packages/mosaic/src/features/switcher/switcher-avatar.styles.ts rename to packages/mosaic/src/components/switcher/switcher-avatar.styles.ts diff --git a/packages/mosaic/src/features/switcher/switcher-avatar.view.tsx b/packages/mosaic/src/components/switcher/switcher-avatar.tsx similarity index 83% rename from packages/mosaic/src/features/switcher/switcher-avatar.view.tsx rename to packages/mosaic/src/components/switcher/switcher-avatar.tsx index bcd9d60c2d4..2e118c1c04d 100644 --- a/packages/mosaic/src/features/switcher/switcher-avatar.view.tsx +++ b/packages/mosaic/src/components/switcher/switcher-avatar.tsx @@ -1,19 +1,21 @@ +'use client'; + import * as stylex from '@stylexjs/stylex'; import type { ReactElement } from 'react'; -import type { AvatarProps } from '../../components/avatar'; -import { Avatar } from '../../components/avatar'; import { mergeStyleProps, themeProps } from '../../props'; import { reset } from '../../styles/reset.styles'; +import type { AvatarProps } from '../avatar'; +import { Avatar } from '../avatar'; +import { useSlot } from './switcher.context'; import { sizes, styles } from './switcher-avatar.styles'; -import { useSlot } from './switcher-surface'; function initials(name: string): string { const [first = '', second = ''] = name.trim().split(/\s+/); return `${first.charAt(0)}${second.charAt(0)}`.toUpperCase() || '?'; } -export interface RowAvatarProps { +export interface SwitcherAvatarProps { name: string; imageUrl?: string; shape: 'circle' | 'square'; @@ -21,7 +23,7 @@ export interface RowAvatarProps { xstyle?: AvatarProps['xstyle']; } -export function RowAvatar({ name, imageUrl, shape, size, xstyle }: RowAvatarProps): ReactElement { +export function RowAvatar({ name, imageUrl, shape, size, xstyle }: SwitcherAvatarProps): ReactElement { return ( // Decorative: the same name is always in text alongside. Held at the root so the whole mark // stays out of the accessible name however the image resolves. @@ -42,14 +44,14 @@ export function RowAvatar({ name, imageUrl, shape, size, xstyle }: RowAvatarProp ); } -export interface BadgedAvatarProps { +export interface SwitcherBadgedAvatarProps { name: string; imageUrl?: string; badge: { name: string; imageUrl?: string }; size: 'sm' | 'md'; } -export function BadgedAvatar({ name, imageUrl, badge, size }: BadgedAvatarProps): ReactElement { +export function BadgedAvatar({ name, imageUrl, badge, size }: SwitcherBadgedAvatarProps): ReactElement { const slot = useSlot(); return ( >(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(function SwitcherItem( { render, xstyle, ...rest }, ref, ) { @@ -28,14 +38,14 @@ export const SwitcherItem = React.forwardRef) { +export function SwitcherItemMedia({ xstyle, ...rest }: SwitcherItemMediaProps) { const slot = useSlot(); return (
); } -export function SwitcherItemContent({ xstyle, ...rest }: MosaicElementProps<'div'>) { +export function SwitcherItemContent({ xstyle, ...rest }: SwitcherItemContentProps) { const slot = useSlot(); return (
) { +export function SwitcherItemDescription({ xstyle, ...rest }: SwitcherItemDescriptionProps) { const slot = useSlot(); return (
) { +export function SwitcherItemTrailing({ xstyle, ...rest }: SwitcherItemTrailingProps) { const slot = useSlot(); return (
) { +export function SwitcherGroup({ xstyle, ...rest }: SwitcherGroupProps) { const slot = useSlot(); return
; } -export function SwitcherSeparator({ xstyle, ...rest }: MosaicElementProps<'hr'>) { +export function SwitcherSeparator({ xstyle, ...rest }: SwitcherSeparatorProps) { const slot = useSlot(); return (
diff --git a/packages/mosaic/src/components/switcher/switcher-trigger.styles.ts b/packages/mosaic/src/components/switcher/switcher-trigger.styles.ts new file mode 100644 index 00000000000..433b0006c9c --- /dev/null +++ b/packages/mosaic/src/components/switcher/switcher-trigger.styles.ts @@ -0,0 +1,68 @@ +import * as stylex from '@stylexjs/stylex'; + +import { colorVars, durationVars, fontWeightVars, radiusVars, space, typeScaleVars } from '../../tokens.stylex'; + +export const styles = stylex.create({ + trigger: { + padding: 0, + borderRadius: radiusVars['--cl-radius-md'], + borderStyle: 'none', + alignItems: 'center', + backgroundColor: 'transparent', + cursor: 'pointer', + display: 'inline-flex', + transitionDuration: { + default: durationVars['--cl-duration-base'], + '@media (hover: hover)': { + default: null, + ':hover:not(:disabled, [data-disabled], [aria-disabled="true"])': durationVars['--cl-duration-instant'], + }, + }, + transitionTimingFunction: 'linear', + maxWidth: '100%', + minWidth: 0, + }, + + triggerLabelled: { + padding: space['1.5'], + borderRadius: radiusVars['--cl-radius-xl'], + gap: space['1.5'], + backgroundColor: { + default: 'transparent', + ':is([data-open])': `color-mix(in oklab, ${colorVars['--cl-color-neutral']} 4%, transparent)`, + '@media (hover: hover)': { + ':hover:not(:disabled, [data-disabled], [aria-disabled="true"])': `color-mix(in oklab, ${colorVars['--cl-color-neutral']} 4%, transparent)`, + }, + }, + transitionProperty: 'background-color', + }, + + triggerAvatarOnly: { + opacity: { + default: 1, + ':is([data-open])': 0.8, + '@media (hover: hover)': { + ':hover:not(:disabled, [data-disabled], [aria-disabled="true"])': 0.8, + }, + }, + transitionProperty: 'opacity', + }, + + triggerRound: { + borderRadius: radiusVars['--cl-radius-full'], + }, + + // Capped, because the trigger sits in a host app's chrome and a long organization name would push it apart. + triggerName: { + color: colorVars['--cl-color-foreground'], + fontSize: typeScaleVars['--cl-text-sm-size'], + fontWeight: fontWeightVars['--cl-font-medium'], + lineHeight: typeScaleVars['--cl-text-sm-leading'], + maxWidth: '12rem', + }, + + triggerCaret: { + '--_cl-icon-color': colorVars['--cl-color-foreground-secondary'], + marginInline: space['1'], + }, +}); diff --git a/packages/mosaic/src/components/switcher/switcher-trigger.tsx b/packages/mosaic/src/components/switcher/switcher-trigger.tsx new file mode 100644 index 00000000000..ebd7f1587da --- /dev/null +++ b/packages/mosaic/src/components/switcher/switcher-trigger.tsx @@ -0,0 +1,106 @@ +'use client'; + +import * as stylex from '@stylexjs/stylex'; +import type { ReactElement, ReactNode } from 'react'; + +import { ChevronDown } from '../../icons/glyphs/chevron-down'; +import type { MosaicElementProps } from '../../props'; +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 { Badge } from '../badge'; +import { Icon } from '../icon'; +import { useSlot } from './switcher.context'; +import { styles } from './switcher-trigger.styles'; + +export function triggerStyles(showLabel: boolean, shape: 'circle' | 'square') { + return [ + focusOutline.visible, + styles.trigger, + showLabel ? styles.triggerLabelled : styles.triggerAvatarOnly, + !showLabel && shape === 'circle' ? styles.triggerRound : null, + ]; +} + +export function SwitcherTriggerContent({ + avatar, + name, + badge, + badgeId, +}: { + avatar: ReactNode; + name?: string; + badge?: string; + badgeId?: string; +}): ReactElement { + const slot = useSlot(); + return ( + <> + {avatar} + {name ? ( + <> + + {name} + + {badge ? ( + + {badge} + + ) : null} + + + ) : null} + + ); +} + +export interface SwitcherTriggerProps extends Omit, 'children'> { + /** The lead's mark, such as a `Switcher.BadgedAvatar`. */ + avatar: ReactNode; + /** The lead's name. Leave it out for the avatar-only trigger. */ + name?: string; + /** A plan or status label beside the name. */ + badge?: string; + shape?: 'circle' | 'square'; +} + +/** The trigger's look on a plain button, without the popover it opens: for showing the trigger on its own. */ +export function SwitcherTriggerButton({ + avatar, + name, + badge, + shape = 'square', + xstyle, + ...rest +}: SwitcherTriggerProps): ReactElement { + const slot = useSlot(); + return ( + + ); +} diff --git a/packages/mosaic/src/components/switcher/switcher.context.ts b/packages/mosaic/src/components/switcher/switcher.context.ts new file mode 100644 index 00000000000..8a750d1654d --- /dev/null +++ b/packages/mosaic/src/components/switcher/switcher.context.ts @@ -0,0 +1,17 @@ +import React from 'react'; + +/** Which component the parts belong to. It prefixes every part's `.cl-*` class, such as `cl-user-button-item`. */ +export type SwitcherSurface = 'switcher' | 'user-button' | 'organization-switcher'; + +const SurfaceContext = React.createContext('switcher'); + +export const SwitcherSurfaceProvider = SurfaceContext.Provider; + +export function useSwitcherSurface(): SwitcherSurface { + return React.useContext(SurfaceContext); +} + +export function useSlot(): (part: string) => string { + const surface = useSwitcherSurface(); + return part => `${surface}-${part}`; +} diff --git a/packages/mosaic/src/components/switcher/switcher.doc.ts b/packages/mosaic/src/components/switcher/switcher.doc.ts new file mode 100644 index 00000000000..cabccc2f0e6 --- /dev/null +++ b/packages/mosaic/src/components/switcher/switcher.doc.ts @@ -0,0 +1,161 @@ +import type { ComponentDoc } from '../../docs-schema'; +import type { SwitcherAvatarProps, SwitcherBadgedAvatarProps } from './switcher-avatar'; +import type { SwitcherHeaderProps } from './switcher-header'; +import type { + SwitcherGroupProps, + SwitcherItemContentProps, + SwitcherItemDescriptionProps, + SwitcherItemLabelProps, + SwitcherItemMediaProps, + SwitcherItemProps, + SwitcherItemTrailingProps, + SwitcherSeparatorProps, +} from './switcher-item'; +import type { SwitcherTriggerProps } from './switcher-trigger'; + +export default { + name: 'Switcher', + description: + "The account and organization switcher's look as parts: the trigger, the popover's header, and its rows. For showing a switcher on static data. `UserButton`, `OrganizationSwitcher` and `Switcher` from `@clerk/mosaic` are the working components, built from these parts.", + useFor: [ + 'a static picture of the user button or organization switcher', + 'a marketing figure or docs illustration of the account switcher', + ], + keywords: ['switcher', 'user button', 'organization switcher', 'account switcher', 'menu rows'], + practices: [ + { + do: true, + text: 'Wrap rows in a `Switcher.Group`, and split groups with a `Switcher.Separator`.', + }, + { + do: true, + text: 'Pass `render` to `Switcher.Item` to make a row a button or link. It then takes the hover and press styles.', + }, + { + do: false, + text: 'Build a working account menu from these parts. Use `UserButton` or `OrganizationSwitcher`, which read Clerk and open the popover.', + }, + ], + parts: { + 'Switcher.Trigger': { + description: + "The trigger's look on a plain `button`, without the popover it opens. With a `name` it shows the name, the badge and a caret; without one, the avatar alone.", + slot: 'cl-switcher-trigger', + props: { + avatar: { type: 'ReactNode', doc: "The lead's mark, such as a `Switcher.BadgedAvatar`." }, + name: { type: 'string', doc: "The lead's name. Leave it out for the avatar-only trigger." }, + badge: { type: 'string', doc: 'A plan or status label beside the name.' }, + shape: { + type: "'circle' | 'square'", + doc: 'Rounds the avatar-only trigger to match a circular avatar.', + default: "'square'", + }, + }, + }, + 'Switcher.Header': { + description: "The popover's header: the lead's avatar, its name and a description.", + slot: 'cl-switcher-header', + props: { + avatar: { type: 'ReactNode', doc: 'The leading mark.' }, + title: { type: 'string', doc: 'The name, on one line.' }, + description: { type: 'string', doc: 'A second line, such as an email address.' }, + }, + }, + 'Switcher.Avatar': { + description: 'A decorative avatar with initials as its fallback, hidden from assistive tech.', + props: { + name: { type: 'string', doc: 'The name the initials come from.' }, + imageUrl: { type: 'string', doc: 'The image.' }, + shape: { type: "'circle' | 'square'", doc: 'Circle for a person, square for an organization.' }, + size: { type: "'xs' | 'sm' | 'md' | 'lg' | 'fit'", doc: 'Box size. `fit` fills the parent.' }, + }, + }, + 'Switcher.BadgedAvatar': { + description: "An organization's square avatar with a person's round avatar cut into its corner.", + slot: 'cl-switcher-avatar', + props: { + name: { type: 'string', doc: 'The lead name.' }, + imageUrl: { type: 'string', doc: 'The lead image.' }, + badge: { type: '{ name: string; imageUrl?: string }', doc: 'The person in the corner.' }, + size: { type: "'sm' | 'md'", doc: 'Box size.' }, + }, + }, + 'Switcher.Group': { + description: 'A run of rows inside the popover.', + slot: 'cl-switcher-group', + }, + 'Switcher.Separator': { + description: 'A rule between groups.', + slot: 'cl-switcher-separator', + }, + 'Switcher.Item': { + description: 'One row. Renders a `div`, or the `render` element, which makes it interactive.', + slot: 'cl-switcher-item', + }, + 'Switcher.ItemMedia': { + description: "The row's leading avatar or icon.", + slot: 'cl-switcher-item-media', + }, + 'Switcher.ItemContent': { + description: "The row's text column.", + slot: 'cl-switcher-item-content', + }, + 'Switcher.ItemLabel': { + description: "The row's name, on one line.", + slot: 'cl-switcher-item-label', + props: { + variant: { + type: "'default' | 'interactive'", + doc: "`default` names the row's subject. `interactive` takes the row's color, for rows such as `Sign out`.", + default: "'default'", + }, + }, + }, + 'Switcher.ItemDescription': { + description: 'A second line under the label.', + slot: 'cl-switcher-item-description', + }, + 'Switcher.ItemTrailing': { + description: 'Content at the end of the row, such as a checkmark or a badge.', + slot: 'cl-switcher-item-trailing', + }, + }, + examples: [ + { + title: 'A header and one organization row', + code: ` +} + title='Acme' + description='alice@example.com' +/> + + + }> + + + + + Globex + Member + + + +`, + }, + ], + related: ['Avatar', 'Popover', 'Card'], +} satisfies ComponentDoc<{ + 'Switcher.Trigger': SwitcherTriggerProps; + 'Switcher.Header': SwitcherHeaderProps; + 'Switcher.Avatar': SwitcherAvatarProps; + 'Switcher.BadgedAvatar': SwitcherBadgedAvatarProps; + 'Switcher.Group': SwitcherGroupProps; + 'Switcher.Separator': SwitcherSeparatorProps; + 'Switcher.Item': SwitcherItemProps; + 'Switcher.ItemMedia': SwitcherItemMediaProps; + 'Switcher.ItemContent': SwitcherItemContentProps; + 'Switcher.ItemLabel': SwitcherItemLabelProps; + 'Switcher.ItemDescription': SwitcherItemDescriptionProps; + 'Switcher.ItemTrailing': SwitcherItemTrailingProps; +}>; diff --git a/packages/mosaic/src/components/switcher/switcher.parts.ts b/packages/mosaic/src/components/switcher/switcher.parts.ts new file mode 100644 index 00000000000..8ab37348eaa --- /dev/null +++ b/packages/mosaic/src/components/switcher/switcher.parts.ts @@ -0,0 +1,13 @@ +export { BadgedAvatar, RowAvatar as Avatar } from './switcher-avatar'; +export { SwitcherHeader as Header } from './switcher-header'; +export { + SwitcherItem as Item, + SwitcherItemMedia as ItemMedia, + SwitcherItemContent as ItemContent, + SwitcherItemLabel as ItemLabel, + SwitcherItemDescription as ItemDescription, + SwitcherItemTrailing as ItemTrailing, + SwitcherGroup as Group, + SwitcherSeparator as Separator, +} from './switcher-item'; +export { SwitcherTriggerButton as Trigger } from './switcher-trigger'; diff --git a/packages/mosaic/src/components/switcher/switcher.test.tsx b/packages/mosaic/src/components/switcher/switcher.test.tsx new file mode 100644 index 00000000000..863c5e0dd50 --- /dev/null +++ b/packages/mosaic/src/components/switcher/switcher.test.tsx @@ -0,0 +1,121 @@ +import { render, screen } from '@testing-library/react'; +import React from 'react'; +import { describe, expect, it } from 'vitest'; + +import { MosaicProvider } from '../../mosaic-provider'; +import { axe } from '../../primitives/test-utils/axe'; +import { Switcher } from '.'; +import { SwitcherSurfaceProvider } from './switcher.context'; + +function Popover() { + return ( + <> + + } + title='Acme' + description='alice@example.com' + /> + + + }> + + + + + Globex + Member + + Pro + + + + ); +} + +describe('Switcher', () => { + it('renders the popover parts with their switcher slots', async () => { + const { container } = render( + + + , + ); + + expect(container.querySelector('.cl-switcher-header')).toHaveTextContent('Acmealice@example.com'); + expect(container.querySelector('.cl-switcher-avatar')).toHaveAttribute('aria-hidden'); + expect(container.querySelector('.cl-switcher-separator')?.tagName).toBe('HR'); + const row = screen.getByRole('button', { name: 'Globex Member Pro' }); + expect(row).toHaveClass('cl-switcher-item'); + expect(row).toHaveAttribute('data-interactive'); + expect(container.querySelector('.cl-switcher-item-label')).toHaveAttribute('data-variant', 'default'); + expect((await axe(container)).violations).toEqual([]); + }); + + it('takes its slot prefix from the surface', () => { + const { container } = render( + + + + + , + ); + + expect(container.querySelector('.cl-organization-switcher-item')).not.toBeNull(); + expect(container.querySelector('.cl-switcher-item')).toBeNull(); + }); + + it('renders the trigger as a plain button, with or without its label', () => { + const { rerender } = render( + + + } + name='Acme' + badge='Pro' + /> + , + ); + + const trigger = screen.getByRole('button', { name: 'Open account menu' }); + expect(trigger).toHaveAttribute('type', 'button'); + expect(trigger).toHaveClass('cl-switcher-trigger'); + expect(trigger).toHaveAttribute('data-variant', 'full'); + expect(trigger.querySelector('.cl-switcher-trigger-label')).toHaveTextContent('Acme'); + expect(trigger).toHaveTextContent('Pro'); + + rerender( + + + } + shape='circle' + /> + , + ); + + expect(screen.getByRole('button', { name: 'Open account menu' }).querySelector('.cl-switcher-trigger-label')).toBe( + null, + ); + }); +}); diff --git a/packages/mosaic/src/features/oauth-consent/oauth-consent.view.tsx b/packages/mosaic/src/features/oauth-consent/oauth-consent.view.tsx index 210fef940e6..b0676cc7a1f 100644 --- a/packages/mosaic/src/features/oauth-consent/oauth-consent.view.tsx +++ b/packages/mosaic/src/features/oauth-consent/oauth-consent.view.tsx @@ -13,6 +13,7 @@ import { Radio } from '../../components/radio'; import { Reveal } from '../../components/reveal'; import { scrollAreaViewport } from '../../components/scroll-area'; import { Select } from '../../components/select'; +import { RowAvatar } from '../../components/switcher/switcher-avatar'; import { Text } from '../../components/text'; import { Tooltip } from '../../components/tooltip'; import { VisuallyHidden } from '../../components/visually-hidden'; @@ -21,7 +22,6 @@ import { fill, plural, rich, useLocale } from '../../localization'; import { Form } from '../../primitives/form'; import { mergeStyleProps, themeProps } from '../../props'; import { reset } from '../../styles/reset.styles'; -import { RowAvatar } from '../switcher/switcher-avatar.view'; import { styles } from './oauth-consent.styles'; import type { OAuthConsentOrganization, diff --git a/packages/mosaic/src/features/organization-list/organization-list.skeleton.tsx b/packages/mosaic/src/features/organization-list/organization-list.skeleton.tsx index 467b7235d5b..ebbf40787cc 100644 --- a/packages/mosaic/src/features/organization-list/organization-list.skeleton.tsx +++ b/packages/mosaic/src/features/organization-list/organization-list.skeleton.tsx @@ -1,9 +1,9 @@ import { Card } from '../../components/card'; import { Item } from '../../components/item'; import { Skeleton } from '../../components/skeleton'; +import { RowAvatar } from '../../components/switcher/switcher-avatar'; import { VisuallyHidden } from '../../components/visually-hidden'; import { useMessages } from '../../localization'; -import { RowAvatar } from '../switcher/switcher-avatar.view'; import type { OrganizationListData } from './organization-list.types'; import { OrganizationListHeader } from './organization-list.view'; diff --git a/packages/mosaic/src/features/organization-list/organization-list.view.tsx b/packages/mosaic/src/features/organization-list/organization-list.view.tsx index c780cc306bc..bc51bb8b316 100644 --- a/packages/mosaic/src/features/organization-list/organization-list.view.tsx +++ b/packages/mosaic/src/features/organization-list/organization-list.view.tsx @@ -7,10 +7,10 @@ import { Flow, useFlowAutoFocus } from '../../components/flow'; import { Icon } from '../../components/icon'; import { Item } from '../../components/item'; import { Spinner } from '../../components/spinner'; +import { RowAvatar } from '../../components/switcher/switcher-avatar'; import { Plus } from '../../icons/glyphs/plus'; import { fill, useMessages } from '../../localization'; import { Button as HeadlessButton } from '../../primitives/button'; -import { RowAvatar } from '../switcher/switcher-avatar.view'; import type { OrganizationListData, OrganizationListInvitation, diff --git a/packages/mosaic/src/features/sign-in/steps/sign-in-accounts.tsx b/packages/mosaic/src/features/sign-in/steps/sign-in-accounts.tsx index 35a07dabae6..40d57a52a19 100644 --- a/packages/mosaic/src/features/sign-in/steps/sign-in-accounts.tsx +++ b/packages/mosaic/src/features/sign-in/steps/sign-in-accounts.tsx @@ -7,10 +7,10 @@ import { useFlowAutoFocus } from '../../../components/flow'; import { Icon } from '../../../components/icon'; import { Item } from '../../../components/item'; import { Spinner } from '../../../components/spinner'; +import { RowAvatar } from '../../../components/switcher/switcher-avatar'; import { Plus } from '../../../icons/glyphs/plus'; import { useMessages } from '../../../localization'; import { Button as HeadlessButton } from '../../../primitives/button'; -import { RowAvatar } from '../../switcher/switcher-avatar.view'; import type { SignInAccount } from '../sign-in.types'; interface SignInAccountsProps { diff --git a/packages/mosaic/src/features/switcher/switcher-surface.tsx b/packages/mosaic/src/features/switcher/switcher-surface.tsx index 20c7d7d2070..9cb290b9c0f 100644 --- a/packages/mosaic/src/features/switcher/switcher-surface.tsx +++ b/packages/mosaic/src/features/switcher/switcher-surface.tsx @@ -1,11 +1,9 @@ -import React from 'react'; - +import type { SwitcherSurface } from '../../components/switcher/switcher.context'; +import { useSwitcherSurface } from '../../components/switcher/switcher.context'; import type { MosaicMessages } from '../../localization'; import { useMessages } from '../../localization'; import type { SwitcherMode } from './switcher.types'; -export type SwitcherSurface = 'switcher' | 'user-button' | 'organization-switcher'; - export function surfaceForMode(mode: SwitcherMode): SwitcherSurface { switch (mode) { case 'combined': @@ -17,19 +15,10 @@ export function surfaceForMode(mode: SwitcherMode): SwitcherSurface { } } -const SurfaceContext = React.createContext('switcher'); - -export const SwitcherSurfaceProvider = SurfaceContext.Provider; - -export function useSlot(): (part: string) => string { - const surface = React.useContext(SurfaceContext); - return part => `${surface}-${part}`; -} - export type SwitcherMessages = Omit | MosaicMessages['organizationSwitcher']; export function useSwitcherMessages(): SwitcherMessages { - const surface = React.useContext(SurfaceContext); + const surface = useSwitcherSurface(); const userButton = useMessages('userButton'); const organizationSwitcher = useMessages('organizationSwitcher'); return surface === 'organization-switcher' ? organizationSwitcher : userButton; diff --git a/packages/mosaic/src/features/switcher/switcher.styles.ts b/packages/mosaic/src/features/switcher/switcher.styles.ts index fd841ee6346..581f272f25e 100644 --- a/packages/mosaic/src/features/switcher/switcher.styles.ts +++ b/packages/mosaic/src/features/switcher/switcher.styles.ts @@ -1,6 +1,6 @@ import * as stylex from '@stylexjs/stylex'; -import { colorVars, durationVars, fontWeightVars, radiusVars, space, typeScaleVars } from '../../tokens.stylex'; +import { radiusVars, space } from '../../tokens.stylex'; export const styles = stylex.create({ rowAvatar: { @@ -9,68 +9,6 @@ export const styles = stylex.create({ height: space['5'], width: space['5'], }, - trigger: { - padding: 0, - borderRadius: radiusVars['--cl-radius-md'], - borderStyle: 'none', - alignItems: 'center', - backgroundColor: 'transparent', - cursor: 'pointer', - display: 'inline-flex', - transitionDuration: { - default: durationVars['--cl-duration-base'], - '@media (hover: hover)': { - default: null, - ':hover:not(:disabled, [data-disabled], [aria-disabled="true"])': durationVars['--cl-duration-instant'], - }, - }, - transitionTimingFunction: 'linear', - maxWidth: '100%', - minWidth: 0, - }, - - triggerLabelled: { - padding: space['1.5'], - borderRadius: radiusVars['--cl-radius-xl'], - gap: space['1.5'], - backgroundColor: { - default: 'transparent', - ':is([data-open])': `color-mix(in oklab, ${colorVars['--cl-color-neutral']} 4%, transparent)`, - '@media (hover: hover)': { - ':hover:not(:disabled, [data-disabled], [aria-disabled="true"])': `color-mix(in oklab, ${colorVars['--cl-color-neutral']} 4%, transparent)`, - }, - }, - transitionProperty: 'background-color', - }, - - triggerAvatarOnly: { - opacity: { - default: 1, - ':is([data-open])': 0.8, - '@media (hover: hover)': { - ':hover:not(:disabled, [data-disabled], [aria-disabled="true"])': 0.8, - }, - }, - transitionProperty: 'opacity', - }, - - triggerRound: { - borderRadius: radiusVars['--cl-radius-full'], - }, - - // Capped, because the trigger sits in a host app's chrome and a long organization name would push it apart. - triggerName: { - color: colorVars['--cl-color-foreground'], - fontSize: typeScaleVars['--cl-text-sm-size'], - fontWeight: fontWeightVars['--cl-font-medium'], - lineHeight: typeScaleVars['--cl-text-sm-leading'], - maxWidth: '12rem', - }, - - triggerCaret: { - '--_cl-icon-color': colorVars['--cl-color-foreground-secondary'], - marginInline: space['1'], - }, // The organization list scrolls; the header and footer stay put. The scroll area carries the // overflow, the edge fades, the scrollbar and the scroll padding they need, so only the cap diff --git a/packages/mosaic/src/features/switcher/switcher.view.tsx b/packages/mosaic/src/features/switcher/switcher.view.tsx index f2b233e3cde..0ad8005c686 100644 --- a/packages/mosaic/src/features/switcher/switcher.view.tsx +++ b/packages/mosaic/src/features/switcher/switcher.view.tsx @@ -1,10 +1,8 @@ 'use client'; -import * as stylex from '@stylexjs/stylex'; import type { ReactElement, ReactNode } from 'react'; import React from 'react'; -import { Badge } from '../../components/badge'; import { SubmitButton } from '../../components/button'; import { Card } from '../../components/card'; import { Icon } from '../../components/icon'; @@ -12,10 +10,23 @@ import { Menu } from '../../components/menu'; import { Popover } from '../../components/popover'; import { scrollAreaViewport } from '../../components/scroll-area'; import { Spinner } from '../../components/spinner'; +import { SwitcherSurfaceProvider, useSlot } from '../../components/switcher/switcher.context'; +import { BadgedAvatar, RowAvatar } from '../../components/switcher/switcher-avatar'; +import { SwitcherHeader } from '../../components/switcher/switcher-header'; +import { + SwitcherGroup, + SwitcherItem, + SwitcherItemContent, + SwitcherItemDescription, + SwitcherItemLabel, + SwitcherItemMedia, + SwitcherItemTrailing, + SwitcherSeparator, +} from '../../components/switcher/switcher-item'; +import { SwitcherTriggerContent, triggerStyles } from '../../components/switcher/switcher-trigger'; import type { IconComponent } from '../../icons/glyph'; import { Building } from '../../icons/glyphs/building'; import { Checkmark } from '../../icons/glyphs/checkmark'; -import { ChevronDown } from '../../icons/glyphs/chevron-down'; import { ChevronRight } from '../../icons/glyphs/chevron-right'; import { Cog6Teeth } from '../../icons/glyphs/cog-6-teeth'; import { Plus } from '../../icons/glyphs/plus'; @@ -26,12 +37,8 @@ import { UsersAddRight } from '../../icons/glyphs/users-add-right'; import { fill, plural, useLocale, useMessages } from '../../localization'; import { Button as HeadlessButton } from '../../primitives/button'; import type { PopoverProps } from '../../primitives/popover'; -import type { MosaicElementProps } from '../../props'; -import { mergeStyleProps, themeProps } from '../../props'; -import { focusOutline } from '../../styles/focus-outline.styles'; +import { themeProps } from '../../props'; import { rtl } from '../../styles/rtl.styles'; -import { reset } from '../../styles/reset.styles'; -import { truncationStyles } from '../../styles/typography.styles'; import { applyOrder } from '../../utils/apply-order'; import type { SwitcherLayout } from './switcher.layout'; import { resolveSwitcherLayout } from './switcher.layout'; @@ -49,20 +56,8 @@ import type { SwitcherTriggerBadge, } from './switcher.types'; import { switcherBusyKeys } from './switcher.types'; -import { BadgedAvatar, RowAvatar } from './switcher-avatar.view'; -import { SwitcherHeader } from './switcher-header.view'; -import { - SwitcherGroup, - SwitcherItem, - SwitcherItemContent, - SwitcherItemDescription, - SwitcherItemLabel, - SwitcherItemMedia, - SwitcherItemTrailing, - SwitcherSeparator, -} from './switcher-item.view'; import type { SwitcherMessages } from './switcher-surface'; -import { surfaceForMode, SwitcherSurfaceProvider, useSlot, useSwitcherMessages } from './switcher-surface'; +import { surfaceForMode, useSwitcherMessages } from './switcher-surface'; import { useSwitcherTriggerController } from './switcher-trigger.controller'; // The data contract, the mode flags, and the menu item shapes live in `switcher.types`; they are @@ -1081,97 +1076,6 @@ export function SwitcherTrigger({ ); } -function triggerStyles(showLabel: boolean, shape: 'circle' | 'square') { - return [ - focusOutline.visible, - styles.trigger, - showLabel ? styles.triggerLabelled : styles.triggerAvatarOnly, - !showLabel && shape === 'circle' ? styles.triggerRound : null, - ]; -} - -function SwitcherTriggerContent({ - avatar, - name, - badge, - badgeId, -}: { - avatar: ReactNode; - name?: string; - badge?: string; - badgeId?: string; -}): ReactElement { - const slot = useSlot(); - return ( - <> - {avatar} - {name ? ( - <> - - {name} - - {badge ? ( - - {badge} - - ) : null} - - - ) : null} - - ); -} - -export interface SwitcherTriggerButtonProps extends Omit, 'children'> { - /** The lead's mark, such as a `BadgedAvatar`. */ - avatar: ReactNode; - /** The lead's name. Leave it out for the avatar-only trigger. */ - name?: string; - /** A plan or status label beside the name. */ - badge?: string; - shape?: 'circle' | 'square'; -} - -/** The trigger's look on a plain button, without the popover it opens: for showing the trigger on its own. */ -export function SwitcherTriggerButton({ - avatar, - name, - badge, - shape = 'square', - xstyle, - ...rest -}: SwitcherTriggerButtonProps): ReactElement { - const slot = useSlot(); - return ( - - ); -} - function TriggerAvatar({ lead, variant, diff --git a/packages/mosaic/src/features/task-choose-organization/task-choose-organization.skeleton.tsx b/packages/mosaic/src/features/task-choose-organization/task-choose-organization.skeleton.tsx index 50d2c6a157a..97f47530c5b 100644 --- a/packages/mosaic/src/features/task-choose-organization/task-choose-organization.skeleton.tsx +++ b/packages/mosaic/src/features/task-choose-organization/task-choose-organization.skeleton.tsx @@ -1,9 +1,9 @@ import { Card } from '../../components/card'; import { Item } from '../../components/item'; import { Skeleton } from '../../components/skeleton'; +import { RowAvatar } from '../../components/switcher/switcher-avatar'; import { VisuallyHidden } from '../../components/visually-hidden'; import { useMessages } from '../../localization'; -import { RowAvatar } from '../switcher/switcher-avatar.view'; import { TaskChooseOrganizationHeader, TaskChooseOrganizationSignOut } from './task-choose-organization.view'; const PLACEHOLDER_ORGANIZATIONS = ['Acme Corporation', 'Globex']; diff --git a/packages/swingset/src/stories/switcher.stories.tsx b/packages/swingset/src/stories/switcher.stories.tsx index 021ea07e661..37fecee5c90 100644 --- a/packages/swingset/src/stories/switcher.stories.tsx +++ b/packages/swingset/src/stories/switcher.stories.tsx @@ -1,7 +1,7 @@ import { Button } from '@clerk/mosaic/components/button'; import { Icon } from '@clerk/mosaic/components/icon'; +import { Switcher } from '@clerk/mosaic/components/switcher'; import { SwitcherView } from '@clerk/mosaic/features/switcher/switcher.view'; -import { BadgedAvatar } from '@clerk/mosaic/features/switcher/switcher-avatar.view'; import type { UserProfileModalOptions } from '@clerk/mosaic/features/user-profile/user-profile.modal.types'; import { UserProfileView } from '@clerk/mosaic/features/user-profile/user-profile.view'; import { Cog6Teeth } from '@clerk/mosaic/icons/glyphs/cog-6-teeth'; @@ -136,7 +136,7 @@ export function CustomizedAvatar(_args: Record) { triggerVariant='full' /> {activeOrganization ? ( - Date: Tue, 17 Nov 2026 14:00:48 -0700 Subject: [PATCH 5/8] docs(mosaic): describe the Switcher parts without use-case framing Co-Authored-By: Claude Opus 5.5 --- .changeset/mosaic-card-field-entry-points.md | 2 +- packages/mosaic/src/components/switcher/index.ts | 6 +++--- packages/mosaic/src/components/switcher/switcher.doc.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.changeset/mosaic-card-field-entry-points.md b/.changeset/mosaic-card-field-entry-points.md index e8dfcdcb17a..ac55ac9b413 100644 --- a/.changeset/mosaic-card-field-entry-points.md +++ b/.changeset/mosaic-card-field-entry-points.md @@ -2,4 +2,4 @@ '@clerk/mosaic': patch --- -Export `Card` and `Field` from `@clerk/mosaic/components/card` and `@clerk/mosaic/components/field`, `ProviderButton` and `ProviderButtonGroup` from `@clerk/mosaic/components/provider-button`, a `Switcher` component namespace from `@clerk/mosaic/components/switcher` (`Switcher.Trigger`, the trigger's look on a plain button; `Switcher.Header`; `Switcher.Avatar` and `Switcher.BadgedAvatar`; `Switcher.Group` and `Switcher.Separator`; and `Switcher.Item` with its `ItemMedia`, `ItemContent`, `ItemLabel`, `ItemDescription` and `ItemTrailing` parts), the presentational parts `UserButton` and `OrganizationSwitcher` are built from, and the `Building`, `Checkmark`, `ChevronDown`, `ChevronRight`, `Cog6Teeth`, `EllipsisHorizontal`, `Key`, `SecurityLockSquare`, `SecurityPhone`, `SignOut`, `SwitchAccount` and `UsersAddRight` glyphs from `@clerk/mosaic/icons/glyphs/`, so a page can rebuild these components on static data. +Export `Card` and `Field` from `@clerk/mosaic/components/card` and `@clerk/mosaic/components/field`, `ProviderButton` and `ProviderButtonGroup` from `@clerk/mosaic/components/provider-button`, a `Switcher` component namespace from `@clerk/mosaic/components/switcher` (`Switcher.Trigger`, the trigger's look on a plain button; `Switcher.Header`; `Switcher.Avatar` and `Switcher.BadgedAvatar`; `Switcher.Group` and `Switcher.Separator`; and `Switcher.Item` with its `ItemMedia`, `ItemContent`, `ItemLabel`, `ItemDescription` and `ItemTrailing` parts), the presentational parts `UserButton` and `OrganizationSwitcher` are built from, and the `Building`, `Checkmark`, `ChevronDown`, `ChevronRight`, `Cog6Teeth`, `EllipsisHorizontal`, `Key`, `SecurityLockSquare`, `SecurityPhone`, `SignOut`, `SwitchAccount` and `UsersAddRight` glyphs from `@clerk/mosaic/icons/glyphs/`. diff --git a/packages/mosaic/src/components/switcher/index.ts b/packages/mosaic/src/components/switcher/index.ts index c6e9a5fd091..0ef0f21bfea 100644 --- a/packages/mosaic/src/components/switcher/index.ts +++ b/packages/mosaic/src/components/switcher/index.ts @@ -1,9 +1,9 @@ 'use client'; /** - * The account and organization switcher's look, as parts to compose on static data, such as a - * marketing figure or a docs illustration. The working components are `UserButton`, - * `OrganizationSwitcher` and `Switcher`, which build their trigger and popover from these parts. + * The account and organization switcher's parts: its trigger, the popover's header, and its rows. + * `UserButton`, `OrganizationSwitcher` and `Switcher` compose them with Clerk's session and + * organization state. * * ```tsx * } title='Acme' /> diff --git a/packages/mosaic/src/components/switcher/switcher.doc.ts b/packages/mosaic/src/components/switcher/switcher.doc.ts index cabccc2f0e6..ad3c0a498a0 100644 --- a/packages/mosaic/src/components/switcher/switcher.doc.ts +++ b/packages/mosaic/src/components/switcher/switcher.doc.ts @@ -16,10 +16,10 @@ import type { SwitcherTriggerProps } from './switcher-trigger'; export default { name: 'Switcher', description: - "The account and organization switcher's look as parts: the trigger, the popover's header, and its rows. For showing a switcher on static data. `UserButton`, `OrganizationSwitcher` and `Switcher` from `@clerk/mosaic` are the working components, built from these parts.", + "The account and organization switcher's parts: the trigger, the popover's header, and its rows. `UserButton`, `OrganizationSwitcher` and `Switcher` from `@clerk/mosaic` compose them with Clerk's session and organization state.", useFor: [ - 'a static picture of the user button or organization switcher', - 'a marketing figure or docs illustration of the account switcher', + 'a custom account or organization switcher composed from its parts', + 'switcher rows or a switcher trigger rendered with your own data', ], keywords: ['switcher', 'user button', 'organization switcher', 'account switcher', 'menu rows'], practices: [ From 7cc3ace0edf80034e25398625dfef53634f61362 Mon Sep 17 00:00:00 2001 From: Max Yinger Date: Tue, 17 Nov 2026 14:14:03 -0700 Subject: [PATCH 6/8] refactor(mosaic): tighten the Switcher component's trigger, theming and docs - `Switcher.Trigger` forwards its ref and takes a `variant` (`full` or `condensed`, default `condensed`) for its `data-variant`, instead of always setting `full`. - The feature trigger gates its label on `showTriggerLabel` and its badge on a string plan label again, as on main. - Export the component from the StyleX barrel as `SwitcherParts`. - Rename the feature's trigger options type to `SwitcherTriggerOptions`. - Doc the slot prefixes and the avatar's `cl-avatar` slot; split the changeset into a list under an accurate name. - Test the user-button prefix, avatar shape, ref and xstyle passthrough, and the trigger variant. Co-Authored-By: Claude Opus 5.5 --- .changeset/mosaic-card-field-entry-points.md | 5 - .changeset/mosaic-component-entry-points.md | 10 ++ .../mosaic/src/components/switcher/index.ts | 2 +- .../components/switcher/switcher-trigger.tsx | 72 +++++++----- .../src/components/switcher/switcher.doc.ts | 8 +- .../src/components/switcher/switcher.test.tsx | 104 +++++++++++++++++- .../features/switcher/switcher.controller.tsx | 4 +- .../mosaic/src/features/switcher/switcher.tsx | 4 +- .../src/features/switcher/switcher.view.tsx | 13 ++- packages/mosaic/src/styles/index.ts | 2 + 10 files changed, 172 insertions(+), 52 deletions(-) delete mode 100644 .changeset/mosaic-card-field-entry-points.md create mode 100644 .changeset/mosaic-component-entry-points.md diff --git a/.changeset/mosaic-card-field-entry-points.md b/.changeset/mosaic-card-field-entry-points.md deleted file mode 100644 index ac55ac9b413..00000000000 --- a/.changeset/mosaic-card-field-entry-points.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@clerk/mosaic': patch ---- - -Export `Card` and `Field` from `@clerk/mosaic/components/card` and `@clerk/mosaic/components/field`, `ProviderButton` and `ProviderButtonGroup` from `@clerk/mosaic/components/provider-button`, a `Switcher` component namespace from `@clerk/mosaic/components/switcher` (`Switcher.Trigger`, the trigger's look on a plain button; `Switcher.Header`; `Switcher.Avatar` and `Switcher.BadgedAvatar`; `Switcher.Group` and `Switcher.Separator`; and `Switcher.Item` with its `ItemMedia`, `ItemContent`, `ItemLabel`, `ItemDescription` and `ItemTrailing` parts), the presentational parts `UserButton` and `OrganizationSwitcher` are built from, and the `Building`, `Checkmark`, `ChevronDown`, `ChevronRight`, `Cog6Teeth`, `EllipsisHorizontal`, `Key`, `SecurityLockSquare`, `SecurityPhone`, `SignOut`, `SwitchAccount` and `UsersAddRight` glyphs from `@clerk/mosaic/icons/glyphs/`. diff --git a/.changeset/mosaic-component-entry-points.md b/.changeset/mosaic-component-entry-points.md new file mode 100644 index 00000000000..bd98368faa8 --- /dev/null +++ b/.changeset/mosaic-component-entry-points.md @@ -0,0 +1,10 @@ +--- +'@clerk/mosaic': patch +--- + +Add component entry points: + +- `Card` from `@clerk/mosaic/components/card` and `Field` from `@clerk/mosaic/components/field` +- `ProviderButton` and `ProviderButtonGroup` from `@clerk/mosaic/components/provider-button` +- `Switcher` from `@clerk/mosaic/components/switcher`: the parts `UserButton` and `OrganizationSwitcher` are built from (`Switcher.Trigger`, `Switcher.Header`, `Switcher.Avatar`, `Switcher.BadgedAvatar`, `Switcher.Group`, `Switcher.Separator`, and `Switcher.Item` with `ItemMedia`, `ItemContent`, `ItemLabel`, `ItemDescription` and `ItemTrailing`) +- The `Building`, `Checkmark`, `ChevronDown`, `ChevronRight`, `Cog6Teeth`, `EllipsisHorizontal`, `Key`, `SecurityLockSquare`, `SecurityPhone`, `SignOut`, `SwitchAccount` and `UsersAddRight` glyphs from `@clerk/mosaic/icons/glyphs/` diff --git a/packages/mosaic/src/components/switcher/index.ts b/packages/mosaic/src/components/switcher/index.ts index 0ef0f21bfea..d1d909e43a7 100644 --- a/packages/mosaic/src/components/switcher/index.ts +++ b/packages/mosaic/src/components/switcher/index.ts @@ -29,4 +29,4 @@ export type { SwitcherItemTrailingProps, SwitcherSeparatorProps, } from './switcher-item'; -export type { SwitcherTriggerProps } from './switcher-trigger'; +export type { SwitcherTriggerProps, SwitcherTriggerVariant } from './switcher-trigger'; diff --git a/packages/mosaic/src/components/switcher/switcher-trigger.tsx b/packages/mosaic/src/components/switcher/switcher-trigger.tsx index ebd7f1587da..aa3af4118ea 100644 --- a/packages/mosaic/src/components/switcher/switcher-trigger.tsx +++ b/packages/mosaic/src/components/switcher/switcher-trigger.tsx @@ -2,6 +2,7 @@ import * as stylex from '@stylexjs/stylex'; import type { ReactElement, ReactNode } from 'react'; +import React from 'react'; import { ChevronDown } from '../../icons/glyphs/chevron-down'; import type { MosaicElementProps } from '../../props'; @@ -25,11 +26,13 @@ export function triggerStyles(showLabel: boolean, shape: 'circle' | 'square') { export function SwitcherTriggerContent({ avatar, + showLabel, name, badge, badgeId, }: { avatar: ReactNode; + showLabel: boolean; name?: string; badge?: string; badgeId?: string; @@ -38,7 +41,7 @@ export function SwitcherTriggerContent({ return ( <> {avatar} - {name ? ( + {showLabel ? ( <> {name} - {badge ? ( + {typeof badge === 'string' ? ( , name?: string; /** A plan or status label beside the name. */ badge?: string; + /** Rounds the avatar-only trigger to match a circular avatar. */ shape?: 'circle' | 'square'; + /** + * Which mark the trigger carries, set as `data-variant`: `full` for a `Switcher.BadgedAvatar`, + * `condensed` for a `Switcher.Avatar`. + * + * @default 'condensed' + */ + variant?: SwitcherTriggerVariant; } -/** The trigger's look on a plain button, without the popover it opens: for showing the trigger on its own. */ -export function SwitcherTriggerButton({ - avatar, - name, - badge, - shape = 'square', - xstyle, - ...rest -}: SwitcherTriggerProps): ReactElement { - const slot = useSlot(); - return ( - - ); -} +export type SwitcherTriggerVariant = 'full' | 'condensed'; + +/** The trigger's look on a plain button, without the popover it opens. */ +export const SwitcherTriggerButton = React.forwardRef( + function SwitcherTriggerButton( + { avatar, name, badge, shape = 'square', variant = 'condensed', xstyle, ...rest }, + ref, + ) { + const slot = useSlot(); + const showLabel = name !== undefined; + return ( + + ); + }, +); diff --git a/packages/mosaic/src/components/switcher/switcher.doc.ts b/packages/mosaic/src/components/switcher/switcher.doc.ts index ad3c0a498a0..af83bfa57cf 100644 --- a/packages/mosaic/src/components/switcher/switcher.doc.ts +++ b/packages/mosaic/src/components/switcher/switcher.doc.ts @@ -16,7 +16,7 @@ import type { SwitcherTriggerProps } from './switcher-trigger'; export default { name: 'Switcher', description: - "The account and organization switcher's parts: the trigger, the popover's header, and its rows. `UserButton`, `OrganizationSwitcher` and `Switcher` from `@clerk/mosaic` compose them with Clerk's session and organization state.", + "The account and organization switcher's parts: the trigger, the popover's header, and its rows. `UserButton`, `OrganizationSwitcher` and `Switcher` from `@clerk/mosaic` compose them with Clerk's session and organization state. These parts carry `cl-switcher-*` classes; inside `UserButton` and `OrganizationSwitcher` the same parts carry `cl-user-button-*` and `cl-organization-switcher-*`. `Switcher.Avatar` carries `cl-avatar`.", useFor: [ 'a custom account or organization switcher composed from its parts', 'switcher rows or a switcher trigger rendered with your own data', @@ -50,6 +50,11 @@ export default { doc: 'Rounds the avatar-only trigger to match a circular avatar.', default: "'square'", }, + variant: { + type: "'full' | 'condensed'", + doc: 'Which mark the trigger carries, set as `data-variant`: `full` for a `Switcher.BadgedAvatar`, `condensed` for a `Switcher.Avatar`.', + default: "'condensed'", + }, }, }, 'Switcher.Header': { @@ -63,6 +68,7 @@ export default { }, 'Switcher.Avatar': { description: 'A decorative avatar with initials as its fallback, hidden from assistive tech.', + slot: 'cl-avatar', props: { name: { type: 'string', doc: 'The name the initials come from.' }, imageUrl: { type: 'string', doc: 'The image.' }, diff --git a/packages/mosaic/src/components/switcher/switcher.test.tsx b/packages/mosaic/src/components/switcher/switcher.test.tsx index 863c5e0dd50..c5b50bdf873 100644 --- a/packages/mosaic/src/components/switcher/switcher.test.tsx +++ b/packages/mosaic/src/components/switcher/switcher.test.tsx @@ -1,3 +1,4 @@ +import * as stylex from '@stylexjs/stylex'; import { render, screen } from '@testing-library/react'; import React from 'react'; import { describe, expect, it } from 'vitest'; @@ -42,6 +43,13 @@ function Popover() { ); } +function atomsOf(style: stylex.StyleXStyles): string[] { + return stylex + .props(style) + .className!.split(' ') + .filter(name => !name.includes('__')); +} + describe('Switcher', () => { it('renders the popover parts with their switcher slots', async () => { const { container } = render( @@ -60,17 +68,81 @@ describe('Switcher', () => { expect((await axe(container)).violations).toEqual([]); }); - it('takes its slot prefix from the surface', () => { + it.each(['user-button', 'organization-switcher'] as const)('takes the %s slot prefix from the surface', surface => { const { container } = render( - + , ); - expect(container.querySelector('.cl-organization-switcher-item')).not.toBeNull(); - expect(container.querySelector('.cl-switcher-item')).toBeNull(); + for (const part of ['header', 'avatar', 'group', 'separator', 'item', 'item-label']) { + expect(container.querySelector(`.cl-${surface}-${part}`)).not.toBeNull(); + } + expect(container.querySelector('[class*="cl-switcher-"]')).toBeNull(); + }); + + it('shapes the avatar by its shape prop', () => { + const { container } = render( + + + + , + ); + + const [circle, square] = container.querySelectorAll('.cl-avatar'); + expect(circle).toHaveAttribute('data-shape', 'circle'); + expect(square).toHaveAttribute('data-shape', 'square'); + }); + + it('forwards refs and xstyle to the root elements', () => { + const probe = stylex.create({ root: { maxWidth: '900px' } }); + const itemRef = React.createRef(); + const triggerRef = React.createRef(); + render( + + + + Globex + + + + + , + ); + + const atoms = atomsOf(probe.root); + expect(itemRef.current).toHaveClass('cl-switcher-item', ...atoms); + expect(triggerRef.current).toBe(screen.getByRole('button', { name: 'Open account menu' })); + expect(triggerRef.current).toHaveClass('cl-switcher-trigger', ...atoms); + expect(screen.getByTestId('group')).toHaveClass('cl-switcher-group', ...atoms); + expect(screen.getByText('Globex')).toHaveClass('cl-switcher-item-label', ...atoms); + expect(document.querySelector('.cl-avatar')).toHaveClass(...atoms); }); it('renders the trigger as a plain button, with or without its label', () => { @@ -87,6 +159,7 @@ describe('Switcher', () => { } name='Acme' badge='Pro' + variant='full' /> , ); @@ -97,6 +170,7 @@ describe('Switcher', () => { expect(trigger).toHaveAttribute('data-variant', 'full'); expect(trigger.querySelector('.cl-switcher-trigger-label')).toHaveTextContent('Acme'); expect(trigger).toHaveTextContent('Pro'); + expect(trigger.querySelector('.cl-badge')).toHaveTextContent('Pro'); rerender( @@ -114,8 +188,26 @@ describe('Switcher', () => { , ); - expect(screen.getByRole('button', { name: 'Open account menu' }).querySelector('.cl-switcher-trigger-label')).toBe( - null, + const avatarOnly = screen.getByRole('button', { name: 'Open account menu' }); + expect(avatarOnly).toHaveAttribute('data-variant', 'condensed'); + expect(avatarOnly.querySelector('.cl-switcher-trigger-label')).toBeNull(); + expect(avatarOnly.querySelector('.cl-avatar')).toHaveAttribute('data-shape', 'circle'); + }); + + it('keeps the label and an empty badge when given empty strings', () => { + render( + + + , ); + + const trigger = screen.getByRole('button', { name: 'Open account menu' }); + expect(trigger.querySelector('.cl-switcher-trigger-label')).not.toBeNull(); + expect(trigger.querySelector('.cl-badge')).not.toBeNull(); }); }); diff --git a/packages/mosaic/src/features/switcher/switcher.controller.tsx b/packages/mosaic/src/features/switcher/switcher.controller.tsx index 9c4dd517f31..fd2a0372774 100644 --- a/packages/mosaic/src/features/switcher/switcher.controller.tsx +++ b/packages/mosaic/src/features/switcher/switcher.controller.tsx @@ -4,7 +4,7 @@ import { useMachine } from '../../machine/use-machine'; import type { SwitcherModel } from './switcher.model'; import type { SwitcherMenuProps, SwitcherMode } from './switcher.types'; import { switcherBusyKeys } from './switcher.types'; -import type { SwitcherTriggerProps, SwitcherViewProps } from './switcher.view'; +import type { SwitcherTriggerOptions, SwitcherViewProps } from './switcher.view'; /** The model once Clerk has answered, which is the only shape an action can start from. */ export type SwitcherReadyModel = Extract; @@ -101,7 +101,7 @@ export type SwitcherControllerOptions = { mode?: SwitcherMode } & SwitcherMenuPr export type SwitcherController = | { status: 'loading' } | { status: 'hidden' } - | ({ status: 'ready' } & Omit); + | ({ status: 'ready' } & Omit); /** * The controller is the layer between the component (view) and the external world (model). diff --git a/packages/mosaic/src/features/switcher/switcher.tsx b/packages/mosaic/src/features/switcher/switcher.tsx index 64f50e4950c..ee087f9c6b3 100644 --- a/packages/mosaic/src/features/switcher/switcher.tsx +++ b/packages/mosaic/src/features/switcher/switcher.tsx @@ -12,10 +12,10 @@ import type { import { useSwitcherModel } from './switcher.model'; import { useCustomPages, useOrganizationProfilePages, useUserProfilePages } from './switcher.pages'; import type { SwitcherMenuProps, SwitcherMode } from './switcher.types'; -import type { SwitcherTriggerProps, SwitcherTriggerVariant } from './switcher.view'; +import type { SwitcherTriggerOptions, SwitcherTriggerVariant } from './switcher.view'; import { SwitcherView } from './switcher.view'; -type SwitcherBaseProps = SwitcherTriggerProps & +type SwitcherBaseProps = SwitcherTriggerOptions & SwitcherMenuProps & { /** * Fallback while loading. diff --git a/packages/mosaic/src/features/switcher/switcher.view.tsx b/packages/mosaic/src/features/switcher/switcher.view.tsx index 0ad8005c686..457a95404c4 100644 --- a/packages/mosaic/src/features/switcher/switcher.view.tsx +++ b/packages/mosaic/src/features/switcher/switcher.view.tsx @@ -23,6 +23,7 @@ import { SwitcherItemTrailing, SwitcherSeparator, } from '../../components/switcher/switcher-item'; +import type { SwitcherTriggerVariant } from '../../components/switcher/switcher-trigger'; import { SwitcherTriggerContent, triggerStyles } from '../../components/switcher/switcher-trigger'; import type { IconComponent } from '../../icons/glyph'; import { Building } from '../../icons/glyphs/building'; @@ -63,6 +64,7 @@ import { useSwitcherTriggerController } from './switcher-trigger.controller'; // The data contract, the mode flags, and the menu item shapes live in `switcher.types`; they are // what the model and the view agree on, so neither file owns them. export type * from './switcher.types'; +export type { SwitcherTriggerVariant }; type SwitcherContextValue = SwitcherData & SwitcherCallbacks & @@ -1011,7 +1013,7 @@ export function SwitcherRoot(props: SwitcherRootProps): ReactElement { ); } -export interface SwitcherTriggerProps { +export interface SwitcherTriggerOptions { /** * Names the lead beside its avatar — the organization wherever one heads the trigger, no * selection when personal is hidden and none is active, the account otherwise. Turn it off for the avatar alone. @@ -1031,14 +1033,12 @@ export interface SwitcherTriggerProps { triggerBadge?: SwitcherTriggerBadge; } -export type SwitcherTriggerVariant = 'full' | 'condensed'; - /** The trigger: the lead's avatar, and what it is called. */ export function SwitcherTrigger({ showTriggerLabel = true, triggerBadge = true, triggerVariant = 'condensed', -}: SwitcherTriggerProps & { triggerVariant?: SwitcherTriggerVariant } = {}): ReactElement { +}: SwitcherTriggerOptions & { triggerVariant?: SwitcherTriggerVariant } = {}): ReactElement { const m = useSwitcherMessages(); const slot = useSlot(); const data = useSwitcherContext(); @@ -1068,7 +1068,8 @@ export function SwitcherTrigger({ variant={showTriggerLabel ? triggerVariant : 'avatarOnly'} /> } - name={showTriggerLabel ? name : undefined} + showLabel={showTriggerLabel} + name={name} badge={typeof planLabel === 'string' ? planLabel : undefined} badgeId={badge?.id} /> @@ -1128,7 +1129,7 @@ export function SwitcherPopup(): ReactElement { } export type SwitcherViewProps = Omit & - SwitcherTriggerProps & { triggerVariant?: SwitcherTriggerVariant }; + SwitcherTriggerOptions & { triggerVariant?: SwitcherTriggerVariant }; /** * Presentational all-in-one: renders the trigger + popup from a single prop-driven call. The diff --git a/packages/mosaic/src/styles/index.ts b/packages/mosaic/src/styles/index.ts index 9d513f68bc1..992591a7a54 100644 --- a/packages/mosaic/src/styles/index.ts +++ b/packages/mosaic/src/styles/index.ts @@ -190,6 +190,8 @@ export type { ProfileRootProps, ProfileTitleProps, } from '../components/profile'; +// Aliased: `Switcher` below is the feature. +export { Switcher as SwitcherParts } from '../components/switcher'; export { OAuthConsent } from '../features/oauth-consent/oauth-consent'; export { CreateOrganization } from '../features/create-organization/create-organization'; export { OrganizationList } from '../features/organization-list/organization-list'; From 31376a864170c49b0a5b182936bd545bd38c35e1 Mon Sep 17 00:00:00 2001 From: Max Yinger Date: Tue, 17 Nov 2026 14:16:06 -0700 Subject: [PATCH 7/8] feat(mosaic): publish Popover and document the Switcher's full composition Add the `@clerk/mosaic/components/popover` entry, and document the Switcher parts as the switcher composes them: `Popover.Trigger` rendering `Switcher.Trigger`, and `Popover.Popup` holding a `Card.Root` with the header and row groups. Test that composition. Co-Authored-By: Claude Opus 5.5 --- .changeset/mosaic-component-entry-points.md | 1 + packages/mosaic/package.json | 5 ++ .../mosaic/src/components/popover/index.ts | 2 + .../mosaic/src/components/switcher/index.ts | 46 ++++++++++--- .../src/components/switcher/switcher.doc.ts | 66 +++++++++++++------ .../src/components/switcher/switcher.test.tsx | 52 ++++++++++++++- packages/mosaic/tsdown.config.mts | 1 + 7 files changed, 141 insertions(+), 32 deletions(-) diff --git a/.changeset/mosaic-component-entry-points.md b/.changeset/mosaic-component-entry-points.md index bd98368faa8..cc99542dfd2 100644 --- a/.changeset/mosaic-component-entry-points.md +++ b/.changeset/mosaic-component-entry-points.md @@ -5,6 +5,7 @@ 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`: the parts `UserButton` and `OrganizationSwitcher` are built from (`Switcher.Trigger`, `Switcher.Header`, `Switcher.Avatar`, `Switcher.BadgedAvatar`, `Switcher.Group`, `Switcher.Separator`, and `Switcher.Item` with `ItemMedia`, `ItemContent`, `ItemLabel`, `ItemDescription` and `ItemTrailing`) - The `Building`, `Checkmark`, `ChevronDown`, `ChevronRight`, `Cog6Teeth`, `EllipsisHorizontal`, `Key`, `SecurityLockSquare`, `SecurityPhone`, `SignOut`, `SwitchAccount` and `UsersAddRight` glyphs from `@clerk/mosaic/icons/glyphs/` diff --git a/packages/mosaic/package.json b/packages/mosaic/package.json index 4747aab8698..ca1aaa26e26 100644 --- a/packages/mosaic/package.json +++ b/packages/mosaic/package.json @@ -106,6 +106,11 @@ "import": "./dist/components/panel.js", "default": "./dist/components/panel.js" }, + "./components/popover": { + "types": "./dist/components/popover.d.ts", + "import": "./dist/components/popover.js", + "default": "./dist/components/popover.js" + }, "./components/profile": { "types": "./dist/components/profile.d.ts", "import": "./dist/components/profile.js", diff --git a/packages/mosaic/src/components/popover/index.ts b/packages/mosaic/src/components/popover/index.ts index 9f9a1f79cd6..b1ebacca9a1 100644 --- a/packages/mosaic/src/components/popover/index.ts +++ b/packages/mosaic/src/components/popover/index.ts @@ -1,3 +1,5 @@ +'use client'; + /** A floating box anchored to a trigger. */ export * as Popover from './popover.parts'; export type { diff --git a/packages/mosaic/src/components/switcher/index.ts b/packages/mosaic/src/components/switcher/index.ts index d1d909e43a7..f560df12703 100644 --- a/packages/mosaic/src/components/switcher/index.ts +++ b/packages/mosaic/src/components/switcher/index.ts @@ -3,17 +3,45 @@ /** * The account and organization switcher's parts: its trigger, the popover's header, and its rows. * `UserButton`, `OrganizationSwitcher` and `Switcher` compose them with Clerk's session and - * organization state. + * organization state. The parts sit inside a `Popover` and a `Card`: `Popover.Trigger` renders + * `Switcher.Trigger`, and `Popover.Popup` holds a `Card.Root` with the header and the row groups. * * ```tsx - * } title='Acme' /> - * - * - * - * - * Globex - * - * + * + * } + * name='Acme' + * badge='Pro' + * variant='full' + * /> + * } + * /> + * + * + * } + * title='Acme' + * description='alice@example.com' + * /> + * + * + * }> + * + * + * + * + * Globex + * Member + * + * … + * + * + * + * + * * ``` */ export * as Switcher from './switcher.parts'; diff --git a/packages/mosaic/src/components/switcher/switcher.doc.ts b/packages/mosaic/src/components/switcher/switcher.doc.ts index af83bfa57cf..4beb88c3f3e 100644 --- a/packages/mosaic/src/components/switcher/switcher.doc.ts +++ b/packages/mosaic/src/components/switcher/switcher.doc.ts @@ -16,13 +16,21 @@ import type { SwitcherTriggerProps } from './switcher-trigger'; export default { name: 'Switcher', description: - "The account and organization switcher's parts: the trigger, the popover's header, and its rows. `UserButton`, `OrganizationSwitcher` and `Switcher` from `@clerk/mosaic` compose them with Clerk's session and organization state. These parts carry `cl-switcher-*` classes; inside `UserButton` and `OrganizationSwitcher` the same parts carry `cl-user-button-*` and `cl-organization-switcher-*`. `Switcher.Avatar` carries `cl-avatar`.", + "The account and organization switcher's parts: the trigger, the popover's header, and its rows. `UserButton`, `OrganizationSwitcher` and `Switcher` from `@clerk/mosaic` compose them with Clerk's session and organization state. They sit inside a `Popover` and a `Card`: `Popover.Trigger` renders `Switcher.Trigger`, and `Popover.Popup` holds a `Card.Root` with `Switcher.Header`, then `Switcher.Group`s of `Switcher.Item`s split by `Switcher.Separator`s. These parts carry `cl-switcher-*` classes; inside `UserButton` and `OrganizationSwitcher` the same parts carry `cl-user-button-*` and `cl-organization-switcher-*`. `Switcher.Avatar` carries `cl-avatar`.", useFor: [ 'a custom account or organization switcher composed from its parts', 'switcher rows or a switcher trigger rendered with your own data', ], keywords: ['switcher', 'user button', 'organization switcher', 'account switcher', 'menu rows'], practices: [ + { + do: true, + text: "Render `Switcher.Trigger` through `Popover.Trigger`'s `render` prop, so the popover owns the open state and the button keeps the trigger's look.", + }, + { + do: true, + text: 'Put `Switcher.Header` and the row groups in a `Card.Root` inside `Popover.Popup`.', + }, { do: true, text: 'Wrap rows in a `Switcher.Group`, and split groups with a `Switcher.Separator`.', @@ -33,7 +41,7 @@ export default { }, { do: false, - text: 'Build a working account menu from these parts. Use `UserButton` or `OrganizationSwitcher`, which read Clerk and open the popover.', + text: 'Expect the parts to read Clerk or hold state. They render the props they are given; `UserButton` and `OrganizationSwitcher` connect them to Clerk.', }, ], parts: { @@ -128,25 +136,43 @@ export default { }, examples: [ { - title: 'A header and one organization row', + title: 'A trigger and its popover', code: ` -} - title='Acme' - description='alice@example.com' -/> - - - }> - - - - - Globex - Member - - - + + } + name='Acme' + badge='Pro' + variant='full' + /> + } + /> + + + } + title='Acme' + description='alice@example.com' + /> + + + }> + + + + + Globex + Member + + … + + + + + `, }, ], diff --git a/packages/mosaic/src/components/switcher/switcher.test.tsx b/packages/mosaic/src/components/switcher/switcher.test.tsx index c5b50bdf873..c47cd4ebbec 100644 --- a/packages/mosaic/src/components/switcher/switcher.test.tsx +++ b/packages/mosaic/src/components/switcher/switcher.test.tsx @@ -1,14 +1,17 @@ import * as stylex from '@stylexjs/stylex'; import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import React from 'react'; import { describe, expect, it } from 'vitest'; import { MosaicProvider } from '../../mosaic-provider'; import { axe } from '../../primitives/test-utils/axe'; +import { Card } from '../card'; +import { Popover } from '../popover'; import { Switcher } from '.'; import { SwitcherSurfaceProvider } from './switcher.context'; -function Popover() { +function PopupContent() { return ( <> { it('renders the popover parts with their switcher slots', async () => { const { container } = render( - + , ); @@ -72,7 +75,7 @@ describe('Switcher', () => { const { container } = render( - + , ); @@ -210,4 +213,47 @@ describe('Switcher', () => { expect(trigger.querySelector('.cl-switcher-trigger-label')).not.toBeNull(); expect(trigger.querySelector('.cl-badge')).not.toBeNull(); }); + + it('composes as the switcher does: a popover trigger rendering Switcher.Trigger, and a card in the popup', async () => { + const user = userEvent.setup(); + render( + + + + } + name='Acme' + variant='full' + /> + } + /> + + + + + + + , + ); + + const trigger = screen.getByRole('button', { name: 'Open account menu' }); + expect(trigger).toHaveClass('cl-popover-trigger', 'cl-switcher-trigger'); + expect(trigger).toHaveAttribute('data-variant', 'full'); + expect(trigger).toHaveAttribute('aria-expanded', 'false'); + + await user.click(trigger); + + expect(trigger).toHaveAttribute('aria-expanded', 'true'); + expect(await screen.findByRole('dialog', { name: 'Account menu' })).toContainElement( + screen.getByRole('button', { name: 'Globex Member Pro' }), + ); + }); }); diff --git a/packages/mosaic/tsdown.config.mts b/packages/mosaic/tsdown.config.mts index 4ebe76e7baa..d5ae76fb5d2 100644 --- a/packages/mosaic/tsdown.config.mts +++ b/packages/mosaic/tsdown.config.mts @@ -30,6 +30,7 @@ export default defineConfig({ 'components/input': './src/components/input/index.ts', 'components/item': './src/components/item/index.ts', 'components/panel': './src/components/panel/index.ts', + 'components/popover': './src/components/popover/index.ts', 'components/profile': './src/components/profile/index.ts', 'components/provider-button': './src/components/provider-button/index.ts', 'components/radio': './src/components/radio/index.ts', From 50243c3702efaee0ff6df55d3e69e8abebce2a0e Mon Sep 17 00:00:00 2001 From: Max Yinger Date: Tue, 17 Nov 2026 14:28:47 -0700 Subject: [PATCH 8/8] feat(mosaic): give Switcher a Root, Trigger and Popup like Select and Menu `Switcher.Root` holds the popover's open state, `Switcher.Trigger` is the real popover trigger, and `Switcher.Popup` positions the card that holds the header and rows. The switcher feature now builds from these parts instead of Popover and Card directly; its output is unchanged. Outside a `Switcher.Root`, `Switcher.Trigger` renders a plain button with the same look instead of throwing. Co-Authored-By: Claude Opus 5.5 --- .changeset/mosaic-component-entry-points.md | 2 +- .../mosaic/src/components/switcher/index.ts | 70 ++++---- .../switcher/switcher-popup.styles.ts | 7 + .../components/switcher/switcher-popup.tsx | 39 +++++ .../src/components/switcher/switcher-root.tsx | 24 +++ .../components/switcher/switcher-trigger.tsx | 77 +++++---- .../components/switcher/switcher.context.ts | 9 + .../src/components/switcher/switcher.doc.ts | 104 ++++++------ .../src/components/switcher/switcher.parts.ts | 4 +- .../src/components/switcher/switcher.test.tsx | 156 +++++++++++++----- .../src/features/switcher/switcher.styles.ts | 4 - .../src/features/switcher/switcher.view.tsx | 64 +++---- 12 files changed, 367 insertions(+), 193 deletions(-) create mode 100644 packages/mosaic/src/components/switcher/switcher-popup.styles.ts create mode 100644 packages/mosaic/src/components/switcher/switcher-popup.tsx create mode 100644 packages/mosaic/src/components/switcher/switcher-root.tsx diff --git a/.changeset/mosaic-component-entry-points.md b/.changeset/mosaic-component-entry-points.md index cc99542dfd2..b24ecf805d7 100644 --- a/.changeset/mosaic-component-entry-points.md +++ b/.changeset/mosaic-component-entry-points.md @@ -7,5 +7,5 @@ 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`: the parts `UserButton` and `OrganizationSwitcher` are built from (`Switcher.Trigger`, `Switcher.Header`, `Switcher.Avatar`, `Switcher.BadgedAvatar`, `Switcher.Group`, `Switcher.Separator`, and `Switcher.Item` with `ItemMedia`, `ItemContent`, `ItemLabel`, `ItemDescription` and `ItemTrailing`) +- `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/` diff --git a/packages/mosaic/src/components/switcher/index.ts b/packages/mosaic/src/components/switcher/index.ts index f560df12703..5538962d854 100644 --- a/packages/mosaic/src/components/switcher/index.ts +++ b/packages/mosaic/src/components/switcher/index.ts @@ -1,47 +1,41 @@ 'use client'; /** - * The account and organization switcher's parts: its trigger, the popover's header, and its rows. - * `UserButton`, `OrganizationSwitcher` and `Switcher` compose them with Clerk's session and - * organization state. The parts sit inside a `Popover` and a `Card`: `Popover.Trigger` renders - * `Switcher.Trigger`, and `Popover.Popup` holds a `Card.Root` with the header and the row groups. + * 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 - * - * + * } - * name='Acme' - * badge='Pro' - * variant='full' - * /> - * } + * avatar={} + * name='Acme' + * badge='Pro' + * variant='full' * /> - * - * - * } - * title='Acme' - * description='alice@example.com' - * /> - * - * - * }> - * - * - * - * - * Globex - * Member - * - * … - * - * - * - * - * + * + * } + * title='Acme' + * description='alice@example.com' + * /> + * + * + * }> + * + * + * + * + * Globex + * Member + * + * … + * + * + * + * * ``` */ export * as Switcher from './switcher.parts'; @@ -57,4 +51,6 @@ export type { SwitcherItemTrailingProps, SwitcherSeparatorProps, } from './switcher-item'; +export type { SwitcherPopupProps } from './switcher-popup'; +export type { SwitcherRootProps } from './switcher-root'; export type { SwitcherTriggerProps, SwitcherTriggerVariant } from './switcher-trigger'; diff --git a/packages/mosaic/src/components/switcher/switcher-popup.styles.ts b/packages/mosaic/src/components/switcher/switcher-popup.styles.ts new file mode 100644 index 00000000000..0a675c3eb0a --- /dev/null +++ b/packages/mosaic/src/components/switcher/switcher-popup.styles.ts @@ -0,0 +1,7 @@ +import * as stylex from '@stylexjs/stylex'; + +export const styles = stylex.create({ + popup: { + width: 'min(21.875rem, calc(100vw - 2rem))', + }, +}); diff --git a/packages/mosaic/src/components/switcher/switcher-popup.tsx b/packages/mosaic/src/components/switcher/switcher-popup.tsx new file mode 100644 index 00000000000..d375d832a46 --- /dev/null +++ b/packages/mosaic/src/components/switcher/switcher-popup.tsx @@ -0,0 +1,39 @@ +'use client'; + +import React from 'react'; + +import type { MosaicElementProps } from '../../props'; +import { themeProps } from '../../props'; +import { Card } from '../card'; +import { Popover } from '../popover'; +import { useSlot } from './switcher.context'; +import { styles } from './switcher-popup.styles'; + +export interface SwitcherPopupProps extends MosaicElementProps<'div'> { + /** Names the popup. */ + 'aria-label': string; + /** + * Shows Clerk branding at the foot of the card. + * + * @default true + */ + renderBranding?: boolean; +} + +/** The floating popup: portals, positions against the trigger, and paints a `Card` holding the header and rows. */ +export const SwitcherPopup = React.forwardRef(function SwitcherPopup( + { renderBranding, children, xstyle, ...rest }, + ref, +) { + const slot = useSlot(); + return ( + + {children} + + ); +}); diff --git a/packages/mosaic/src/components/switcher/switcher-root.tsx b/packages/mosaic/src/components/switcher/switcher-root.tsx new file mode 100644 index 00000000000..f6d8447e3cd --- /dev/null +++ b/packages/mosaic/src/components/switcher/switcher-root.tsx @@ -0,0 +1,24 @@ +'use client'; + +import type { ReactElement } from 'react'; + +import type { PopoverRootProps } from '../popover'; +import { Popover } from '../popover'; +import { SwitcherRootProvider } from './switcher.context'; + +export type SwitcherRootProps = Pick< + PopoverRootProps, + 'open' | 'defaultOpen' | 'onOpenChange' | 'placement' | 'sideOffset' | 'alignOffset' | 'children' +>; + +/** Holds the popover's open state; renders no element of its own. */ +export function SwitcherRoot({ placement = 'bottom-start', children, ...rest }: SwitcherRootProps): ReactElement { + return ( + + {children} + + ); +} diff --git a/packages/mosaic/src/components/switcher/switcher-trigger.tsx b/packages/mosaic/src/components/switcher/switcher-trigger.tsx index aa3af4118ea..7303d16dfdd 100644 --- a/packages/mosaic/src/components/switcher/switcher-trigger.tsx +++ b/packages/mosaic/src/components/switcher/switcher-trigger.tsx @@ -8,14 +8,14 @@ import { ChevronDown } from '../../icons/glyphs/chevron-down'; import type { MosaicElementProps } from '../../props'; 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 { Badge } from '../badge'; import { Icon } from '../icon'; -import { useSlot } from './switcher.context'; +import { Popover } from '../popover'; +import { useInSwitcherRoot, useSlot } from './switcher.context'; import { styles } from './switcher-trigger.styles'; -export function triggerStyles(showLabel: boolean, shape: 'circle' | 'square') { +function triggerStyles(showLabel: boolean, shape: 'circle' | 'square') { return [ focusOutline.visible, styles.trigger, @@ -24,7 +24,7 @@ export function triggerStyles(showLabel: boolean, shape: 'circle' | 'square') { ]; } -export function SwitcherTriggerContent({ +function SwitcherTriggerContent({ avatar, showLabel, name, @@ -77,6 +77,8 @@ export interface SwitcherTriggerProps extends Omit, name?: string; /** A plan or status label beside the name. */ badge?: string; + /** Set as `data-badge-id` on the badge. */ + badgeId?: string; /** Rounds the avatar-only trigger to match a circular avatar. */ shape?: 'circle' | 'square'; /** @@ -90,31 +92,50 @@ export interface SwitcherTriggerProps extends Omit, export type SwitcherTriggerVariant = 'full' | 'condensed'; -/** The trigger's look on a plain button, without the popover it opens. */ -export const SwitcherTriggerButton = React.forwardRef( - function SwitcherTriggerButton( - { avatar, name, badge, shape = 'square', variant = 'condensed', xstyle, ...rest }, - ref, - ) { - const slot = useSlot(); - const showLabel = name !== undefined; +/** Opens the popup. */ +export const SwitcherTrigger = React.forwardRef(function SwitcherTrigger( + { avatar, name, badge, badgeId, shape = 'square', variant = 'condensed', xstyle, ...rest }, + ref, +) { + const slot = useSlot(); + const inRoot = useInSwitcherRoot(); + const showLabel = name !== undefined; + const content = ( + + ); + + if (inRoot) { return ( - + {content} + ); - }, -); + } + + // Outside a `Switcher.Root` there is no popover to wire up, so render the same look, slots and + // data attributes on a plain button rather than throw. This lets the trigger render on its own. + return ( + + ); +}); diff --git a/packages/mosaic/src/components/switcher/switcher.context.ts b/packages/mosaic/src/components/switcher/switcher.context.ts index 8a750d1654d..bb2416af4a1 100644 --- a/packages/mosaic/src/components/switcher/switcher.context.ts +++ b/packages/mosaic/src/components/switcher/switcher.context.ts @@ -15,3 +15,12 @@ export function useSlot(): (part: string) => string { const surface = useSwitcherSurface(); return part => `${surface}-${part}`; } + +const RootContext = React.createContext(false); + +export const SwitcherRootProvider = RootContext.Provider; + +/** Whether a part renders inside a `Switcher.Root`. Outside one, `Switcher.Trigger` renders a plain button. */ +export function useInSwitcherRoot(): boolean { + return React.useContext(RootContext); +} diff --git a/packages/mosaic/src/components/switcher/switcher.doc.ts b/packages/mosaic/src/components/switcher/switcher.doc.ts index 4beb88c3f3e..a3de6f8b97c 100644 --- a/packages/mosaic/src/components/switcher/switcher.doc.ts +++ b/packages/mosaic/src/components/switcher/switcher.doc.ts @@ -11,25 +11,20 @@ import type { SwitcherItemTrailingProps, SwitcherSeparatorProps, } from './switcher-item'; +import type { SwitcherPopupProps } from './switcher-popup'; +import type { SwitcherRootProps } from './switcher-root'; import type { SwitcherTriggerProps } from './switcher-trigger'; export default { name: 'Switcher', description: - "The account and organization switcher's parts: the trigger, the popover's header, and its rows. `UserButton`, `OrganizationSwitcher` and `Switcher` from `@clerk/mosaic` compose them with Clerk's session and organization state. They sit inside a `Popover` and a `Card`: `Popover.Trigger` renders `Switcher.Trigger`, and `Popover.Popup` holds a `Card.Root` with `Switcher.Header`, then `Switcher.Group`s of `Switcher.Item`s split by `Switcher.Separator`s. These parts carry `cl-switcher-*` classes; inside `UserButton` and `OrganizationSwitcher` the same parts carry `cl-user-button-*` and `cl-organization-switcher-*`. `Switcher.Avatar` carries `cl-avatar`.", - useFor: [ - 'a custom account or organization switcher composed from its parts', - 'switcher rows or a switcher trigger rendered with your own data', - ], + "The account and organization switcher. `Switcher.Root` holds the open state, `Switcher.Trigger` opens it, and `Switcher.Popup` positions a `Card` holding `Switcher.Header`, then `Switcher.Group`s of `Switcher.Item`s split by `Switcher.Separator`s. `UserButton`, `OrganizationSwitcher` and `Switcher` from `@clerk/mosaic` compose these parts with Clerk's session and organization state. The parts carry `cl-switcher-*` classes; inside `UserButton` and `OrganizationSwitcher` the same parts carry `cl-user-button-*` and `cl-organization-switcher-*`. `Switcher.Avatar` carries `cl-avatar`.", + useFor: ['an account or organization switcher composed from its parts'], keywords: ['switcher', 'user button', 'organization switcher', 'account switcher', 'menu rows'], practices: [ { do: true, - text: "Render `Switcher.Trigger` through `Popover.Trigger`'s `render` prop, so the popover owns the open state and the button keeps the trigger's look.", - }, - { - do: true, - text: 'Put `Switcher.Header` and the row groups in a `Card.Root` inside `Popover.Popup`.', + text: 'Put `Switcher.Trigger` and `Switcher.Popup` inside one `Switcher.Root`, and label the popup with `aria-label`.', }, { do: true, @@ -41,18 +36,30 @@ export default { }, { do: false, - text: 'Expect the parts to read Clerk or hold state. They render the props they are given; `UserButton` and `OrganizationSwitcher` connect them to Clerk.', + text: 'Expect the parts to read Clerk. They render the props they are given; `UserButton` and `OrganizationSwitcher` connect them to Clerk.', }, ], parts: { + 'Switcher.Root': { + description: 'Holds the open state. Renders no element of its own.', + props: { + open: { type: 'boolean', doc: 'The controlled open state.' }, + defaultOpen: { type: 'boolean', doc: 'The initial open state when uncontrolled.', default: 'false' }, + onOpenChange: { type: '(open: boolean) => void', doc: 'Called when the popup opens or closes.' }, + placement: { type: 'Placement', doc: 'Where the popup sits against the trigger.', default: "'bottom-start'" }, + sideOffset: { type: 'number', doc: 'The gap between the trigger and the popup.', default: '4' }, + alignOffset: { type: 'number', doc: 'Shifts the popup along the trigger edge.', default: '0' }, + }, + }, 'Switcher.Trigger': { description: - "The trigger's look on a plain `button`, without the popover it opens. With a `name` it shows the name, the badge and a caret; without one, the avatar alone.", + 'Opens the popup. With a `name` it shows the name, the badge and a caret; without one, the avatar alone.', slot: 'cl-switcher-trigger', props: { avatar: { type: 'ReactNode', doc: "The lead's mark, such as a `Switcher.BadgedAvatar`." }, name: { type: 'string', doc: "The lead's name. Leave it out for the avatar-only trigger." }, badge: { type: 'string', doc: 'A plan or status label beside the name.' }, + badgeId: { type: 'string', doc: 'Set as `data-badge-id` on the badge.' }, shape: { type: "'circle' | 'square'", doc: 'Rounds the avatar-only trigger to match a circular avatar.', @@ -65,6 +72,15 @@ export default { }, }, }, + 'Switcher.Popup': { + description: + 'The floating popup: portals, positions against the trigger, and paints a `Card` holding its children. A dialog named by `aria-label`.', + slot: 'cl-switcher-popover', + props: { + 'aria-label': { type: 'string', doc: 'Names the popup.' }, + renderBranding: { type: 'boolean', doc: 'Shows Clerk branding at the foot of the card.', default: 'true' }, + }, + }, 'Switcher.Header': { description: "The popover's header: the lead's avatar, its name and a description.", slot: 'cl-switcher-header', @@ -136,49 +152,45 @@ export default { }, examples: [ { - title: 'A trigger and its popover', + title: 'A trigger and its popup', code: ` - - + } - name='Acme' - badge='Pro' - variant='full' - /> - } + avatar={} + name='Acme' + badge='Pro' + variant='full' /> - - - } - title='Acme' - description='alice@example.com' - /> - - - }> - - - - - Globex - Member - - … - - - - - + + } + title='Acme' + description='alice@example.com' + /> + + + }> + + + + + Globex + Member + + … + + + + `, }, ], related: ['Avatar', 'Popover', 'Card'], } satisfies ComponentDoc<{ + 'Switcher.Root': SwitcherRootProps; 'Switcher.Trigger': SwitcherTriggerProps; + 'Switcher.Popup': SwitcherPopupProps; 'Switcher.Header': SwitcherHeaderProps; 'Switcher.Avatar': SwitcherAvatarProps; 'Switcher.BadgedAvatar': SwitcherBadgedAvatarProps; diff --git a/packages/mosaic/src/components/switcher/switcher.parts.ts b/packages/mosaic/src/components/switcher/switcher.parts.ts index 8ab37348eaa..66ac65f5f5d 100644 --- a/packages/mosaic/src/components/switcher/switcher.parts.ts +++ b/packages/mosaic/src/components/switcher/switcher.parts.ts @@ -10,4 +10,6 @@ export { SwitcherGroup as Group, SwitcherSeparator as Separator, } from './switcher-item'; -export { SwitcherTriggerButton as Trigger } from './switcher-trigger'; +export { SwitcherPopup as Popup } from './switcher-popup'; +export { SwitcherRoot as Root } from './switcher-root'; +export { SwitcherTrigger as Trigger } from './switcher-trigger'; diff --git a/packages/mosaic/src/components/switcher/switcher.test.tsx b/packages/mosaic/src/components/switcher/switcher.test.tsx index c47cd4ebbec..fc0d79acac2 100644 --- a/packages/mosaic/src/components/switcher/switcher.test.tsx +++ b/packages/mosaic/src/components/switcher/switcher.test.tsx @@ -1,13 +1,13 @@ import * as stylex from '@stylexjs/stylex'; -import { render, screen } from '@testing-library/react'; +import { render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import React from 'react'; -import { describe, expect, it } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import { MosaicProvider } from '../../mosaic-provider'; import { axe } from '../../primitives/test-utils/axe'; import { Card } from '../card'; -import { Popover } from '../popover'; +import type { SwitcherRootProps } from '.'; import { Switcher } from '.'; import { SwitcherSurfaceProvider } from './switcher.context'; @@ -214,46 +214,126 @@ describe('Switcher', () => { expect(trigger.querySelector('.cl-badge')).not.toBeNull(); }); - it('composes as the switcher does: a popover trigger rendering Switcher.Trigger, and a card in the popup', async () => { - const user = userEvent.setup(); - render( - - - - } - name='Acme' - variant='full' - /> - } - /> - - + describe('Root, Trigger and Popup', () => { + function Composed(props: Partial) { + return ( + + + + } + name='Acme' + badge='Pro' + variant='full' + /> + - - - + + + + ); + } + + it('opens the popup from the trigger, and closes it with Escape', async () => { + const user = userEvent.setup(); + render(); + + const trigger = screen.getByRole('button', { name: 'Open account menu' }); + expect(trigger).toHaveClass('cl-popover-trigger', 'cl-switcher-trigger'); + expect(trigger).toHaveAttribute('data-variant', 'full'); + expect(trigger).toHaveAttribute('aria-expanded', 'false'); + expect(screen.queryByRole('dialog')).toBeNull(); + + await user.click(trigger); + + expect(trigger).toHaveAttribute('aria-expanded', 'true'); + expect(trigger).toHaveAttribute('data-open'); + const dialog = await screen.findByRole('dialog', { name: 'Account menu' }); + expect(trigger).toHaveAttribute('aria-controls', dialog.id); + const popup = dialog.querySelector('.cl-switcher-popover'); + expect(popup).toHaveClass('cl-popover-popup'); + expect(popup?.querySelector('.cl-card-root')).toContainElement( + screen.getByRole('button', { name: 'Globex Member Pro' }), + ); + expect(popup?.querySelector('.cl-switcher-header')).not.toBeNull(); + + await user.keyboard('{Escape}'); + + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); + expect(trigger).toHaveAttribute('aria-expanded', 'false'); + expect(trigger).toHaveFocus(); + }); + + it('opens from the keyboard and moves focus into the popup', async () => { + const user = userEvent.setup(); + render(); + + await user.tab(); + expect(screen.getByRole('button', { name: 'Open account menu' })).toHaveFocus(); + await user.keyboard('{Enter}'); + + await screen.findByRole('dialog', { name: 'Account menu' }); + await waitFor(() => expect(screen.getByRole('button', { name: 'Globex Member Pro' })).toHaveFocus()); + }); + + it('follows a controlled open state', async () => { + const user = userEvent.setup(); + const onOpenChange = vi.fn(); + const { rerender } = render( + , + ); + + expect(await screen.findByRole('dialog', { name: 'Account menu' })).toBeInTheDocument(); + await user.click(screen.getByRole('button', { name: 'Open account menu' })); + expect(onOpenChange).toHaveBeenCalledWith(false); + + rerender( + , + ); + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); + }); + }); + + it('renders open in normal flow from the content parts inside a Card, with the trigger beside it on its own', () => { + const { container } = render( + + + + + + } + name='Acme' + variant='full' + /> , ); + expect(screen.queryByRole('dialog')).toBeNull(); + expect(container.querySelector('.cl-card-root .cl-switcher-header')).not.toBeNull(); + expect(container.querySelector('.cl-card-root .cl-switcher-item')).not.toBeNull(); const trigger = screen.getByRole('button', { name: 'Open account menu' }); - expect(trigger).toHaveClass('cl-popover-trigger', 'cl-switcher-trigger'); + expect(trigger).toHaveClass('cl-switcher-trigger'); + expect(trigger).not.toHaveClass('cl-popover-trigger'); expect(trigger).toHaveAttribute('data-variant', 'full'); - expect(trigger).toHaveAttribute('aria-expanded', 'false'); - - await user.click(trigger); - - expect(trigger).toHaveAttribute('aria-expanded', 'true'); - expect(await screen.findByRole('dialog', { name: 'Account menu' })).toContainElement( - screen.getByRole('button', { name: 'Globex Member Pro' }), - ); + expect(trigger).not.toHaveAttribute('aria-expanded'); }); }); diff --git a/packages/mosaic/src/features/switcher/switcher.styles.ts b/packages/mosaic/src/features/switcher/switcher.styles.ts index 581f272f25e..3f25c3b539e 100644 --- a/packages/mosaic/src/features/switcher/switcher.styles.ts +++ b/packages/mosaic/src/features/switcher/switcher.styles.ts @@ -16,8 +16,4 @@ export const styles = stylex.create({ scroll: { maxHeight: '18rem', }, - - popup: { - width: 'min(21.875rem, calc(100vw - 2rem))', - }, }); diff --git a/packages/mosaic/src/features/switcher/switcher.view.tsx b/packages/mosaic/src/features/switcher/switcher.view.tsx index 457a95404c4..1f3c05366c0 100644 --- a/packages/mosaic/src/features/switcher/switcher.view.tsx +++ b/packages/mosaic/src/features/switcher/switcher.view.tsx @@ -4,13 +4,12 @@ import type { ReactElement, ReactNode } from 'react'; import React from 'react'; import { SubmitButton } from '../../components/button'; -import { Card } from '../../components/card'; import { Icon } from '../../components/icon'; import { Menu } from '../../components/menu'; -import { Popover } from '../../components/popover'; import { scrollAreaViewport } from '../../components/scroll-area'; import { Spinner } from '../../components/spinner'; -import { SwitcherSurfaceProvider, useSlot } from '../../components/switcher/switcher.context'; +import { Switcher } from '../../components/switcher'; +import { SwitcherSurfaceProvider } from '../../components/switcher/switcher.context'; import { BadgedAvatar, RowAvatar } from '../../components/switcher/switcher-avatar'; import { SwitcherHeader } from '../../components/switcher/switcher-header'; import { @@ -24,7 +23,6 @@ import { SwitcherSeparator, } from '../../components/switcher/switcher-item'; import type { SwitcherTriggerVariant } from '../../components/switcher/switcher-trigger'; -import { SwitcherTriggerContent, triggerStyles } from '../../components/switcher/switcher-trigger'; import type { IconComponent } from '../../icons/glyph'; import { Building } from '../../icons/glyphs/building'; import { Checkmark } from '../../icons/glyphs/checkmark'; @@ -38,7 +36,6 @@ import { UsersAddRight } from '../../icons/glyphs/users-add-right'; import { fill, plural, useLocale, useMessages } from '../../localization'; import { Button as HeadlessButton } from '../../primitives/button'; import type { PopoverProps } from '../../primitives/popover'; -import { themeProps } from '../../props'; import { rtl } from '../../styles/rtl.styles'; import { applyOrder } from '../../utils/apply-order'; import type { SwitcherLayout } from './switcher.layout'; @@ -989,7 +986,7 @@ export interface SwitcherRootProps /** * Owns the account/organization data + callbacks and forwards the popover's open state straight to - * the headless `Popover.Root` — it does not keep a second controllable-state copy. Leaves consume + * `Switcher.Root` — it does not keep a second controllable-state copy. Leaves consume * the data through context. */ export function SwitcherRoot(props: SwitcherRootProps): ReactElement { @@ -999,17 +996,17 @@ export function SwitcherRoot(props: SwitcherRootProps): ReactElement { const layout = resolveSwitcherLayout(mode, data); return ( - {children} - + ); } @@ -1040,7 +1037,6 @@ export function SwitcherTrigger({ triggerVariant = 'condensed', }: SwitcherTriggerOptions & { triggerVariant?: SwitcherTriggerVariant } = {}): ReactElement { const m = useSwitcherMessages(); - const slot = useSlot(); const data = useSwitcherContext(); const lead = leadSelection(data, m); const { name, shape } = lead; @@ -1056,24 +1052,20 @@ export function SwitcherTrigger({ const user = leadUser(lead); return ( - - - } - showLabel={showTriggerLabel} - name={name} - badge={typeof planLabel === 'string' ? planLabel : undefined} - badgeId={badge?.id} - /> - + avatar={ + + } + name={showTriggerLabel ? name : undefined} + badge={typeof planLabel === 'string' ? planLabel : undefined} + badgeId={badge?.id} + shape={shape} + variant={triggerVariant} + /> ); } @@ -1109,22 +1101,18 @@ function TriggerAvatar({ /** The popover surface: header, organizations, what can be done about the lead, and footer. */ export function SwitcherPopup(): ReactElement { const m = useSwitcherMessages(); - const slot = useSlot(); const { renderBranding } = useSwitcherContext(); return ( - - -
- - -