Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions integrations/bricks/admin-app/src/components/LivePreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
const statuses = ['success', 'warning', 'error', 'info', 'danger'];
const defaultColors = meta.defaults?.colors ?? {};

// Auto-derivation formulas matching core/tokens.css verbatim.
// Module-level so they're defined once, not recreated per render.
const autoDarkStandard = (light) =>
`oklch(from var(${light}) clamp(0.65, calc(0.95 - l * 0.5), 0.88) calc(c * 0.9) h)`;
const autoDarkBase = (light) =>
`oklch(from var(${light}) clamp(0.16, calc(1.18 - l), 0.24) calc(c * 0.5) h)`;
const autoDark = (name) => {
const light = `--sf-color-${name}-light`;
return name === 'base' ? autoDarkBase(light) : autoDarkStandard(light);
};

/** Light / dark mode toggle for the preview panel. */
let darkMode = $state(false);

Expand All @@ -43,17 +54,22 @@
const radius = tokens.radius ?? {};
const shadows = tokens.shadows ?? {};

// When dark overrides are disabled the framework auto-derives dark colors
// via CSS relative color syntax. Mirror that exactly so the preview matches
// what the front-end actually renders. When enabled, use stored values.
const darkEnabled = colors.dark_overrides_enabled !== '0';

for (const name of brand) {
const v = colors[`brand_${name}`] ?? defaultColors.brand_hex_hints?.[name];
if (v) pairs.push(`--sf-color-${name}-light:${v}`);
const vd = colors[`brand_dark_${name}`] ?? defaultColors.brand_dark_hex_hints?.[name];
if (vd) pairs.push(`--sf-color-${name}-dark:${vd}`);
const storedDark = darkEnabled ? colors[`brand_dark_${name}`] : '';
pairs.push(`--sf-color-${name}-dark:${storedDark || autoDark(name)}`);
}
for (const name of statuses) {
const v = colors[`status_${name}`] ?? defaultColors.status_hex_hints?.[name];
if (v) pairs.push(`--sf-color-${name}-light:${v}`);
const vd = colors[`status_dark_${name}`] ?? defaultColors.status_dark_hex_hints?.[name];
if (vd) pairs.push(`--sf-color-${name}-dark:${vd}`);
const storedDark = darkEnabled ? colors[`status_dark_${name}`] : '';
pairs.push(`--sf-color-${name}-dark:${storedDark || autoDark(name)}`);
}
if (typography.font_body) pairs.push(`--sf-font-body:${typography.font_body}`);
if (typography.font_heading) pairs.push(`--sf-font-heading:${typography.font_heading}`);
Expand Down
Loading