@eldrajs/ui
Accessible Vue 3 core components for Eldra storefronts, themed through CSS design tokens.
The components are built to
eldra-starter-spec/01-core-components.md (WCAG
2.2 AA). Plan 1 — foundations, actions and forms (Button/ButtonGroup, Link, Input,
Textarea, FieldWrapper, FormLayout, Checkbox/CheckboxGroup, Radio/RadioGroup, Switch,
Select/MultiSelect, QuantityStepper, VariantPicker, SearchBar) — is complete, plus
UnitInput and CurrencyInput, which the spec has no equivalent of; display, commerce, layout, overlays, navigation
and feedback components land in the two sub-projects that follow, in the same delivery order the
spec's "Components and delivery order" section lays out. What this package ships that the spec does
not name is listed under
Additions beyond the spec, and where it departs from a property table
it is recorded under Deviations — neither is left for a reader to find.
Install
pnpm add @eldrajs/ui vue
Peer: vue ^3.5. The floor is 3.5, not 3.4: every control's ids come from useId(), which Vue
added in 3.5, so on 3.4 the install succeeds and the first control to mount throws
useId is not a function. vee-validate ^4.12 is an optional peer — only the ./vee-validate
entry needs it, and nothing else in the package imports it.
libphonenumber-js ^1.13 is an optional peer in the same way: only the ./phone
entries need it.
Styles
The components come prebuilt: an app never compiles this package's styles and needs no Tailwind
of its own to use them. Every class a component renders is eldra:-prefixed (eldra:px-4,
eldra:hover:bg-primary), compiled with Tailwind's prefix(eldra), and every theme variable it
reads is --eldra-*. Nothing in the package's CSS uses a name an app's own Tailwind build uses, so
the two never restyle each other's markup.
Five CSS entries ship. Every one starts from the same --eldra-* variables, so none is a different
theme, only a different delivery shape.
-
@eldrajs/ui/style.css — the tokens, Tailwind's preflight and every component's styles, for
a page built from this package:
@import '@eldrajs/ui/style.css';
-
@eldrajs/ui/components.css — style.css without Tailwind's preflight, for a site that has
its own stylesheet (or its own Tailwind) and adds components to it:
@import '@eldrajs/ui/components.css';
Preflight is a reset for the whole page: style.css sets every h1–h6 to the surrounding
size and weight, every ul/ol to no bullets and no indent, every a to the surrounding colour
with no underline, every p and heading to no margin, and every button to no border or fill.
It sits in @layer base, so a site's own rules still win where they exist, but anything the site
left to the browser — rich text from the CMS, most often — loses its defaults. components.css
carries the same theme and the same utilities, byte for byte, and narrows the reset to the
elements the components render themselves, so the site's own elements keep the browser's
defaults and anything passed into a component's slot keeps the site's styling. Use style.css
when the page is built from this package; use components.css when the page is the site's own.
src/styles/__tests__/componentsCss.browser.spec.ts renders every component family under both,
the overlays open, and requires identical pixels.
-
@eldrajs/ui/tokens.css — the --eldra-* variables only (colours, radii, spacing, type,
motion, z-index, and the one opacity — --eldra-revalidating-opacity), declared on :root with
the spec's defaults, plus a @media (prefers-reduced-motion: reduce) rule that zeroes every
duration variable.
-
@eldrajs/ui/tailwind.css — for an app that runs Tailwind v4 and wants its own markup
on the same design tokens: tokens.css, then a @theme block mapping Tailwind's namespaces
onto those variables (--color-primary: var(--eldra-color-primary), --radius-md,
--font-heading, --spacing-*, --shadow-*, --ease-*) and the package's custom utilities
(control heights, the eldra-focus ring, the type styles, motion and layer utilities). It builds
none of the components; import the prebuilt ones beside it. theme.css (the @theme block) and
utilities.css (the utilities) ship on their own too.
@import 'tailwindcss';
@import '@eldrajs/ui/tailwind.css';
@import '@eldrajs/ui/components.css';
The type styles (text-body, text-h2, …) set longhands, never the font shorthand, and read
their weight as var(--tw-font-weight, <token>), the declaration Tailwind writes for its own
--text-*--font-weight. So a font-medium/font-semibold beside one wins whatever order the two
compile in, and a tabular-nums beside one is no longer reset. A base-layer
@apply font-* sets --tw-font-weight as well, so it reaches a type style on the same element.
Line height and tracking are plain longhands on purpose: the starter's own base rule
(h1–h4 @apply leading-[1.1] tracking-tight) would otherwise override every heading's type
style.
Overriding a component's classes
The components' styles sit in @layer components, below Tailwind's @layer utilities, and both
style.css and components.css declare the standard order (properties, theme, base, components, utilities), so it holds whichever stylesheet loads first. A class you put on a component, with
class (its outermost element) or a part of classes (an element inside it), is not prefixed and
is added to the component's own classes; it wins by layer, whatever its specificity. Nothing is
merged or removed at runtime: the components bind their classes the plain Vue way, one class per
concern on each element.
<Button class="px-8">Checkout</Button>
<!-- renders class="eldra:control-h eldra:px-4.5 … px-8": px-8 wins -->
- It wins in every state: a plain
bg-red-600 on a Button replaces its hover and active fills
too, because a utilities-layer rule beats any components-layer one. Write the states you want
(bg-red-600 hover:bg-red-700).
- Your app's own Tailwind must generate the class (it is in your source, so it does). Without a
Tailwind of your own, any CSS of yours that is unlayered or in a layer declared after
components wins the same way.
The data-eldra-ui marker
Every component's outermost element carries data-eldra-ui, and so does every element a component
renders outside it: a Select or MultiSelect panel, a SearchBar results panel, a Popover
panel, a Tooltip bubble and the Toaster region, each teleported out of its component.
components.css's reset reaches exactly those elements and the data-part elements inside them,
:where([data-eldra-ui], [data-eldra-ui] [data-part]), at zero specificity. data-part alone is
not enough, because it is not this package's name: a site's own <h2 data-part="title">, or any
Ark UI or Zag component (which put data-part on every element they render), keeps the browser's
defaults. The attribute is public and stable, so a site can use it as a hook too
(a:not([data-eldra-ui], [data-eldra-ui] *) keeps a site's global link rule out of the
components). One case stays inside the scope: an element carrying its own data-part that the site
passes into a component's slot (an Ark UI widget inside a Dialog, say) is a data-part element
inside a marked root, so it gets the reset as well.
A site's unlayered element rules beat the package's layered ones regardless of specificity: a
global a { color: … } or button { font: … } restyles those elements inside the components too.
Scope such rules (.prose a) or put them in a layer.
Theming a subtree
provideEldraScope(name), called in the setup() of a wrapper or an app root, makes every
component below it render data-eldra-scope="<name>" on its root and on every part it teleports
(panels, bubbles, dialogs, toasts), so the --eldra-* variables can be set for those components
alone, teleported parts included:
[data-eldra-scope='studio'] {
--eldra-color-primary: #0b5cad;
}
Every element holding slot content you passed in also carries data-eldra-slot (a Button's
label, a Dialog's title, body and footer, a Popover panel…), whenever the slot has content and
never for a fallback, as a hook for your own CSS.
Fonts
The type tokens' defaults are --eldra-font-heading: "Bricolage Grotesque", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif and --eldra-font-body: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif. The package does not load either
font — it only names them — so a consumer either loads Bricolage Grotesque and Instrument Sans
themselves (self-hosted, or a Google Fonts <link>/@import) or overrides --eldra-font-heading
and --eldra-font-body with their own stack. Until one or the other happens, text renders in the
fallback system stack, which is legible but not the spec's intended look.
Customisation
Every component supports all five of these; none hard-codes anything a store might want to change.