--- name: building-web-artifacts description: Use when building elaborate, multi-component HTML artifacts using modern frontend technologies (React, Tailwind CSS, shadcn/ui). Triggers include requests for complex web artifacts requiring state management, routing, or shadcn/ui components. Not for simple single-file HTML/JSX artifacts — use direct generation for those. license: Complete terms in LICENSE.txt --- # Building Web Artifacts To build powerful frontend opencode artifacts, follow these steps: 1. Initialize the frontend repo using `scripts/init-artifact.cjs` 2. Develop your artifact by editing the generated code 3. Bundle all code into a single HTML file using `scripts/bundle-artifact.cjs` 4. Save the artifact file and inform the user of its location 5. (Optional) Test the artifact **Stack**: React 18 + TypeScript + Vite + Parcel (bundling) + Tailwind CSS + shadcn/ui ## Design & Style Guidelines **REQUIRED SUB-SKILL:** Use `designing-frontend-interfaces` before writing components. Write the design brief and lock the token block first — shadcn's defaults are a starting point, not a design, and shipping them unmodified produces exactly the generic output this section warns about. Also required before shipping: `designing-user-experience` for state coverage, `building-accessible-interfaces` for keyboard and screen-reader support. **The specific slop signature to avoid:** centered `max-w-4xl` for everything, purple/violet→blue gradients on white, uniform `rounded-lg` on every surface, `shadow-md` everywhere, Inter or `system-ui` as the display face, `text-gray-500` body copy, and the hero → three feature cards → CTA skeleton. ### Configure Tailwind, Don't Accept It Tailwind's defaults are a palette of defaults — using them raw is how artifacts converge on the same look. Override them with the token block from your brief: ```js // tailwind.config.js export default { theme: { extend: { colors: { base: "#f7f6f0", surface: "#fffffb", line: "#dcded1", ink: { DEFAULT: "#1a271a", 2: "#4a5a46", 3: "#79876f" }, accent: { DEFAULT: "#2f6b3c", ink: "#f4fbf5" }, }, fontFamily: { display: ['"Young Serif"', "Georgia", "serif"], text: ['"Work Sans"', "system-ui", "sans-serif"], }, borderRadius: { DEFAULT: "2px" }, // ONE radius }, }, }; ``` Now `bg-base`, `text-ink-2`, `border-line`, `font-display` carry the semantics, and the theme is swappable in one file. The `applying-themes` skill provides ten contrast-verified palettes ready to drop in here. Also disable shadcn's default radius variable if you committed to a different one — `--radius` in `globals.css` silently applies to every component. ## Component and State Requirements Every data-driven component in the artifact needs its full state set — see `designing-user-experience` for the matrix. In a self-contained artifact these are cheap to get wrong because there is usually no real backend to force them. ```tsx if (error) return ; if (loading) return ; // matching the real layout if (!items.length) return query ? : ; return ; ``` The two empty states are different and both are needed. `No data` for both is the most common shortcut in generated artifacts. ## Accessibility in Artifacts shadcn/ui is built on Radix, so its primitives are accessible **as long as you use them as intended**. The defects come from what you add around them: - Icon-only buttons need `aria-label` — Radix cannot infer one - Custom `
` handlers bypass everything Radix gives you; use `