@gjsify/adwaita-storybook 0.37.0 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/types/app.d.ts +9 -0
- package/lib/types/appearance.d.ts +15 -0
- package/lib/types/styles.d.ts +1 -1
- package/package.json +6 -5
- package/src/app.ts +34 -1
- package/src/appearance.ts +182 -0
- package/src/styles.ts +80 -0
package/lib/types/app.d.ts
CHANGED
|
@@ -17,6 +17,15 @@ export declare class StorybookWebApp implements StorybookView<StoryElement> {
|
|
|
17
17
|
private _controller;
|
|
18
18
|
private _options;
|
|
19
19
|
private _container;
|
|
20
|
+
/**
|
|
21
|
+
* Colour scheme + accent for the whole storybook, not for one story.
|
|
22
|
+
*
|
|
23
|
+
* Scoped to the storybook's own container rather than `documentElement`: this
|
|
24
|
+
* app is EMBEDDED by the website, and stamping `.theme-dark` on the document
|
|
25
|
+
* would re-theme the host page around it. `_theme.scss` scopes on the class
|
|
26
|
+
* wherever it sits, so a subtree works.
|
|
27
|
+
*/
|
|
28
|
+
private _appearance;
|
|
20
29
|
private _listEl;
|
|
21
30
|
private _previewEl;
|
|
22
31
|
private _previewTitle;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StorybookSettings } from '@gjsify/storybook-core';
|
|
2
|
+
/** Owns the browser side of {@link StorybookSettings}: the theme scope and the accent. */
|
|
3
|
+
export declare class StorybookWebAppearance {
|
|
4
|
+
readonly settings: StorybookSettings;
|
|
5
|
+
private readonly _root;
|
|
6
|
+
constructor(root?: HTMLElement);
|
|
7
|
+
private _apply;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The appearance dialog: the colour scheme, and the accent behind a switch.
|
|
11
|
+
*
|
|
12
|
+
* Built once and reused — unlike the GTK `Adw.Dialog`, `<adw-preferences-dialog>`
|
|
13
|
+
* reopens after a dismissal, so there is nothing to rebuild.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildAppearanceDialog(appearance: StorybookWebAppearance): HTMLElement;
|
package/lib/types/styles.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const STORYBOOK_WEB_CSS = "\n.sb-window {\n width: 100%;\n height: 100%;\n min-width: 0;\n min-height: 0;\n}\n\n/* Each pane in the outer split view is a flex column that fills its height. */\n.sb-sidebar-pane,\n.sb-content-pane {\n display: flex;\n flex-direction: column;\n min-height: 0;\n min-width: 0;\n flex: 1 1 auto;\n}\n\n/* The toolbar-view content holds either a scroller (sidebar) or the split view\n (content); the inner panes own the scrolling, so this level never scrolls. */\n.sb-sidebar-pane adw-toolbar-view > .adw-toolbar-view-content,\n.sb-content-pane adw-toolbar-view > .adw-toolbar-view-content {\n overflow: hidden;\n}\n\n/* Background scheme: the content header + preview + controls all sit on the\n window (story) background as one surface; only the left story-list column\n (its header + list) keeps the distinct sidebar shade. Matches the native\n renderer. The default adw-header-bar background is its own headerbar shade,\n so override it per pane here. */\n.sb-content-pane adw-header-bar {\n background-color: var(--window-bg-color);\n}\n.sb-sidebar-pane adw-header-bar {\n background-color: var(--sidebar-bg-color);\n}\n\n.sb-sidebar-scroll {\n flex: 1 1 auto;\n min-height: 0;\n overflow-y: auto;\n background-color: var(--sidebar-bg-color);\n}\n\n/* --- Story list (mirrors GTK .navigation-sidebar) --- */\n.sb-sidebar-list {\n padding: var(--spacing-xs);\n display: flex;\n flex-direction: column;\n gap: 1px;\n}\n\n.sb-category {\n font-size: var(--font-size-small);\n font-weight: 700;\n opacity: var(--dim-opacity);\n padding: 10px var(--spacing-m) 4px;\n}\n\n.sb-story-row {\n padding: var(--spacing-xs) var(--spacing-m);\n margin: 0 var(--spacing-xs);\n border-radius: var(--button-radius);\n cursor: pointer;\n color: var(--window-fg-color);\n font-size: var(--font-size-base);\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\n.sb-story-row:hover {\n background-color: var(--button-bg-color);\n}\n\n.sb-story-row.selected {\n background-color: var(--accent-bg-color);\n color: var(--accent-fg-color);\n}\n\n/* --- Preview area --- */\n.sb-preview-scroll {\n flex: 1 1 auto;\n min-height: 0;\n min-width: 0;\n overflow: auto;\n background-color: var(--window-bg-color);\n}\n\n.sb-story-page {\n display: flex;\n justify-content: center;\n padding: var(--spacing-xl) var(--spacing-m);\n min-height: 100%;\n box-sizing: border-box;\n}\n\n.sb-story-clamp {\n width: 100%;\n max-width: 600px;\n}\n\n.sb-story-group-header {\n padding: var(--spacing-xs) 2px;\n display: flex;\n flex-direction: column;\n gap: 2px;\n}\n\n.sb-story-group-title {\n font-size: var(--font-size-heading);\n font-weight: 700;\n color: var(--window-fg-color);\n}\n\n.sb-story-group-description {\n font-size: var(--font-size-base);\n opacity: var(--dim-opacity);\n color: var(--window-fg-color);\n}\n\n/* Centered, dashed-framed preview stage (mirrors the native .story-stage). */\n.story-stage {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: var(--spacing-m);\n padding: var(--spacing-l);\n margin-top: var(--spacing-s);\n border: 1px dashed rgba(127, 127, 127, 0.28);\n border-radius: var(--card-radius);\n min-height: 80px;\n}\n\n/* --- Controls panel --- */\n.sb-controls-scroll {\n height: 100%;\n overflow-y: auto;\n background-color: var(--window-bg-color);\n}\n\n.sb-controls-page {\n padding: var(--spacing-l);\n}\n\n/* Range-control card (mirrors the native .story-range-row). */\n.sb-range-row {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-xs);\n padding: var(--spacing-m);\n border-bottom: 1px solid var(--card-shade-color);\n}\n\n.sb-range-row:last-child {\n border-bottom: none;\n}\n\n.sb-range-header {\n display: flex;\n justify-content: space-between;\n align-items: baseline;\n gap: var(--spacing-m);\n}\n\n.sb-range-title {\n font-size: var(--font-size-base);\n font-weight: 700;\n color: var(--card-fg-color);\n}\n\n.sb-range-value {\n font-size: var(--font-size-base);\n font-variant-numeric: tabular-nums;\n opacity: var(--dim-opacity);\n}\n\n.sb-range-description {\n font-size: var(--font-size-small);\n opacity: var(--dim-opacity);\n}\n\n.sb-range-input {\n width: 100%;\n accent-color: var(--accent-bg-color);\n}\n\n.sb-color-input {\n width: 42px;\n height: 28px;\n padding: 0;\n border: 1px solid var(--card-shade-color);\n border-radius: var(--button-radius);\n background: none;\n cursor: pointer;\n}\n";
|
|
1
|
+
export declare const STORYBOOK_WEB_CSS = "\n/* Appearance dialog \u2014 round swatches with a selection ring. The web twin of the GTK\n renderer's rules, themselves adapted from Learn6502.\n\n The CARD is not decoration: in the dark scheme the \"dark\" swatch is a near-black\n circle on a near-black dialog and is invisible without a lighter surface behind\n it. Centring happens INSIDE the full-width card, so the row does not read as\n left-aligned under the group title. */\n.sb-swatch-card {\n display: flex;\n flex-wrap: wrap;\n justify-content: center;\n gap: 8px;\n padding: 12px;\n}\n/* Squaring the card's top alone leaves a notch: the row above lives in the group's\n own rounded list, so BOTH sides have to be squared for the join to read as one\n list. The attached card and the group rule below are the two halves of that. */\n.sb-swatch-card--attached {\n border-top-left-radius: 0;\n border-top-right-radius: 0;\n}\n.sb-attached-group .boxed-list {\n border-bottom-left-radius: 0;\n border-bottom-right-radius: 0;\n}\n/* Desaturated rather than merely dimmed: while the accent follows the desktop the\n palette must read as unavailable, not as nine slightly faded choices. */\n.sb-swatch-card--disabled {\n filter: saturate(0.4) brightness(1.05);\n opacity: 0.7;\n}\n/* A radio input, so grouping and arrow-key navigation are the platform's. Its own\n glyph is switched off because the swatch IS the indicator \u2014 a dot drawn on a\n colour competes with the ring that already says which one is selected. */\n.sb-swatch {\n appearance: none;\n -webkit-appearance: none;\n margin: 0;\n width: 24px;\n height: 24px;\n border-radius: 9999px;\n box-shadow: 0 0 0 3px transparent;\n cursor: pointer;\n /* A hairline on the fill itself. Without it the LIGHT scheme swatch is a\n near-white circle on a near-white card and vanishes \u2014 the exact mirror of the\n dark swatch on a dark dialog, and a card alone only fixes one direction.\n --border-color is a currentColor mix, so it holds in both schemes. */\n border: 1px solid var(--border-color);\n}\n.sb-swatch:checked {\n box-shadow: 0 0 0 3px var(--accent-bg-color);\n}\n.sb-swatch:focus-visible {\n outline: 2px solid var(--accent-color);\n outline-offset: 3px;\n}\n.sb-swatch:disabled {\n cursor: default;\n}\n/* The scheme swatches are larger \u2014 they are the dialog's primary choice. */\n.sb-swatch--scheme {\n width: 44px;\n height: 44px;\n}\n/* \"Follow system\" is the two schemes meeting on a diagonal, so the option looks like\n what it does instead of needing a word for it. */\n/* light_2 / dark_4 from libadwaita's palette (_palette.scss:37,44), which is what\n Learn6502's selector uses. NOT light_1 (#ffffff): pure white is invisible against\n a light card even with the hairline, and light_2 is the shade the palette offers\n for exactly this. */\n.sb-swatch--scheme-system {\n background: linear-gradient(to bottom right, #f6f5f4 49.99%, #241f31 50.01%);\n}\n.sb-swatch--scheme-light {\n background-color: #f6f5f4;\n}\n.sb-swatch--scheme-dark {\n background-color: #241f31;\n}\n\n.sb-window {\n width: 100%;\n height: 100%;\n min-width: 0;\n min-height: 0;\n}\n\n/* Each pane in the outer split view is a flex column that fills its height. */\n.sb-sidebar-pane,\n.sb-content-pane {\n display: flex;\n flex-direction: column;\n min-height: 0;\n min-width: 0;\n flex: 1 1 auto;\n}\n\n/* The toolbar-view content holds either a scroller (sidebar) or the split view\n (content); the inner panes own the scrolling, so this level never scrolls. */\n.sb-sidebar-pane adw-toolbar-view > .adw-toolbar-view-content,\n.sb-content-pane adw-toolbar-view > .adw-toolbar-view-content {\n overflow: hidden;\n}\n\n/* Background scheme: the content header + preview + controls all sit on the\n window (story) background as one surface; only the left story-list column\n (its header + list) keeps the distinct sidebar shade. Matches the native\n renderer. The default adw-header-bar background is its own headerbar shade,\n so override it per pane here. */\n.sb-content-pane adw-header-bar {\n background-color: var(--window-bg-color);\n}\n.sb-sidebar-pane adw-header-bar {\n background-color: var(--sidebar-bg-color);\n}\n\n.sb-sidebar-scroll {\n flex: 1 1 auto;\n min-height: 0;\n overflow-y: auto;\n background-color: var(--sidebar-bg-color);\n}\n\n/* --- Story list (mirrors GTK .navigation-sidebar) --- */\n.sb-sidebar-list {\n padding: var(--spacing-xs);\n display: flex;\n flex-direction: column;\n gap: 1px;\n}\n\n.sb-category {\n font-size: var(--font-size-small);\n font-weight: 700;\n opacity: var(--dim-opacity);\n padding: 10px var(--spacing-m) 4px;\n}\n\n.sb-story-row {\n padding: var(--spacing-xs) var(--spacing-m);\n margin: 0 var(--spacing-xs);\n border-radius: var(--button-radius);\n cursor: pointer;\n color: var(--window-fg-color);\n font-size: var(--font-size-base);\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\n.sb-story-row:hover {\n background-color: var(--button-bg-color);\n}\n\n.sb-story-row.selected {\n background-color: var(--accent-bg-color);\n color: var(--accent-fg-color);\n}\n\n/* --- Preview area --- */\n.sb-preview-scroll {\n flex: 1 1 auto;\n min-height: 0;\n min-width: 0;\n overflow: auto;\n background-color: var(--window-bg-color);\n}\n\n.sb-story-page {\n display: flex;\n justify-content: center;\n padding: var(--spacing-xl) var(--spacing-m);\n min-height: 100%;\n box-sizing: border-box;\n}\n\n.sb-story-clamp {\n width: 100%;\n max-width: 600px;\n}\n\n.sb-story-group-header {\n padding: var(--spacing-xs) 2px;\n display: flex;\n flex-direction: column;\n gap: 2px;\n}\n\n.sb-story-group-title {\n font-size: var(--font-size-heading);\n font-weight: 700;\n color: var(--window-fg-color);\n}\n\n.sb-story-group-description {\n font-size: var(--font-size-base);\n opacity: var(--dim-opacity);\n color: var(--window-fg-color);\n}\n\n/* Centered, dashed-framed preview stage (mirrors the native .story-stage). */\n.story-stage {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: var(--spacing-m);\n padding: var(--spacing-l);\n margin-top: var(--spacing-s);\n border: 1px dashed rgba(127, 127, 127, 0.28);\n border-radius: var(--card-radius);\n min-height: 80px;\n}\n\n/* --- Controls panel --- */\n.sb-controls-scroll {\n height: 100%;\n overflow-y: auto;\n background-color: var(--window-bg-color);\n}\n\n.sb-controls-page {\n padding: var(--spacing-l);\n}\n\n/* Range-control card (mirrors the native .story-range-row). */\n.sb-range-row {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-xs);\n padding: var(--spacing-m);\n border-bottom: 1px solid var(--card-shade-color);\n}\n\n.sb-range-row:last-child {\n border-bottom: none;\n}\n\n.sb-range-header {\n display: flex;\n justify-content: space-between;\n align-items: baseline;\n gap: var(--spacing-m);\n}\n\n.sb-range-title {\n font-size: var(--font-size-base);\n font-weight: 700;\n color: var(--card-fg-color);\n}\n\n.sb-range-value {\n font-size: var(--font-size-base);\n font-variant-numeric: tabular-nums;\n opacity: var(--dim-opacity);\n}\n\n.sb-range-description {\n font-size: var(--font-size-small);\n opacity: var(--dim-opacity);\n}\n\n.sb-range-input {\n width: 100%;\n accent-color: var(--accent-bg-color);\n}\n\n.sb-color-input {\n width: 42px;\n height: 28px;\n padding: 0;\n border: 1px solid var(--card-shade-color);\n border-radius: var(--button-radius);\n background: none;\n cursor: pointer;\n}\n";
|
|
2
2
|
/** Inject the chrome stylesheet once (idempotent, browser-only). */
|
|
3
3
|
export declare function injectStorybookStyles(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/adwaita-storybook",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "Browser renderer for the @gjsify/stories contract — the web counterpart of @gjsify/storybook, built on @gjsify/adwaita-web",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -29,12 +29,13 @@
|
|
|
29
29
|
"browser"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@gjsify/adwaita-
|
|
33
|
-
"@gjsify/
|
|
34
|
-
"@gjsify/
|
|
32
|
+
"@gjsify/adwaita-core": "^0.38.0",
|
|
33
|
+
"@gjsify/adwaita-web": "^0.38.0",
|
|
34
|
+
"@gjsify/stories": "^0.38.0",
|
|
35
|
+
"@gjsify/storybook-core": "^0.38.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@gjsify/cli": "^0.
|
|
38
|
+
"@gjsify/cli": "^0.38.0",
|
|
38
39
|
"typescript": "^6.0.3"
|
|
39
40
|
},
|
|
40
41
|
"gjsify": {
|
package/src/app.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
type StorybookView,
|
|
17
17
|
type StorySummary,
|
|
18
18
|
} from '@gjsify/storybook-core';
|
|
19
|
+
import { buildAppearanceDialog, StorybookWebAppearance } from './appearance.js';
|
|
19
20
|
import { createControlRow } from './controls.js';
|
|
20
21
|
import type { StoryElement } from './story-element.js';
|
|
21
22
|
import { injectStorybookStyles } from './styles.js';
|
|
@@ -57,6 +58,15 @@ export class StorybookWebApp implements StorybookView<StoryElement> {
|
|
|
57
58
|
private _controller = new StorybookController<StoryElement>(this, (story) => this._buildControls(story));
|
|
58
59
|
private _options: StorybookWebOptions;
|
|
59
60
|
private _container: HTMLElement;
|
|
61
|
+
/**
|
|
62
|
+
* Colour scheme + accent for the whole storybook, not for one story.
|
|
63
|
+
*
|
|
64
|
+
* Scoped to the storybook's own container rather than `documentElement`: this
|
|
65
|
+
* app is EMBEDDED by the website, and stamping `.theme-dark` on the document
|
|
66
|
+
* would re-theme the host page around it. `_theme.scss` scopes on the class
|
|
67
|
+
* wherever it sits, so a subtree works.
|
|
68
|
+
*/
|
|
69
|
+
private _appearance: StorybookWebAppearance;
|
|
60
70
|
|
|
61
71
|
private _listEl!: HTMLElement;
|
|
62
72
|
private _previewEl!: HTMLElement;
|
|
@@ -71,6 +81,7 @@ export class StorybookWebApp implements StorybookView<StoryElement> {
|
|
|
71
81
|
constructor(container: HTMLElement, options: StorybookWebOptions) {
|
|
72
82
|
this._container = container;
|
|
73
83
|
this._options = options;
|
|
84
|
+
this._appearance = new StorybookWebAppearance(container);
|
|
74
85
|
}
|
|
75
86
|
|
|
76
87
|
/** Build the UI, instantiate stories, and select the first one. */
|
|
@@ -256,7 +267,29 @@ export class StorybookWebApp implements StorybookView<StoryElement> {
|
|
|
256
267
|
controlsSplit as HTMLElement & { showSidebar: boolean }
|
|
257
268
|
).showSidebar;
|
|
258
269
|
});
|
|
259
|
-
|
|
270
|
+
// Appearance is a property of the STORYBOOK, not of any story — every story
|
|
271
|
+
// is previewed under it — so it belongs in the chrome, not in the controls.
|
|
272
|
+
const appearanceBtn = h('button', {
|
|
273
|
+
class: 'adw-header-btn sb-appearance-btn',
|
|
274
|
+
slot: 'end',
|
|
275
|
+
title: 'Appearance',
|
|
276
|
+
'aria-label': 'Appearance',
|
|
277
|
+
});
|
|
278
|
+
appearanceBtn.append(h('span', { class: 'adw-icon adw-icon--preferences-system' }));
|
|
279
|
+
const appearanceDialog = buildAppearanceDialog(this._appearance);
|
|
280
|
+
appearanceBtn.addEventListener('click', () => {
|
|
281
|
+
// Mounted on first press: a dialog nobody opens should not sit in the
|
|
282
|
+
// tree of every storybook that never asks for it.
|
|
283
|
+
if (!appearanceDialog.isConnected) this._container.append(appearanceDialog);
|
|
284
|
+
appearanceDialog.toggleAttribute('open', true);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const previewHeader = h('adw-header-bar', { slot: 'top' }, [
|
|
288
|
+
this._backBtn,
|
|
289
|
+
this._previewTitle,
|
|
290
|
+
appearanceBtn,
|
|
291
|
+
toggleControls,
|
|
292
|
+
]);
|
|
260
293
|
|
|
261
294
|
const contentPane = h('div', { slot: 'content', class: 'sb-content-pane' }, [
|
|
262
295
|
h('adw-toolbar-view', {}, [previewHeader, controlsSplit]),
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Applying the storybook's appearance settings in the browser, and the dialog
|
|
2
|
+
// that drives them — the web twin of `@gjsify/storybook`'s `appearance.ts`.
|
|
3
|
+
//
|
|
4
|
+
// The model is `@gjsify/storybook-core`'s `StorybookSettings`, so this target and
|
|
5
|
+
// the GTK one agree on what a colour scheme and an accent ARE. Only the two halves
|
|
6
|
+
// below are per-target:
|
|
7
|
+
//
|
|
8
|
+
// scheme → `.theme-dark` / `.theme-light` on the root, which is what
|
|
9
|
+
// `_theme.scss` scopes on. NEITHER class means "follow the desktop",
|
|
10
|
+
// so `'system'` removes both and lets `prefers-color-scheme` decide.
|
|
11
|
+
// accent → the two custom properties, through `@gjsify/adwaita-web`'s
|
|
12
|
+
// `applyAdwaitaAccent`.
|
|
13
|
+
//
|
|
14
|
+
// Original implementation.
|
|
15
|
+
|
|
16
|
+
import { ADW_ACCENT_COLOR_NAMES, adwaitaAccentBgColor, type AdwAccentColorName } from '@gjsify/adwaita-core';
|
|
17
|
+
import { applyAdwaitaAccent, clearAdwaitaAccent } from '@gjsify/adwaita-web';
|
|
18
|
+
import { STORYBOOK_COLOR_SCHEMES, StorybookSettings, type StorybookColorScheme } from '@gjsify/storybook-core';
|
|
19
|
+
|
|
20
|
+
const SCHEME_LABELS: Record<StorybookColorScheme, string> = {
|
|
21
|
+
system: 'Follow system',
|
|
22
|
+
light: 'Light',
|
|
23
|
+
dark: 'Dark',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const ACCENT_LABELS: Record<AdwAccentColorName, string> = {
|
|
27
|
+
blue: 'Blue',
|
|
28
|
+
teal: 'Teal',
|
|
29
|
+
green: 'Green',
|
|
30
|
+
yellow: 'Yellow',
|
|
31
|
+
orange: 'Orange',
|
|
32
|
+
red: 'Red',
|
|
33
|
+
pink: 'Pink',
|
|
34
|
+
purple: 'Purple',
|
|
35
|
+
slate: 'Slate',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** Owns the browser side of {@link StorybookSettings}: the theme scope and the accent. */
|
|
39
|
+
export class StorybookWebAppearance {
|
|
40
|
+
readonly settings: StorybookSettings;
|
|
41
|
+
private readonly _root: HTMLElement;
|
|
42
|
+
|
|
43
|
+
constructor(root: HTMLElement = document.documentElement) {
|
|
44
|
+
this._root = root;
|
|
45
|
+
const query = globalThis.matchMedia?.('(prefers-color-scheme: dark)') ?? null;
|
|
46
|
+
|
|
47
|
+
this.settings = new StorybookSettings(() => query?.matches ?? false);
|
|
48
|
+
this.settings.subscribe(() => this._apply());
|
|
49
|
+
// Wired unconditionally — `systemChanged` no-ops unless the preference is
|
|
50
|
+
// `'system'`, so the guard lives in one place.
|
|
51
|
+
query?.addEventListener('change', () => this.settings.systemChanged());
|
|
52
|
+
|
|
53
|
+
this._apply();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private _apply(): void {
|
|
57
|
+
const scheme = this.settings.colorScheme;
|
|
58
|
+
// Both classes off is the "follow the desktop" state, not a third theme:
|
|
59
|
+
// `_theme.scss` applies its dark palette from `prefers-color-scheme` when
|
|
60
|
+
// no explicit scope is present.
|
|
61
|
+
this._root.classList.toggle('theme-dark', scheme === 'dark');
|
|
62
|
+
this._root.classList.toggle('theme-light', scheme === 'light');
|
|
63
|
+
|
|
64
|
+
const accent = this.settings.resolvedAccent;
|
|
65
|
+
if (accent) applyAdwaitaAccent(accent, { target: this._root, dark: this.settings.resolvedDark });
|
|
66
|
+
else clearAdwaitaAccent(this._root);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A round swatch: a radio input, so grouping and keyboard nav come for free. */
|
|
71
|
+
function buildSwatch(name: string, value: string, label: string, classes: readonly string[]): HTMLInputElement {
|
|
72
|
+
const swatch = document.createElement('input');
|
|
73
|
+
swatch.type = 'radio';
|
|
74
|
+
swatch.name = name;
|
|
75
|
+
swatch.value = value;
|
|
76
|
+
swatch.title = label;
|
|
77
|
+
// A coloured circle has no text; without this a screen reader reads unnamed
|
|
78
|
+
// radios, and `title` is not an accessible name.
|
|
79
|
+
swatch.setAttribute('aria-label', label);
|
|
80
|
+
swatch.classList.add('sb-swatch', ...classes);
|
|
81
|
+
return swatch;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The appearance dialog: the colour scheme, and the accent behind a switch.
|
|
86
|
+
*
|
|
87
|
+
* Built once and reused — unlike the GTK `Adw.Dialog`, `<adw-preferences-dialog>`
|
|
88
|
+
* reopens after a dismissal, so there is nothing to rebuild.
|
|
89
|
+
*/
|
|
90
|
+
export function buildAppearanceDialog(appearance: StorybookWebAppearance): HTMLElement {
|
|
91
|
+
const settings = appearance.settings;
|
|
92
|
+
|
|
93
|
+
const dialog = document.createElement('adw-preferences-dialog');
|
|
94
|
+
dialog.setAttribute('title', 'Appearance');
|
|
95
|
+
const page = document.createElement('adw-preferences-page');
|
|
96
|
+
|
|
97
|
+
// --- Colour scheme ---
|
|
98
|
+
const schemeGroup = document.createElement('adw-preferences-group');
|
|
99
|
+
schemeGroup.setAttribute('title', 'Style');
|
|
100
|
+
|
|
101
|
+
const schemeCard = document.createElement('div');
|
|
102
|
+
schemeCard.className = 'card sb-swatch-card';
|
|
103
|
+
const schemeSwatches = new Map<string, HTMLInputElement>();
|
|
104
|
+
|
|
105
|
+
for (const scheme of STORYBOOK_COLOR_SCHEMES) {
|
|
106
|
+
const swatch = buildSwatch('sb-scheme', scheme, SCHEME_LABELS[scheme], [
|
|
107
|
+
'sb-swatch--scheme',
|
|
108
|
+
`sb-swatch--scheme-${scheme}`,
|
|
109
|
+
]);
|
|
110
|
+
swatch.checked = settings.colorScheme === scheme;
|
|
111
|
+
swatch.addEventListener('change', () => {
|
|
112
|
+
if (swatch.checked) settings.colorScheme = scheme;
|
|
113
|
+
});
|
|
114
|
+
schemeSwatches.set(scheme, swatch);
|
|
115
|
+
schemeCard.append(swatch);
|
|
116
|
+
}
|
|
117
|
+
schemeGroup.append(schemeCard);
|
|
118
|
+
page.append(schemeGroup);
|
|
119
|
+
|
|
120
|
+
// --- Accent ---
|
|
121
|
+
const accentGroup = document.createElement('adw-preferences-group');
|
|
122
|
+
accentGroup.setAttribute('title', 'Accent colour');
|
|
123
|
+
// Squares the group list's BOTTOM corners. The attached card squares its top;
|
|
124
|
+
// without both, the row above keeps its round bottom and the two meet with a
|
|
125
|
+
// notch at each end.
|
|
126
|
+
accentGroup.classList.add('sb-attached-group');
|
|
127
|
+
|
|
128
|
+
const accentSwitch = document.createElement('adw-switch-row');
|
|
129
|
+
accentSwitch.setAttribute('title', 'Use a custom accent colour');
|
|
130
|
+
accentSwitch.setAttribute('subtitle', 'Off follows the desktop, which owns the accent');
|
|
131
|
+
accentSwitch.toggleAttribute('active', settings.accentMode === 'custom');
|
|
132
|
+
accentGroup.append(accentSwitch);
|
|
133
|
+
|
|
134
|
+
// Attached: the switch row and the palette read as one boxed list rather than
|
|
135
|
+
// two stacked cards with a seam between them.
|
|
136
|
+
const accentCard = document.createElement('div');
|
|
137
|
+
accentCard.className = 'card sb-swatch-card sb-swatch-card--attached';
|
|
138
|
+
const accentSwatches = new Map<string, HTMLInputElement>();
|
|
139
|
+
|
|
140
|
+
for (const accent of ADW_ACCENT_COLOR_NAMES) {
|
|
141
|
+
const swatch = buildSwatch('sb-accent', accent, ACCENT_LABELS[accent], []);
|
|
142
|
+
// The fill comes from core, per swatch — one source of truth for the nine
|
|
143
|
+
// colours, and a tenth upstream would need no CSS here.
|
|
144
|
+
swatch.style.backgroundColor = adwaitaAccentBgColor(accent);
|
|
145
|
+
swatch.checked = settings.accent === accent;
|
|
146
|
+
swatch.addEventListener('change', () => {
|
|
147
|
+
if (swatch.checked) settings.accent = accent;
|
|
148
|
+
});
|
|
149
|
+
accentSwatches.set(accent, swatch);
|
|
150
|
+
accentCard.append(swatch);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const syncAccentEnabled = (custom: boolean): void => {
|
|
154
|
+
accentCard.classList.toggle('sb-swatch-card--disabled', !custom);
|
|
155
|
+
for (const swatch of accentSwatches.values()) swatch.disabled = !custom;
|
|
156
|
+
};
|
|
157
|
+
syncAccentEnabled(settings.accentMode === 'custom');
|
|
158
|
+
|
|
159
|
+
accentSwitch.addEventListener('notify::active', () => {
|
|
160
|
+
settings.accentMode = accentSwitch.hasAttribute('active') ? 'custom' : 'system';
|
|
161
|
+
});
|
|
162
|
+
accentGroup.append(accentCard);
|
|
163
|
+
page.append(accentGroup);
|
|
164
|
+
|
|
165
|
+
dialog.append(page);
|
|
166
|
+
|
|
167
|
+
// One-way sync FROM the model, so the dialog keeps no second copy of the state
|
|
168
|
+
// and a change made anywhere else still shows here.
|
|
169
|
+
settings.subscribe((state) => {
|
|
170
|
+
const scheme = schemeSwatches.get(state.colorScheme);
|
|
171
|
+
if (scheme && !scheme.checked) scheme.checked = true;
|
|
172
|
+
|
|
173
|
+
const accent = accentSwatches.get(state.accent);
|
|
174
|
+
if (accent && !accent.checked) accent.checked = true;
|
|
175
|
+
|
|
176
|
+
const custom = state.accentMode === 'custom';
|
|
177
|
+
accentSwitch.toggleAttribute('active', custom);
|
|
178
|
+
syncAccentEnabled(custom);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return dialog;
|
|
182
|
+
}
|
package/src/styles.ts
CHANGED
|
@@ -3,6 +3,86 @@
|
|
|
3
3
|
// adwaita-web CSS custom properties, so it follows the active light/dark theme.
|
|
4
4
|
|
|
5
5
|
export const STORYBOOK_WEB_CSS = `
|
|
6
|
+
/* Appearance dialog — round swatches with a selection ring. The web twin of the GTK
|
|
7
|
+
renderer's rules, themselves adapted from Learn6502.
|
|
8
|
+
|
|
9
|
+
The CARD is not decoration: in the dark scheme the "dark" swatch is a near-black
|
|
10
|
+
circle on a near-black dialog and is invisible without a lighter surface behind
|
|
11
|
+
it. Centring happens INSIDE the full-width card, so the row does not read as
|
|
12
|
+
left-aligned under the group title. */
|
|
13
|
+
.sb-swatch-card {
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-wrap: wrap;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
gap: 8px;
|
|
18
|
+
padding: 12px;
|
|
19
|
+
}
|
|
20
|
+
/* Squaring the card's top alone leaves a notch: the row above lives in the group's
|
|
21
|
+
own rounded list, so BOTH sides have to be squared for the join to read as one
|
|
22
|
+
list. The attached card and the group rule below are the two halves of that. */
|
|
23
|
+
.sb-swatch-card--attached {
|
|
24
|
+
border-top-left-radius: 0;
|
|
25
|
+
border-top-right-radius: 0;
|
|
26
|
+
}
|
|
27
|
+
.sb-attached-group .boxed-list {
|
|
28
|
+
border-bottom-left-radius: 0;
|
|
29
|
+
border-bottom-right-radius: 0;
|
|
30
|
+
}
|
|
31
|
+
/* Desaturated rather than merely dimmed: while the accent follows the desktop the
|
|
32
|
+
palette must read as unavailable, not as nine slightly faded choices. */
|
|
33
|
+
.sb-swatch-card--disabled {
|
|
34
|
+
filter: saturate(0.4) brightness(1.05);
|
|
35
|
+
opacity: 0.7;
|
|
36
|
+
}
|
|
37
|
+
/* A radio input, so grouping and arrow-key navigation are the platform's. Its own
|
|
38
|
+
glyph is switched off because the swatch IS the indicator — a dot drawn on a
|
|
39
|
+
colour competes with the ring that already says which one is selected. */
|
|
40
|
+
.sb-swatch {
|
|
41
|
+
appearance: none;
|
|
42
|
+
-webkit-appearance: none;
|
|
43
|
+
margin: 0;
|
|
44
|
+
width: 24px;
|
|
45
|
+
height: 24px;
|
|
46
|
+
border-radius: 9999px;
|
|
47
|
+
box-shadow: 0 0 0 3px transparent;
|
|
48
|
+
cursor: pointer;
|
|
49
|
+
/* A hairline on the fill itself. Without it the LIGHT scheme swatch is a
|
|
50
|
+
near-white circle on a near-white card and vanishes — the exact mirror of the
|
|
51
|
+
dark swatch on a dark dialog, and a card alone only fixes one direction.
|
|
52
|
+
--border-color is a currentColor mix, so it holds in both schemes. */
|
|
53
|
+
border: 1px solid var(--border-color);
|
|
54
|
+
}
|
|
55
|
+
.sb-swatch:checked {
|
|
56
|
+
box-shadow: 0 0 0 3px var(--accent-bg-color);
|
|
57
|
+
}
|
|
58
|
+
.sb-swatch:focus-visible {
|
|
59
|
+
outline: 2px solid var(--accent-color);
|
|
60
|
+
outline-offset: 3px;
|
|
61
|
+
}
|
|
62
|
+
.sb-swatch:disabled {
|
|
63
|
+
cursor: default;
|
|
64
|
+
}
|
|
65
|
+
/* The scheme swatches are larger — they are the dialog's primary choice. */
|
|
66
|
+
.sb-swatch--scheme {
|
|
67
|
+
width: 44px;
|
|
68
|
+
height: 44px;
|
|
69
|
+
}
|
|
70
|
+
/* "Follow system" is the two schemes meeting on a diagonal, so the option looks like
|
|
71
|
+
what it does instead of needing a word for it. */
|
|
72
|
+
/* light_2 / dark_4 from libadwaita's palette (_palette.scss:37,44), which is what
|
|
73
|
+
Learn6502's selector uses. NOT light_1 (#ffffff): pure white is invisible against
|
|
74
|
+
a light card even with the hairline, and light_2 is the shade the palette offers
|
|
75
|
+
for exactly this. */
|
|
76
|
+
.sb-swatch--scheme-system {
|
|
77
|
+
background: linear-gradient(to bottom right, #f6f5f4 49.99%, #241f31 50.01%);
|
|
78
|
+
}
|
|
79
|
+
.sb-swatch--scheme-light {
|
|
80
|
+
background-color: #f6f5f4;
|
|
81
|
+
}
|
|
82
|
+
.sb-swatch--scheme-dark {
|
|
83
|
+
background-color: #241f31;
|
|
84
|
+
}
|
|
85
|
+
|
|
6
86
|
.sb-window {
|
|
7
87
|
width: 100%;
|
|
8
88
|
height: 100%;
|