Mixins / foldkit-mixins-ui
Recipes
The adapters only name slots. Recipes gives those slots, and the views above, a look:
one Style.recipeFor per contract, built on the tokens of foldkit-mixins/theme. Select
variants (an axis's values are listed in the catalog rows) with .style, and attach the
result like any other Style:
import { Layers, Style } from 'foldkit-mixins'
import { Theme } from 'foldkit-mixins/theme'
import { ButtonSlots, Recipes } from 'foldkit-mixins-ui'
const DeleteStyle = Recipes.Button.style({ tone: 'danger', variant: 'outline', size: 'sm' })
// The same Style in two calls: the selection's pieces, then `Style.forSlots` of them.
// Take the pieces when you compose them with your own first (see Segmented).
const Spelled = Style.forSlots(ButtonSlots)(
Recipes.Button({ tone: 'danger', variant: 'outline', size: 'sm' }),
)
const L = Layers.standard
const theme = Theme.make({ accent: { hue: 280, chroma: 0.15, lightness: 60 } })
export const sheet = Style.stylesheet(
L.declare,
L.in('theme', Theme.root(Theme.standard(theme))),
DeleteStyle,
)DeleteStyle.mixin then goes to Button.toView as in the first example. What a recipe
assumes and does:
- The page ships the tokens. Every value is a
var(--fk-…)reference to the shipped tokens (Theme.standard), so another theme's knobs restyle every recipe with no new CSS. - Bases sit in
components, variants invariantsofLayers.standard, so an application'sapplayer overrides both without specificity fights. Every declaration is a layered rule and none is inline style, since inline style beats every layer and could not be overridden this way:tsconst Red = Style.forSlots(ButtonSlots)( { button: Style.self({ background: 'red' }) }, { layer: L.layer('app') }, ) // Style.stylesheet(L.declare, …, DeleteStyle, Red): Red's background wins..styletakes the same options asStyle.forSlots. An application onAppStylepasses its layer,Recipes.Button.style(selection, { layer: L.layer('app') }): the shipped pieces keep their own layers either way, and a piece its.extendadded with no layer lands inapp, asAppStyle'sforSlotswould place it. - Controls stand on one size ladder. A button, a field, a select, a tab, a segmented
control, a table row and the rows of a menu, listbox or combobox are all one rung tall:
36px by default and 28px compact, their padding, gap and text stepping with them
(
Theme.ladder, read on the element).--fk-knob-step: 1on any element makes everything inside it compact, the popups it opens included when they stay in the page (an anchor'sportal: false, as the gallery's do); a panel upstream portals out of the page (the default of its own anchor) is given the region's custom properties as it leaves, so the region reaches it too, unless the panel sets the property itself. That holds for Menu, Listbox, Combobox and theAnchorMount; a Popover or Tooltip withportal: trueis not supported (draw it in place, asanchor()does). A recipe'ssize(smcompact,mddefault,lga half step up at 40px) sets the step on its own element and beats the region, and a popup's sets it on its panel too, so it holds portaled or not; unset, which is the default, follows the region. An icon, checkbox, radio or switch with no size stands on the ladder's icon rung, 16px or 14px compact. - Text comes in roles.
Theme.role(name)is a size and its leading, stepping with the ladder:display,title,subtitle,body(a control's text, 14px on 20),caption(badges, tooltips, a table's headings) andmicro(keycaps). A tab's and a segmented option's label is trimmed to its capitals (text-box), centering it optically; a pressed segmented option and a chosen card title turn semibold without moving anything (the card writes its title indata-label; give an option its text there,h.DataAttribute('label', 'Week'), and draw its words in thelabelSlot, which holds the trim: on the option itself, the hidden copy took the trim's lower half); and a field's text is 16px on a coarse pointer, so iOS Safari does not zoom the page into it. - A state is a tint, not a surface. An unfilled control's hover is a faint film of the
state ink over whatever is under it, so it reads on a muted page, a colored band or an
inverted panel; a press lays that film stronger (
state.press, 1.75 of the hover's). The ink is the theme's--fk-state-ink(state.ink: the element's own text, or the accent's ink undersurface.hover: 'accent') unless a painted surface above names its paint in the local--_fk-state-ink: the accent and danger tones name their fill, a subtle alert band its ink and a bold one its fill, so a hover on blue is a deeper blue. The neutral and ink tones name the theme's ink back, so a neutral control on a band does not take the band's hue, and onesurface.hoverchoice reaches every component. The neutral button is see-through (state.tint), and images carry a hairline inside their edge (state.edge). A popup's rows round concentrically inside its panel (Theme.nested), as a segmented option does inside its tray. A fluid highlight (Table's, Segmented's, pill Tabs', Nav's, TreeView's, a Card group's) lays that same film, sosurface.hoverandsurface.hoverStrengthmove it with every other hover. - A press gives. Held, every button scales to 98% (the 2% multiplied by
travel, so reduced motion holds its size). A solid or primary button's fill also deepens to its family'sactiveand clears the 1px border of its own color that it stands in, so the fill draws in by 1px a side; an outline, ghost or icon button lays a deeper film of its tone's ink. A pressed toggle (aria-pressed="true") rests on its tone's fill, a solid one on theactivefill; hovered, a solid toggle keeps it and an unfilled one takes its tone's hover fill; held, it deepens to theactivefill; and its text stays the fill's throughout. A hovered row, tab, menu item or accordion row darkens while the press is held, and a fluid highlight darkens with the item it lights (FluidHovermarks the containerdata-fluid-held). Chosen rows next to each other in a multiple listbox or combobox merge into one block. A disabled control fades bystate.disabledOpacity(half by default), so one page shows one fade. - Raised surfaces nest. Popups, popovers, date picker panels and toasts sit two levels
above what holds them and dialogs four (
Theme.raise), each painted for its level, so a popover in a dialog lands above the dialog: a step lighter in a dark scheme, the same flat surface with its own shadow in a light one. - State comes from the component's own attributes. Checked, selected and disabled looks
read
aria-checked,aria-selectedandaria-disabled, which@foldkit/uialready writes; nowhenInputis needed. - Tone and variant are independent. A tone sets a few private custom properties that
solid,outlineandghostread — exceptprimary, which is ink by definition, andicon, a square one rung of the size ladder on a side. A tone also carries the line anoutlinedraws: the fill, or forneutral, whose fill is a quiet grey, the page's default line. A neutral Checkbox or Switch that is on is in the page's ink, not the neutral grey, so it stands out without a color. - On a colored band, unfilled buttons take the band's color.
outlineandghostdraw their text in the tone's ink, which reads on the page's surface and not on a band of the accent. A band setsStyle.vars({ '--fk-ink': 'currentColor' }), beside--fk-headingfor its headings, and their text is the band's.
Adjust a recipe with extend instead of forking it. Base pieces compose per slot, a
variant's pieces compose over the shipped ones, and compounds append:
const BrandButton = Recipes.Button.extend({
base: { button: Style.class('brand-button') },
variants: { size: { lg: { button: Style.class('brand-button-lg') } } },
})Recipes.Badge is a recipe of two axes, appearance and size. The tone is not an axis: the view
writes it as data-tone, so one style serves badges of every tone, and the six names of the tone
vocabulary are in the recipe. A badge toned by an attribute the application already writes maps its
values with Recipes.badgeTones through extend; a value the map leaves out keeps the base pill.
Recipes.Badge.add gives it a size or an appearance of your own. A toned pill is grounded on its
tone's subtle, which keeps the tone's hue over a tinted page:
const EntrySlots = Slots.define({ badge: Slot.make({ capability: Capability.Container }) })
const EntryStyle = Style.forSlots(EntrySlots)({
badge: Recipes.Badge.extend({
base: {
badge: Recipes.badgeTones('data-state', { Published: 'success', Changed: 'warning' }),
},
})().badge,
})Badge.view({ text, icon, onDismiss }) draws an icon before the text and a dismiss button named by
words.dismiss ('Dismiss {text}'); { text, href, external } draws the pill as a link. A link
holds no dismiss button, and the types refuse both.
Recipes.InputGroup draws a text field with a prefix or suffix, such as an address's /, as one
box: group carries the border, its hover and the focus ring (while the control inside has
focus), affix sits inside it, muted, and control makes the input inside borderless. They are
pieces for your own group, affix and control slots, as foldkit-mixins-form's field publishes
them. control is in variants, so it wins over a components look on the same slot; over a
look of your own in a later layer, say the same in that layer:
const FieldSlots = Slots.define({
group: Slot.make({ capability: Capability.Container }),
affix: Slot.make({ capability: Capability.Container }),
text: Slot.make({ capability: Capability.Container }),
})
const AddressStyle = Style.forSlots(FieldSlots)({
group: Recipes.InputGroup.group,
affix: Recipes.InputGroup.affix,
text: Style.compose(Recipes.Input({}).input, Recipes.InputGroup.control),
})Recipes.Calendar styles CalendarSlots in every mode: days in seven columns, months and years
in three, each button reading its state off the cell (data-today, data-selected,
data-focused, data-outside-month, data-disabled). Each cell is a rung of the size ladder,
so size (sm, md) or the region steps it. It draws no card, so the same style serves a
calendar on the page and one in a date picker's panel. Recipes.Tabs({ variant: 'pill' })'s
chosen tab is a raised surface with a hairline edge and shadow on the tray, in the default text
colour. To preview every recipe across variants, states, and light/dark schemes at once, browse the component gallery.