Breakpoints
BREAKPOINTS: Readonly<Record<string, string>>
getBreakpoints(): Record<string, string>
setBreakpoints(next: Record<string, string>): voidThe named breakpoint set is the single source of truth for every responsive spelling in the framework.
The defaults
import { BREAKPOINTS, getBreakpoints } from '@studiometa/js-toolkit';
getBreakpoints(); // the current set
BREAKPOINTS; // the defaults| Name | Min width |
|---|---|
xxs | 0rem |
xs | 30rem |
s | 48rem |
m | 64rem |
l | 80rem |
xl | 90rem |
xxl | 120rem |
xxxl | 160rem |
These are the names every data-component:<name> and data-option-<x>:<name> suffix is checked against.
Replacing them
import { setBreakpoints } from '@studiometa/js-toolkit';
setBreakpoints({
xs: '0rem',
s: '48rem',
m: '64rem',
l: '80rem',
xl: '96rem',
});setBreakpoints() is the single source of breakpoint truth, and calling it does three things at once:
- rebuilds the scoped attribute names — every
data-component:<name>and everydata-option-<x>:<name>spelling; - replaces that slice of the observer's
attributeFilter, draining the records of the previous filter first; - emits at once on
useBreakpoint(), so a subscriber sees the new active name immediately.
The values are in rem
And in a media query, rem resolves against the initial font size, not against the root element. That is deliberate: a breakpoint that moved when a component changed the root font size would not be a breakpoint.
What uses them
| Feature | How |
|---|---|
| responsive options | data-option-x:<name>, cascading upwards |
| responsive components | data-component:<name>, replacing not merging |
useBreakpoint() | the active name, as a service |
A suffix that names no configured breakpoint gives one responsive.unknown-breakpoint warning and is ignored — including the v3 list syntax :xxs:xs:s.
What it costs
- The
MediaQueryListobjects are built once. - The active name is memoised for the length of one task, through
utils/memo.setBreakpoints()and thechangehandler of a running service clear that memo at once. - A
matchMediasubscription opens only for a component that declaresoption<Name>Changed(); connected elements with a scopeddata-componentshare one reference-counted subscription. A page with plain declarations and read-only options opens none.
The breakpoint service is part of the core graph on every page. What a page pays is the subscriptions it asks for.
The defaults and Tailwind
The current default breakpoints are not aligned with @studiometa/tailwind-config. That alignment is a separate product decision. Call setBreakpoints() to match your own scale.
There is no defineFeatures()
Breakpoints are the one configurable feature, and setBreakpoints() is it. Attribute names and the attribute prefix are not configurable.