Design tokens: themes on any element, primary-inverse, form template
Follow-ups from the reference site's first visual test: - data-theme="dark"/"light" switches the tokens on any element (LIGHT_SELECTOR, DARK_SELECTOR as selector lists); the base layer colours a themed panel's text - inverted sections re-map primary / primary-hover / primary-text to the new primary-inverse / primary-inverse-text roles; the contrast report checks them (inherited roles resolved on the ancestor, as the cascade does) - ipal-form formClasses.ts on token utilities + buttonClass(); theme.md: one-icon ThemeSwitcher pattern (the default two-option toggle stays) Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
51f80cea13
commit
d6675d2979
@@ -23,6 +23,10 @@ fifteen ready page sections and ten page templates.
|
|||||||
New bin `ipal-tokens`: `src/design/tokens.ts` → `src/design/tokens.css` + WCAG contrast check (`--check` for CI).
|
New bin `ipal-tokens`: `src/design/tokens.ts` → `src/design/tokens.css` + WCAG contrast check (`--check` for CI).
|
||||||
Templates `DESIGN.md` and `tokens.ts` in `ipal-setup/resources`. `ipal-audit` checks the standard.
|
Templates `DESIGN.md` and `tokens.ts` in `ipal-setup/resources`. `ipal-audit` checks the standard.
|
||||||
- `fluid.css` / `fluid-wide.css`: `--ipal-fs-xs`, `--ipal-fs-h4`, `--ipal-space-stack`, `--ipal-space-section-sm`.
|
- `fluid.css` / `fluid-wide.css`: `--ipal-fs-xs`, `--ipal-fs-h4`, `--ipal-space-stack`, `--ipal-space-section-sm`.
|
||||||
|
- Design tokens: `data-theme="dark"` / `"light"` switches the tokens on any element (a dark panel, a styleguide), not
|
||||||
|
only on `<html>` (`LIGHT_SELECTOR`, `DARK_SELECTOR`). Inside an inverted section `primary` reads the new
|
||||||
|
`primary-inverse` / `primary-inverse-text` roles (default: the brand primary), and the contrast report checks primary
|
||||||
|
buttons there. The `ipal-form` `formClasses.ts` template uses the token utilities and `buttonClass()`.
|
||||||
- **Block library** ([block-library.md](./block-library.md)): `hero`, `textMedia`, `featureGrid`, `cta`, `richText`, `faq`,
|
- **Block library** ([block-library.md](./block-library.md)): `hero`, `textMedia`, `featureGrid`, `cta`, `richText`, `faq`,
|
||||||
`contact`, `gallery`, `testimonials`, `stats`, `steps`, `logos`, `team`, `pricing`, `entryList` — Payload block +
|
`contact`, `gallery`, `testimonials`, `stats`, `steps`, `logos`, `team`, `pricing`, `entryList` — Payload block +
|
||||||
server component each, `{ en, pl }` panel, accessibility built in, styled only with design-token utilities.
|
server component each, `{ en, pl }` panel, accessibility built in, styled only with design-token utilities.
|
||||||
|
|||||||
+3
-2
@@ -895,7 +895,8 @@ Every site uses the same `--ipal-*` token names and Tailwind utilities; only the
|
|||||||
`rounded-card`, `shadow-sm`, `max-w-container`, `duration-fast ease-out`. **Never** hex, `bg-[#…]`, `var(--color-…)`,
|
`rounded-card`, `shadow-sm`, `max-w-container`, `duration-fast ease-out`. **Never** hex, `bg-[#…]`, `var(--color-…)`,
|
||||||
or `dark:` for colours (the roles switch with `data-theme` themselves). `dark:` only for non-colour differences.
|
or `dark:` for colours (the roles switch with `data-theme` themselves). `dark:` only for non-colour differences.
|
||||||
- **Inverted section:** `<Section>` with `settings.background = inverted` → `bg-inverse` + `data-surface="inverse"`;
|
- **Inverted section:** `<Section>` with `settings.background = inverted` → `bg-inverse` + `data-surface="inverse"`;
|
||||||
content inside keeps `text-fg` / `text-link` (the scope re-maps them).
|
content inside keeps `text-fg` / `text-link` / `bg-primary` (the scope re-maps them; a dark brand primary needs
|
||||||
|
`primary-inverse` in `tokens.ts` — the contrast report says when). `data-theme="dark"` on any element = a dark panel.
|
||||||
- Fonts via `next/font` with `variable: '--font-family-body'` / `'--font-family-heading'` on `<html>` (not
|
- Fonts via `next/font` with `variable: '--font-family-body'` / `'--font-family-heading'` on `<html>` (not
|
||||||
`--font-body`: a `var()` cycle with the `font-body` utility). Max 2 families.
|
`--font-body`: a `var()` cycle with the `font-body` utility). Max 2 families.
|
||||||
- Values a CSS variable can't reach (`next/og`, e-mail, `theme-color`): `resolveColors(tokens)` from `@/design/tokens`.
|
- Values a CSS variable can't reach (`next/og`, e-mail, `theme-color`): `resolveColors(tokens)` from `@/design/tokens`.
|
||||||
@@ -1043,7 +1044,7 @@ project → **plugin gap**, not a copy.
|
|||||||
| `next.config` | `buildImagesConfig`, `buildSecurityHeaders` (`csp`), `buildCsp`, `buildCspHeaders`, `buildAdminCsp` / `buildAdminCspHeaders`, `buildUploadSecurityHeaders`, `withSecurityConfig` (hides `X-Powered-By`) | storage.md, security.md |
|
| `next.config` | `buildImagesConfig`, `buildSecurityHeaders` (`csp`), `buildCsp`, `buildCspHeaders`, `buildAdminCsp` / `buildAdminCspHeaders`, `buildUploadSecurityHeaders`, `withSecurityConfig` (hides `X-Powered-By`) | storage.md, security.md |
|
||||||
| CSP reports, nonces | `createCspReportRoute` (`parseCspReports`, type `CspViolation`), `createProxy({ csp })` + `<SiteProviders nonce>` (dynamic pages only), `createCspNonce`, `CSP_NONCE_HEADER`, `buildReportingEndpoints`, `cspHeaderKey`, `DEFAULT_CSP_REPORT_GROUP`; types `BuildAdminCspArgs`, `CspDirective`, `CspSources`, `CreateCspReportRouteArgs`, `WithSecurityConfigOptions` | security.md |
|
| CSP reports, nonces | `createCspReportRoute` (`parseCspReports`, type `CspViolation`), `createProxy({ csp })` + `<SiteProviders nonce>` (dynamic pages only), `createCspNonce`, `CSP_NONCE_HEADER`, `buildReportingEndpoints`, `cspHeaderKey`, `DEFAULT_CSP_REPORT_GROUP`; types `BuildAdminCspArgs`, `CspDirective`, `CspSources`, `CreateCspReportRouteArgs`, `WithSecurityConfigOptions` | security.md |
|
||||||
| Fluid typography and spacing | `fluid.css` / `fluid-wide.css` (`--ipal-*` variables); your own sizes: `fluidClamp`, `FLUID_SCALE`, `FLUID_RANGES` | design-tokens.md |
|
| Fluid typography and spacing | `fluid.css` / `fluid-wide.css` (`--ipal-*` variables); your own sizes: `fluidClamp`, `FLUID_SCALE`, `FLUID_RANGES` | design-tokens.md |
|
||||||
| Brand colours, fonts, radii, motion, dark mode | `tokens.css` + `tailwind.css`, `src/design/tokens.ts` (`defineTokens`, types `TokensInput`, `ColorInput`, `ColorRole`), `pnpm exec ipal-tokens` (`--check`, `--report`, `--warn-only`); building blocks `tokensToCss`, `defaultTokensCss`, `contrastReport` (`ContrastRow`), `contrastRatio`, `parseColor`, `resolveColors`, `IPAL_TOKENS`, `ipalVar`, `IpalTokenName`, `IPAL_BREAKPOINTS`, `COLOR_DEFAULTS`, `STATIC_DEFAULTS`, `FLUID_TOKENS`, `INVERSE_SCOPE`, `LEGACY_DARK_ROLES`, `DARK_SELECTOR`, `INVERSE_SELECTOR`, `RemValue`, `FluidRange` | design-tokens.md |
|
| Brand colours, fonts, radii, motion, dark mode | `tokens.css` + `tailwind.css`, `src/design/tokens.ts` (`defineTokens`, types `TokensInput`, `ColorInput`, `ColorRole`), `pnpm exec ipal-tokens` (`--check`, `--report`, `--warn-only`); building blocks `tokensToCss`, `defaultTokensCss`, `contrastReport` (`ContrastRow`), `contrastRatio`, `parseColor`, `resolveColors`, `IPAL_TOKENS`, `ipalVar`, `IpalTokenName`, `IPAL_BREAKPOINTS`, `COLOR_DEFAULTS`, `STATIC_DEFAULTS`, `FLUID_TOKENS`, `INVERSE_SCOPE`, `LEGACY_DARK_ROLES`, `LIGHT_SELECTOR`, `DARK_SELECTOR`, `INVERSE_SELECTOR`, `RemValue`, `FluidRange` | design-tokens.md |
|
||||||
| Accessibility widget CSS | `@intecion/ipal-kit/a11y.css` (works through the tokens) | accessibility.md |
|
| Accessibility widget CSS | `@intecion/ipal-kit/a11y.css` (works through the tokens) | accessibility.md |
|
||||||
|
|
||||||
**Consent, analytics, operations**
|
**Consent, analytics, operations**
|
||||||
|
|||||||
@@ -1,29 +1,36 @@
|
|||||||
// src/components/forms/formClasses.ts — the ONLY place forms are styled. Every
|
// src/components/forms/formClasses.ts — the ONLY place forms are styled. Every
|
||||||
// panel form (RenderForm / BuilderForm) uses it. Values = the project's design
|
// panel form (RenderForm / BuilderForm) uses it. Design-token utilities only
|
||||||
// tokens (DESIGN.md); the plugin ships no styles. Delete keys you don't need.
|
// (node_modules/@intecion/ipal-kit/docs/design-tokens.md): a brand changes
|
||||||
|
// src/design/tokens.ts, never this file. Delete keys you don't need.
|
||||||
import type { BuilderFormClassNames } from '@intecion/ipal-kit/client'
|
import type { BuilderFormClassNames } from '@intecion/ipal-kit/client'
|
||||||
|
import { buttonClass } from '@intecion/ipal-kit/blocks/rsc'
|
||||||
|
|
||||||
|
const control =
|
||||||
|
'w-full rounded-control border border-border-strong bg-surface px-3 py-2 text-fg placeholder:text-fg-muted ' +
|
||||||
|
'transition-colors duration-fast ease-out focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus ' +
|
||||||
|
'aria-invalid:border-danger'
|
||||||
|
|
||||||
export const formClasses: BuilderFormClassNames = {
|
export const formClasses: BuilderFormClassNames = {
|
||||||
form: 'grid gap-6',
|
form: 'grid gap-6',
|
||||||
progress: 'text-sm text-muted', // "Step 1 of 3"
|
progress: 'text-sm text-fg-muted', // "Step 1 of 3"
|
||||||
step: 'grid gap-4',
|
step: 'grid gap-4',
|
||||||
stepTitle: 'text-h3 font-semibold',
|
stepTitle: 'text-h4',
|
||||||
stepDescription: 'text-muted',
|
stepDescription: 'text-fg-muted',
|
||||||
fields: 'grid grid-cols-12 gap-4',
|
fields: 'grid grid-cols-12 gap-4',
|
||||||
field: 'col-span-12',
|
field: 'col-span-12',
|
||||||
fieldHalf: 'md:col-span-6', // width ≤ 50 in the panel
|
fieldHalf: 'md:col-span-6', // width ≤ 50 in the panel
|
||||||
label: 'mb-1 block font-medium',
|
label: 'mb-1 block font-medium text-fg-strong',
|
||||||
input: 'w-full rounded-md border border-border px-3 py-2',
|
input: control,
|
||||||
textarea: 'w-full rounded-md border border-border px-3 py-2',
|
textarea: control,
|
||||||
select: 'w-full rounded-md border border-border px-3 py-2',
|
select: control,
|
||||||
checkboxLabel: 'flex items-start gap-2',
|
checkboxLabel: 'flex items-start gap-2',
|
||||||
choices: 'grid gap-2', // radio / checkbox group <fieldset>
|
choices: 'grid gap-2', // radio / checkbox group <fieldset>
|
||||||
legend: 'mb-1 font-medium',
|
legend: 'mb-1 font-medium text-fg-strong',
|
||||||
choice: 'flex items-center gap-2',
|
choice: 'flex items-center gap-2',
|
||||||
error: 'mt-1 text-sm text-danger',
|
error: 'mt-1 text-sm text-danger',
|
||||||
formError: 'text-danger',
|
formError: 'rounded-control bg-danger-surface p-4 text-danger',
|
||||||
actions: 'flex gap-3',
|
actions: 'flex flex-wrap gap-3',
|
||||||
back: 'btn btn-secondary', // same classes as Button.tsx variants
|
back: buttonClass('secondary'), // the same looks as the section buttons
|
||||||
submit: 'btn btn-primary',
|
submit: buttonClass('primary'),
|
||||||
success: 'rounded-md bg-surface p-6',
|
success: 'rounded-card bg-success-surface p-6 text-success',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -759,7 +759,7 @@ CSS: `@intecion/ipal-kit/tokens.css` (neutral `--ipal-*` defaults, light/dark, `
|
|||||||
| `ipalVar(name, fallback?)` | `@intecion/ipal-kit/tokens`, `@intecion/ipal-kit` | `var(--ipal-<name>[, fallback])`. |
|
| `ipalVar(name, fallback?)` | `@intecion/ipal-kit/tokens`, `@intecion/ipal-kit` | `var(--ipal-<name>[, fallback])`. |
|
||||||
| `IPAL_BREAKPOINTS` | `@intecion/ipal-kit/tokens`, `@intecion/ipal-kit` | `{ sm: 40, md: 48, lg: 64, xl: 80, '2xl': 96 }` (rem) — for `sizes=` / `matchMedia`. |
|
| `IPAL_BREAKPOINTS` | `@intecion/ipal-kit/tokens`, `@intecion/ipal-kit` | `{ sm: 40, md: 48, lg: 64, xl: 80, '2xl': 96 }` (rem) — for `sizes=` / `matchMedia`. |
|
||||||
| `COLOR_DEFAULTS`, `STATIC_DEFAULTS`, `FLUID_TOKENS`, `INVERSE_SCOPE`, `LEGACY_DARK_ROLES` | `@intecion/ipal-kit/tokens` | The catalogue: colour defaults per theme, theme-independent defaults, fluid names, inverse re-map, the old `-dark` twins. |
|
| `COLOR_DEFAULTS`, `STATIC_DEFAULTS`, `FLUID_TOKENS`, `INVERSE_SCOPE`, `LEGACY_DARK_ROLES` | `@intecion/ipal-kit/tokens` | The catalogue: colour defaults per theme, theme-independent defaults, fluid names, inverse re-map, the old `-dark` twins. |
|
||||||
| `DARK_SELECTOR`, `INVERSE_SELECTOR` | `@intecion/ipal-kit/tokens` | `:root[data-theme="dark"]`, `[data-surface="inverse"]`. |
|
| `LIGHT_SELECTOR`, `DARK_SELECTOR`, `INVERSE_SELECTOR` | `@intecion/ipal-kit/tokens` | `:root, [data-theme="light"]`, `:root[data-theme="dark"], [data-theme="dark"]` (a theme on any element), `[data-surface="inverse"]`. |
|
||||||
|
|
||||||
**Types:** `TokensInput`, `IpalTokenName` (root, `/tokens`), `ColorInput`, `ColorRole`, `ContrastRow`, `FluidRange`, `RemValue` (`/tokens`).
|
**Types:** `TokensInput`, `IpalTokenName` (root, `/tokens`), `ColorInput`, `ColorRole`, `ContrastRow`, `FluidRange`, `RemValue` (`/tokens`).
|
||||||
|
|
||||||
|
|||||||
+18
-7
@@ -11,7 +11,7 @@ Everything here is opt-in. A site that imports none of it looks exactly as befor
|
|||||||
|
|
||||||
| Export | What it is |
|
| Export | What it is |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `@intecion/ipal-kit/tokens.css` | neutral defaults for every token: light on `:root`, dark on `:root[data-theme="dark"]`, the inverse scope, reduced motion |
|
| `@intecion/ipal-kit/tokens.css` | neutral defaults for every token: light on `:root` / `[data-theme="light"]`, dark on `[data-theme="dark"]` (any element), the inverse scope, reduced motion |
|
||||||
| `@intecion/ipal-kit/tailwind.css` | Tailwind 4 preset: `@theme inline` map (utilities below), `dark:` on `data-theme`, `duration-*` / `z-*` utilities, a small base layer, the theme-switch transition |
|
| `@intecion/ipal-kit/tailwind.css` | Tailwind 4 preset: `@theme inline` map (utilities below), `dark:` on `data-theme`, `duration-*` / `z-*` utilities, a small base layer, the theme-switch transition |
|
||||||
| `@intecion/ipal-kit/fluid-wide.css` / `fluid.css` | the type and space scale (`--ipal-fs-*`, `--ipal-space-*`, containers, height helpers): grows to 1920 px / 1280 px |
|
| `@intecion/ipal-kit/fluid-wide.css` / `fluid.css` | the type and space scale (`--ipal-fs-*`, `--ipal-space-*`, containers, height helpers): grows to 1920 px / 1280 px |
|
||||||
| `@intecion/ipal-kit/a11y.css` | optional CSS for the accessibility widget's attributes, working through the tokens (accessibility.md) |
|
| `@intecion/ipal-kit/a11y.css` | optional CSS for the accessibility widget's attributes, working through the tokens (accessibility.md) |
|
||||||
@@ -88,7 +88,7 @@ Dark mode: `<SiteProviders theme>` (theme.md). Nothing else is needed: the roles
|
|||||||
| `secondary` · `secondary-hover` · `secondary-text` | second button (default: neutral strong) | `bg-secondary` · `text-on-secondary` |
|
| `secondary` · `secondary-hover` · `secondary-text` | second button (default: neutral strong) | `bg-secondary` · `text-on-secondary` |
|
||||||
| `accent` · `accent-text` | highlight, badge, rating stars (default: primary) | `bg-accent` · `text-accent` · `text-on-accent` |
|
| `accent` · `accent-text` | highlight, badge, rating stars (default: primary) | `bg-accent` · `text-accent` · `text-on-accent` |
|
||||||
| `link` · `link-hover` | links in running text | `text-link` · `hover:text-link-hover` |
|
| `link` · `link-hover` | links in running text | `text-link` · `hover:text-link-hover` |
|
||||||
| `link-inverse` · `focus-inverse` | link and focus ring inside an inverted section | (read through the inverse scope) |
|
| `link-inverse` · `focus-inverse` · `primary-inverse` · `primary-inverse-text` | link, focus ring and primary button inside an inverted section | (read through the inverse scope) |
|
||||||
| `hover` | neutral hover (ghost button, row) | `bg-hover` |
|
| `hover` | neutral hover (ghost button, row) | `bg-hover` |
|
||||||
| `focus` | focus ring | `outline-focus` · `ring-focus` |
|
| `focus` | focus ring | `outline-focus` · `ring-focus` |
|
||||||
| `overlay` | scrim, hero image overlay | `bg-overlay` · `from-overlay` |
|
| `overlay` | scrim, hero image overlay | `bg-overlay` · `from-overlay` |
|
||||||
@@ -113,13 +113,24 @@ standard). Any CSS colour works.
|
|||||||
|
|
||||||
A project may *add* a breakpoint (`--breakpoint-xs`) as a deviation recorded in `DESIGN.md`. It never moves an existing one.
|
A project may *add* a breakpoint (`--breakpoint-xs`) as a deviation recorded in `DESIGN.md`. It never moves an existing one.
|
||||||
|
|
||||||
|
### Themes on any element
|
||||||
|
|
||||||
|
`data-theme="dark"` / `"light"` switches the colour roles on any element, not only `<html>`: a dark panel on a light
|
||||||
|
page, or a styleguide showing both themes side by side (`<div data-theme="dark" className="bg-bg">…</div>`). The
|
||||||
|
preset's base layer gives such a panel its text colour; give it a background yourself (`bg-bg` or `bg-surface`). The
|
||||||
|
Tailwind `dark:` variant follows the nearest `data-theme`.
|
||||||
|
|
||||||
### Inverted sections
|
### Inverted sections
|
||||||
|
|
||||||
`<Section>` with `settings.background = inverted` renders `bg-inverse` and `data-surface="inverse"`. Inside that
|
`<Section>` with `settings.background = inverted` renders `bg-inverse` and `data-surface="inverse"`. Inside that
|
||||||
scope, `text`, `text-strong`, `text-muted`, `border(-strong)`, `surface`, `hover`, `link` and `focus` are re-mapped
|
scope, `text`, `text-strong`, `text-muted`, `border(-strong)`, `surface`, `hover`, `link`, `focus` and `primary`
|
||||||
for the inverse surface, and `color-scheme` flips. Cards, rich text, links and focus rings need no inverse variants:
|
(+ `primary-hover`, `primary-text`) are re-mapped for the inverse surface, and `color-scheme` flips. Cards, rich text,
|
||||||
they keep `text-fg`, `text-link`, `border-border`. `primary` / `accent` are not re-mapped. The contrast report warns
|
links, focus rings and primary buttons need no inverse variants: they keep `text-fg`, `text-link`, `border-border`,
|
||||||
when `primary` on `surface-inverse` is below 3:1.
|
`bg-primary text-on-primary`. `primary` inside reads **`primary-inverse`** / **`primary-inverse-text`** (default: the
|
||||||
|
brand primary). A dark brand colour vanishes on a dark inverse surface: the contrast report warns (`primary on
|
||||||
|
surface-inverse` below 3:1, inverse scope), so set a lighter one, per theme: `color: { light: { 'primary-inverse':
|
||||||
|
'oklch(0.85 0.1 150)', 'primary-inverse-text': 'oklch(0.2 0.05 150)' } }`. `accent` is not re-mapped. Put
|
||||||
|
`data-surface` and `data-theme` on different elements.
|
||||||
|
|
||||||
### Legacy `-dark` names
|
### Legacy `-dark` names
|
||||||
|
|
||||||
@@ -154,7 +165,7 @@ and focus rings (3:1).
|
|||||||
| `fluidClamp(min, max, range)` | the fluid.css `clamp()` for your own sizes; `FLUID_SCALE`, `FLUID_RANGES`, type `FluidRange`, `RemValue` |
|
| `fluidClamp(min, max, range)` | the fluid.css `clamp()` for your own sizes; `FLUID_SCALE`, `FLUID_RANGES`, type `FluidRange`, `RemValue` |
|
||||||
| `IPAL_TOKENS`, `ipalVar(name, fallback?)` | `var(--ipal-…)` strings for inline styles, charts, a styleguide page (type `IpalTokenName`) |
|
| `IPAL_TOKENS`, `ipalVar(name, fallback?)` | `var(--ipal-…)` strings for inline styles, charts, a styleguide page (type `IpalTokenName`) |
|
||||||
| `IPAL_BREAKPOINTS` | breakpoints in rem |
|
| `IPAL_BREAKPOINTS` | breakpoints in rem |
|
||||||
| `COLOR_DEFAULTS`, `STATIC_DEFAULTS`, `FLUID_TOKENS`, `INVERSE_SCOPE`, `LEGACY_DARK_ROLES`, `DARK_SELECTOR`, `INVERSE_SELECTOR`, type `ColorRole` | the catalogue itself |
|
| `COLOR_DEFAULTS`, `STATIC_DEFAULTS`, `FLUID_TOKENS`, `INVERSE_SCOPE`, `LEGACY_DARK_ROLES`, `LIGHT_SELECTOR`, `DARK_SELECTOR`, `INVERSE_SELECTOR`, type `ColorRole` | the catalogue itself |
|
||||||
|
|
||||||
Values that CSS variables can't reach (`next/og` images, e-mail templates, `<meta name="theme-color">`): import `tokens`
|
Values that CSS variables can't reach (`next/og` images, e-mail templates, `<meta name="theme-color">`): import `tokens`
|
||||||
from `@/design/tokens` and read `resolveColors(tokens).light.primary`.
|
from `@/design/tokens` and read `resolveColors(tokens).light.primary`.
|
||||||
|
|||||||
@@ -68,6 +68,13 @@ import { ThemeSwitcher } from '@intecion/ipal-kit/client'
|
|||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Both icons render: the default is a two-option toggle with the active one highlighted (the `classNames` above).
|
||||||
|
For one icon that changes with the theme (sun in light, moon in dark), hide the other with the `dark:` variant:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
<ThemeSwitcher label={themeLabel} classNames={{ light: 'block dark:hidden', dark: 'hidden dark:block' }} />
|
||||||
|
```
|
||||||
|
|
||||||
`<button role="switch" aria-checked>` (checked = dark). Which button looks active is decided by CSS
|
`<button role="switch" aria-checked>` (checked = dark). Which button looks active is decided by CSS
|
||||||
from the attribute on `<html>` (`dark:`), not React state — nothing jumps after hydration.
|
from the attribute on `<html>` (`dark:`), not React state — nothing jumps after hydration.
|
||||||
Hooks for styling: `data-ipal="theme-switch"`, `data-ipal-theme-icon="light|dark"`.
|
Hooks for styling: `data-ipal="theme-switch"`, `data-ipal-theme-icon="light|dark"`.
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export {
|
|||||||
IPAL_TOKENS,
|
IPAL_TOKENS,
|
||||||
ipalVar,
|
ipalVar,
|
||||||
LEGACY_DARK_ROLES,
|
LEGACY_DARK_ROLES,
|
||||||
|
LIGHT_SELECTOR,
|
||||||
parseColor,
|
parseColor,
|
||||||
resolveColors,
|
resolveColors,
|
||||||
STATIC_DEFAULTS,
|
STATIC_DEFAULTS,
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ export const COLOR_DEFAULTS = {
|
|||||||
dark: 'color-mix(in oklch, var(--ipal-primary), black 12%)',
|
dark: 'color-mix(in oklch, var(--ipal-primary), black 12%)',
|
||||||
light: '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)' },
|
'primary-text': { dark: 'oklch(1 0 0)', light: 'oklch(1 0 0)' },
|
||||||
secondary: { dark: 'var(--ipal-text-strong)', light: 'var(--ipal-text-strong)' },
|
secondary: { dark: 'var(--ipal-text-strong)', light: 'var(--ipal-text-strong)' },
|
||||||
'secondary-hover': {
|
'secondary-hover': {
|
||||||
@@ -76,6 +79,9 @@ export const INVERSE_SCOPE: Partial<Record<ColorRole, string>> = {
|
|||||||
focus: 'var(--ipal-focus-inverse)',
|
focus: 'var(--ipal-focus-inverse)',
|
||||||
hover: onInverse(12),
|
hover: onInverse(12),
|
||||||
link: 'var(--ipal-link-inverse)',
|
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),
|
surface: onInverse(8),
|
||||||
text: 'var(--ipal-text-inverse)',
|
text: 'var(--ipal-text-inverse)',
|
||||||
'text-muted': onInverse(72),
|
'text-muted': onInverse(72),
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ const PAIRS: Pair[] = [
|
|||||||
{ bg: 'surface-inverse', fg: 'link-inverse', min: 4.5 },
|
{ bg: 'surface-inverse', fg: 'link-inverse', min: 4.5 },
|
||||||
{ bg: 'bg', fg: 'focus', min: 3 },
|
{ bg: 'bg', fg: 'focus', min: 3 },
|
||||||
{ bg: 'surface-inverse', fg: 'focus-inverse', 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) => [
|
...(['success', 'warning', 'danger', 'info'] as const).flatMap((state) => [
|
||||||
{ bg: 'bg' as const, fg: state, min: 4.5 },
|
{ bg: 'bg' as const, fg: state, min: 4.5 },
|
||||||
{ bg: `${state}-surface` 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. */
|
/** Content inside an inverted section: muted text and links on the inverse surface. */
|
||||||
const INVERSE_PAIRS: Pair[] = [
|
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-inverse', fg: 'text-muted', min: 4.5 },
|
||||||
{ bg: 'surface', fg: 'text', min: 4.5 },
|
{ bg: 'surface', fg: 'text', min: 4.5 },
|
||||||
{ bg: 'surface', fg: 'link', min: 4.5 },
|
{ bg: 'surface', fg: 'link', min: 4.5 },
|
||||||
@@ -56,7 +58,15 @@ export function contrastReport(input: TokensInput = {}): ContrastRow[] {
|
|||||||
const resolved = resolveColors(input)
|
const resolved = resolveColors(input)
|
||||||
return themes.flatMap((theme) => {
|
return themes.flatMap((theme) => {
|
||||||
const colors: Record<string, string> = resolved[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 check = (map: Record<string, string>, scope: ContrastRow['scope']) => (pair: Pair): ContrastRow => {
|
||||||
const lookup = (name: string) => (name.startsWith('ipal-') ? map[name.slice(5)] : undefined)
|
const lookup = (name: string) => (name.startsWith('ipal-') ? map[name.slice(5)] : undefined)
|
||||||
const fg = parseColor(map[pair.fg], lookup)
|
const fg = parseColor(map[pair.fg], lookup)
|
||||||
|
|||||||
+21
-10
@@ -9,10 +9,17 @@ import {
|
|||||||
import { resolveColors, staticOverrides, type TokensInput } from './define.js'
|
import { resolveColors, staticOverrides, type TokensInput } from './define.js'
|
||||||
import { fluidClamp, type RemValue } from './fluid.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"]'
|
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]>
|
type Entries = Iterable<readonly [string, string]>
|
||||||
|
|
||||||
function block(selector: string, entries: Entries, indent = ''): 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
|
* @intecion/ipal-kit/tokens.css — neutral defaults for every --ipal-* design token
|
||||||
* (generated from src/modules/tokens/catalog.ts; docs/design-tokens.md).
|
* (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>,
|
* Light values on :root, dark values on [data-theme="dark"] (on <html> set by <ThemeScript>,
|
||||||
* storage key "theme"). A brand overrides them in src/design/tokens.css, generated by
|
* 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.
|
* \`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.
|
* 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.
|
* 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']]),
|
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(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). */`,
|
`/* 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}`,
|
`@media (prefers-reduced-motion: reduce) {\n${block('html:root', reducedMotion, ' ')}\n}`,
|
||||||
block('html[data-a11y-motion="reduce"]', reducedMotion),
|
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 statics = Object.entries(staticOverrides(input))
|
||||||
const parts = [header]
|
const parts = [header]
|
||||||
if (theme === 'both') {
|
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
|
// 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)))
|
parts.push(block(DARK_SELECTOR, changed('dark', dark)))
|
||||||
} else {
|
} 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(Object.entries(shadowSource).filter(([name]) => name.startsWith('shadow-'))),
|
||||||
...Object.fromEntries(statics.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(':root', [...statics, ...fluidEntries(input)]))
|
||||||
parts.push(block(DARK_SELECTOR, [...all, ...shadows, scheme]))
|
parts.push(block(`${LIGHT_SELECTOR}, ${DARK_SELECTOR}`, [...all, ...shadows, scheme]))
|
||||||
parts.push(block(INVERSE_SELECTOR, [['color-scheme', theme === 'dark' ? 'light' : 'dark']]))
|
parts.push(block(INVERSE_SELECTOR, [['color-scheme', theme === 'dark' ? 'light' : 'dark']]))
|
||||||
}
|
}
|
||||||
return parts.filter(Boolean).join('\n\n') + '\n'
|
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. */
|
/** Roles whose light value carries over to dark when the brand sets no dark value. */
|
||||||
export const BRAND_ROLES: readonly ColorRole[] = [
|
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) {
|
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 { contrastRatio, parseColor } from './color.js'
|
||||||
export { contrastReport } from './contrast.js'
|
export { contrastReport } from './contrast.js'
|
||||||
export type { ContrastRow } 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 { defineTokens, resolveColors } from './define.js'
|
||||||
export type { ColorInput, TokensInput } from './define.js'
|
export type { ColorInput, TokensInput } from './define.js'
|
||||||
export { FLUID_RANGES, FLUID_SCALE, fluidClamp } from './fluid.js'
|
export { FLUID_RANGES, FLUID_SCALE, fluidClamp } from './fluid.js'
|
||||||
|
|||||||
@@ -134,8 +134,9 @@
|
|||||||
letter-spacing: var(--ipal-tracking-heading);
|
letter-spacing: var(--ipal-tracking-heading);
|
||||||
line-height: var(--ipal-lh-heading);
|
line-height: var(--ipal-lh-heading);
|
||||||
}
|
}
|
||||||
/* a scope that re-maps the text roles (data-surface="inverse") also sets its own text colour */
|
/* a scope that re-maps the text roles (data-surface="inverse", a nested data-theme panel) also sets its text colour */
|
||||||
[data-surface] {
|
[data-surface],
|
||||||
|
[data-theme] {
|
||||||
color: var(--ipal-text);
|
color: var(--ipal-text);
|
||||||
}
|
}
|
||||||
:focus-visible {
|
:focus-visible {
|
||||||
|
|||||||
+44
-29
@@ -2,14 +2,41 @@
|
|||||||
* @intecion/ipal-kit/tokens.css — neutral defaults for every --ipal-* design token
|
* @intecion/ipal-kit/tokens.css — neutral defaults for every --ipal-* design token
|
||||||
* (generated from src/modules/tokens/catalog.ts; docs/design-tokens.md).
|
* (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>,
|
* Light values on :root, dark values on [data-theme="dark"] (on <html> set by <ThemeScript>,
|
||||||
* storage key "theme"). A brand overrides them in src/design/tokens.css, generated by
|
* 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.
|
* `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.
|
* 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.
|
* The type and space scale is in fluid.css / fluid-wide.css — import one of them as well.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
:root {
|
: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-bg: oklch(1 0 0);
|
||||||
--ipal-border: oklch(0.922 0 0);
|
--ipal-border: oklch(0.922 0 0);
|
||||||
--ipal-border-strong: oklch(0.87 0 0);
|
--ipal-border-strong: oklch(0.87 0 0);
|
||||||
@@ -36,6 +63,8 @@
|
|||||||
--ipal-link-inverse: var(--ipal-text-inverse);
|
--ipal-link-inverse: var(--ipal-text-inverse);
|
||||||
--ipal-overlay: oklch(0 0 0 / 0.5);
|
--ipal-overlay: oklch(0 0 0 / 0.5);
|
||||||
--ipal-primary-hover: color-mix(in oklch, var(--ipal-primary), black 12%);
|
--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-primary-text: oklch(1 0 0);
|
||||||
--ipal-secondary: var(--ipal-text-strong);
|
--ipal-secondary: var(--ipal-text-strong);
|
||||||
--ipal-secondary-hover: color-mix(in oklch, var(--ipal-secondary), white 18%);
|
--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-success-surface: oklch(0.982 0.018 155.826);
|
||||||
--ipal-warning: oklch(0.555 0.163 48.998);
|
--ipal-warning: oklch(0.555 0.163 48.998);
|
||||||
--ipal-warning-surface: oklch(0.987 0.022 95.277);
|
--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-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-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-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;
|
color-scheme: light;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root[data-theme="dark"] {
|
:root[data-theme="dark"], [data-theme="dark"] {
|
||||||
--ipal-bg: oklch(0.145 0 0);
|
--ipal-bg: oklch(0.145 0 0);
|
||||||
--ipal-border: oklch(0.269 0 0);
|
--ipal-border: oklch(0.269 0 0);
|
||||||
--ipal-border-strong: oklch(0.371 0 0);
|
--ipal-border-strong: oklch(0.371 0 0);
|
||||||
@@ -101,6 +106,8 @@
|
|||||||
--ipal-link-inverse: var(--ipal-text-inverse);
|
--ipal-link-inverse: var(--ipal-text-inverse);
|
||||||
--ipal-overlay: oklch(0 0 0 / 0.65);
|
--ipal-overlay: oklch(0 0 0 / 0.65);
|
||||||
--ipal-primary-hover: color-mix(in oklch, var(--ipal-primary), black 12%);
|
--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-primary-text: oklch(1 0 0);
|
||||||
--ipal-secondary: var(--ipal-text-strong);
|
--ipal-secondary: var(--ipal-text-strong);
|
||||||
--ipal-secondary-hover: color-mix(in oklch, var(--ipal-secondary), black 12%);
|
--ipal-secondary-hover: color-mix(in oklch, var(--ipal-secondary), black 12%);
|
||||||
@@ -124,7 +131,8 @@
|
|||||||
color-scheme: dark;
|
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"] {
|
[data-surface="inverse"] {
|
||||||
--ipal-border: color-mix(in oklch, var(--ipal-text-inverse) 18%, var(--ipal-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-focus: var(--ipal-focus-inverse);
|
||||||
--ipal-hover: color-mix(in oklch, var(--ipal-text-inverse) 12%, var(--ipal-surface-inverse));
|
--ipal-hover: color-mix(in oklch, var(--ipal-text-inverse) 12%, var(--ipal-surface-inverse));
|
||||||
--ipal-link: var(--ipal-link-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-surface: color-mix(in oklch, var(--ipal-text-inverse) 8%, var(--ipal-surface-inverse));
|
||||||
--ipal-text: var(--ipal-text-inverse);
|
--ipal-text: var(--ipal-text-inverse);
|
||||||
--ipal-text-muted: color-mix(in oklch, var(--ipal-text-inverse) 72%, var(--ipal-surface-inverse));
|
--ipal-text-muted: color-mix(in oklch, var(--ipal-text-inverse) 72%, var(--ipal-surface-inverse));
|
||||||
@@ -140,10 +151,14 @@
|
|||||||
color-scheme: dark;
|
color-scheme: dark;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root[data-theme="dark"] [data-surface="inverse"] {
|
[data-theme="dark"] [data-surface="inverse"] {
|
||||||
color-scheme: light;
|
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). */
|
/* No motion for people who asked for none (the a11y widget's "no animations" too). */
|
||||||
|
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
|||||||
@@ -48,8 +48,9 @@ describe('shipped CSS files', () => {
|
|||||||
|
|
||||||
test('the preset maps every colour role and keeps the dark variant on data-theme', () => {
|
test('the preset maps every colour role and keeps the dark variant on data-theme', () => {
|
||||||
const preset = read('src/styles/tailwind.css')
|
const preset = read('src/styles/tailwind.css')
|
||||||
// link-inverse / focus-inverse are read through the inverse scope, not by a utility
|
// *-inverse roles are read through the inverse scope, not by a utility
|
||||||
for (const role of Object.keys(COLOR_DEFAULTS).filter((r) => r !== 'link-inverse' && r !== 'focus-inverse')) {
|
const scoped = ['link-inverse', 'focus-inverse', 'primary-inverse', 'primary-inverse-text']
|
||||||
|
for (const role of Object.keys(COLOR_DEFAULTS).filter((r) => !scoped.includes(r))) {
|
||||||
expect(preset, role).toContain(`var(--ipal-${role})`)
|
expect(preset, role).toContain(`var(--ipal-${role})`)
|
||||||
}
|
}
|
||||||
expect(preset).toContain('@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));')
|
expect(preset).toContain('@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));')
|
||||||
@@ -127,10 +128,35 @@ describe('defineTokens / tokensToCss', () => {
|
|||||||
expect(light).toEqual(dark)
|
expect(light).toEqual(dark)
|
||||||
const css = tokensToCss(tokens)
|
const css = tokensToCss(tokens)
|
||||||
expect(css).toContain('color-scheme: dark;')
|
expect(css).toContain('color-scheme: dark;')
|
||||||
expect(css.match(/--ipal-bg: #070707;/g)).toHaveLength(2)
|
expect(css.match(/--ipal-bg: #070707;/g)).toHaveLength(1)
|
||||||
|
expect(css).toContain(':root, [data-theme="light"], :root[data-theme="dark"], [data-theme="dark"] {')
|
||||||
expect(contrastReport(tokens).every((r) => r.theme === 'dark')).toBe(true)
|
expect(contrastReport(tokens).every((r) => r.theme === 'dark')).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('themes switch on any element, not only <html>', () => {
|
||||||
|
const defaults = defaultTokensCss()
|
||||||
|
expect(defaults).toContain(':root, [data-theme="light"] {')
|
||||||
|
expect(defaults).toContain(':root[data-theme="dark"], [data-theme="dark"] {')
|
||||||
|
const css = tokensToCss({ color: { dark: { bg: '#111' }, light: { bg: '#fefefe' } } })
|
||||||
|
expect(css).toMatch(/:root, \[data-theme="light"\] \{\n {2}--ipal-bg: #fefefe;/)
|
||||||
|
expect(css).toMatch(/:root\[data-theme="dark"\], \[data-theme="dark"\] \{\n {2}--ipal-bg: #111;/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('primary is re-mapped inside an inverted section and checked there', () => {
|
||||||
|
expect(defaultTokensCss()).toMatch(/\[data-surface="inverse"\] \{[^}]*--ipal-primary: var\(--ipal-primary-inverse\);/)
|
||||||
|
const darkBrand = { color: { light: { primary: 'oklch(0.3 0.08 150)' } } }
|
||||||
|
const warn = contrastReport(darkBrand).find((r) => r.scope === 'inverse' && r.fg === 'primary' && r.theme === 'light')
|
||||||
|
expect(warn).toMatchObject({ level: 'warn', pass: false })
|
||||||
|
// the dark theme's inverse surface is light: there the dark brand colour works again
|
||||||
|
const fixed = contrastReport({
|
||||||
|
color: {
|
||||||
|
dark: { 'primary-inverse': 'oklch(0.3 0.08 150)', 'primary-inverse-text': 'oklch(0.98 0 0)' },
|
||||||
|
light: { ...darkBrand.color.light, 'primary-inverse': 'oklch(0.85 0.1 150)', 'primary-inverse-text': 'oklch(0.2 0.05 150)' },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(fixed.filter((r) => r.scope === 'inverse' && !r.pass)).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
test('the contrast report fails a low-contrast brand', () => {
|
test('the contrast report fails a low-contrast brand', () => {
|
||||||
const rows = contrastReport({ color: { light: { primary: '#ffeb3b', 'primary-text': '#ffffff' } } })
|
const rows = contrastReport({ color: { light: { primary: '#ffeb3b', 'primary-text': '#ffffff' } } })
|
||||||
expect(rows.find((r) => r.theme === 'light' && r.fg === 'primary-text' && r.bg === 'primary')).toMatchObject({ pass: false })
|
expect(rows.find((r) => r.theme === 'light' && r.fg === 'primary-text' && r.bg === 'primary')).toMatchObject({ pass: false })
|
||||||
|
|||||||
Reference in New Issue
Block a user