Appearance
Theme
@domphy/theme provides the design tokens and context-aware resolvers used by Domphy.
It is responsible for:
- theme colors through
dataTheme - local tone shifts through
dataTone - local size shifts through
dataSize - local density shifts through
dataDensity - final spacing values through
themeSpacing()
In normal usage, most code only touches four helpers:
themeColor()for colorsthemeSize()for font sizethemeDensity()for the current density factorthemeSpacing()for final spacing values
Basic Usage
ts
import { themeColor, themeDensity, themeSize, themeSpacing } from "@domphy/theme"
const button = {
button: "Save",
style: {
fontSize: (listener) => themeSize(listener, "inherit"),
paddingBlock: (listener) => themeSpacing(themeDensity(listener) * 1),
paddingInline: (listener) => themeSpacing(themeDensity(listener) * 3),
borderRadius: (listener) => themeSpacing(themeDensity(listener) * 1),
backgroundColor: (listener) => themeColor(listener, "inherit", "primary"),
color: (listener) => themeColor(listener, "shift-9", "primary"),
},
}Main mental model:
themeDensity(listener)returns the local density factor fromdataDensitythemeSpacing(n)converts the final numeric result into a CSS spacing valuethemeSize(listener, key)resolves size from the nearestdataSizecontextthemeColor(listener, tone, color?)resolves color from theme and tone context