Helpers and types
Class, keyboard, URL, storage and field helpers with browser/data boundaries.
Public reference 0.6.4
Reference text comes from the installed Contour UI 0.6.4 package. See the changelog for release details.
Versioned public source
# Helpers and public types
Use direct imports from `@abuzareal/contour-ui`. [PUBLIC-API.md](PUBLIC-API.md) links exact release source/types; [REFERENCE.md](REFERENCE.md) checks complete export coverage. Helpers do not require a provider. Only the pure operations below are server-call safe; importing the module and invoking a browser operation are different contracts.
| Helper | Inputs/defaults and result | Boundaries |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| cx | Variadic string/false/null/undefined; joins truthy parts with spaces. | No class parsing, deduplication, token validation or prefixing. Use for arbitrary consumer strings/IDs only when joining is appropriate. |
| ccx | Same inputs; deduplicates whitespace-separated names and appends contour-prefixed equivalents for known library classes. | Compatibility class helper, not an ID/ARIA builder. Unknown consumer classes remain unchanged. |
| buttonClassName | variant="primary", size="md", optional className; returns compatibility/prefixed button classes. | ButtonVariant: primary/accent/secondary/ghost/danger; ButtonSize: sm/md/lg. Styling an anchor does not give it button semantics. |
| formatIndex | number; String(value).padStart(2,"0"). | 3 → "03", 12 → "12". It does not round, add one, validate finite values, format a locale or normalize negative/fractional inputs. Pass an already chosen index. |
| fieldDescribedBy | id, optional hint/error; error → id-error, else hint → id-hint, else undefined. | Matches Field's message priority. Does not render an element or preserve arbitrary caller description IDs; callers merge those separately. |
| nextIndexForKey | key/current/count, orientation="horizontal", direction="ltr"; wrapped index or null. | count<=0 and unrelated keys return null. Home/End choose extremes. RTL reverses horizontal arrows. It does not skip disabled items, focus DOM nodes or validate every numeric input. Caller owns a valid current index/count and disabled-item policy. |
| safeHref | string or undefined; returns allowed href unchanged or undefined. | Rejects executable/disallowed schemes, including whitespace-obfuscated forms. Relative/hash/protocol-relative and permitted https/http/mailto/tel links are not a trusted-destination allowlist. Validate destination/origin and authorize redirects separately. |
| storageKeys | openingSeen="aa-opening-seen", theme="aa-theme". | Retained legacy origin-wide keys; not namespaced per application/scope. |
| readStorage | area="local" or "session", key; string or null. | Browser storage access wrapped in try/catch; blocked/missing/SSR access returns null. It does not parse/validate JSON or distinguish missing from denied. |
| writeStorage | area/key/string value; boolean success. | False for inaccessible/throwing storage. It does not encrypt data, provide a schema, broadcast an app event or write a server cookie. |
| motionDisabledFor | Element; boolean. | Browser-only synchronous preference/ancestor check; see HOOKS.md. |
## Public types
Section is `{id: string; label: string; title: string; number: number}`. It describes repeated page metadata, not a router, validator or React element. The application supplies stable IDs and valid numbers. CopyStatus, Theme, DismissReason/Options, PanelFocusOptions, FloatingOptions, ToastInput and ToastContextValue are described with their hooks in HOOKS.md. Component Props/item/variant aliases remain in the emitted declarations; they are types, not additional component exports. Generic TableColumn and TabItem must be read with their associated component contracts.
Use `import type` for type-only values. Do not deep-import dist files or assume a type-named symbol exists at runtime. Native inherited React props and overloads are retained by the declarations; generated metadata is a discovery aid and does not replace them. No arbitrary polymorphic component or enterprise grid contract is implied by these helpers.
## Data and URL responsibility
Read parsed storage/network data as unknown. Validate structures, elements, finite numbers/ranges and IDs before supplying components. A successful storage write is not server persistence. A safe URL scheme is not proof of a safe destination, a permitted server redirect or sanitized remote HTML. React escaping does not authorize data access; server validation and permissions remain at the relevant boundary.
The JavaScript onboarding example in [GETTING-STARTED.md](GETTING-STARTED.md) uses the same native form payload contract without requiring TypeScript syntax. Report synthetic reproductions and exact package/browser versions; never include private storage contents or credentials.
## Version and reproduction
Reference version **0.6.4**. A source version does not establish publication; check the npm registry for availability. [Versioned source](https://github.com/abuzareal/contour-ui/tree/v0.6.4/src) and [emitted type inventory](PUBLIC-API.md) describe this contract; tag links resolve after release. [Report Helpers 0.6.4](https://github.com/abuzareal/contour-ui/issues/new?template=bug_report.yml&component=Helpers&version=0.6.4), using the [public minimal reproduction](examples/reproduction) and synthetic data.