# @devmoods/ui: guide for building apps > React 19 components, hooks, themes and schema-driven forms. This guide is > for anyone, person or AI agent, building an app with the library. Every > code example is a complete module you can copy, and is type-checked > against the library. Read the "Rules" section first. They are what makes apps built with this library look good in every theme, work on phones, and work with keyboard and screen readers. ## Setup ```tsx 'use client'; // needed in Next.js, harmless elsewhere import '@devmoods/ui/global.css'; // reset, page background, text and spacing classes import '@devmoods/ui/styles.css'; // component styles import { LocaleProvider, ThemeProvider, ToastProvider, createTheme, } from '@devmoods/ui'; import { type ReactNode } from 'react'; const theme = createTheme({ colors: { primary: '#2563eb' }, }); export function Providers({ children }: { children: ReactNode }) { return ( {children} ); } ``` - Import both CSS files once, at the root of the app. - Put `ThemeProvider` at the root. It writes the theme as CSS variables. - `ToastProvider` is needed for `useToast`. - `LocaleProvider` sets the language and region, like `nb-NO` or `en-US`. `DatePicker`, `Calendar`, `TimePicker` and `Money` follow it: date format (`20.10.2026` or `10/20/2026`), month and weekday names, first day of the week, 12 or 24 hours, and number format. In an app with many languages, pass the user's current language, and the components update when it changes. `en_US` works too. A `locale` prop on any of these components wins (`TimePicker` also takes `use12Hour`). Without a valid locale (`undefined`, or a tag that is not valid), dates are `2026-10-20`, names are English, weeks start on Monday and times use 24 hours. `useLocale()` reads the locale. - The default font is Inter. The library does not load fonts. Load the font yourself (for example from Google Fonts), or set `fonts.base` in the theme. ### Next.js and Server Components The components are client components (`'use client'` is set in the package). A Server Component in the App Router can import and render them: ```tsx import { Button, Stack } from '@devmoods/ui'; import { formatCurrency } from '@devmoods/ui/format'; export default function Page() { return (

From {formatCurrency(249)} a month

); } ``` - In a Server Component, pass only data as props: strings, numbers, plain objects and elements. Event handlers like `onClick` need a `'use client'` file. - Functions and hooks from `@devmoods/ui`, `@devmoods/ui/forms` and `@devmoods/ui/helmet` only work in `'use client'` files. This includes `createTheme`, `convertToDarkTheme`, `isDarkTheme` and `getThemeStyle`. That is why the `Providers` file in Setup starts with `'use client'`. Wrap the app in it in `app/layout.tsx`. - Dot names like `Modal.Footer` and `Wizard.Step` do not work in a Server Component. Use them in a `'use client'` file. - `@devmoods/ui/format` does not use React. Its functions work anywhere. - `as={Link}` does not work in a Server Component. A component is a function too, and Next.js stops with "Functions cannot be passed directly to Client Components". Make a small `'use client'` file with the link, and use it from Server Components: ```tsx 'use client'; import { Button } from '@devmoods/ui'; import Link from 'next/link'; import { type ReactNode } from 'react'; export function LinkButton({ href, children, }: { href: string; children: ReactNode; }) { return ( ); } ``` - Then `Invoices` works in a Server Component. Do the same for `ResponsiveSidebarAppSidebarMenuItem` and any other `as={Link}`. Name the props you need, like `href` above. A wrapper that spreads all `Link` props into `Button` does not type-check. - Pages Router: wrap the app in `Providers` in `pages/_app.tsx`. There are no Server Components there, so `as={Link}` works directly. - Page title and meta tags: use what Next.js has, the `metadata` export in the App Router and `next/head` in the Pages Router. They are in the HTML from the server, so search engines and link previews see them. Do not use `@devmoods/ui/helmet` in Next.js (see "Page title and head tags"). ### Page title and head tags `@devmoods/ui/helmet` sets the page title and meta tags from any component. It is [`@dr.pogodin/react-helmet`](https://www.npmjs.com/package/@dr.pogodin/react-helmet). Put `HelmetProvider` once at the root of the app. Without it, `Helmet` crashes ("must be within a children tree"). ```tsx import { Stack } from '@devmoods/ui'; import { Helmet, HelmetProvider } from '@devmoods/ui/helmet'; function InvoicesPage() { return ( Invoices | Acme

Invoices

); } export function InvoicesApp() { return ( ); } ``` - The tags are set in the browser, after the page has loaded. With server rendering they are not in the HTML from the server. To get them there, pass a `context` object to `HelmetProvider` and write the tags into the HTML yourself. In Next.js, use `metadata` or `next/head` instead. ## Rules 1. Build layouts with `Stack`, not custom flexbox CSS. Use `spacing`, `padding` and `margin` props with theme tokens. 2. Never hard-code colors, spacing or radius. Use the CSS variables from the theme: `var(--colors-primary)`, `var(--spacing-m)`, `var(--border-radius-m)`. 3. Backgrounds use `var(--colors-surface)`. Text uses `var(--colors-primary-text)`, muted text `var(--colors-gray-50)`. Make tints with `color-mix(in srgb, var(--colors-primary) 15%, var(--colors-surface))`. This keeps dark mode and dark themes working. 4. Use the library component when one exists. Popover, Modal, Dialog, DropdownMenu, Tabs and Tooltip already handle focus, Escape and ARIA. 5. Give every field a `label`, and every button that only has an icon an `aria-label`. 6. Design for phones first. Pass arrays to responsive props: `horizontal={[false, true, true]}` is a column on phones and a row from tablets up. Breakpoints: phone from 0px, tablet from 600px, desktop from 1200px. Responsive style props and `ResponsiveSidebarAppLayout` become CSS media queries, so server rendered HTML is right on every screen. `useResponsiveValue` and `Modal`'s `sheet` run in JavaScript: the server renders the desktop value, and phones switch after hydration, so the page jumps. Use the hook only for behavior CSS can not do, like rendering another component. For anything you see, use responsive props, `display={['flex', 'none', 'none']}` on a `Stack` to show a part on phones only, or a media query in your own CSS. 7. Show state: `isPending` on buttons that submit, `Loader` or `Skeleton` while loading, `Alert` for errors, toasts for results. 8. Use the state hooks for simple controlled fields: `useInputState`, `useSelectState`, `useCheckboxState`, `useSwitchState`, `useRadioGroupState`, `useCheckboxGroupState`, `useCounterState`, `useSliderState`, `useRatingState`, `useModal`. 9. Use `useQuery` for loading data and `useMutation` for changing it. Keep the function you give `useQuery` free of side effects. 10. Before shipping, check the app in dark mode and at phone width (390px). ## Layout ### Stack `Stack` is a flex container. Vertical by default, `horizontal` for a row. | Prop | Values | Default | | ---------------------------- | ------------------------------------------------------------------- | ------------ | | `horizontal` | `boolean` | `false` | | `spacing` | `none` `xxs` `xs` `s` `m` `l` `xl` `xxl` | `m` | | `alignItems` | `flex-start` `center` `flex-end` `stretch` `baseline` | `stretch` | | `justifyContent` | `flex-start` `center` `flex-end` `space-between` `space-around` `space-evenly` | `flex-start` | | `wrap` | `boolean` | `false` | | `padding`, `paddingX`, … | spacing token | | | `margin`, `marginTop`, … | spacing token, or `auto` | | | `as` | any element, for example `form`, `ul`, `nav` | `div` | Every prop takes one value, or an array of three: phone, tablet, desktop. A `Stack` takes the full width. For a row inside a row, like a group of buttons, set `style={{ width: 'auto' }}` on the inner Stack. Spacing tokens are 0, 2, 4, 8, 16, 24, 32 and 64px in the default theme. Themes can change them. ```tsx import { Button, Stack } from '@devmoods/ui'; export function Toolbar() { return (

Invoices

); } ``` ```tsx import { Stack } from '@devmoods/ui'; const features = ['Fast', 'Themed', 'Responsive']; export function Features() { return ( {features.map((feature) => ( {feature} A short description. ))} ); } ``` ### Other layout pieces - `Panel`: a box with padding, border and an optional `title`, a short label on the top edge. Props: `padding`, `elevation` (`'0'`, `'1'`, `'2'`), `transparent`. - `Divider`: a vertical line by default, for rows like a toolbar. Set `horizontal` for a line between stacked content, and `title` for text in the middle. - `Spacer`: a fixed space, `height` is a spacing token, `horizontal` for width. - `ListGroup` with `ListGroupItem`: a list with dividers between rows. Give `ListGroupItem` `start` (icon, avatar, checkbox), `title`, `description` and `end` (value, badge, button) for a row with two lines of text. Rows are at least 44px high. `flush` drops the outer border, for a list inside a `Card` or `Panel`: put it directly in the card, and the dividers reach the edges while the text lines up with the title. - `Grid`: equal columns that wrap by themselves. `minItemWidth` (default 240px) and `spacing`. Use it for cards. `as="ul"` for a list. ### Cards, clickable rows and empty states - `Card`: one thing in a list or grid, like a product or an activity. Props: `media` (an image on top), `eyebrow` (small text above the title), `title` (an `h3`), `description`, `actions` (buttons at the bottom), `horizontal` (media on the left, responsive), `padding`, `elevation`. Cards in a `Grid` get the same height, with the actions at the bottom. - `LinkOverlay`: put it around the title of a `Card` or `ListGroupItem` to make the whole box clickable. Use `as` for a router link or a button. For a checklist row, use `as="label"` with `htmlFor` set to the checkbox `id`, so a tap anywhere on the row checks it. Other buttons and links in the box keep working. Do not wrap a whole card in ``, and do not put an `onClick` on the card. - `EmptyState`: what to show when a list, a search or a page is empty. Props: `icon`, `title` (an `h2`), `description`, `actions`, `size` (`s` inside lists and panels, `m` for a page). Say why it is empty and give the user a way to move on. ```tsx import { Button, Card, EmptyState, Grid, LinkOverlay, ListGroup, ListGroupItem, } from '@devmoods/ui'; interface Product { id: string; name: string; city: string; price: string; imageUrl: string; } export function ProductGrid({ products, onClear, }: { products: Product[]; onClear: () => void; }) { if (products.length === 0) { return ( Clear filters} /> ); } return ( {products.map((product) => (
  • } eyebrow={product.city} title={ {product.name} } actions={{product.price}} />
  • ))}
    ); } export function Members({ onRemove }: { onRemove: (id: string) => void }) { return ( Kari Nordmann} description="kari@example.com" end={ } /> ); } ``` ### App shell `ResponsiveSidebarAppLayout` gives a header and a sidebar. On phones the sidebar becomes a menu that opens from the header, and can be closed by swiping or with Escape. ```tsx import { DarkModeSwitch, ResponsiveSidebarAppHeader, ResponsiveSidebarAppLayout, ResponsiveSidebarAppSidebarMenuItem, ResponsiveSidebarAppSidebarSection, } from '@devmoods/ui'; import { type ReactNode } from 'react'; export function AppShell({ children }: { children: ReactNode }) { return ( Acme}> } sidebar={ Dashboard Invoices } > {children} ); } ``` With a router, pass its link component: ``. In a Next.js Server Component, put it in a `'use client'` file first (see "Next.js and Server Components"). `headerHeight` sets the header height (default `120px`), and `maxWidth` the width of the content. A header that wraps on phones can be taller there: `headerHeight={['200px', '120px', '120px']}`. `ResponsiveMobileAppLayout` with `ResponsiveMobileAppHeader` is a simpler layout with only a header, made for phone-style apps. ### Front pages - `Hero`: the top of a front page. `title` (an `h1`), `eyebrow`, `description`, `actions` (the main buttons), `media` (an image beside the text on wide screens, below it on phones), `centered` (only without media), `tinted` (a background in a light primary color). The layout follows the width of the hero, not the window, so it is right in a server render before the page is hydrated. - `Footer` with `FooterColumn`: the footer of a site. `brand`, `description`, `bottom` (copyright and legal links), and columns of links as children. Each column is a `nav` named by its `title`. ```tsx import { Button, Footer, FooterColumn, Hero } from '@devmoods/ui'; export function FrontPage() { return ( <> Open your shop } media={A shop in the app} />
    ); } ``` ## Text and utility classes From `global.css`: - Text: `dmk-text-large-title`, `dmk-text-title1`, `dmk-text-title2`, `dmk-text-title3`, `dmk-text-headline`, `dmk-text-body`, `dmk-text-callout`, `dmk-text-subhead`, `dmk-text-footnote`, `dmk-text-caption1`, `dmk-text-caption2`. - Text style: `dmk-text-muted`, `dmk-text-semibold`, `dmk-text-bold`, `dmk-text-uppercase`, `dmk-text-with-icon`. - `` gets a dotted underline. Wrap it in `Tooltip` to show the full term. - Spacing: `dmk-margin-{side}-{token}` and `dmk-padding-{side}-{token}`, where side is `top`, `bottom`, `left`, `right`, `x`, or left out for all sides. Short forms: `dmk-mt-m`, `dmk-px-l`, … - `dmk-line-clamp-{n}` cuts text after n lines. `dmk-visually-hidden` hides content but keeps it for screen readers (or use `VisuallyHidden`). `dmk-visually-hidden-focusable` (or ``) is hidden until it has focus. Use it for a skip link, and give it your own class for the look when it shows. Prefer `Stack` props over margin classes for space between elements. ## Components ### Actions - `Button`: `variant` `contained` (default), `outlined` or `text`. `intent` `danger` or `none`. `size` `s`, `m`, `l`. `isPending` shows a spinner and disables the button. - `DropdownMenu`: `label`, and `items` with `{ label, action, separator, selected, icon, intent, disabled }`. `icon` goes in front of the label, `intent: 'danger'` is for Delete and the like, and an item without `action` or with `disabled` can not be chosen. `{ label: null, separator: true }` is a line between groups. `buttonProps` go to the button: `variant`, `size` and any button prop. A button with only an icon needs a name: `label={}` with `buttonProps={{ 'aria-label': 'Actions' }}`. - `ShareButton`: `title` and `url`. Uses the native share sheet on phones. - `DarkModeSwitch`: toggles dark mode. Needs `allowDarkMode` on `ThemeProvider`. It is an icon button named "Dark mode", with `aria-pressed` on while dark mode is on. ```tsx import { Button, DropdownMenu, Stack } from '@devmoods/ui'; export function Actions({ onDelete }: { onDelete: () => void }) { return ( {} }, { label: null, separator: true }, { label: 'Delete', intent: 'danger', action: onDelete }, ]} /> ); } ``` ### Inputs All fields take `label`, `hint` and `error`. Set `error` to a message to show it, and the field is marked invalid. - `Input`: text fields. `multiline` for a textarea (then it takes textarea props, like `rows={5}` for the height), `startAdornment` and `endAdornment` for icons or units. - `NumberInput`: numbers as text, reads a comma as a decimal point, clamps to `min`/`max` when leaving the field. Use `value` and `onChange`, or `defaultValue` for a start value. - `Counter`: a number with − and + buttons. `min`, `max`, `step`. - `SearchInput`: an input with a search icon and a clear button ("Clear search"). Keep it controlled with `value`, so the clear button shows. Escape also clears it. - `Select`: a native select. Children are `