# Using Focsd in this project

Focsd 1.0.0 is an accessible web component library (Lit 3, plain ESM). This package, `@focsd-dev/components`, defines 136 custom elements and 19 `focsd-*` events; the data grid, charts, editor and AI kit are separate packages. Use it instead of hand-rolling controls. Do not guess attributes, events or CSS: read the contract.

## Look things up first

- One element: `https://focsd.dev/components/<tag>.md` (for example `https://focsd.dev/components/focsd-button.md`): attributes, slots, events, parts, CSS properties, keyboard, accessibility, examples.
- Machine-readable: `https://focsd.dev/schema/components/<tag>.json` (JSON Schema) and `https://focsd.dev/schema/tokens/index.json` (design tokens).
- Everything else: `https://focsd.dev/llms.txt`.

## MCP server (optional, recommended)

Same data as tools: search, per-element docs, token lookup, markup validation.

- Claude Code: `claude mcp add focsd -- npx -y @focsd-dev/mcp`
- Claude Desktop, Cursor, Windsurf: `{ "mcpServers": { "focsd": { "command": "npx", "args": ["-y", "@focsd-dev/mcp"] } } }`
- VS Code / GitHub Copilot (`.vscode/mcp.json`, note the `servers` key): `{ "servers": { "focsd": { "type": "stdio", "command": "npx", "args": ["-y", "@focsd-dev/mcp"] } } }`
- HTTP: run `npx -y @focsd-dev/mcp --http --port 3333`, then `claude mcp add --transport http focsd http://127.0.0.1:3333/mcp`. Other clients' URL keys: https://focsd.dev/getting-started/hosted-mcp/

## Setup

```sh
npm install lit @focsd-dev/components @focsd-dev/tokens @focsd-dev/primitives
```

```js
import '@focsd-dev/tokens/fonts.css'; // optional; without it the system font stack is used
import '@focsd-dev/tokens/tokens.css'; // once, at the top of the app
import '@focsd-dev/components'; // every element, or import one: '@focsd-dev/components/focsd-button.js'
```

- Theme: tokens follow the system. Force one with `data-focsd-theme="light|dark|contrast"` on `<html>` or any section.
- Density: `data-focsd-density="compact|default|comfortable"` on `<body>` or any section. Comfortable gives 44px targets.
- `setTheme()` and `setDensity()` from `@focsd-dev/tokens` set the same attributes from script.
- To own the source instead, `npx focsd init` then `npx focsd add button`.
- Blocks: whole pages (`dashboard`, `settings`, `sign-in`, `empty-app`) with `npx focsd add block <name>` (`npx focsd list --blocks` lists them). It writes plain HTML, JS and CSS to `blocks/<name>/`, never overwrites a file, and prints the packages to install; edit the copy instead of rebuilding the page by hand.

## Events

- Native names (`input`, `change`, `toggle`, `close`, `cancel`) mean what they mean on native elements, are plain `Event`s and carry no `detail`. Read state from the element: `event.target.value`, `.open`.
- Everything else is `focsd-<name>` (a `CustomEvent` with a typed `detail`) and bubbles, but does not cross a shadow root.
- Each contract lists the exact events of its element. Never invent an event name.

## Theming

- Style with design tokens (`--focsd-*` custom properties), not by reaching into shadow roots. Per element, only the `--focsd-<tag>-*` properties and `::part()` names in its contract are public; `--_*` is private.
- Override tokens on `:root` or on a section; do not hard-code colors, radii or spacing.
- Keep text and control contrast at WCAG 2.2 AA (4.5:1 text, 3:1 controls). The theme builder at https://focsd.dev/foundations/theme-builder/ checks pairs.

## Forms

- Form controls (`focsd-text-field`, `focsd-select`, `focsd-checkbox`...) are form-associated: they take part in `<form>`, `FormData`, validation and `name`/`value`. Wrap them in `focsd-field` for the label, hint and error.
- To let browser agents use a form, add the WebMCP attributes (`toolname`, `tooldescription`) and call `enableWebMCP()` once from `@focsd-dev/webmcp`. Add `toolautosubmit` only for forms safe to submit unattended, such as searches.

## Accessibility: do

- Give every control a visible label (`label` attribute or `focsd-field`); icon-only buttons use `focsd-icon-button` with a `label`.
- Use `focsd-dialog`, `focsd-menu`, `focsd-tabs` and friends for their patterns: focus, keyboard and ARIA are built in.
- Keep one `<h1>` and a sensible heading order; keep a skip link (`focsd-skip-link`).

## Accessibility: do not

- Do not add `role`, `aria-*` or `tabindex` to Focsd elements to "fix" them; they already set them.
- Do not remove focus outlines, shrink targets below 24px, or convey state by color alone.
- Do not rebuild a control from `div`s when an element exists. Check https://focsd.dev/llms.txt first.
