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. Nois,allowsorshouldprefix:allowCustomValue,closeOnSelect. - Booleans are positive, with the common case as the default:
deselectable(defaulttrue), notdisallowEmptySelection. - 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 sayselected, as M3 does; navigation items saycurrent, 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 itsvalue/defaultValue/onChange, several keys withselectionMode="multiple"(Select,Autocomplete), asTabsand a radioListreport theirs. - Ranges are
minandmax, as on an HTML input. - Hooks follow the same rule:
defaultExpanded, notinitialExpanded.
Events
- Buttons, cards, chips and links take
onPress, which covers mouse, touch, pen and keyboard alike;onClickstill works. - An item of a collection is activated with
onAction(key)(List,Menu); aCarousel's items have no keys, so itsonAction(index)gets the item's index. - The end of a motion is
onOpened/onClosed; a drag or key that finishes changing a value isonChangeEnd.
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.
- 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:ButtoncoversButtonandIconButton,Chipthe chips,DatePickerboth date pickers andSnackbarthe snackbar and its host. - A component built from another reads that one's words too, then its own:
DateFieldreadsDatePicker's, andTimeFieldreadsTimePicker's andPickerDialog'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'slabels, 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
useLabelsfrom@windmorph/react/primitives, after adding its key toWindmorphLabelsby 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
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
langordir: 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".
useLocalereturns 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 logicalstartandend, which follow the text direction. - Multi-word values are hyphenated:
bottom-start,full-screen,space-between. - Icon slots are M3's
leadingIconandtrailingIcon. - Sizes share one scale,
xstoxl(a FAB addsdefault). M3's named variants, such as a top app bar'ssmallorlarge, arevariants, not sizes. The indicators M3 sizes freely,LoadingIndicatorand a circularProgressIndicator, takesizeas 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,refandid. A field'sidgoes 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 astitleandlang, 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 wrappingdivorlabel. Where the component sets those itself (a select's trigger, a combo box's input), it doesn't take them. classNameandstylego on the outermost element;classNamesreaches each part, with one slot name per part everywhere (supportingText,close,back).aspicks the element where a component offers a choice (as="div");hrefturns 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>:closedByisany,closerequestornone.
In Windmorph Pro
Pro's components follow the same rules, and the same kind of test reads their props:
- A colour is
coloronAvatar,Tag,Link,Skeleton,ShapedIconandEmptyState. AnAlertnames its kind withseverity(infoby default;erroris read at once), since it decides the live region as well as the colours. - Work in flight is
pending, as on the core'sButton:MessageFieldwhile sending,ImageCropDialogwhile saving. - The end of a motion is
onClosed(Alert,Collapse), focus on mount isautoFocus, and a tile of a grid is activated withonAction(MediaGrid). - Sizes are on the same scale (
PinInputandLinktakesm,md,lg), and a shape is a value: a constant such ascookie12SidedShapefrom@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
The words, keyed by component:
{ TextField: { error: '…' }, DialogHeader: { close: '…' } }. Keep the object the same between renders (a constant, oruseMemo), so the components below render again only when a word changes.Autocomplete's words.Badge's words.BottomSheet's words.Button's andIconButton's words.ButtonGroup's words.Carousel's words.FilterChip's andInputChip's words.DateField's words. It readsDatePicker's first, then these.DatePicker's andDateRangePicker's words.DialogHeader's words.A reorderable
List's words.ListItemVideo's words.Menu's words.PickerDialog's words.PullToRefresh's words.RangeSlider's words.SearchField's words.Select's words.SideSheet's words.Snackbar's words, and those of the snackbars aSnackbarHostshows.SplitButton's words.TextField's words.TimeField's words. It readsTimePicker's andPickerDialog's first, then these.TimePicker's andTimePickerModeToggle's words.
useLocale
useLocale(): LocaleContextValueThe 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
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 matchdirection: readdirection, never work it out from the locale, and don't hand this locale to a provider of your own inside such a region.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).