Design Tokens Presets
Overview
The useDesignTokensPreset composable creates a complete design token system with sensible defaults in a single function call. It's perfect for quickly bootstrapping a new project or as a starting point that you can customize.
Why use presets?
- Quick Start: Get a complete design system up and running in seconds
- Sensible Defaults: Carefully chosen values that work well together
- Fully Customizable: Override any domain or individual value
- Comprehensive Coverage: Includes spacing, colors, typography, borders, shadows, and more
Quick Start
import { styleframe } from 'styleframe';
import { useDesignTokensPreset } from '@styleframe/theme';
const s = styleframe();
// Create a complete design token system with all defaults
const preset = useDesignTokensPreset(s);
// Destructure the variables you need
const { colorPrimary, colorSecondary } = preset.colors;
const { spacingMd, spacingLg } = preset.spacing;
export default s;
:root {
/* Spacing */
--spacing: 1rem;
--spacing--2xs: 0.25rem;
--spacing--xs: 0.5rem;
--spacing--sm: 0.75rem;
--spacing--md: 1rem;
--spacing--lg: 1.5rem;
--spacing--xl: 2rem;
--spacing--2xl: 3rem;
--spacing--3xl: 4rem;
/* Colors (base + variations) */
--color--primary: oklch(0.62 0.21 255);
--color--primary-50: oklch(from var(--color--primary) 0.05 c h / a);
--color--primary-100: oklch(from var(--color--primary) 0.1 c h / a);
/* ... more color variations */
/* Typography */
--font-family--base: -apple-system, BlinkMacSystemFont, ...;
--font-size: 1rem;
--font-size--xs: 0.75rem;
/* ... more typography tokens */
/* And many more... */
}
useDesignTokensPreset
Creates a complete design token system with customizable defaults.
Signature
function useDesignTokensPreset(
s: Styleframe,
config?: DesignTokensPresetConfig
): DesignTokensPresetResult
Configuration Options
Each domain can be configured as:
- Omitted/
undefined(default): Use the preset's default values false: Skip this domain entirelyRecord<string, TokenValue>: Use custom values
| Option | Type | Description |
|---|---|---|
spacing | false | Record<string, TokenValue> | Spacing tokens (padding, margin, gap) |
borderWidth | false | Record<string, TokenValue> | Border width tokens |
borderRadius | false | Record<string, TokenValue> | Border radius tokens |
borderStyle | false | Record<string, TokenValue> | Border style tokens |
boxShadow | false | Record<string, TokenValue> | Box shadow elevation tokens |
colors | false | Record<string, string> | Semantic color tokens |
meta.colors | ColorsMetaConfig | Color generation options |
fontFamily | false | Record<string, TokenValue> | Font family tokens |
fontSize | false | Record<string, TokenValue> | Font size tokens |
fontStyle | false | Record<string, TokenValue> | Font style tokens |
fontWeight | false | Record<string, TokenValue> | Font weight tokens |
lineHeight | false | Record<string, TokenValue> | Line height tokens |
letterSpacing | false | Record<string, TokenValue> | Letter spacing tokens |
scale | false | Record<string, TokenValue> | Modular scale ratios (must include default key referencing scale for scalePowers) |
scalePowers | readonly number[] | Scale power levels |
breakpoint | false | Record<string, number> | Responsive breakpoints |
easing | false | Record<string, TokenValue> | Animation easing functions |
themes | Record<string, ThemeTokenOverrides> | Per-theme token overrides (see Themes) |
Default Values
Border Radius
const preset = useDesignTokensPreset(s);
const {
borderRadius, // Variable<'border-radius'>
borderRadiusNone, // Variable<'border-radius.none'>
borderRadiusSm, // Variable<'border-radius.sm'>
borderRadiusMd, // Variable<'border-radius.md'>
borderRadiusLg, // Variable<'border-radius.lg'>
borderRadiusXl, // Variable<'border-radius.xl'>
borderRadius2xl, // Variable<'border-radius.2xl'>
borderRadiusFull, // Variable<'border-radius.full'>
} = preset.borderRadius;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @md | borderRadius | --border-radius |
none | 0 | borderRadiusNone | --border-radius--none |
sm | 0.125rem | borderRadiusSm | --border-radius--sm |
md | 0.25rem | borderRadiusMd | --border-radius--md |
lg | 0.5rem | borderRadiusLg | --border-radius--lg |
xl | 0.75rem | borderRadiusXl | --border-radius--xl |
2xl | 1rem | borderRadius2xl | --border-radius--2xl |
full | 9999px | borderRadiusFull | --border-radius--full |
Border Style
const preset = useDesignTokensPreset(s);
const {
borderStyle, // Variable<'border-style'>
borderStyleNone, // Variable<'border-style.none'>
borderStyleSolid, // Variable<'border-style.solid'>
borderStyleDashed, // Variable<'border-style.dashed'>
borderStyleDotted, // Variable<'border-style.dotted'>
borderStyleDouble, // Variable<'border-style.double'>
borderStyleGroove, // Variable<'border-style.groove'>
borderStyleInset, // Variable<'border-style.inset'>
borderStyleOutset, // Variable<'border-style.outset'>
} = preset.borderStyle;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @solid | borderStyle | --border-style |
none | none | borderStyleNone | --border-style--none |
solid | solid | borderStyleSolid | --border-style--solid |
dashed | dashed | borderStyleDashed | --border-style--dashed |
dotted | dotted | borderStyleDotted | --border-style--dotted |
double | double | borderStyleDouble | --border-style--double |
groove | groove | borderStyleGroove | --border-style--groove |
inset | inset | borderStyleInset | --border-style--inset |
outset | outset | borderStyleOutset | --border-style--outset |
Border Width
const preset = useDesignTokensPreset(s);
const {
borderWidth, // Variable<'border-width'>
borderWidthNone, // Variable<'border-width.none'>
borderWidthThin, // Variable<'border-width.thin'>
borderWidthMedium, // Variable<'border-width.medium'>
borderWidthThick, // Variable<'border-width.thick'>
} = preset.borderWidth;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @thin | borderWidth | --border-width |
none | 0 | borderWidthNone | --border-width--none |
thin | thin | borderWidthThin | --border-width--thin |
medium | medium | borderWidthMedium | --border-width--medium |
thick | thick | borderWidthThick | --border-width--thick |
Box Shadow
const preset = useDesignTokensPreset(s);
const {
boxShadow, // Variable<'box-shadow'>
boxShadowNone, // Variable<'box-shadow.none'>
boxShadowXs, // Variable<'box-shadow.xs'>
boxShadowSm, // Variable<'box-shadow.sm'>
boxShadowMd, // Variable<'box-shadow.md'>
boxShadowLg, // Variable<'box-shadow.lg'>
boxShadowXl, // Variable<'box-shadow.xl'>
boxShadow2xl, // Variable<'box-shadow.2xl'>
boxShadowInner, // Variable<'box-shadow.inner'>
boxShadowRing, // Variable<'box-shadow.ring'>
} = preset.boxShadow;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @md | boxShadow | --box-shadow |
none | none | boxShadowNone | --box-shadow--none |
xs | Subtle card/surfaces shadow | boxShadowXs | --box-shadow--xs |
sm | Small elevation shadow | boxShadowSm | --box-shadow--sm |
md | Popover/raised button shadow | boxShadowMd | --box-shadow--md |
lg | Modal/floating panel shadow | boxShadowLg | --box-shadow--lg |
xl | Drawer/high elevation shadow | boxShadowXl | --box-shadow--xl |
2xl | Highest elevation/toast shadow | boxShadow2xl | --box-shadow--2xl |
inner | Inset shadow for wells | boxShadowInner | --box-shadow--inner |
ring | Focus ring shadow | boxShadowRing | --box-shadow--ring |
Breakpoint
const preset = useDesignTokensPreset(s);
const {
breakpointXs, // Variable<'breakpoint.xs'>
breakpointSm, // Variable<'breakpoint.sm'>
breakpointMd, // Variable<'breakpoint.md'>
breakpointLg, // Variable<'breakpoint.lg'>
breakpointXl, // Variable<'breakpoint.xl'>
} = preset.breakpoint;
| Key | Value (px) | Variable | Output |
|---|---|---|---|
xs | 0 | breakpointXs | --breakpoint--xs |
sm | 576 | breakpointSm | --breakpoint--sm |
md | 992 | breakpointMd | --breakpoint--md |
lg | 1200 | breakpointLg | --breakpoint--lg |
xl | 1440 | breakpointXl | --breakpoint--xl |
Colors
const preset = useDesignTokensPreset(s);
const {
colorPrimary, // Variable<'color.primary'>
colorSecondary, // Variable<'color.secondary'>
colorSuccess, // Variable<'color.success'>
colorWarning, // Variable<'color.warning'>
colorDanger, // Variable<'color.danger'>
colorInfo, // Variable<'color.info'>
colorLight, // Variable<'color.light'>
colorDark, // Variable<'color.dark'>
} = preset.colors;
| Key | Value | Variable | Output |
|---|---|---|---|
primary | #3b82f6 | colorPrimary | --color--primary |
secondary | #6b7280 | colorSecondary | --color--secondary |
success | #22c55e | colorSuccess | --color--success |
warning | #f59e0b | colorWarning | --color--warning |
danger | #ef4444 | colorDanger | --color--danger |
info | #06b6d4 | colorInfo | --color--info |
light | #f8fafc | colorLight | --color--light |
dark | #1e293b | colorDark | --color--dark |
By default, each color also generates:
- Lightness levels: 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950
- Shades (darker): shade-50, shade-100, shade-150, shade-200
- Tints (lighter): tint-50, tint-100, tint-150, tint-200
Color Generation Options
The meta.colors option controls how color variations are generated:
| Option | Type | Default | Description |
|---|---|---|---|
generateLightness | boolean | true | Generate lightness levels (50-950) |
generateShades | boolean | true | Generate darker shades |
generateTints | boolean | true | Generate lighter tints |
lightnessLevels | Record<string | number, number> | { 50: 5, 100: 10, ... } | Custom lightness levels |
shadeLevels | Record<string | number, number> | { "shade-50": 5, "shade-100": 10, ... } | Custom shade levels |
tintLevels | Record<string | number, number> | { "tint-50": 5, "tint-100": 10, ... } | Custom tint levels |
Easing
const preset = useDesignTokensPreset(s);
const {
easingLinear, // Variable<'easing.linear'>
easingEase, // Variable<'easing.ease'>
easingEaseIn, // Variable<'easing.ease-in'>
easingEaseOut, // Variable<'easing.ease-out'>
easingEaseInOut, // Variable<'easing.ease-in-out'>
easingEaseInSine, // Variable<'easing.ease-in-sine'>
easingEaseOutCubic, // Variable<'easing.ease-out-cubic'>
easingSpring, // Variable<'easing.spring'>
easingBounce, // Variable<'easing.bounce'>
} = preset.easing;
Basic CSS Keywords:
| Key | Value | Variable | Output |
|---|---|---|---|
linear | linear | easingLinear | --easing--linear |
ease | ease | easingEase | --easing--ease |
ease-in | ease-in | easingEaseIn | --easing--ease-in |
ease-out | ease-out | easingEaseOut | --easing--ease-out |
ease-in-out | ease-in-out | easingEaseInOut | --easing--ease-in-out |
Sine:
| Key | Value | Variable | Output |
|---|---|---|---|
ease-in-sine | cubic-bezier(0.47, 0, 0.745, 0.715) | easingEaseInSine | --easing--ease-in-sine |
ease-out-sine | cubic-bezier(0.39, 0.575, 0.565, 1) | easingEaseOutSine | --easing--ease-out-sine |
ease-in-out-sine | cubic-bezier(0.445, 0.05, 0.55, 0.95) | easingEaseInOutSine | --easing--ease-in-out-sine |
Quad:
| Key | Value | Variable | Output |
|---|---|---|---|
ease-in-quad | cubic-bezier(0.55, 0.085, 0.68, 0.53) | easingEaseInQuad | --easing--ease-in-quad |
ease-out-quad | cubic-bezier(0.25, 0.46, 0.45, 0.94) | easingEaseOutQuad | --easing--ease-out-quad |
ease-in-out-quad | cubic-bezier(0.455, 0.03, 0.515, 0.955) | easingEaseInOutQuad | --easing--ease-in-out-quad |
Cubic:
| Key | Value | Variable | Output |
|---|---|---|---|
ease-in-cubic | cubic-bezier(0.55, 0.055, 0.675, 0.19) | easingEaseInCubic | --easing--ease-in-cubic |
ease-out-cubic | cubic-bezier(0.215, 0.61, 0.355, 1) | easingEaseOutCubic | --easing--ease-out-cubic |
ease-in-out-cubic | cubic-bezier(0.645, 0.045, 0.355, 1) | easingEaseInOutCubic | --easing--ease-in-out-cubic |
Quart:
| Key | Value | Variable | Output |
|---|---|---|---|
ease-in-quart | cubic-bezier(0.895, 0.03, 0.685, 0.22) | easingEaseInQuart | --easing--ease-in-quart |
ease-out-quart | cubic-bezier(0.165, 0.84, 0.44, 1) | easingEaseOutQuart | --easing--ease-out-quart |
ease-in-out-quart | cubic-bezier(0.77, 0, 0.175, 1) | easingEaseInOutQuart | --easing--ease-in-out-quart |
Quint:
| Key | Value | Variable | Output |
|---|---|---|---|
ease-in-quint | cubic-bezier(0.755, 0.05, 0.855, 0.06) | easingEaseInQuint | --easing--ease-in-quint |
ease-out-quint | cubic-bezier(0.23, 1, 0.32, 1) | easingEaseOutQuint | --easing--ease-out-quint |
ease-in-out-quint | cubic-bezier(0.86, 0, 0.07, 1) | easingEaseInOutQuint | --easing--ease-in-out-quint |
Expo:
| Key | Value | Variable | Output |
|---|---|---|---|
ease-in-expo | cubic-bezier(0.95, 0.05, 0.795, 0.035) | easingEaseInExpo | --easing--ease-in-expo |
ease-out-expo | cubic-bezier(0.19, 1, 0.22, 1) | easingEaseOutExpo | --easing--ease-out-expo |
ease-in-out-expo | cubic-bezier(1, 0, 0, 1) | easingEaseInOutExpo | --easing--ease-in-out-expo |
Circ:
| Key | Value | Variable | Output |
|---|---|---|---|
ease-in-circ | cubic-bezier(0.6, 0.04, 0.98, 0.335) | easingEaseInCirc | --easing--ease-in-circ |
ease-out-circ | cubic-bezier(0.075, 0.82, 0.165, 1) | easingEaseOutCirc | --easing--ease-out-circ |
ease-in-out-circ | cubic-bezier(0.785, 0.135, 0.15, 0.86) | easingEaseInOutCirc | --easing--ease-in-out-circ |
Back (with overshoot):
| Key | Value | Variable | Output |
|---|---|---|---|
ease-in-back | cubic-bezier(0.6, -0.28, 0.735, 0.045) | easingEaseInBack | --easing--ease-in-back |
ease-out-back | cubic-bezier(0.175, 0.885, 0.32, 1.275) | easingEaseOutBack | --easing--ease-out-back |
ease-in-out-back | cubic-bezier(0.68, -0.55, 0.265, 1.55) | easingEaseInOutBack | --easing--ease-in-out-back |
Special (linear() functions):
| Key | Description | Variable | Output |
|---|---|---|---|
spring | Natural spring animation | easingSpring | --easing--spring |
bounce | Bouncy animation effect | easingBounce | --easing--bounce |
Font Family
const preset = useDesignTokensPreset(s);
const {
fontFamily, // Variable<'font-family'>
fontFamilyBase, // Variable<'font-family.base'>
fontFamilyPrint, // Variable<'font-family.print'>
fontFamilyMono, // Variable<'font-family.mono'>
} = preset.fontFamily;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @base | fontFamily | --font-family |
base | System font stack (sans-serif) | fontFamilyBase | --font-family--base |
print | Georgia, Times New Roman (serif) | fontFamilyPrint | --font-family--print |
mono | SFMono-Regular, Menlo (monospace) | fontFamilyMono | --font-family--mono |
Font Size
const preset = useDesignTokensPreset(s);
const {
fontSize, // Variable<'font-size'>
fontSizeXs, // Variable<'font-size.xs'>
fontSizeSm, // Variable<'font-size.sm'>
fontSizeMd, // Variable<'font-size.md'>
fontSizeLg, // Variable<'font-size.lg'>
fontSizeXl, // Variable<'font-size.xl'>
fontSize2xl, // Variable<'font-size.2xl'>
fontSize3xl, // Variable<'font-size.3xl'>
fontSize4xl, // Variable<'font-size.4xl'>
} = preset.fontSize;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @md | fontSize | --font-size |
xs | 0.75rem | fontSizeXs | --font-size--xs |
sm | 0.875rem | fontSizeSm | --font-size--sm |
md | 1rem | fontSizeMd | --font-size--md |
lg | 1.125rem | fontSizeLg | --font-size--lg |
xl | 1.25rem | fontSizeXl | --font-size--xl |
2xl | 1.5rem | fontSize2xl | --font-size--2xl |
3xl | 1.875rem | fontSize3xl | --font-size--3xl |
4xl | 2.25rem | fontSize4xl | --font-size--4xl |
Font Style
const preset = useDesignTokensPreset(s);
const {
fontStyle, // Variable<'font-style'>
fontStyleItalic, // Variable<'font-style.italic'>
fontStyleOblique, // Variable<'font-style.oblique'>
fontStyleNormal, // Variable<'font-style.normal'>
fontStyleInherit, // Variable<'font-style.inherit'>
} = preset.fontStyle;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @normal | fontStyle | --font-style |
italic | italic | fontStyleItalic | --font-style--italic |
oblique | oblique | fontStyleOblique | --font-style--oblique |
normal | normal | fontStyleNormal | --font-style--normal |
inherit | inherit | fontStyleInherit | --font-style--inherit |
Font Weight
const preset = useDesignTokensPreset(s);
const {
fontWeight, // Variable<'font-weight'>
fontWeightExtralight, // Variable<'font-weight.extralight'>
fontWeightLight, // Variable<'font-weight.light'>
fontWeightNormal, // Variable<'font-weight.normal'>
fontWeightMedium, // Variable<'font-weight.medium'>
fontWeightSemibold, // Variable<'font-weight.semibold'>
fontWeightBold, // Variable<'font-weight.bold'>
fontWeightBlack, // Variable<'font-weight.black'>
fontWeightLighter, // Variable<'font-weight.lighter'>
fontWeightBolder, // Variable<'font-weight.bolder'>
fontWeightInherit, // Variable<'font-weight.inherit'>
} = preset.fontWeight;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @normal | fontWeight | --font-weight |
extralight | 200 | fontWeightExtralight | --font-weight--extralight |
light | 300 | fontWeightLight | --font-weight--light |
normal | normal | fontWeightNormal | --font-weight--normal |
medium | 500 | fontWeightMedium | --font-weight--medium |
semibold | 600 | fontWeightSemibold | --font-weight--semibold |
bold | bold | fontWeightBold | --font-weight--bold |
black | 900 | fontWeightBlack | --font-weight--black |
lighter | lighter | fontWeightLighter | --font-weight--lighter |
bolder | bolder | fontWeightBolder | --font-weight--bolder |
inherit | inherit | fontWeightInherit | --font-weight--inherit |
Letter Spacing
const preset = useDesignTokensPreset(s);
const {
letterSpacing, // Variable<'letter-spacing'>
letterSpacingTighter, // Variable<'letter-spacing.tighter'>
letterSpacingTight, // Variable<'letter-spacing.tight'>
letterSpacingNormal, // Variable<'letter-spacing.normal'>
letterSpacingWide, // Variable<'letter-spacing.wide'>
letterSpacingWider, // Variable<'letter-spacing.wider'>
} = preset.letterSpacing;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @normal | letterSpacing | --letter-spacing |
tighter | -0.05em | letterSpacingTighter | --letter-spacing--tighter |
tight | -0.025em | letterSpacingTight | --letter-spacing--tight |
normal | normal | letterSpacingNormal | --letter-spacing--normal |
wide | 0.05em | letterSpacingWide | --letter-spacing--wide |
wider | 0.1em | letterSpacingWider | --letter-spacing--wider |
Line Height
const preset = useDesignTokensPreset(s);
const {
lineHeight, // Variable<'line-height'>
lineHeightTight, // Variable<'line-height.tight'>
lineHeightSnug, // Variable<'line-height.snug'>
lineHeightNormal, // Variable<'line-height.normal'>
lineHeightRelaxed, // Variable<'line-height.relaxed'>
lineHeightLoose, // Variable<'line-height.loose'>
} = preset.lineHeight;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @normal | lineHeight | --line-height |
tight | 1.2 | lineHeightTight | --line-height--tight |
snug | 1.35 | lineHeightSnug | --line-height--snug |
normal | 1.5 | lineHeightNormal | --line-height--normal |
relaxed | 1.65 | lineHeightRelaxed | --line-height--relaxed |
loose | 1.9 | lineHeightLoose | --line-height--loose |
Scale
const preset = useDesignTokensPreset(s);
const {
scale, // Variable<'scale'>
scaleMinorSecond, // Variable<'scale.minor-second'>
scaleMajorSecond, // Variable<'scale.major-second'>
scaleMinorThird, // Variable<'scale.minor-third'>
scaleMajorThird, // Variable<'scale.major-third'>
scalePerfectFourth, // Variable<'scale.perfect-fourth'>
scaleAugmentedFourth, // Variable<'scale.augmented-fourth'>
scalePerfectFifth, // Variable<'scale.perfect-fifth'>
scaleGolden, // Variable<'scale.golden'>
} = preset.scale;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @minor-third | scale | --scale |
minor-second | 1.067 | scaleMinorSecond | --scale--minor-second |
major-second | 1.125 | scaleMajorSecond | --scale--major-second |
minor-third | 1.2 | scaleMinorThird | --scale--minor-third |
major-third | 1.25 | scaleMajorThird | --scale--major-third |
perfect-fourth | 1.333 | scalePerfectFourth | --scale--perfect-fourth |
augmented-fourth | 1.414 | scaleAugmentedFourth | --scale--augmented-fourth |
perfect-fifth | 1.5 | scalePerfectFifth | --scale--perfect-fifth |
golden | 1.618 | scaleGolden | --scale--golden |
Scale Powers
The preset generates scale power values using the default scale variable. These are computed values based on the scale ratio.
const preset = useDesignTokensPreset(s);
// Access computed scale powers
const scalePowers = preset.scalePowers;
// Returns: { -2: CSS, -1: CSS, 0: CSS, 1: CSS, 2: CSS, 3: CSS, 4: CSS, 5: CSS }
| Power | Formula | Output |
|---|---|---|
-2 | 1 / scale / scale | --scale-power---2 |
-1 | 1 / scale | --scale-power---1 |
0 | 1 | --scale-power--0 |
1 | scale | --scale-power--1 |
2 | scale * scale | --scale-power--2 |
3 | scale * scale * scale | --scale-power--3 |
4 | scale * scale * scale * scale | --scale-power--4 |
5 | scale * scale * scale * scale * scale | --scale-power--5 |
Spacing
const preset = useDesignTokensPreset(s);
const {
spacing, // Variable<'spacing'>
spacing2xs, // Variable<'spacing.2xs'>
spacingXs, // Variable<'spacing.xs'>
spacingSm, // Variable<'spacing.sm'>
spacingMd, // Variable<'spacing.md'>
spacingLg, // Variable<'spacing.lg'>
spacingXl, // Variable<'spacing.xl'>
spacing2xl, // Variable<'spacing.2xl'>
spacing3xl, // Variable<'spacing.3xl'>
} = preset.spacing;
| Key | Value | Variable | Output |
|---|---|---|---|
default | @md | spacing | --spacing |
2xs | 0.25rem | spacing2xs | --spacing--2xs |
xs | 0.5rem | spacingXs | --spacing--xs |
sm | 0.75rem | spacingSm | --spacing--sm |
md | 1rem | spacingMd | --spacing--md |
lg | 1.5rem | spacingLg | --spacing--lg |
xl | 2rem | spacingXl | --spacing--xl |
2xl | 3rem | spacing2xl | --spacing--2xl |
3xl | 4rem | spacing3xl | --spacing--3xl |
Examples
Full Customization
import { styleframe } from 'styleframe';
import { useDesignTokensPreset } from '@styleframe/theme';
const s = styleframe();
const preset = useDesignTokensPreset(s, {
// Spacing
spacing: {
default: '@md',
xs: '0.25rem',
sm: '0.5rem',
md: '1rem',
lg: '2rem',
xl: '4rem',
},
// Border
borderWidth: {
default: '@thin',
none: '0',
thin: '1px',
medium: '2px',
thick: '4px',
},
borderRadius: {
default: '@md',
none: '0',
sm: '0.125rem',
md: '0.25rem',
lg: '0.5rem',
full: '9999px',
},
borderStyle: {
default: '@solid',
none: 'none',
solid: 'solid',
dashed: 'dashed',
dotted: 'dotted',
},
// Shadows
boxShadow: {
default: '@md',
none: 'none',
sm: '0 1px 2px 0 rgb(0 0 0 / 0.05)',
md: '0 4px 6px -1px rgb(0 0 0 / 0.1)',
lg: '0 10px 15px -3px rgb(0 0 0 / 0.1)',
},
// Colors
colors: {
primary: '#0066cc',
secondary: '#6c757d',
success: '#28a745',
warning: '#ffc107',
danger: '#dc3545',
info: '#17a2b8',
light: '#f8f9fa',
dark: '#343a40',
},
meta: {
colors: {
generateLightness: true,
generateShades: true,
generateTints: true,
},
},
// Typography
fontFamily: {
default: '@base',
base: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
mono: 'SFMono-Regular, Menlo, Monaco, monospace',
},
fontSize: {
default: '@md',
xs: '0.75rem',
sm: '0.875rem',
md: '1rem',
lg: '1.25rem',
xl: '1.5rem',
'2xl': '2rem',
},
fontWeight: {
default: '@normal',
light: '300',
normal: '400',
medium: '500',
semibold: '600',
bold: '700',
},
lineHeight: {
default: '@normal',
tight: '1.25',
normal: '1.5',
relaxed: '1.75',
},
letterSpacing: {
default: '@normal',
tight: '-0.025em',
normal: '0',
wide: '0.025em',
},
// Scale
scale: {
default: '@minor-third',
'minor-second': '1.067',
'major-second': '1.125',
'minor-third': '1.2',
'major-third': '1.25',
'perfect-fourth': '1.333',
},
// Breakpoints
breakpoint: {
xs: 0,
sm: 576,
md: 768,
lg: 992,
xl: 1200,
},
// Animations
easing: {
linear: 'linear',
ease: 'ease',
'ease-in': 'ease-in',
'ease-out': 'ease-out',
'ease-in-out': 'ease-in-out',
},
});
export default s;
Disabling Specific Domains
import { styleframe } from 'styleframe';
import { useDesignTokensPreset } from '@styleframe/theme';
const s = styleframe();
// Only include colors, spacing, and typography
const preset = useDesignTokensPreset(s, {
borderWidth: false,
borderRadius: false,
borderStyle: false,
boxShadow: false,
scale: false,
breakpoint: false,
easing: false,
});
const { colorPrimary } = preset.colors;
const { spacingMd } = preset.spacing;
export default s;
Accessing Generated Variables
import { styleframe } from 'styleframe';
import { useDesignTokensPreset } from '@styleframe/theme';
const s = styleframe();
const { ref, selector } = s;
const preset = useDesignTokensPreset(s);
// Destructure the variables you need from each domain
const { spacingMd } = preset.spacing;
const { colorPrimary, colorPrimary600 } = preset.colors;
const { borderRadiusMd } = preset.borderRadius;
const { fontWeightSemibold } = preset.fontWeight;
const { boxShadowSm } = preset.boxShadow;
// Use the generated variables in your styles
selector('.button', {
padding: ref(spacingMd),
backgroundColor: ref(colorPrimary),
borderRadius: ref(borderRadiusMd),
fontWeight: ref(fontWeightSemibold),
boxShadow: ref(boxShadowSm),
});
selector('.button:hover', {
backgroundColor: ref(colorPrimary600),
});
export default s;
Importing Default Values
You can import the default value objects directly if you need to reference them or build upon them:
import { styleframe } from 'styleframe';
import {
useDesignTokensPreset,
// Import default values
defaultSpacingValues,
defaultColorValues,
defaultBorderRadiusValues,
} from '@styleframe/theme';
const s = styleframe();
// Use defaults with customizations
const preset = useDesignTokensPreset(s, {
meta: { merge: true },
spacing: {
...defaultSpacingValues,
'4xl': '6rem', // Add a new size
},
});
export default s;
Available Default Value Exports
| Export | Description |
|---|---|
defaultSpacingValues | Spacing scale values |
defaultBorderWidthValues | Border width values |
defaultBorderRadiusValues | Border radius values |
defaultBorderStyleValues | Border style values |
defaultBoxShadowValues | Box shadow elevation values |
defaultColorValues | Semantic color values |
defaultColorLightnessValues | Lightness level values |
defaultColorShadeValues | Shade level values |
defaultColorTintValues | Tint level values |
defaultFontFamilyValues | Font family values |
defaultFontSizeValues | Font size scale values |
defaultFontStyleValues | Font style values |
defaultFontWeightValues | Font weight values |
defaultLineHeightValues | Line height values |
defaultLetterSpacingValues | Letter spacing values |
defaultScaleValues | Modular scale ratio values |
defaultScalePowerValues | Scale power levels |
defaultBreakpointValues | Responsive breakpoint values |
defaultEasingValues | Animation easing function values |
defaultColorsMetaConfig | Default color generation configuration |
Themes
The themes option lets you define per-theme token overrides directly in the preset. Each theme generates a [data-theme="name"] block that overrides the root-level tokens.
Dark Mode
import { styleframe } from 'styleframe';
import { useDesignTokensPreset } from '@styleframe/theme';
const s = styleframe();
const preset = useDesignTokensPreset(s, {
colors: {
primary: '#007bff',
secondary: '#6c757d',
},
themes: {
dark: {
colors: {
primary: '#60a5fa',
secondary: '#cbd5e1',
},
},
},
});
export default s;
:root {
--color--primary: #007bff;
--color--secondary: #6c757d;
/* ... other tokens */
}
[data-theme="dark"] {
--color--primary: #60a5fa;
--color--secondary: #cbd5e1;
}
Multiple Themes
You can define multiple themes at once. Each theme can override any domain (colors, spacing, typography, etc.):
const preset = useDesignTokensPreset(s, {
colors: { primary: '#007bff' },
spacing: { default: '@md', sm: '0.5rem', md: '1rem', lg: '2rem' },
themes: {
dark: {
colors: { primary: '#60a5fa' },
},
compact: {
spacing: { default: '0.75rem', sm: '0.25rem', lg: '1.5rem' },
},
high_contrast: {
colors: { primary: '#0000ff' },
},
},
});
Default Theme
The special themes.default key does not create a [data-theme="default"] block. Instead, it provides fallback values for undefined root-level config:
const preset = useDesignTokensPreset(s, {
// No root-level colors or spacing defined
themes: {
default: {
colors: { primary: '#ff6600', secondary: '#333' },
spacing: { default: '0.5rem', sm: '0.25rem' },
},
dark: {
colors: { primary: '#60a5fa' },
},
},
});
// Colors and spacing are created at :root from themes.default
// Only "dark" gets a [data-theme="dark"] block
Root-level config always takes precedence over themes.default:
const preset = useDesignTokensPreset(s, {
colors: { brand: '#ff0000' }, // This wins
themes: {
default: {
colors: { primary: '#007bff' }, // Ignored (root-level colors defined)
},
},
});
Theme Overrides Interface
Each theme can override any of the following domains:
| Domain | Type |
|---|---|
spacing | Record<string, TokenValue> |
borderWidth | Record<string, TokenValue> |
borderRadius | Record<string, TokenValue> |
borderStyle | Record<string, TokenValue> |
boxShadow | Record<string, TokenValue> |
colors | Record<string, string> |
fontFamily | Record<string, TokenValue> |
fontSize | Record<string, TokenValue> |
fontStyle | Record<string, TokenValue> |
fontWeight | Record<string, TokenValue> |
lineHeight | Record<string, TokenValue> |
letterSpacing | Record<string, TokenValue> |
scale | Record<string, TokenValue> |
breakpoint | Record<string, number> |
easing | Record<string, TokenValue> |
Theme overrides cannot disable domains (no false values) and do not support meta or scalePowers configuration.
Best Practices
- Start with defaults: Use the preset as-is initially, then customize as needed
- Override strategically: Only customize the domains that need to differ from defaults
- Use the return value: Access the returned variables for use with
ref()in your styles - Combine with themes: Use the
themesoption to define dark mode, compact, or brand theme overrides directly in the preset - Use
meta.merge: When adding values, usemeta: { merge: true }to keep defaults
FAQ
useColor() or useSpacing() for additional custom tokens.Color variations follow a consistent naming pattern:
const {
colorPrimary,
colorPrimary500,
colorPrimaryShade100,
colorPrimaryTint100,
} = preset.colors;
- Base color:
colorPrimary - Lightness:
colorPrimary500(for 50% lightness) - Shade:
colorPrimaryShade100 - Tint:
colorPrimaryTint100
The preset provides:
- Consistent, well-tested default values
- Automatic color variation generation
- Less boilerplate code
- Easy customization through a single config object
Yes! After calling the preset, you can use any composable to add more tokens:
const preset = useDesignTokensPreset(s);
const { colorPrimary } = preset.colors;
// Add custom tokens
const { colorBrand } = useColor(s, { brand: '#ff00ff' });
Use the meta.merge option to merge your custom values with the defaults:
const preset = useDesignTokensPreset(s, {
meta: { merge: true },
// Custom values are ADDED to defaults, not replacing them
spacing: { '4xl': '6rem', '5xl': '8rem' },
colors: { brand: '#ff6600' },
});
// Now you have all default spacing values PLUS '4xl' and '5xl'
// And all default colors PLUS 'brand'
Without meta.merge, providing custom values completely replaces the defaults for that domain.
Overview
Explore Styleframe's comprehensive design token system. Create consistent, scalable design systems with composable functions for colors, typography, spacing, and more.
Borders
Create and manage border design tokens with CSS variables for consistent border styles, widths, and colors across your application.