Merge claude/design-tokens-build (d6675d2): theme on any element, primary-inverse roles
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -21,6 +21,7 @@ export {
|
||||
IPAL_TOKENS,
|
||||
ipalVar,
|
||||
LEGACY_DARK_ROLES,
|
||||
LIGHT_SELECTOR,
|
||||
parseColor,
|
||||
resolveColors,
|
||||
STATIC_DEFAULTS,
|
||||
|
||||
@@ -42,6 +42,9 @@ export const COLOR_DEFAULTS = {
|
||||
dark: 'color-mix(in oklch, var(--ipal-primary), black 12%)',
|
||||
light: 'color-mix(in oklch, var(--ipal-primary), black 12%)',
|
||||
},
|
||||
// primary inside an inverted section (a dark brand colour vanishes on a dark inverse surface)
|
||||
'primary-inverse': { dark: 'var(--ipal-primary)', light: 'var(--ipal-primary)' },
|
||||
'primary-inverse-text': { dark: 'var(--ipal-primary-text)', light: 'var(--ipal-primary-text)' },
|
||||
'primary-text': { dark: 'oklch(1 0 0)', light: 'oklch(1 0 0)' },
|
||||
secondary: { dark: 'var(--ipal-text-strong)', light: 'var(--ipal-text-strong)' },
|
||||
'secondary-hover': {
|
||||
@@ -76,6 +79,9 @@ export const INVERSE_SCOPE: Partial<Record<ColorRole, string>> = {
|
||||
focus: 'var(--ipal-focus-inverse)',
|
||||
hover: onInverse(12),
|
||||
link: 'var(--ipal-link-inverse)',
|
||||
primary: 'var(--ipal-primary-inverse)',
|
||||
'primary-hover': 'color-mix(in oklch, var(--ipal-primary-inverse), black 12%)',
|
||||
'primary-text': 'var(--ipal-primary-inverse-text)',
|
||||
surface: onInverse(8),
|
||||
text: 'var(--ipal-text-inverse)',
|
||||
'text-muted': onInverse(72),
|
||||
|
||||
@@ -33,7 +33,6 @@ const PAIRS: Pair[] = [
|
||||
{ bg: 'surface-inverse', fg: 'link-inverse', min: 4.5 },
|
||||
{ bg: 'bg', fg: 'focus', min: 3 },
|
||||
{ bg: 'surface-inverse', fg: 'focus-inverse', min: 3 },
|
||||
{ bg: 'surface-inverse', fg: 'primary', level: 'warn', min: 3 },
|
||||
...(['success', 'warning', 'danger', 'info'] as const).flatMap((state) => [
|
||||
{ bg: 'bg' as const, fg: state, min: 4.5 },
|
||||
{ bg: `${state}-surface` as const, fg: state, min: 4.5 },
|
||||
@@ -42,6 +41,9 @@ const PAIRS: Pair[] = [
|
||||
|
||||
/** Content inside an inverted section: muted text and links on the inverse surface. */
|
||||
const INVERSE_PAIRS: Pair[] = [
|
||||
// primary is re-mapped to primary-inverse: a dark brand colour needs a lighter one here
|
||||
{ bg: 'surface-inverse', fg: 'primary', level: 'warn', min: 3 },
|
||||
{ bg: 'primary', fg: 'primary-text', min: 4.5 },
|
||||
{ bg: 'surface-inverse', fg: 'text-muted', min: 4.5 },
|
||||
{ bg: 'surface', fg: 'text', min: 4.5 },
|
||||
{ bg: 'surface', fg: 'link', min: 4.5 },
|
||||
@@ -56,7 +58,15 @@ export function contrastReport(input: TokensInput = {}): ContrastRow[] {
|
||||
const resolved = resolveColors(input)
|
||||
return themes.flatMap((theme) => {
|
||||
const colors: Record<string, string> = resolved[theme]
|
||||
const inverse: Record<string, string> = { ...colors, ...INVERSE_SCOPE }
|
||||
const outer = (name: string) => (name.startsWith('ipal-') ? colors[name.slice(5)] : undefined)
|
||||
// Roles the scope does not declare are inherited, i.e. computed on the ancestor: resolve them there first.
|
||||
const inherited = Object.fromEntries(
|
||||
Object.entries(colors).flatMap(([role, value]) => {
|
||||
const rgb = parseColor(value, outer)
|
||||
return rgb ? [[role, `rgb(${rgb.r * 255} ${rgb.g * 255} ${rgb.b * 255} / ${rgb.a})`]] : []
|
||||
}),
|
||||
)
|
||||
const inverse: Record<string, string> = { ...inherited, ...INVERSE_SCOPE }
|
||||
const check = (map: Record<string, string>, scope: ContrastRow['scope']) => (pair: Pair): ContrastRow => {
|
||||
const lookup = (name: string) => (name.startsWith('ipal-') ? map[name.slice(5)] : undefined)
|
||||
const fg = parseColor(map[pair.fg], lookup)
|
||||
|
||||
+21
-10
@@ -9,10 +9,17 @@ import {
|
||||
import { resolveColors, staticOverrides, type TokensInput } from './define.js'
|
||||
import { fluidClamp, type RemValue } from './fluid.js'
|
||||
|
||||
/** The dark theme. Two parts so it beats a brand's plain `:root` (the brand file comes later). */
|
||||
export const DARK_SELECTOR = ':root[data-theme="dark"]'
|
||||
/**
|
||||
* The themes. `data-theme` works on any element (a dark panel on a light page, a styleguide).
|
||||
* On <html> the dark selector has two parts so it beats the brand's light block (the brand file comes later).
|
||||
*/
|
||||
export const LIGHT_SELECTOR = ':root, [data-theme="light"]'
|
||||
export const DARK_SELECTOR = ':root[data-theme="dark"], [data-theme="dark"]'
|
||||
export const INVERSE_SELECTOR = '[data-surface="inverse"]'
|
||||
|
||||
const SHADOWS_LIGHT = Object.entries(STATIC_DEFAULTS).filter(([name]) => name.startsWith('shadow-'))
|
||||
const STATICS = Object.entries(STATIC_DEFAULTS).filter(([name]) => !name.startsWith('shadow-'))
|
||||
|
||||
type Entries = Iterable<readonly [string, string]>
|
||||
|
||||
function block(selector: string, entries: Entries, indent = ''): string {
|
||||
@@ -45,17 +52,20 @@ export function defaultTokensCss(): string {
|
||||
* @intecion/ipal-kit/tokens.css — neutral defaults for every --ipal-* design token
|
||||
* (generated from src/modules/tokens/catalog.ts; docs/design-tokens.md).
|
||||
*
|
||||
* Light values on :root, dark values on :root[data-theme="dark"] (set by <ThemeScript>,
|
||||
* storage key "theme"). A brand overrides them in src/design/tokens.css, generated by
|
||||
* Light values on :root, dark values on [data-theme="dark"] (on <html> set by <ThemeScript>,
|
||||
* storage key "theme"; on any element for a dark panel). A brand overrides them in src/design/tokens.css, generated by
|
||||
* \`ipal-tokens\` from src/design/tokens.ts and imported after this file.
|
||||
* Components read only the role names, never "-dark": the roles switch with the theme.
|
||||
* The type and space scale is in fluid.css / fluid-wide.css — import one of them as well.
|
||||
*/`,
|
||||
block(':root', [...colorEntries('light'), ...Object.entries(STATIC_DEFAULTS), ['color-scheme', 'light']]),
|
||||
block(':root', STATICS),
|
||||
block(LIGHT_SELECTOR, [...colorEntries('light'), ...SHADOWS_LIGHT, ['color-scheme', 'light']]),
|
||||
block(DARK_SELECTOR, [...colorEntries('dark'), ...Object.entries(DARK_SHADOWS), ...legacyAliases, ['color-scheme', 'dark']]),
|
||||
`/* Inverted section (settings.background = inverted): content inside reads the inverse roles. */`,
|
||||
`/* Inverted section (settings.background = inverted): content inside reads the inverse roles.
|
||||
Put data-surface and data-theme on different elements: on one, the primary re-map is a var() cycle. */`,
|
||||
block(INVERSE_SELECTOR, inverseEntries),
|
||||
block(`${DARK_SELECTOR} ${INVERSE_SELECTOR}`, [['color-scheme', 'light']]),
|
||||
block('[data-theme="dark"] [data-surface="inverse"]', [['color-scheme', 'light']]),
|
||||
block('[data-theme="dark"] [data-theme="light"] [data-surface="inverse"]', [['color-scheme', 'dark']]),
|
||||
`/* No motion for people who asked for none (the a11y widget's "no animations" too). */`,
|
||||
`@media (prefers-reduced-motion: reduce) {\n${block('html:root', reducedMotion, ' ')}\n}`,
|
||||
block('html[data-a11y-motion="reduce"]', reducedMotion),
|
||||
@@ -86,7 +96,8 @@ export function tokensToCss(input: TokensInput, { source = 'src/design/tokens.ts
|
||||
const statics = Object.entries(staticOverrides(input))
|
||||
const parts = [header]
|
||||
if (theme === 'both') {
|
||||
parts.push(block(':root', [...changed('light', light), ...statics, ...fluidEntries(input)]))
|
||||
parts.push(block(':root', [...statics, ...fluidEntries(input)]))
|
||||
parts.push(block(LIGHT_SELECTOR, changed('light', light)))
|
||||
// brand roles set only for light carry over to dark (resolveColors); other roles keep the dark defaults
|
||||
parts.push(block(DARK_SELECTOR, changed('dark', dark)))
|
||||
} else {
|
||||
@@ -98,8 +109,8 @@ export function tokensToCss(input: TokensInput, { source = 'src/design/tokens.ts
|
||||
...Object.fromEntries(Object.entries(shadowSource).filter(([name]) => name.startsWith('shadow-'))),
|
||||
...Object.fromEntries(statics.filter(([name]) => name.startsWith('shadow-'))),
|
||||
})
|
||||
parts.push(block(':root', [...all, ...statics, ...shadows, ...fluidEntries(input), scheme]))
|
||||
parts.push(block(DARK_SELECTOR, [...all, ...shadows, scheme]))
|
||||
parts.push(block(':root', [...statics, ...fluidEntries(input)]))
|
||||
parts.push(block(`${LIGHT_SELECTOR}, ${DARK_SELECTOR}`, [...all, ...shadows, scheme]))
|
||||
parts.push(block(INVERSE_SELECTOR, [['color-scheme', theme === 'dark' ? 'light' : 'dark']]))
|
||||
}
|
||||
return parts.filter(Boolean).join('\n\n') + '\n'
|
||||
|
||||
@@ -43,7 +43,7 @@ type FluidSizeName<P extends string> = FluidSize extends infer K ? (K extends `$
|
||||
|
||||
/** Roles whose light value carries over to dark when the brand sets no dark value. */
|
||||
export const BRAND_ROLES: readonly ColorRole[] = [
|
||||
'primary', 'primary-text', 'secondary', 'secondary-text', 'accent', 'accent-text',
|
||||
'primary', 'primary-text', 'primary-inverse', 'primary-inverse-text', 'secondary', 'secondary-text', 'accent', 'accent-text',
|
||||
]
|
||||
|
||||
function check(keys: Iterable<string>, known: Record<string, unknown>, where: string) {
|
||||
|
||||
@@ -3,7 +3,7 @@ export type { ColorRole, IpalTokenName } from './catalog.js'
|
||||
export { contrastRatio, parseColor } from './color.js'
|
||||
export { contrastReport } from './contrast.js'
|
||||
export type { ContrastRow } from './contrast.js'
|
||||
export { DARK_SELECTOR, defaultTokensCss, INVERSE_SELECTOR, tokensToCss } from './css.js'
|
||||
export { DARK_SELECTOR, defaultTokensCss, INVERSE_SELECTOR, LIGHT_SELECTOR, tokensToCss } from './css.js'
|
||||
export { defineTokens, resolveColors } from './define.js'
|
||||
export type { ColorInput, TokensInput } from './define.js'
|
||||
export { FLUID_RANGES, FLUID_SCALE, fluidClamp } from './fluid.js'
|
||||
|
||||
@@ -134,8 +134,9 @@
|
||||
letter-spacing: var(--ipal-tracking-heading);
|
||||
line-height: var(--ipal-lh-heading);
|
||||
}
|
||||
/* a scope that re-maps the text roles (data-surface="inverse") also sets its own text colour */
|
||||
[data-surface] {
|
||||
/* a scope that re-maps the text roles (data-surface="inverse", a nested data-theme panel) also sets its text colour */
|
||||
[data-surface],
|
||||
[data-theme] {
|
||||
color: var(--ipal-text);
|
||||
}
|
||||
:focus-visible {
|
||||
|
||||
+44
-29
@@ -2,14 +2,41 @@
|
||||
* @intecion/ipal-kit/tokens.css — neutral defaults for every --ipal-* design token
|
||||
* (generated from src/modules/tokens/catalog.ts; docs/design-tokens.md).
|
||||
*
|
||||
* Light values on :root, dark values on :root[data-theme="dark"] (set by <ThemeScript>,
|
||||
* storage key "theme"). A brand overrides them in src/design/tokens.css, generated by
|
||||
* Light values on :root, dark values on [data-theme="dark"] (on <html> set by <ThemeScript>,
|
||||
* storage key "theme"; on any element for a dark panel). A brand overrides them in src/design/tokens.css, generated by
|
||||
* `ipal-tokens` from src/design/tokens.ts and imported after this file.
|
||||
* Components read only the role names, never "-dark": the roles switch with the theme.
|
||||
* The type and space scale is in fluid.css / fluid-wide.css — import one of them as well.
|
||||
*/
|
||||
|
||||
:root {
|
||||
--ipal-container-narrow: 48rem;
|
||||
--ipal-duration: 250ms;
|
||||
--ipal-duration-fast: 150ms;
|
||||
--ipal-duration-slow: 400ms;
|
||||
--ipal-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
|
||||
--ipal-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
|
||||
--ipal-focus-offset: 2px;
|
||||
--ipal-focus-width: 2px;
|
||||
--ipal-font-body: var(--font-family-body, ui-sans-serif, system-ui, sans-serif);
|
||||
--ipal-font-heading: var(--font-family-heading, var(--ipal-font-body));
|
||||
--ipal-font-mono: var(--font-family-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
|
||||
--ipal-fw-body: 400;
|
||||
--ipal-fw-heading: 650;
|
||||
--ipal-lh-body: 1.6;
|
||||
--ipal-lh-heading: 1.15;
|
||||
--ipal-radius: 0.375rem;
|
||||
--ipal-radius-card: 0.75rem;
|
||||
--ipal-radius-full: 9999px;
|
||||
--ipal-radius-media: 0.5rem;
|
||||
--ipal-radius-sm: 0.25rem;
|
||||
--ipal-tracking-heading: -0.01em;
|
||||
--ipal-z-header: 40;
|
||||
--ipal-z-overlay: 50;
|
||||
--ipal-z-toast: 60;
|
||||
}
|
||||
|
||||
:root, [data-theme="light"] {
|
||||
--ipal-bg: oklch(1 0 0);
|
||||
--ipal-border: oklch(0.922 0 0);
|
||||
--ipal-border-strong: oklch(0.87 0 0);
|
||||
@@ -36,6 +63,8 @@
|
||||
--ipal-link-inverse: var(--ipal-text-inverse);
|
||||
--ipal-overlay: oklch(0 0 0 / 0.5);
|
||||
--ipal-primary-hover: color-mix(in oklch, var(--ipal-primary), black 12%);
|
||||
--ipal-primary-inverse: var(--ipal-primary);
|
||||
--ipal-primary-inverse-text: var(--ipal-primary-text);
|
||||
--ipal-primary-text: oklch(1 0 0);
|
||||
--ipal-secondary: var(--ipal-text-strong);
|
||||
--ipal-secondary-hover: color-mix(in oklch, var(--ipal-secondary), white 18%);
|
||||
@@ -44,37 +73,13 @@
|
||||
--ipal-success-surface: oklch(0.982 0.018 155.826);
|
||||
--ipal-warning: oklch(0.555 0.163 48.998);
|
||||
--ipal-warning-surface: oklch(0.987 0.022 95.277);
|
||||
--ipal-container-narrow: 48rem;
|
||||
--ipal-duration: 250ms;
|
||||
--ipal-duration-fast: 150ms;
|
||||
--ipal-duration-slow: 400ms;
|
||||
--ipal-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
|
||||
--ipal-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
|
||||
--ipal-focus-offset: 2px;
|
||||
--ipal-focus-width: 2px;
|
||||
--ipal-font-body: var(--font-family-body, ui-sans-serif, system-ui, sans-serif);
|
||||
--ipal-font-heading: var(--font-family-heading, var(--ipal-font-body));
|
||||
--ipal-font-mono: var(--font-family-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
|
||||
--ipal-fw-body: 400;
|
||||
--ipal-fw-heading: 650;
|
||||
--ipal-lh-body: 1.6;
|
||||
--ipal-lh-heading: 1.15;
|
||||
--ipal-radius: 0.375rem;
|
||||
--ipal-radius-card: 0.75rem;
|
||||
--ipal-radius-full: 9999px;
|
||||
--ipal-radius-media: 0.5rem;
|
||||
--ipal-radius-sm: 0.25rem;
|
||||
--ipal-shadow-lg: 0 16px 32px -8px oklch(0 0 0 / 0.14), 0 4px 8px -4px oklch(0 0 0 / 0.08);
|
||||
--ipal-shadow-md: 0 4px 8px -2px oklch(0 0 0 / 0.08), 0 2px 4px -2px oklch(0 0 0 / 0.06);
|
||||
--ipal-shadow-sm: 0 1px 2px 0 oklch(0 0 0 / 0.06), 0 1px 3px 0 oklch(0 0 0 / 0.08);
|
||||
--ipal-tracking-heading: -0.01em;
|
||||
--ipal-z-header: 40;
|
||||
--ipal-z-overlay: 50;
|
||||
--ipal-z-toast: 60;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] {
|
||||
:root[data-theme="dark"], [data-theme="dark"] {
|
||||
--ipal-bg: oklch(0.145 0 0);
|
||||
--ipal-border: oklch(0.269 0 0);
|
||||
--ipal-border-strong: oklch(0.371 0 0);
|
||||
@@ -101,6 +106,8 @@
|
||||
--ipal-link-inverse: var(--ipal-text-inverse);
|
||||
--ipal-overlay: oklch(0 0 0 / 0.65);
|
||||
--ipal-primary-hover: color-mix(in oklch, var(--ipal-primary), black 12%);
|
||||
--ipal-primary-inverse: var(--ipal-primary);
|
||||
--ipal-primary-inverse-text: var(--ipal-primary-text);
|
||||
--ipal-primary-text: oklch(1 0 0);
|
||||
--ipal-secondary: var(--ipal-text-strong);
|
||||
--ipal-secondary-hover: color-mix(in oklch, var(--ipal-secondary), black 12%);
|
||||
@@ -124,7 +131,8 @@
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
/* Inverted section (settings.background = inverted): content inside reads the inverse roles. */
|
||||
/* Inverted section (settings.background = inverted): content inside reads the inverse roles.
|
||||
Put data-surface and data-theme on different elements: on one, the primary re-map is a var() cycle. */
|
||||
|
||||
[data-surface="inverse"] {
|
||||
--ipal-border: color-mix(in oklch, var(--ipal-text-inverse) 18%, var(--ipal-surface-inverse));
|
||||
@@ -132,6 +140,9 @@
|
||||
--ipal-focus: var(--ipal-focus-inverse);
|
||||
--ipal-hover: color-mix(in oklch, var(--ipal-text-inverse) 12%, var(--ipal-surface-inverse));
|
||||
--ipal-link: var(--ipal-link-inverse);
|
||||
--ipal-primary: var(--ipal-primary-inverse);
|
||||
--ipal-primary-hover: color-mix(in oklch, var(--ipal-primary-inverse), black 12%);
|
||||
--ipal-primary-text: var(--ipal-primary-inverse-text);
|
||||
--ipal-surface: color-mix(in oklch, var(--ipal-text-inverse) 8%, var(--ipal-surface-inverse));
|
||||
--ipal-text: var(--ipal-text-inverse);
|
||||
--ipal-text-muted: color-mix(in oklch, var(--ipal-text-inverse) 72%, var(--ipal-surface-inverse));
|
||||
@@ -140,10 +151,14 @@
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] [data-surface="inverse"] {
|
||||
[data-theme="dark"] [data-surface="inverse"] {
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
[data-theme="dark"] [data-theme="light"] [data-surface="inverse"] {
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
/* No motion for people who asked for none (the a11y widget's "no animations" too). */
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
|
||||
Reference in New Issue
Block a user