Eunomia @eunomia/elements@eunomia/charts@eunomia/core
AllAngularReactNext.jsJavaScriptVue
EunomiaSalmonForestVioletOceanGoldFireCustom…
🇬🇧 English🇫🇷 Français

Get started

Eunomia is one library of ready-made pieces, buttons, inputs, tabs, and more, built as standard web components. There's no separate React version or Vue version to choose between: the same package works the same way everywhere, in React, Vue, Angular, Next.js, or a plain HTML page, because a web component is understood by the browser itself rather than by one particular framework. Getting a component running takes four steps: install the package, import the one component you need, drop its tag into your markup, and add a theme so it looks right.

1. Install

npm install @eunomia/elements

It installs the two things the components rely on with it: Lit, the small library each component is built with, and @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 Charts).

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 Migrating to v2.

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 Tabs).

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.

Confirm
<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.

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 Theming, Prebuilt themes and Custom theme.

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 Button: API).

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 Button: Accessibility) spelling out exactly which keyboard shortcuts and ARIA behavior it implements.

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 Theming). A component with no theme applied at all still renders fine, just with its built-in default colors, which can look like theming "isn't working" if you were expecting a different brand.

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 Theming: How switching works.

Next steps

Web components

How they work in any framework

Foundations

The design tokens behind every component

Theming

Prebuilt or custom themes, light and dark

Components

Every available component

Features

Higher-level pieces, like a data table

Charts

Data visualization, in its own package

Icons

The full searchable icon set

Utilities

Plain JavaScript helpers

Guides

Forms, events, SSR, and more

Compatibility

Which package versions go together