Get started
Eunomia is one library of ready-made pieces, buttons, inputs,
tabs, and more, built as standard
1. Install
npm install @eunomia/elements
It installs the two things the components rely on with it:
@eunomia/core, the design tokens,
themes and default locale every Eunomia package shares. There's nothing
else to install: @eunomia/elements also exposes what an app needs from
@eunomia/core (time.js, theme.js, locale.js, breakpoints.js,
and the compiled themes under styles/), so your app never has to
declare @eunomia/core itself, even under pnpm or Yarn's strict modes.
An app that already uses Lit 3 keeps a single copy of it.
One exception, under pnpm or Yarn's strict modes only: compiling a
theme from its Sass source, which only @eunomia/core/styles/ ships.
Your app then needs @eunomia/core in its own dependencies:
npm install @eunomia/core
Charts ship separately, in @eunomia/charts: add it only if you use
them (npm install @eunomia/charts, see
npx -p @eunomia/elements@2 eunomia-migrate does most of it in one
command. Review its diff before committing, and fix the lines it lists
at the end: it leaves alone what it can't rewrite for sure. See
2. Import a component
Each component has its own file, and importing it is what makes its tag usable: it registers the element with the browser as a side effect of the import. Import each component you use from its own path, so your app only ships the code of the ones it renders.
import "@eunomia/elements/button.js";
import "@eunomia/elements/tab-group.js";
import "@eunomia/elements/tab.js";
import "@eunomia/elements/tab-panel.js";
Importing @eunomia/elements/button.js makes <eun-button> available,
and also gives you its class (import { EunomiaButton } from "@eunomia/elements/button.js") when you need it as a type. Tabs need
three tags working together as one system, <eun-tab-group>,
<eun-tab>, and <eun-tab-panel>, so import all three (see
A component that displays another one doesn't import it for you:
<eun-button> draws its icon with <eun-icon> and its loading state
with <eun-loader>, so add @eunomia/elements/icon.js and
@eunomia/elements/loader.js when you use them. Each component's page
lists these under Dependencies, at the top.
import { EunomiaButton } from "@eunomia/elements" works, but it loads
the whole library: every component registers itself on import, so a
bundler can't leave any of them out, and the app ships about 6 MB of
code (minified) for a single button, against about 60 KB from
@eunomia/elements/button.js. The same goes for a utility: take it from
its own path, which registers no component, such as debounce from
@eunomia/elements/time.js, initializeTheme from
@eunomia/elements/theme.js or setDefaultLocale from
@eunomia/elements/locale.js.
This import registers the element with the browser as a side effect,
which means it needs a real browser window to exist. In a framework that
renders on the server (Next.js, Nuxt, SvelteKit, Angular Universal, or
any other SSR setup), a plain top-level import evaluated during the
server render throws ReferenceError: customElements is not defined,
even for a Server Component that only imports a utility like
initializeTheme from @eunomia/elements (import it from
@eunomia/elements/theme.js instead, which is safe on the server). Keep
every import behind your framework's client-only boundary (Next.js'
"use client", Nuxt's <ClientOnly>/.client.ts, or the equivalent
elsewhere) or inside a browser-only lifecycle hook (useEffect,
onMounted, ...). The Next.js tab below shows the exact pattern; it
carries over directly to any other SSR framework.
3. Use the tag
Pick a framework in the toolbar above and every snippet on this page adapts.
<eun-button color="primary">Confirm</eun-button>
<eun-tab-group>
<eun-tab slot="navigation" panel="a">First</eun-tab>
<eun-tab slot="navigation" panel="b">Second</eun-tab>
<eun-tab-panel name="a">First panel.</eun-tab-panel>
<eun-tab-panel name="b">Second panel.</eun-tab-panel>
</eun-tab-group>
This is plain HTML, so it works with any framework, or with none at all.
<script type="module">
import "@eunomia/elements/button.js";
</script>
<eun-button color="primary">Confirm</eun-button>
import "@eunomia/elements/button.js";
function App() {
return <eun-button color="primary">Confirm</eun-button>;
}
React 19 renders custom elements natively, so properties and events
just work as you'd expect. React 18 and earlier write every prop as a
text attribute instead. A string or a number goes through, but a
boolean attribute such as disabled is on as soon as it's written,
even as disabled={false}: leave it out to turn it off. An object or
an array can't go through at all, and neither can a custom event
listener such as oneunnavigate. Set those from the element's ref
with eunProps (see Properties and events, below).
"use client";
import "@eunomia/elements/button.js";
export function ConfirmButton() {
return <eun-button color="primary">Confirm</eun-button>;
}
Import the component inside a client component, marked
"use client". Registering a custom element calls
customElements.define as soon as the file loads, and that needs a
real browser window to exist. A plain import at the top of a Server
Component runs during the server render, before any browser exists,
and throws.
<script setup>
import "@eunomia/elements/button.js";
</script>
<template>
<eun-button color="primary">Confirm</eun-button>
</template>
Vue treats any tag containing a hyphen as a custom element
automatically, with nothing extra to configure. Bind a property with
:color="..." and listen for a custom event with
@eunnavigate="...", exactly like any built-in DOM event.
Rendering with Nuxt instead of plain Vue? Nuxt renders on the server by
default, so this same import needs a client-only boundary: wrap the
import in <ClientOnly> or move it to a .client.ts plugin. See the
SSR warning above.
import { CUSTOM_ELEMENTS_SCHEMA, Component } from "@angular/core";
import "@eunomia/elements/button.js";
@Component({
selector: "app-root",
template: `<eun-button color="primary">Confirm</eun-button>`,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppComponent {}
Angular's template compiler rejects unfamiliar tags by default.
CUSTOM_ELEMENTS_SCHEMA tells it to allow any tag containing a
hyphen through unchecked. Add it once to every module (or every
standalone component) that uses a Eunomia tag.
Rendering with Angular Universal (SSR)? This same import needs a
client-only boundary: guard it with isPlatformBrowser(platformId)
(or move it into ngOnInit behind that same check) so it never runs
during the server render. See the SSR warning above.
Binding a form field with ngModel or a reactive form? Import
EunomiaValueAccessor from @eunomia/elements/angular as well, see
4. Theme it
Every color, corner rounding, spacing, and shadow a component uses comes from a shared set of design values behind the scenes, never a color or size baked directly into the component. Skip this step entirely and components still render just fine, using sensible built-in defaults, the same ones shown throughout this documentation site.
To ship a real theme instead, include one of the 7 ready-made
palettes. Each one ships compiled to .css, so a plain <link> works
without any Sass step (with a bundler, import the .css from your
entry file instead, or its .scss source from @eunomia/core/styles/,
at the same path). Load the base
theme, which carries the greys, the fonts, the spacing, the radii and
the shadows, then the palette, which carries its brand colors, and
add both classes to your app root:
<link
rel="stylesheet"
href="node_modules/@eunomia/elements/styles/themes/eunomia-theme.css"
/>
<link
rel="stylesheet"
href="node_modules/@eunomia/elements/styles/themes/prebuilt-themes/violet/eunomia-violet.theme.css"
/>
<body class="eunomia-theme eunomia-violet-theme">
<app-root></app-root>
</body>
For dark mode, swap both classes for their dark versions:
eunomia-theme--dark eunomia-violet-theme--dark.
Switching palettes at runtime instead? styles/eunomia-themes.css
holds all 7 palettes in both modes, picked with two attributes on
<html>: data-brand names the palette, data-theme is light or
dark.
<link
rel="stylesheet"
href="node_modules/@eunomia/elements/styles/eunomia-themes.css"
/>
<html data-brand="violet" data-theme="light"></html>
None of the 7 palettes match your brand? Generate a custom theme from just two colors, your primary and secondary: the full palette, light and dark, is derived from them. Load the base theme as above, then apply your colors once the page is in the browser:
import { initializeTheme } from "@eunomia/elements/theme.js";
initializeTheme("#0f766e", "#f59e0b");
The full picture, dark mode, all 7 palettes, and how a custom theme
is generated (including server-side rendering without a flash), is in
TypeScript
@eunomia/elements ships its own type declarations, so a class like
EunomiaButton and its properties are already typed the moment you
import it. Each component's module also augments the global
HTMLElementTagNameMap with its own tag as soon as it's imported, so
document.createElement("eun-button") is already typed correctly
too, the moment anything from the package has been imported anywhere
in your program: there's nothing to write for that yourself.
JSX and TSX
Writing <eun-button color="primary"> directly in a .tsx file
needs one more step, since JSX reads its own separate
JSX.IntrinsicElements type rather than HTMLElementTagNameMap.
Import @eunomia/elements/jsx once, anywhere in your program:
import type {} from "@eunomia/elements/jsx";
It's a type-only import, so it carries no runtime cost and never
registers a custom element itself: a good place for it is right next
to your app's other global type declarations. Every eun-* tag then
becomes a typed JSX element, with the same property autocomplete and
invalid-value rejection as the component's own class.
When the page is rendered on the server, write attributes in
kebab-case (transparent-at-top, tablet-animation) rather than
camelCase. React renders a camelCase prop on a custom element as a
camelCase attribute, which the component and its SSR stylesheet don't
recognize. Both spellings are typed, with the same values.
<eun-toolbar transparent-at-top mobile-hide="md">
...
</eun-toolbar>
An array or a date that a component parses from its attribute, such as
steps on eun-stepper (JSON) or default-value on eun-date-picker
(yyyy-mm-dd), also accepts a string, the only form a server render
writes into the markup:
<eun-stepper steps={JSON.stringify(steps)} active-step={1}></eun-stepper>
Properties and events
React applies none of the props it gives a custom element while it
hydrates server-rendered markup: an object property such as events or
displayedDate, or a listener for an event such as eunperiodchange,
only reaches the element on a later render whose value changed. Pass
them through eunProps, which sets them from the element's ref, once
React attaches it:
import { eunProps } from "@eunomia/elements/react";
function Agenda({ events }) {
const [range, setRange] = useState(null);
return (
<eun-calendar
view="week"
ref={eunProps({
events,
oneunperiodchange: (event) => setRange(event.displayedDate),
})}
></eun-calendar>
);
}
A key made of on and an event name, in lowercase (oneunchange,
oneuneventclick), adds a listener for that event, typed with the
event's own class, and every other key sets the property of that name.
Listeners are removed when the element leaves the page or the component
renders again. The module doesn't import React at runtime and works in a
page rendered on the client only as well. Each component's own page
lists its events (for example
Accessibility
Keyboard focus, screen reader announcements, and the right ARIA
attributes are already built into every component: nothing to add
yourself. Each component's own page has an Accessibility tab (for
example
Troubleshooting
Its file hasn't been imported yet, so the browser doesn't recognize the tag at all. Double-check that the import for that component actually ran: no typo in the path, not removed by tree-shaking, and not sitting behind a condition that never executes.
See the Angular tab above: add CUSTOM_ELEMENTS_SCHEMA. Other strict
template compilers usually offer their own equivalent escape hatch for
allowing custom elements through.
A component's file is being imported during a server render: a Next.js
Server Component, a Nuxt page rendered without <ClientOnly>, a
SvelteKit load function, an Angular Universal render, or any other
SSR/static-generation pass. Move the import behind that framework's
client-only boundary instead (see the SSR warning and the
Next.js/Vue/Angular tabs above).
With a palette's own stylesheet, confirm that eunomia-theme.css is
loaded too, and that both the eunomia-theme and eunomia-<name>-theme
classes are on <body>. With eunomia-themes.css, confirm that
data-brand is set on <html> (see
With a palette's own stylesheet, check that both classes switch to their
dark versions, eunomia-theme--dark and eunomia-<name>-theme--dark:
changing only one leaves either the greys or the brand colors in light
mode. With eunomia-themes.css, check that data-theme="dark" sits on
<html> next to data-brand; see
Next steps
How they work in any framework
The design tokens behind every component
Prebuilt or custom themes, light and dark
Every available component
Higher-level pieces, like a data table
Data visualization, in its own package
The full searchable icon set
Plain JavaScript helpers
Forms, events, SSR, and more
Which package versions go together