Skip to content

feat(ui): Mosaic <Card /> component scaffolding#8893

Open
alexcarpenter wants to merge 4 commits into
mainfrom
carp/mosaic-card
Open

feat(ui): Mosaic <Card /> component scaffolding#8893
alexcarpenter wants to merge 4 commits into
mainfrom
carp/mosaic-card

Conversation

@alexcarpenter

@alexcarpenter alexcarpenter commented Jun 17, 2026

Copy link
Copy Markdown
Member

Description

Scaffolds new Mosaic <Card /> component

https://swingset-git-carp-mosaic-card.clerkstage.dev/components/card

Introduces component contexts to supply defaults for slots.

<Card.Header>
  <Heading>Hello world</Heading>
  <Text>This is a description</Text> <- defaults to { intent: 'mutedForeground' }
</Card.Header>

due to <TextContext.Provider value={{ intent: 'mutedForeground' }}> usage https://github.com/clerk/javascript/pull/8893/changes#diff-995e269e94151b9b4203bd0881168e3efa678d79930d0225f58aaae1476a7ac1R83

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
swingset Ready Ready Preview, Comment Jun 17, 2026 2:57pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
clerk-js-sandbox Skipped Skipped Jun 17, 2026 2:57pm

Request Review

@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3ec67fd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new Mosaic Card component with a slot recipe (root, header, content, footer) and an alignment variant. Introduces a useContextProps utility hook used by Text and Heading for context-driven prop resolution. Adds a fullWidth boolean variant to Button, card color tokens to the theme, and registers a Card docs page in the Swingset storybook.

Changes

Mosaic Card Component and Supporting Infrastructure

Layer / File(s) Summary
useContextProps hook
packages/ui/src/mosaic/utils/context.ts
New useContextProps<T> hook merges a React context value with incoming props, using props as the override source for any defined fields.
Card theme tokens
packages/ui/src/mosaic/variables.ts
Adds color.card and color.cardForeground to defaultMosaicVariables, expanding the inferred MosaicTokens/MosaicTheme types. Reformats merge() guard logic to explicit if/continue blocks.
TextContext and HeadingContext
packages/ui/src/mosaic/components/text.tsx, packages/ui/src/mosaic/components/heading.tsx
Exports new TextContext and HeadingContext React contexts; updates Text and Heading to resolve props via useContextProps instead of reading incoming props directly.
Button fullWidth variant
packages/ui/src/mosaic/components/button.tsx
Adds a fullWidth boolean variant to buttonRecipe (applying width: 100% when true), sets fullWidth: false in defaultVariants, and updates Button to forward it into recipe variant selection.
Card component
packages/ui/src/mosaic/components/card.tsx
Introduces cardRecipe with root/header/content/footer slots and an alignment variant. Exports Card with Card.Root, Card.Header (wraps children in TextContext.Provider with intent: 'mutedForeground'), Card.Content, and Card.Footer subcomponents via forwardRef.
DialogContent non-function children guard
packages/ui/src/mosaic/components/dialog.tsx
Expands the children type guard in DialogContent to return children directly when it is not a render function, before calling it as a render prop.
Swingset Card docs and stories
packages/swingset/src/stories/card.component.stories.tsx, packages/swingset/src/stories/card.component.mdx, packages/swingset/src/lib/registry.ts, packages/swingset/src/components/DocsViewer.tsx
Adds Default and Centered story renderers with full-width buttons; an MDX page with Preview, PropTable, usage snippet, and Examples section; and wires the Card module into the registry and DocsViewer doc module map.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • clerk/javascript#8755: Both PRs modify packages/ui/src/mosaic/variables.ts — this PR extends defaultMosaicVariables with color.card and color.cardForeground tokens on top of the foundation introduced there.
  • clerk/javascript#8814: Both PRs extend the same Swingset DocsViewer.tsx docModules map and lib/registry.ts array to register a new component doc module (Card here, Input in #8814).
  • clerk/javascript#8830: This PR uses the same defineSlotRecipe/useRecipe slot recipe system and variant/condition infrastructure introduced in #8830 to build the Card component.

Suggested reviewers

  • brkalow

🐇 A card with a header and footer so neat,
With slots and alignment — what a feat!
TextContext whispers props through the tree,
fullWidth buttons spread wide and free.
The rabbit stamps the registry with glee! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature being added: a new Mosaic Card component with scaffolding. It directly aligns with the substantial changes across multiple files implementing the Card component, its stories, and supporting infrastructure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8893

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8893

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8893

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8893

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8893

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8893

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8893

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8893

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8893

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8893

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8893

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8893

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8893

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8893

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8893

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8893

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8893

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8893

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8893

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8893

commit: 3ec67fd

@alexcarpenter alexcarpenter marked this pull request as ready for review June 17, 2026 17:40
@github-actions

Copy link
Copy Markdown
Contributor

API Changes Report

Generated by Break Check on 2026-06-17T17:45:10.099Z

Summary

Metric Count
Packages analyzed 19
Packages with changes 0
🔴 Breaking changes 0
🟡 Non-breaking changes 0
🟢 Additions 0

No API Changes Detected

All packages have stable APIs with no detected changes.


Report generated by Break Check

Last ran on 3ec67fd.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
packages/ui/src/mosaic/components/dialog.tsx (1)

130-136: ⚡ Quick win

Add explicit return type to DialogContent for consistency with other components in this file.

All other internal components (Backdrop, Viewport, Popup) use explicit return types via React.forwardRef<…>(). While DialogContent is internal-only, adding an explicit return type aligns with the file's pattern and satisfies the coding guideline to define explicit return types for functions.

♻️ Proposed fix
-function DialogContent({ children }: { children: DialogProps['children'] }) {
+function DialogContent({ children }: { children: DialogProps['children'] }): JSX.Element {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/mosaic/components/dialog.tsx` around lines 130 - 136, The
DialogContent function lacks an explicit return type annotation while other
components in the file like Backdrop, Viewport, and Popup use explicit return
types. Add an explicit return type annotation to the DialogContent function
signature to specify that it returns React.ReactNode or JSX.Element, matching
the consistent pattern used by other internal components in the file.

Source: Coding guidelines

packages/swingset/src/stories/card.component.stories.tsx (1)

43-59: ⚡ Quick win

Make Centered follow the story props contract.

Centered should accept props: Record<string, unknown> and use knobsAsProps, same as other story renderers.

Suggested patch
-export function Centered() {
+export function Centered(props: Record<string, unknown>) {
+  const knobs = knobsAsProps(props);
   return (
     <Card
+      {...knobs}
       alignment='center'
       style={{ maxWidth: 400 }}
     >

As per coding guidelines, “Story functions must accept props: Record<string, unknown> and cast to the real prop type via a local knobsAsProps helper.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/swingset/src/stories/card.component.stories.tsx` around lines 43 -
59, The Centered story function does not follow the story props contract
required by the codebase guidelines. Update the Centered function signature to
accept a props parameter of type Record<string, unknown>, use the knobsAsProps
helper to cast the props to the correct Card component type (similar to how
other story renderers in the file are implemented), and then use these casted
props when rendering the Card component instead of hardcoding the alignment and
style values directly.

Source: Coding guidelines

packages/ui/src/mosaic/components/card.tsx (2)

121-121: ⚡ Quick win

Add an explicit return type to exported Card

Please add an explicit return type on the exported API function for consistency with the TypeScript rules used in this repository.

Suggested fix
-export function Card({ alignment, children, ...props }: CardProps) {
+export function Card({ alignment, children, ...props }: CardProps): React.JSX.Element {

As per coding guidelines, **/*.{ts,tsx}: “Always define explicit return types for functions, especially public APIs.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/mosaic/components/card.tsx` at line 121, The exported Card
function is missing an explicit return type annotation. Add a return type to the
Card function signature that specifies what the function returns (typically
JSX.Element or React.ReactElement for React components). This should be added
after the closing parenthesis of the function parameters and before the opening
curly brace of the function body, following TypeScript conventions for public
API functions in this repository.

Source: Coding guidelines


7-8: ⚡ Quick win

Confirm JSDoc coverage for new Card exports

This file introduces new exports (cardRecipe, CardProps, Card). If these are reference-facing, they likely need JSDoc blocks so generated docs don’t drift. If they are internal-only, please clarify so docs requirements can be waived for this surface.

As per coding guidelines, in packages/**/src public/reference-facing APIs should have comprehensive JSDoc, and changes that affect generated docs may need Docs-team review.

Also applies to: 117-121

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/mosaic/components/card.tsx` around lines 7 - 8, Add
comprehensive JSDoc blocks to the new Card exports (cardRecipe, CardProps, and
Card) in the card.tsx file. Each export should include a description of its
purpose and any relevant parameter/return type documentation. If these are
internal-only APIs, instead add a comment clarifying their internal-only status.
Ensure all public-facing exports in packages/**/src follow the coding guidelines
for JSDoc documentation.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ui/src/mosaic/components/card.tsx`:
- Around line 26-46: The `alignment` variant applies `alignItems` CSS property
to the header element in lines 42 and 45, but the header base styles do not
define the header as a flex container, making the alignItems property
ineffective. Add `display: 'flex'` to the base header object (in the root styles
section alongside the padding properties) to make it a flex container so that
the alignItems variant can properly control the alignment of header content.

---

Nitpick comments:
In `@packages/swingset/src/stories/card.component.stories.tsx`:
- Around line 43-59: The Centered story function does not follow the story props
contract required by the codebase guidelines. Update the Centered function
signature to accept a props parameter of type Record<string, unknown>, use the
knobsAsProps helper to cast the props to the correct Card component type
(similar to how other story renderers in the file are implemented), and then use
these casted props when rendering the Card component instead of hardcoding the
alignment and style values directly.

In `@packages/ui/src/mosaic/components/card.tsx`:
- Line 121: The exported Card function is missing an explicit return type
annotation. Add a return type to the Card function signature that specifies what
the function returns (typically JSX.Element or React.ReactElement for React
components). This should be added after the closing parenthesis of the function
parameters and before the opening curly brace of the function body, following
TypeScript conventions for public API functions in this repository.
- Around line 7-8: Add comprehensive JSDoc blocks to the new Card exports
(cardRecipe, CardProps, and Card) in the card.tsx file. Each export should
include a description of its purpose and any relevant parameter/return type
documentation. If these are internal-only APIs, instead add a comment clarifying
their internal-only status. Ensure all public-facing exports in packages/**/src
follow the coding guidelines for JSDoc documentation.

In `@packages/ui/src/mosaic/components/dialog.tsx`:
- Around line 130-136: The DialogContent function lacks an explicit return type
annotation while other components in the file like Backdrop, Viewport, and Popup
use explicit return types. Add an explicit return type annotation to the
DialogContent function signature to specify that it returns React.ReactNode or
JSX.Element, matching the consistent pattern used by other internal components
in the file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 5820d874-ec6e-4be9-9d81-92f565cd98f6

📥 Commits

Reviewing files that changed from the base of the PR and between f4ecc13 and 3ec67fd.

📒 Files selected for processing (11)
  • packages/swingset/src/components/DocsViewer.tsx
  • packages/swingset/src/lib/registry.ts
  • packages/swingset/src/stories/card.component.mdx
  • packages/swingset/src/stories/card.component.stories.tsx
  • packages/ui/src/mosaic/components/button.tsx
  • packages/ui/src/mosaic/components/card.tsx
  • packages/ui/src/mosaic/components/dialog.tsx
  • packages/ui/src/mosaic/components/heading.tsx
  • packages/ui/src/mosaic/components/text.tsx
  • packages/ui/src/mosaic/utils/context.ts
  • packages/ui/src/mosaic/variables.ts

Comment on lines +26 to +46
header: {
paddingBlockStart: theme.spacing(5),
paddingInline: theme.spacing(4),
},
content: {
paddingInline: theme.spacing(4),
flex: '1 1 auto',
},
footer: {
paddingBlockEnd: theme.spacing(5),
paddingInline: theme.spacing(4),
},
},
variants: {
alignment: {
start: {
header: { alignItems: 'flex-start', textAlign: 'start' },
},
center: {
header: { alignItems: 'center', textAlign: 'center' },
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

alignment variant uses alignItems on a non-flex header

Line 42 and Line 45 set alignItems, but header is not a flex container, so this part of the variant is currently a no-op.

Suggested fix
   header: {
+    display: 'flex',
+    flexDirection: 'column',
     paddingBlockStart: theme.spacing(5),
     paddingInline: theme.spacing(4),
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
header: {
paddingBlockStart: theme.spacing(5),
paddingInline: theme.spacing(4),
},
content: {
paddingInline: theme.spacing(4),
flex: '1 1 auto',
},
footer: {
paddingBlockEnd: theme.spacing(5),
paddingInline: theme.spacing(4),
},
},
variants: {
alignment: {
start: {
header: { alignItems: 'flex-start', textAlign: 'start' },
},
center: {
header: { alignItems: 'center', textAlign: 'center' },
},
header: {
display: 'flex',
flexDirection: 'column',
paddingBlockStart: theme.spacing(5),
paddingInline: theme.spacing(4),
},
content: {
paddingInline: theme.spacing(4),
flex: '1 1 auto',
},
footer: {
paddingBlockEnd: theme.spacing(5),
paddingInline: theme.spacing(4),
},
},
variants: {
alignment: {
start: {
header: { alignItems: 'flex-start', textAlign: 'start' },
},
center: {
header: { alignItems: 'center', textAlign: 'center' },
},
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/mosaic/components/card.tsx` around lines 26 - 46, The
`alignment` variant applies `alignItems` CSS property to the header element in
lines 42 and 45, but the header base styles do not define the header as a flex
container, making the alignItems property ineffective. Add `display: 'flex'` to
the base header object (in the root styles section alongside the padding
properties) to make it a flex container so that the alignItems variant can
properly control the alignment of header content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant