Styles
A style draws the components: their shape, type, density and motion. The user picks it beside the theme, and no style may move what keeps a screen usable.
API Theme ThemeMenu Card EmptyState Kbd LinkCard GroupHeading List NavList Pane SegmentedControl Toggle Separator TabNav Table Tree Toolbar CodeEditor
Leave how the components are drawn to the style, and build every surface of your own from the same components and tokens, so a style the user picks redraws it too. A theme says what colour each role is; a style says what shape it takes. Together they are the look, and both are the user's.
The buttons above call setStyle, and the whole page redraws, this text included: the card's
header, the tabs, the field and the buttons change their corners, edges, type and height, and the
site's own chrome follows, because it is built from the same components. Pick a style in the top
bar's theme menu for the same.
What a style changes#
A style is the tokens @orz/ui's components read for everything but colour, and the look each
component carries for it where a token cannot draw it:
- Shape. Corner radii, and how an edge is drawn: a 1px rule, or the two-tone bevel a Windows 2000 button has.
- Depth. Whether surfaces cast shadows, and what lifts a menu or a dialog above the page: a light shadow under each layer, or a raised bevel.
- Type. The families, the size of body text and each step of the scale.
- Density at a pointer. The height of a control and of a row, and the padding inside them.
- Focus. How the focus indicator is drawn: a solid ring, or a dotted rectangle.
- State. How a selected row, a highlighted menu item and the current tab are told apart.
- Motion. How long an overlay takes to arrive, and whether it fades, zooms or slides.
- Its own colours. A style may ask its themes for colour tokens beyond the shared ones, such as raymond's 3D face and edges and its title bar's gradient.
What a style never changes#
These hold under every style, and outrank it:
- The components' structure, props and behaviour. Code written against one style runs under all of them.
- What a coarse pointer adds: a 36px hit area around every control, neighbouring targets that far apart, and 16px text in a field, so a phone does not zoom. How a part is drawn stays the style's under either pointer (Touch & mobile).
- The contrast floors: 4.5:1 for text, 3:1 for an edge a control is found by and for a state cue. Every palette a style ships is held to them (Accessibility).
- A visible focus indicator, and reduced motion (Motion).
Offering styles#
A theme belongs to the styles it lists in styles, or to the default style when it lists none, so
the user picks a style and then one of its themes.
- Offer the styles whose stylesheets you import.
createThemeStore({ styles, defaultStyle })takes them and starts a new user ondefaultStyle; withoutstylesthe store offers the default style alone, and the menu has no Style row. Beside the default style,@orz/uiships raymond, Windows 2000: import@orz/ui/styles/raymond.cssafter@orz/ui/styles.css, and offerraymondStylefrom@orz/themes, whose built-in themes include its own. That import is what turns on every part's raymond look, in every package; an app that leaves it out carries none of raymond's CSS. Imported before@orz/ui/styles.css, only its colours and sizes apply, and no part is drawn in raymond. - Let the user switch. With more than one style,
ThemeMenushows a Style row above the modes, which switches on a click; from code,setStyleon the store or fromuseStyle()switches it. Either way the user lands on the theme they last picked under that style, or on its first theme. - Hold the user to one style by offering that one alone. A terminal theme is not tied to a style: terminal output is content, and its own pick shows under any.
Your own surfaces#
A style draws a part by what it is for. The same rows are a menu, a list box or a folder pane
depending on what picking one does, and a region is a document to read, a toolbar to act on it, or
the window's face around them; each style draws each of those its own way. Say which with
purpose, or with the component made for it, and the style does the rest:
- Places to go are a
NavList, in aNavListFramewhen it is a pane of the app's frame, whose groups' toggles raymond draws as a tree view's +/- boxes, a hierarchy the reader opens and closes aTree, which raymond draws as a tree view, or aTabNavfor a row of sections; see Navigation. - A list is
Listwithpurpose="listbox"when its rows are things to pick,"menu"when they are actions, and"collection"when they are things the user keeps, each row carrying its own actions (access tokens with a Revoke button). Mark a list box's rows withListItem's props, never a fill of your own: the row whose item is open beside the list takescurrent, rows ticked or picked takeselected, and in a list whose focus stays in a field, as a search box's results, the row the keys are on takeshighlighted. A style may draw a picked row that shows a ticked checkbox by the tick alone, and keep its highlight for the open one. A list set in the flow of a surface (a card, a sheet, a pane) rather than filling a column, a pull request's commits say, takesframedinstead of a border of its own. Framed, it is a frame, which never stands on the ground alone: a list there is rows in aCard(Surfaces). - A table's rows are marked by
TableRow's attributes, never a fill of your own: the row whose details are open beside the table takesaria-current="true", and rows picked for an action takedata-state="selected". A style may draw a picked row that shows a ticked checkbox by the tick alone, and keep its highlight for the current one. - A region is
Panewithpurpose="app"for the box an app's panes sit side by side in,"document"for what is read or written (a message, a diff),"toolbar"for the controls that act on it,"statusbar"for the line along the foot that says how it stands (a line count, the first error),"sidebar"for the column of places to go beside the rest, and"panel"for the rest of the window. A window of the app's own that floats over the rest, a docked composer say, is"window", withdockednaming the edge it sits against, and its caption"titlebar". The bar across the top of a site that its pages scroll under is"banner", which keeps the height you give it, since what sticks below it is offset by that height. The pane draws its own look in every style: name the side that meets its neighbour withedgerather than a border of your own. A box that stands on the ground on its own, a module or a comment, is aCard; a box set in a pane's flow rather than filling it, a block or a sample, is aFrame, its heading line and its closing actions onFrameBars (Surfaces). - An editor is
CodeEditororMarkdownEditorwithpurpose="field", the default, when it is one input among others on a form or under a message, and"document"when it is the file or text its pane exists to edit and fills that pane, which draws the edges. - A row of commands is a
ToolbarofToolbarButtons, each named witharia-labelwhen it shows an icon alone, and a mode of the tool picked from two or three there is aSegmentedControl, which a style may draw as toolbar buttons only one of which stays down. A command with its variants beside it is aSplitButton. A tag or filter that is on or off on its own is aToggle, which a style may draw as a toolbar button that stays down. - A group of controls' title on a form or settings screen is a
GroupHeading; a group that wants a frame of its own is aCard. A rule between the group's rows is aSeparatorwithpurpose="row", and one between groups that space does not set apart keeps the default"group". - What stands in an empty list or pane is an
EmptyState: its icon, its title, the line under it and the next step, which a style may set in its window text. - A docs page's own parts are components too. The sections of the page in view are a
NavList variant="rail", a link to another page with a line on what is there aLinkCard, a live sample a block, aContentFrameunder aContentHeaderwhose Source shows its file, a table of sentences aTable purpose="prose", and a key to press aKbd. Set the prose itself in the prose scale (Typography), which a style sizes for itself.
A style redraws these where they stand: it keeps what they hold and in what order, adds nothing you
did not write, and may tighten their spacing. So size a toolbar or a header by the padding around
its controls rather than a fixed height, and a style's denser controls bring the bar in with them.
A Toolbar keeps its order too, but how many of its commands fit at a width follows each style's
sizes, and the rest wait in its ⋯: give it an order and priorities, never a breakpoint
(Toolbars).
A list or pane that scrolls puts its scroller inside, so a style's sunken edge stays drawn around
it.
Build a panel from Card, a toolbar from Toolbar and ToolbarButton, a list from List, its
rows at min-h-row, and round a part of your own with rounded-control or rounded-surface.
Under another style it changes with everything around it.
Write rounded-lg, h-8 or shadow-md on a part of your own, hand-roll a list or a toolbar
from bare markup, or style by [data-style="raymond"] or raymond:. The first two stay as they
are when the style changes; the last breaks under every style you did not write it for.
The numbers the other guideline pages give, a row's height or a button's, are the default style's. Another style draws the same parts at its own sizes, and the pages' rules hold for it all the same.
In the demos
- GalleryPick Raymond in the top bar's theme menu: every tile redraws, its lid, its controls and the viewer inside it, because the gallery draws nothing of its own, only the components.
- SettingsOpen Appearance's Theme menu and pick Raymond in its Style row: the whole demo redraws as Windows 2000 from the same components, and Default brings back the theme last picked under it.