---
name: strongtie-component
description: "Create React components for @strongtie/design-system by reusing existing Strongtie primitives first, then applying Radix UI, CVA variants, and Tailwind CSS v4 through the package's two-layer architecture. Use when: (1) Creating new components, (2) Modifying existing components, (3) Adding component variants."
---

# Component Creation Skill

Author components for the `@strongtie/design-system` package so they land in the same two-layer shape as everything already shipped.

## When to use this skill

Reach for it when you are working **inside** the library: creating a new component as a base primitive plus its public wrapper, adding or reshaping CVA variants on one that exists, or when you need to understand why the base/wrapper split exists before you touch either half. The common thread is that your edit ends up in `packages/design-system/src/` and ships to consumers under a package sub-path.

## When NOT to use this skill

If you are assembling already-published components into a page or feature, you are an app consumer — that is `strongtie-react-practices`, and this skill's internals will only mislead you. If you are writing the test suite, the ref/interaction/accessibility conventions live in `strongtie-test`; if you are writing JSDoc, a story, MDX, or a registry example, that is `strongtie-docs`. And nothing here applies to a generic React app that does not depend on `@strongtie/design-system` — the two-layer rule is a library-authoring constraint, not general React advice.

## Reuse before you build

The most expensive component is the one you wrote when a maintained one already existed, because now the design system has two of them and they drift. Before writing anything, search `packages/design-system/src/components/`, then the public registry catalog at https://design.strongtie.io/getting-started/strongtie-registry, then the upstream Radix primitives at https://www.radix-ui.com/primitives (fall back to the WAI-ARIA pattern only when Strongtie and Radix both come up empty). Write a custom implementation only once you can say which of those you checked and why none fit.

## The two-layer architecture, and why it is two

Every component is two files, and the split is load-bearing rather than ceremonial. The **base primitive** at `src/components/ui/<name>.tsx` owns the behavior — the Radix primitive, the CVA variant table, and the `data-*` hooks that styling targets. The **public wrapper** at `src/components/<name>.tsx` is the only thing a consumer imports: it carries the JSDoc that feeds auto-generated docs, attaches the semantic CSS class, and forwards the rest straight through. Collapse the two into one file and you lose the seam — the styling contract stops being stable, and the documented public surface starts leaking implementation. Keep them apart and the base can churn its internals while the wrapper, and therefore the consumer's import, stays still. Each wrapper maps to one package sub-path export.

Do not reconstruct this shape from memory. Read the Button — it is the reference implementation, and mirroring it is faster and more correct than inventing a parallel structure:

| Layer | File |
|-------|------|
| Base primitive | `packages/design-system/src/components/ui/button.tsx` |
| Public wrapper | `packages/design-system/src/components/button.tsx` |
| Tests | `packages/design-system/tests/button.test.tsx` |
| Story | `packages/design-system/stories/components/button.stories.tsx` |

## The conventions that actually carry weight

**Type it as a plain function — there is no `forwardRef` here.** React 19 passes `ref` as an ordinary prop, so the base is a plain function component with no `forwardRef` wrapper and no `displayName`; reach for `forwardRef` and you are writing React 18 against a React 19 library. Type the props as the intrinsic element intersected with the CVA variants, and let inference do the rest:

```tsx
function Button({ className, variant = "default", size = "default", asChild = false, ...props }:
  React.ComponentProps<"button"> &
    VariantProps<typeof buttonVariants> & { asChild?: boolean }) {
  const Comp = asChild ? Slot.Root : "button"
  return <Comp data-slot="button" data-variant={variant} data-size={size}
    className={cn(buttonVariants({ variant, size, className }))} {...props} />
}
```

The wrapper never restates that type — it defers to the base with `React.ComponentProps<typeof BaseButton>`, so a prop added to the base reaches consumers with no second edit:

```tsx
({ className, ...props }: React.ComponentProps<typeof BaseButton>) =>
  <BaseButton className={cn("button", "cursor-pointer", className)} {...props} />
```

**The `data-*` attributes are not decoration — they are the selectors.** Tailwind CSS v4 targets `data-slot` and `data-variant`/`data-size` from `globals.css`, so a base root that omits them renders with no variant styling and no obvious error to explain why. Set `data-slot="<name>"` on every base root, and add `data-variant`/`data-size` wherever those variants exist.

**The semantic class lives in the wrapper, and its name is the component's.** The wrapper adds `cn("<name>", className)` — lowercase, hyphenated, matching the component name — so consumers and global CSS have a stable class to reach for. `cn()` is from `src/lib/utils.ts`.

**`asChild` is how a button becomes a link without lying about it.** Render through `Slot.Root` from `radix-ui` (`import { Slot } from "radix-ui"`) so a caller can put button styling on an anchor or a custom element while keeping the correct underlying semantics.

## Package exports

The wrapper is invisible to consumers until it has a sub-path in `packages/design-system/package.json` — `tsdown.config.ts` auto-discovers the entry file, but the export map is what makes `@strongtie/design-system/<name>` resolve:

```json
"./component-name": {
  "import": { "types": "./dist/component-name.d.mts", "default": "./dist/component-name.mjs" },
  "require": { "types": "./dist/component-name.d.cts", "default": "./dist/component-name.js" }
}
```

## Before you call it done

- [ ] Confirmed no existing Strongtie package/registry primitive fits
- [ ] Base primitive in `src/components/ui/` with CVA variants
- [ ] `data-slot` on the base root; `data-variant`/`data-size` where variants exist
- [ ] Plain function typed `React.ComponentProps<...> & VariantProps<...>` — no `forwardRef`
- [ ] Wrapper in `src/components/` with `cn("component-name", className)`
- [ ] JSDoc on the wrapper (it powers the generated docs)
- [ ] Exported from `src/components/index.tsx` and the `package.json` export map
- [ ] Tests written (`strongtie-test`); story, MDX, and registry example written (`strongtie-docs`)

## Related skills

Authoring a component is rarely the whole job. `strongtie-test` covers the test suite that proves it, `strongtie-docs` covers the JSDoc/story/MDX/registry that publishes it, and `strongtie-react-practices` is where consumers pick it back up.
