# Get started

> Install Eunomia from npm and add your first web component to a page, in plain HTML, React, Next.js, Vue or Angular.

Source: https://eunomia-ds.com/get-started/

Eunomia is one library of ready-made pieces, buttons, inputs, tabs, and more, built as standard [web components](https://eunomia-ds.com/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

```bash
npm install @eunomia/elements
```

It installs the two things the components rely on with it: [Lit](https://lit.dev/), 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:

```bash
npm install @eunomia/core
```

Charts ship separately, in `@eunomia/charts`: add it only if you use them (`npm install @eunomia/charts`, see [Charts](https://eunomia-ds.com/charts/)).

> **Upgrading from 1.x?**
>
> `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](https://eunomia-ds.com/guides/migrate-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.

```js
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](https://eunomia-ds.com/components/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.

> **Don't import from the package root**
>
> `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`.

> **Server-side rendering: import client-side only**
>
> 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.

**HTML / any framework:**

```html
<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.

**JavaScript:**

```html
<script type="module">
  import "@eunomia/elements/button.js";
</script>

<eun-button color="primary">Confirm</eun-button>
```

**React:**

```jsx
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).

**Next.js:**

```jsx
"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.

**Vue:**

```html
<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.

**Angular:**

```ts
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 [Angular forms](https://eunomia-ds.com/guides/angular-forms/).

## 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:

```html
<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`.

```html
<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:

```js
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](https://eunomia-ds.com/theming/), [Prebuilt themes](https://eunomia-ds.com/theming/prebuilt-themes/) and [Custom theme](https://eunomia-ds.com/theming/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:

```ts
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.

```tsx
<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:

```tsx
<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:

```tsx
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](https://eunomia-ds.com/components/button/)).

## 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](https://eunomia-ds.com/components/button/)) spelling out exactly which keyboard shortcuts and ARIA behavior it implements.

## Troubleshooting

> **The tag renders as plain text and does nothing**
>
> 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.

> **Angular (or another strict framework) complains about an unknown element**
>
> 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.

> **"document is not defined" or "customElements is not defined"**
>
> 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).

> **The component doesn't match my theme**
>
> 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](https://eunomia-ds.com/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.

> **Styles look right in light mode but wrong in dark mode**
>
> 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](https://eunomia-ds.com/theming/#how-switching-works).

## Next steps

- [Web components](https://eunomia-ds.com/web-components/): How they work in any framework

- [Foundations](https://eunomia-ds.com/foundations/): The design tokens behind every component

- [Theming](https://eunomia-ds.com/theming/): Prebuilt or custom themes, light and dark

- [Components](https://eunomia-ds.com/components/): Every available component

- [Features](https://eunomia-ds.com/features/): Higher-level pieces, like a data table

- [Charts](https://eunomia-ds.com/charts/): Data visualization, in its own package

- [Icons](https://eunomia-ds.com/icons/): The full searchable icon set

- [Utilities](https://eunomia-ds.com/utilities/): Plain JavaScript helpers

- [Guides](https://eunomia-ds.com/guides/): Forms, events, SSR, and more

- [Compatibility](https://eunomia-ds.com/compatibility/): Which package versions go together
