@orvain/utils
v0.1.3
Published
Orvain Design System — shared utilities, types and a11y helpers
Maintainers
Readme
@orvain/utils
Small shared helpers and types used across the Orvain Design System packages.
Commercial software. See LICENSE — use is governed by your agreement with Orvain Labs.
This is an internal support package, published because @orvain/react and
@orvain/vue depend on it. It is not a general-purpose utility library and its
surface may change between minors. Prefer a dedicated library for anything you
need in application code.
Install
npm install @orvain/utilsExports
import { clamp, cx, omit, typedEntries, generateId, announce, trapFocus } from '@orvain/utils';| Export | Signature | Notes |
|---|---|---|
| clamp | (value, min, max) => number | inclusive |
| cx | (...classes) => string | joins truthy class strings |
| omit | (obj, keys) => Omit<T, K> | for prop forwarding |
| typedEntries | (obj) => [keyof T, T[keyof T]][] | Object.entries with inferred keys |
| generateId | (prefix?) => string | module-scoped counter — see Caveats |
| getFocusableElements | (container) => HTMLElement[] | |
| trapFocus | (container) => cleanup | cycles Tab within container |
| announce | (message, politeness?) => void | writes to a shared aria-live region |
| Size, Variant, Intent, ColorScheme | type aliases | shared prop vocabularies |
Caveats
generateIdis not SSR-safe. It increments a module-level counter, so server and client can disagree and hydration will mismatch. Use React'suseIdor Vue'suseIdinstead;generateIdis for non-component code.trapFocusdoes not restore focus when it tears down, and does not move focus into the container on setup. You need to handle both yourself.announceandtrapFocustouchdocumentand must only run in the browser.
Related packages
@orvain/react,@orvain/vue— the component libraries
