defineTheme
Builds a complete, contract-satisfying theme from a partial one.
Signature
import { defineTheme, type ThemeInput, type ThemeDefinition } from 'sveltier';
function defineTheme(input: ThemeInput, base: ThemeDefinition): ThemeDefinition;Parameters
| Name | Type | Default | Description |
|---|---|---|---|
input.dark | boolean | base.dark | Whether the theme is dark. |
input.colors | Partial<ThemeColors> | โ | Colours to override or add, as oklch() strings. Each overridden colour gets a fresh on- colour unless you pass one. |
input.variables | Partial<ThemeVariables> | โ | Theme contract variables to override, plus any extra custom properties. |
base | ThemeDefinition | โ | Required. The theme to extend, usually a pack theme such as monolithLight. It is never mutated. |
Example
import { defineTheme } from 'sveltier';
import { monolithLight } from 'sveltier/themes/monolith';
// Extends Monolith light; everything you leave out comes from it.
export const brand = defineTheme({
colors: {
primary: 'oklch(0.52 0.16 255)', // on-primary is computed for you
brand: 'oklch(0.62 0.17 35)' // custom colour: --sv-color-brand, --sv-on-brand
},
variables: {
'radius-md': '13px',
'font-display': "'Fraunces Variable', Georgia, serif"
}
}, monolithLight);Size
defineTheme() carries the colour maths that computes on- colours (under
1 KB gzipped). The built-in theme packs do not need it; they ship precomputed values.
More in Custom themes.