@fluxus-ui/ui
v0.24.0
Published
Fluxus interface layer: design tokens with themes as data, layouts a user configures, navigation, atoms, form fields, what opens over the page, what shows content, toasts and templates. More components follow (SPEC §14).
Maintainers
Readme
@fluxus-ui/ui
The interface layer of Fluxus: design tokens with themes as data, layouts a user configures, navigation, form fields, what opens over the page (Dialog, Sheet, Menu…), what shows content, toasts and templates. Its motion comes from @fluxus-ui/core.
npm install @fluxus-ui/ui @fluxus-ui/core @fluxus-ui/icons @fluxus-ui/reactimport '@fluxus-ui/ui/tokens.css';
import '@fluxus-ui/ui/styles.css';
import { Button, Field, Input } from '@fluxus-ui/ui/react';
export function SignIn() {
return (
<form>
<Field label="Email" hint="The one you signed up with">
<Input type="email" name="email" />
</Field>
<Button variant="primary" type="submit">
Sign in
</Button>
</form>
);
}styles.css is every sheet in one. Each component also has its own (@fluxus-ui/ui/button.css, @fluxus-ui/ui/dialog.css…), for an app that ships only what it uses.
A strict CSP (style-src 'self', no 'unsafe-inline') needs nothing open. Fluxus writes no style attribute from the server and inserts no <style>: what is fixed is in the sheet, a value of a bounded scale is an attribute with a rule (Stack gap="4", the value of Progress and Slider, Grid min={12}), and what moves is written by the client through el.style. A value of your own (gap="1.3rem") still goes inline: put it in a class of yours instead. CellsLayout is the exception. If you load single sheets instead of styles.css, load engine.css and scales.css too.
Less motion chosen by the app: data-fx-motion="reduced" on <html> reduces the motion of Fluxus as the system setting does. The system still wins.
Browsers without light-dark() (before Chrome 123, Safari 17.5, Firefox 120): styles-attr.css instead of styles.css writes each mode by attribute; set data-fx-mode="dark" or leave it to prefers-color-scheme. themeToCss(base, theme, { modes: 'attribute' }) does the same for a theme. Overlays still need the Popover API (Chrome 114, Safari 17, Firefox 125).
Texts. Every word Fluxus shows or says has a prop: AppShell skip ('Skip to content') and, with the drawer, menuLabel and closeLabel ('Menu', 'Close'), NavCollapseButton children ('Menu'), Breadcrumbs label ('Breadcrumb'), ToastProvider label and closeLabel ('Notifications', 'Close'), ConfirmButton cancel ('Cancel'), Combobox emptyLabel ('No results'), FileDrop refusedLabel ('Not accepted:'), DatePicker labels ({ previous: 'Previous month', next: 'Next month', marked, clear: 'Clear', open: 'Choose date' }) and locale ('en-US'), DataTable expandLabel ('Details') and locale ('en'), Sheet closeLabel (no default: without it there is no close button), ToastProvider toneLabels (no default: the word of each tone, said before the title).
What its owner opens. Dialog, Sheet and Menu take open and onOpenChange: then the trigger, Escape, a click outside and data-fx-close only ask, and your state answers. trigger is optional in Dialog and Sheet; without one the focus goes back to what had it. dismissible={false} stops Escape and the click outside while something is being saved; description is linked with aria-describedby; size is 'sm' | 'md' | 'lg', and the body of a dialog scrolls inside.
<Dialog open={open} onOpenChange={setOpen} title="Edit student" description="Saved when you confirm." dismissible={!saving} size="lg" actions={<Button data-fx-close="">Cancel</Button>}>
…
</Dialog>
<Menu trigger={<Button>View</Button>} label="View">
<MenuGroup label="Show as" value={view} onValueChange={setView}>
<MenuItemRadio value="list">List</MenuItemRadio>
<MenuItemRadio value="table">Table</MenuItemRadio>
</MenuGroup>
<MenuSeparator />
<MenuItem tone="danger" description="It cannot be undone">Delete</MenuItem>
</Menu>A Tooltip and a Menu on one button. Either way round, and with Dialog and Sheet too: both hold your button, not each other's wrapper. The tooltip gives way: it closes when the menu opens, stays shut while it is open, and does not come back with the focus that returns from it; Escape closes the menu. While a Tooltip is on it, a trigger that has a name loses its title: one tooltip, not two.
<Menu label="More actions" className="my-menu" trigger={<Tooltip content="More actions" describes={false}><IconButton label="More actions">…</IconButton></Tooltip>}>
<MenuGroup aria-label="View" layout="row" value={view} onValueChange={setView}>
<MenuItemRadio value="list" icon={<Icon icon={list} />}>List</MenuItemRadio>
<MenuItemRadio value="map" icon={<Icon icon={map} />} aria-label="Map" />
</MenuGroup>
<MenuItem lines={1} end={<Icon icon={arrowRight} />}>A long title, cut with an ellipsis</MenuItem>
<MenuItem lines={2} end="New" endDecorative={false}>A longer title, in two lines at most</MenuItem>
</Menu>Menu items. end closes the row (an arrow, a mark); a screen reader skips it unless endDecorative={false}. lines={1 | 2} cuts the label with an ellipsis at the width of the menu, which a class of yours sets (.my-menu { inline-size: 15rem }); with 2, the row lines up at its top. MenuGroup layout="row" puts its items side by side, 44 px each: an item with icon shows only the icon, and its children or aria-label name it. Left and right move along the row; up and down leave it, and it is entered at the chosen item. A MenuItemRadio with its own icon is filled when chosen instead of checked. MenuGroup takes aria-label in place of label.
Segmented. With items it is links in a <nav> (each one a URL, the current one with aria-current="page"); with options, value and onChange it is buttons in a role="group" (aria-pressed), to change a view without a URL. Narrower than its options it stays on one line and scrolls, and the chosen one is kept in sight.
<Segmented label="View" value={view} onChange={setView} options={[
{ value: 'list', label: 'List', icon: <Icon icon={list} /> },
{ value: 'map', label: 'Map', icon: <Icon icon={map} /> },
]} />DataTable. density="compact" leaves less air in each row and valign="top" puts cells at the top of a tall one. A column takes narrow (only the width of what it holds) and headerLabel (its name for a screen reader, when header is an icon). Figures are tabular in every column, with or without align: 'end'. With expand, expanded and onExpandedChange let the owner hold which rows are open, and expandLabel(row, open) knows whether its row is.
Tag. <Tag as="a" href="…"> answers the pointer and the keyboard as a button tag does, and both reach a 44 px target.
Navigation. NavGroup label puts destinations under a title: a role="group" named by it. An open rail shows the title, a folded one leaves a rule in its place, and a row (top or bottom) does not show it; the name stays. NavItem end goes after the label (a count); a screen reader skips it unless endDecorative={false}, and then says it with the name ("Messages 3"). A rail whose list does not fit the window scrolls it; start and end stay.
<AppShell narrow="drawer" menuLabel="Menu" closeLabel="Close" bar={<strong>ALBA</strong>} nav={
<NavRail label="Main" start={<SpaceSwitcher />} end={<Account />}>
<NavGroup label="Operation">
<NavItem href="/messages" icon={<Icon icon={chat} />} end={3} endDecorative={false}>Messages</NavItem>
</NavGroup>
</NavRail>
}>…</AppShell>Narrow. Below 48rem the shell puts the items in a bar at the bottom, without start and end (narrow="bottom", the default). With narrow="drawer" a bar at the top holds a button (menuLabel, aria-expanded) and whatever bar is, and the whole navigation waits in a Sheet from start, as a rail. Choosing a destination closes it, the current one too, and the focus goes back to the button. There is one navigation in the page, not two: it is mounted in the rail or in the drawer, so state kept inside it starts again when the window crosses that width. Without JavaScript the bar is painted and the drawer does not open. With single sheets, it needs sheet.css beside nav.css and layout.css.
Toasts. toast.show({ key: 'save', title, tone, action: { label, onAction, altText } }): a toast with the key of one that is showing takes its place; the tone is a word (toneLabels) and an icon, not only a color; altText is said with the toast for who does not get to the button.
One client module a component. @fluxus-ui/ui/react/dialog, /react/menu, /react/toast, /react/button… (30 of them) carry only that component, so a page does not load the whole /react entry. They share their contexts with it: a ToastProvider of one serves the useToast of another.
Entries: /react (client components), /react/<component> (one of them), /markup (server components), /theme (the token engine: tokensToCss, validateTheme), /layout, /nav, /atoms, /forms, /disclosure and /toast (the same behaviours without React).
A theme is a tokens file. A theme may add its app's own tokens under the group app; everything else is a closed contract, checked for contrast, touch target and text size.
For React Native, the same theme file gives a theme for @fluxus-ui/native:
npx fluxus-native-theme --theme its.tokens.json --out its-theme.tsDesign and decisions: SPEC.md, §14.
MIT
