Skip to content

API conventions

Every Windmorph component, in the core and in Pro, names its props the same way, so what you learn on one carries over to the next. The names follow HTML first, then M3 and the leading React libraries. A unit test reads every public prop, inherited ones included, and fails on a name these rules leave out.

Booleans

  • A state is a plain adjective, as in HTML: disabled, readOnly, required, invalid, open. No is, allows or should prefix: allowCustomValue, closeOnSelect.
  • Booleans are positive, with the common case as the default: deselectable (default true), not disallowEmptySelection.
  • A prop that shows or hides an optional part is named after the part: valueLabel, counter, ticks, closeButton.
  • A function that answers a question keeps its question form: isDateUnavailable(date).

Controlled and uncontrolled state

Every piece of state comes as a triple: the value, its default… twin for uncontrolled use, and an on…Change callback that receives the new value first.

  • One choice: value / defaultValue / onChange (Select, Tabs, RadioGroup, the sliders and pickers).
  • Checkable inputs: checked / defaultChecked / onCheckedChange (Checkbox, Switch, list items). Toggle buttons and chips say selected, as M3 does; navigation items say current, since they mark the page the app is on (aria-current), not a selection.
  • Overlays: open / defaultOpen / onOpenChange. Several choices in a group or collection (ButtonGroup, ChipSet, List, Menu): selectedKeys / defaultSelectedKeys / onSelectionChange. A field's choice is its value / defaultValue / onChange, several keys with selectionMode="multiple" (Select, Autocomplete), as Tabs and a radio List report theirs.
  • Ranges are min and max, as on an HTML input.
  • Hooks follow the same rule: defaultExpanded, not initialExpanded.

Events

  • Buttons, cards, chips and links take onPress, which covers mouse, touch, pen and keyboard alike; onClick still works.
  • An item of a collection is activated with onAction(key) (List, Menu); a Carousel's items have no keys, so its onAction(index) gets the item's index.
  • The end of a motion is onOpened / onClosed; a drag or key that finishes changing a value is onChangeEnd.

Words

Every word a component shows or announces comes from its labels prop, with English defaults, so an app can translate all of them. Each key is documented with its default, and labels takes any of them (labels={{ close: "Fermer" }}). Names only your app knows, such as a list's aria-label, are required by the types.

Translating the built-in words

An app in another language gives its words once, to a LabelsProvider near its root. Its labels are keyed by component, and each key takes the words that component's own labels prop takes, so the editor completes them. The provider ships no translations: the words are your app's.

app-labels.tsx
// app/app-labels.tsx
'use client';

import type { ReactNode } from 'react';
import { LabelsProvider, type WindmorphLabels } from '@windmorph/react';

const words: WindmorphLabels = {
  TextField: {
    error: 'Fehler',
    characterCount: (count, max) => `Zeichen: ${count} von ${max}`,
  },
  DialogHeader: { close: 'Schließen' },
  Button: { pending: 'Wird geladen' },
};

export function AppLabels({ children }: { children: ReactNode }) {
  return <LabelsProvider labels={words}>{children}</LabelsProvider>;
}
  • A component uses its English default, then the provider's word, then its own labels, which always wins. Providers nest and merge word by word, so a part of the app can change one word and keep the rest.
  • A key is a labels type's name without Labels, so components that share a type share a key: Button covers Button and IconButton, Chip the chips, DatePicker both date pickers and Snackbar the snackbar and its host.
  • A component built from another reads that one's words too, then its own: DateField reads DatePicker's, and TimeField reads TimePicker's and PickerDialog's, so the words they share are written once.
  • Windmorph Pro's components read the same provider. Importing one adds its key (Alert, DataTable, MessageField…) to the provider's labels, so Pro's words sit beside the core's.
  • Some words are functions (a character count), which a Server Component can't pass to a Client Component. Render the provider from a client file of your own, as above, and wrap the app in it.
  • A component of your own reads the provider with useLabels from @windmorph/react/primitives, after adding its key to WindmorphLabels by declaration merging.

The provider's table below lists every key; each component's API tab lists its words under labels, with their defaults.

Dates, times and numbers

How a component writes a date, a time or a number (the order of a date, the 12- or 24-hour clock, digits, the first day of the week) comes from its locale, not from labels. Set it once with a LocaleProvider, passing the language your page is written in. Without one the components follow the browser's language (en-US on the server), which may not be the page's: an English page in a British browser gets 24-hour time fields beside 12-hour text.

app/layout.tsx
// app/layout.tsx
import { LocaleProvider, ThemeProvider } from '@windmorph/react';

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <ThemeProvider>
          <LocaleProvider locale="en-US">{children}</LocaleProvider>
        </ThemeProvider>
      </body>
    </html>
  );
}
  • Pass the same locale on the server and in the browser, so the first render matches. It is a string, so a Server Component can render the provider.
  • A provider inside another sets the locale for its part of the page. It sets no lang or dir: set those on your own elements, dir="rtl" included for a right-to-left language.
  • Windmorph Pro's components follow the same provider: a calendar's month names, a data grid's decimal separator, a count written "1.3K".
  • useLocale returns the locale and its direction, for your own formatting, so your dates match the fields beside them, in a toolbar or list laid out the other way too: new Intl.DateTimeFormat(useLocale().locale).

Placement, sizes and colours

  • Where a part goes is …Placement: iconPlacement, fabPlacement, controlPlacement. Sides are CSS's logical start and end, which follow the text direction.
  • Multi-word values are hyphenated: bottom-start, full-screen, space-between.
  • Icon slots are M3's leadingIcon and trailingIcon.
  • Sizes share one scale, xs to xl (a FAB adds default). M3's named variants, such as a top app bar's small or large, are variants, not sizes. The indicators M3 sizes freely, LoadingIndicator and a circular ProgressIndicator, take size as a number of px.
  • A colour choice is color, named after an M3 colour role.

Elements and styling

  • Every component with an element of its own takes className, style, ref and id. A field's id goes to its input or trigger, so a <label for> or an error summary reaches it.
  • The root also takes its element's DOM attributes: data-*, aria-*, global attributes such as title and lang, and events. Where React Aria labels an inner element (a field's input, a tab list), the naming attributes (aria-label, aria-labelledby, aria-describedby), the attributes that describe that element (aria-controls, aria-expanded, aria-haspopup, aria-autocomplete, aria-activedescendant, aria-required, aria-invalid, aria-readonly) and the focus, key and input events go to that element instead, never to a wrapping div or label. Where the component sets those itself (a select's trigger, a combo box's input), it doesn't take them.
  • className and style go on the outermost element; classNames reaches each part, with one slot name per part everywhere (supportingText, close, back).
  • as picks the element where a component offers a choice (as="div"); href turns a button into a link.
  • State shows on the root as data-* attributes, present or absent (data-disabled, data-checked, data-open), and choices as values (data-variant, data-size).
  • How a dialog or sheet may be closed follows HTML's <dialog closedby>: closedBy is any, closerequest or none.

In Windmorph Pro

Pro's components follow the same rules, and the same kind of test reads their props:

  • A colour is color on Avatar, Tag, Link, Skeleton, ShapedIcon and EmptyState. An Alert names its kind with severity (info by default; error is read at once), since it decides the live region as well as the colours.
  • Work in flight is pending, as on the core's Button: MessageField while sending, ImageCropDialog while saving.
  • The end of a motion is onClosed (Alert, Collapse), focus on mount is autoFocus, and a tile of a grid is activated with onAction (MediaGrid).
  • Sizes are on the same scale (PinInput and Link take sm, md, lg), and a shape is a value: a constant such as cookie12SidedShape from @windmorph/react/primitives, so an app bundles only the outlines it uses.
  • Optional parts are named after the part (counter, lineNumbers, idleIcon), and root props reach the root on every component.

API reference

LabelsProvider 1 prop

  • labelstype WindmorphLabelsRequired

    The words, keyed by component: { TextField: { error: '…' }, DialogHeader: { close: '…' } }. Keep the object the same between renders (a constant, or useMemo), so the components below render again only when a word changes.

LocaleProvider 1 prop

  • localetype stringRequired

    The locale, as a BCP 47 language tag: 'en-US', 'de-DE', 'ar-EG'. Pass the language the page is written in, the same value on the server and in the browser.

useLocale

useLocale signature
useLocale(): LocaleContextValue

The locale the components here use: the nearest LocaleProvider's, or the browser's language without one (en-US on the server). For an app's own formatting, so its dates and numbers match the fields beside them: new Intl.DateTimeFormat(useLocale().locale).format(date).

Returns LocaleContextValue

  • localetype stringRequired

    The locale, as a BCP 47 language tag ('en-US'): the page's, also in a toolbar, list or other region laid out the other way, where React Aria is given it in another script for its arrow keys. So there it may not match direction: read direction, never work it out from the locale, and don't hand this locale to a provider of your own inside such a region.

  • directiontype "ltr" | "rtl"Required

    The direction the components here follow: the locale's, or that of a region laid out the other way (a list in dir="rtl" on a left-to-right page).