Style
Restyle Slant without fighting it: className on parts, tone, variant and size, the variables meant to be set, and overrides around @layer slant.
Demo
Usage
import { Button, Slant, Slider, Tabs } from '@tuttn/slant'
// className and style go on each part's root element, after Slant's own class.
<Button className="checkout-button" variant="primary" size="lg">Pay</Button>
<Tabs defaultValue="files" className="task-tabs">
<Tabs.List label="Task details" className="task-tabs-list">
<Tabs.Tab value="files">Files</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="files" style={{ minHeight: 240 }}><FileList /></Tabs.Panel>
</Tabs>
// Slider is the exception: className and style dress the wrapper, and the
// ref and every other attribute reach the range input.
<Slider className="volume" label="Volume" ref={inputRef} data-testid="volume-input" />
// Meaning, emphasis and height are props, not classes.
<Button tone="danger" variant="ghost" size="sm">Remove</Button>
// Variables go on a root. A nested root restyles only its subtree.
<Slant className="brand" density="compact">
<Settings />
</Slant>Slant is built to be restyled from outside: a class on any part, props for what a component means, variables for what a theme decides, and a cascade layer that lets your rules win. None of it needs a fork or !important.
className and style
Every component that renders an element takes className and style, along with any other attribute, and puts them on its root element. Your class is added after Slant's own (sl-btn, sl-card), so both apply. Compound parts are components too: Tabs.List, Tabs.Tab, Tabs.Panel, Menu.Item and Menu.Group each take their own. Where a component sets an inline style itself, such as Stack's gap or Avatar's size, yours is merged over it.
A few components have more than one element that matters:
- Slider:
classNameandstylego on the wrapper that holds the label, the readout and the track. The ref and every other attribute reach the range input. - Menu: the ref and attributes go on the wrapper. The trigger is
.sl-menu-trigger, and the list renders in a portal at the end of the page as.sl-menu-list, with no class of yours, so select it by its own class. - Table: the ref and attributes go on the scrolling wrapper,
.sl-table; the table inside is.sl-table-inner. - Switch: everything goes on the button. With a
name, a hidden input follows it as a sibling while it is on.
The data-array forms (items, options) build their parts for you, so those parts take no props. Reach them through your class on the root and Slant's class on the part, as in .task-tabs .sl-tab, or use the compound parts instead.
tone, variant and size
Before reaching for a class, check whether a prop says it. tone is what something means: neutral, accent, success, warning or danger. The component writes it as data-tone, and the stylesheet turns that into three variables: --sl-tone for text, marks and fills, --sl-tone-soft for a tinted background, and --sl-tone-text for text on a solid fill. Any element inside a root can carry data-tone, so your own components can share the tones, as the third frame above does.
variant is how loud it is: a primary, secondary or ghost button, a bar or pixel meter. It is written as data-variant. size is sm, md or lg, steps on the control-height scale (28, 34 and 40px at regular density), written as data-size. The root's density moves the whole scale: compact is 26, 32 and 38px, comfortable 32, 40 and 46px. Set data-density on any element inside a root to change one region.
Variables to set
These are the inputs. Set them on a .slant element, the root or a nested <Slant>, for the whole tree or one subtree. The Tokens page lists every value, and the Theme builder writes a whole theme for you.
| Variables | What they are |
|---|---|
--sl-bg, --sl-surface, --sl-surface-2, --sl-line, --sl-line-strong, --sl-text, --sl-muted | The theme's neutrals: backgrounds, hairlines and text. |
--sl-accent, --sl-accent-text, --sl-success, --sl-warning, --sl-danger | The accent, text on a solid fill, and the three states. |
--sl-radius-small, --sl-radius, --sl-radius-large | Corners: controls, then cards, then sheets and dialogs. |
--sl-shadow-sm, --sl-shadow-md, --sl-shadow-lg | Raised controls and cards, then menus, then dialogs. |
--sl-font-sans, --sl-font-mono | The two faces. |
--sl-space-*, --sl-font-size-*, --sl-duration-*, --sl-ease-*, --sl-z-* | The scales, the same in every theme. |
--sl-focus-ring-width, --sl-focus-ring-offset, --sl-disabled-opacity, --sl-radius-full | The focus ring's shape, how far disabled controls fade, and the pill radius. |
--sl-control-sm, --sl-control-md, --sl-control-lg | Control heights. Move them with density on a root, or data-density on any element inside one. |
--sl-slant | The slanted pixel's lean. Other transforms are added to it, so it must stay a transform function: skewX(0deg) stands the pixel upright, none breaks it. |
Variables Slant works out
These are derived from the ones above, so don't set them directly. Change their inputs instead.
| Variables | Where they come from |
|---|---|
--sl-accent-soft, --sl-success-soft, --sl-warning-soft, --sl-danger-soft | A tint of each colour over --sl-surface, mixed on every root. |
--sl-focus-ring | The outline, built from --sl-focus-ring-width and --sl-accent on every root. |
--sl-tone, --sl-tone-soft, --sl-tone-text | The element's tone, set from its data-tone. |
--sl-avatar-size, --sl-code-length, --sl-toast-life, --sl-switch-*, --sl-slider-to, --sl-pop-transform | Set by one component from its props (Avatar's size, CodeInput's length, a toast's lifetime) or for its own layout. |
This is why the variables go on a root. The tints and the focus ring are mixed on each .slant element from the values it has there. Set --sl-accent on a plain div inside a root, and solid fills take the new colour while tints and focus rings keep the old one. Set it on a nested <Slant>, as the first frame above does, and everything follows.
Overrides and @layer slant
The whole stylesheet sits in @layer slant. A rule outside any layer wins over every rule inside one, whatever the specificity, so .checkout-button beats .sl-btn[data-size="lg"] without help. If your own styles live in layers, their order decides: a layer named after slant wins over it, and one named before loses. That is where element resets belong, or a rule such as button { color: inherit } restyles Slant's buttons too. The first rule that names a layer fixes its place, so put the order before Slant's stylesheet loads:
/* First, before Slant's stylesheet: resets under Slant, overrides over it. */
@layer base, slant, overrides;
@layer base {
button { color: inherit; font: inherit; }
}
/* Unlayered: wins over @layer slant, whatever the specificity. */
.brand {
--sl-accent: #6a46b8;
--sl-radius: 18px;
--sl-radius-small: 12px;
--sl-font-sans: "Inter", system-ui, sans-serif;
}
.checkout-button { border-radius: var(--sl-radius-full); }
/* State and variants are attributes, so select on them. */
.sl-btn[data-variant="ghost"]:hover { text-decoration: underline; }
.task-tabs .sl-tab[aria-selected="true"] { font-weight: 600; }Modifiers are data attributes and ARIA states, never extra class names: [data-variant], [data-tone], [data-size], [data-open], [aria-checked="true"]. Select on those for a state, rather than toggling classes of your own alongside Slant's.
Never reach for !important; the layer makes it unnecessary. Slant uses it once, on purpose: under reduced motion it turns its own animations and transitions off with !important, and an important rule in a layer beats an unlayered one, so a host stylesheet can't turn them back on by accident.