diff --git a/AGENT.md b/AGENT.md index 132fd19..4372bb7 100644 --- a/AGENT.md +++ b/AGENT.md @@ -22,6 +22,167 @@ This repository is `@bquery/ui`, a framework-agnostic Web Components library bui 5. Treat import side effects (`import '@bquery/ui'`) and per-component entrypoints (`@bquery/ui/components/`) as the canonical registration model; `registerAll()` is deprecated compatibility-only. 6. When touching versioned install snippets or release-facing docs, keep pinned CDN examples aligned with the current package version in `package.json`. +## Component conventions + +### Styles + +Declare styles with the `css` tagged template from `@bquery/bquery/component` and +interpolate the shared fragments from `src/utils/styles.ts`: + +```ts +import { component, css, html } from '@bquery/bquery/component'; +import { baseStyles, fieldStyles, focusRing, reset, srOnly } from '../../utils/styles.js'; + +styles: css` + ${baseStyles} + ${reset} + ${focusRing} + :host { display: block; } +` +``` + +The fragments, and when to reach for each: + +| Fragment | Provides | +| -------------- | ------------------------------------------------------------------- | +| `baseStyles` | Tokens + both colour schemes. Every component. | +| `reset` | `box-sizing`, `[hidden]`, and the reduced-motion opt-out. | +| `focusRing` | The standard ring on the usual focusable elements, at zero specificity. | +| `fieldStyles` | `.field` / `.label` / `.hint` / `.error-msg` / `.required-mark` for form controls. | +| `srOnly` | `.sr-only`. | + +**A backtick inside a CSS comment terminates the template literal.** Two +components have been broken this way; write ``accent-color`` without the +backticks inside `css` blocks. + +This matters for more than tidiness. A `css` payload is handed to +`adoptedStyleSheets`, so the stylesheet is constructed **once per component and +shared by every instance**, and re-renders no longer rewrite it. A plain string +falls back to a per-instance `