mosaic

โดย clerk

Work on Mosaic UI: styling a component with slot recipes (`defineSlotRecipe` / `useRecipe` / slots / variants), or building a flow — authoring a state machine…

npx skills add https://github.com/clerk/javascript --skill mosaic

Mosaic UI

Two things live under Mosaic, and this skill covers the how-to for both:

  • Styled components are authored with StyleX — stylex.create declares the styles, themeProps emits the part's public identity (the .cl-<slot> class plus data-<axis> attrs), and mergeStyleProps fuses the two with the props the part was called with. A part takes xstyle (StyleX atoms for its root), never className/style.
  • Flows follow a model → controller → view split — where the data comes from → what the user is doing to it → what that looks like. What crosses each boundary is plain data: no Clerk resource reaches the controller, no machine snapshot reaches the view.
model       Clerk adapter: reads Clerk hooks and resources, resolves the
            environment, gates permissions, and answers with plain data plus
            plain callbacks under an explicit `status`. The only layer that may
            import Clerk hooks or call Clerk resource methods.

controller  Local state: what is open, what is in flight, what the view may do
            next — held in React state or a state machine, whichever the
            interaction's complexity calls for. Wraps the model's callbacks so
            an action can report pending, hold the surface still while it runs,
            and close on success. No Clerk imports.

view        Rendering: takes plain props and callbacks, renders UI, calls them
            back. No Clerk imports. No data-fetching. No machine snapshot.

A machine is not a fourth layer, and not a requirement. It is one of the two ways a controller can hold its state, and picking one is a complexity call: useState for a boolean that never touches async, a machine once the interaction has an async lifecycle or two values that must change together, and sometimes both in one controller. Either way the controller returns plain props, so the view cannot tell and neither can its tests. Criteria and worked before/afters: packages/mosaic/src/machine/ADOPTION.md.

references/mosaic-architecture.md (repo root, read by all agents) is the canonical contract for the whole design system — the --cl-* tokens, the .cl-<slot> + data-<axis> styling API, the CSS build, and the "Flow and data architecture" section that defines the split. Read it for the what; this skill is the how-to.

packages/mosaic/src/features/user-button/ is the fullest worked example of the split in the repo — model, controller, view, wrapper, types, messages, and a feature test. Copy from it.

Which reference to read

You are…Read
Building on / authoring a headless primitive (src/primitives/)references/headless.md
Styling a component (tokens, stylex.create, themeProps, CSS build)references/stylex.md
Building an enter/exit transition, or any motion that reads as wrongreferences/motion.md
Writing the model (the Clerk adapter, status, permissions)references/models.md
Writing the controller (local state, pending, action wrapping)references/controllers.md
Authoring or debugging a state machine, or wiring one to Reactreferences/machines.md → in-tree machine/README.md
Writing the view (rendering plain props)references/views.md
Testing a feature (feature tests, unit tests)references/testing.md
Migrating a legacy component into Mosaic (the end-to-end workflow)references/migration.md
Running the parity audit that guards a migrationreferences/parity-audit.md

The migration workflow (migration.md) ties the flow references together: it treats the legacy component as the spec and drives you through the model, controller, and view layers, then verifies parity with parity-audit.md.

Documenting a component in swingset

packages/swingset/CLAUDE.md is the house style — archetypes, required section order, meta conventions. One rule on top of it, because it is the one agents get wrong:

The docs describe the API as it is. They do not carry the reasoning that produced it. No "not a size, because…", no rejected alternatives, no history of what the prop used to be. A reader is there to learn what the thing does, and every sentence of rationale is a sentence they have to skim past to find it. State the behaviour plainly and briefly, then stop.

<!-- no -->

### Variant

Which surface the dialog holds, and so the geometry it is given. Not a `size`,
because these are different surfaces rather than one surface at two widths — a
second card width would be a size of the `card` variant, with nowhere to sit on
this axis.

<!-- yes -->

### Variant

Which surface the dialog holds, and the geometry that comes with it.

This is the opposite of the rule for code, where a comment earns its place by explaining what the code cannot say for itself — the cascade fight behind a null, the measured reason a duration is what it is. Keep that reasoning where a future maintainer will hit it, which is the source file. The trade you rejected belongs in a code comment or the PR description; the docs get the conclusion.

Skills เพิ่มเติมจาก clerk

clerk-billing
clerk
Clerk Billing สำหรับการจัดการการสมัครสมาชิก - แสดง PricingTable ของ Clerk
clerk-nextjs-patterns
clerk
รูปแบบ Next.js ขั้นสูงสำหรับการตรวจสอบสิทธิ์ มิดเดิลแวร์ Server Actions และการแคชตามขอบเขตผู้ใช้ด้วย Clerk แยกความแตกต่างระหว่าง auth() แบบฝั่งเซิร์ฟเวอร์ที่รอคอยผลลัพธ์กับ useAuth() hook ฝั่งไคลเอ็นต์ การผสมกันเป็นข้อผิดพลาดที่พบบ่อย ครอบคลุมกลยุทธ์มิดเดิลแวร์ (สาธารณะก่อนเทียบกับป้องกันก่อน) การป้องกันเส้นทาง API และรหัสสถานะ HTTP ที่เหมาะสม (401 เทียบกับ 403) รวมถึงรูปแบบการแคชตามขอบเขตผู้ใช้ด้วย unstable_cache และการป้องกัน Server Actions จากการกลายพันธุ์ที่ไม่ได้รับอนุญาต ให้ความเข้ากันได้กับ Core 2...
clerk-expo-patterns
clerk
รูปแบบ Expo / React Native กับ Clerk — แคชโทเค็น SecureStore, OAuth
changesets
clerk
Create or refresh a `.changeset/<slug>.md` for the current branch, or report that none is required. Triggers on "/changesets create", "add a changeset",…
clerk
clerk
ไบนารี clerk เป็นเกตเวย์ที่ผ่านการรับรองความถูกต้องล่วงหน้าไปยัง Clerk's Backend API และ Platform API พร้อมด้วยเครื่องมือระดับโปรเจกต์ (การรับรองความถูกต้อง การเชื่อมโยง การดึง env การกำหนดค่าอินสแตนซ์) เมื่อผู้ใช้ถามถึงสิ่งใดก็ตามที่เกี่ยวข้องกับทรัพยากร Clerk ให้ใช้ clerk ก่อนแทนที่จะเขียน curl ด้วยตนเอง
clerk-cli
clerk
ไบนารี clerk เป็นเกตเวย์ที่ผ่านการรับรองความถูกต้องล่วงหน้าไปยัง Clerk's Backend API และ Platform API พร้อมด้วยเครื่องมือระดับโปรเจกต์ (การตรวจสอบสิทธิ์ การเชื่อมโยง การดึง env การกำหนดค่าอินสแตนซ์) เมื่อผู้ใช้ถามถึงสิ่งใดก็ตามที่เกี่ยวข้องกับทรัพยากรของ Clerk ให้ใช้ clerk ก่อนแทนที่จะเขียน curl ด้วยตนเอง
clerk-astro-patterns
clerk
รูปแบบ Astro กับ Clerk — มิดเดิลแวร์, หน้า SSR, คอมโพเนนต์ไอส์แลนด์
audit-expo-skill
clerk
Audits the bundled `clerk-expo` skill against the @clerk/expo SDK source and clerk-docs, then proposes or applies updates. Use when the user says "audit the…