@openbrf/tokens
v1.1.0
Published
The Open BRF design token contract, its default theme and the stylesheet built from it.
Maintainers
Readme
@openbrf/tokens
The design token contract of Open BRF: every token a theme can set, the default theme, Porttavlan, and the functions that resolve a token set and build the stylesheet from it.
The contract is versioned with semver, independently of the application.
Installing
npm install @openbrf/tokensA theme is data, not code, so a theme author usually reaches this package
through @openbrf/theme-tools,
which depends on it. A plugin's view styles itself with the CSS custom
properties the contract names, which the instance already serves.
What it exports
TOKENS,TOKEN_NAMESandREQUIRED_TOKEN_NAMES: the contract, one definition per token, andcssVariableNamefor the custom property each one becomes.PORTTAVLAN_LIGHTandPORTTAVLAN_DARK: the default theme's two token sets.resolveTokens(theme, inheritFrom): merges a partial token set over the one it inherits from and reports what was derived and what is still missing.buildThemeStylesheet({ light, dark }): the stylesheet an instance serves, with light on:root, dark for a system that asks for it, and an explicit choice winning in both directions.checkContrast,contrastRatioandCONTRAST_PAIRS: the WCAG contrast checks the theme lint applies, text atAA_CONTRAST_RATIO(4.5:1) and control borders atNON_TEXT_CONTRAST_RATIO(3:1).
import {
buildThemeStylesheet,
PORTTAVLAN_DARK,
PORTTAVLAN_LIGHT,
} from "@openbrf/tokens";
const css = buildThemeStylesheet({
light: PORTTAVLAN_LIGHT,
dark: PORTTAVLAN_DARK,
});Documentation
- The token contract: every token, the accessibility rules and what is themeable.
Licence
AGPL-3.0-only, with the Open BRF Module Exception. A theme or plugin view written against the token contract is a module under that exception and may be licensed on any terms. Both texts are in the package.
