@nswds/ui 9.4.0 → 9.6.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/dist/components/alert-dialog.js +2 -2
- package/dist/components/alert-dialog.js.map +1 -1
- package/dist/components/button-group.d.ts +2 -2
- package/dist/components/button-group.js.map +1 -1
- package/dist/components/combobox.js +2 -2
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/component-preview.d.ts +153 -0
- package/dist/components/component-preview.js +690 -0
- package/dist/components/component-preview.js.map +1 -0
- package/dist/components/dialog.js +2 -2
- package/dist/components/dialog.js.map +1 -1
- package/dist/components/drawer.js +2 -2
- package/dist/components/drawer.js.map +1 -1
- package/dist/components/dropdown-menu.js +2 -2
- package/dist/components/dropdown-menu.js.map +1 -1
- package/dist/components/hover-card.js +2 -2
- package/dist/components/hover-card.js.map +1 -1
- package/dist/components/navigation-menu.js +2 -1
- package/dist/components/navigation-menu.js.map +1 -1
- package/dist/components/popover.js +2 -2
- package/dist/components/popover.js.map +1 -1
- package/dist/components/select.js +2 -2
- package/dist/components/select.js.map +1 -1
- package/dist/components/sheet.js +2 -2
- package/dist/components/sheet.js.map +1 -1
- package/dist/components/site-search.js +2 -2
- package/dist/components/site-search.js.map +1 -1
- package/dist/components/tooltip.js +2 -2
- package/dist/components/tooltip.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/lib/portal-boundary.d.ts +47 -0
- package/dist/lib/portal-boundary.js +24 -0
- package/dist/lib/portal-boundary.js.map +1 -0
- package/dist/lib/preview-theme.d.ts +167 -0
- package/dist/lib/preview-theme.js +176 -0
- package/dist/lib/preview-theme.js.map +1 -0
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/styles/theme.css +12 -2
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What a region of the page hands the popups opened from inside it, so they
|
|
5
|
+
* look as though they were still inside it: a class, a text direction,
|
|
6
|
+
* attributes and custom properties for an element wrapped around the popup's
|
|
7
|
+
* portalled contents.
|
|
8
|
+
*
|
|
9
|
+
* A popup portals to the end of the page, so nothing set on an ancestor of its
|
|
10
|
+
* trigger reaches it through the DOM: not a custom property, not the `dark`
|
|
11
|
+
* class, not `dir`. React context does cross a portal, and every popup in this
|
|
12
|
+
* package passes through `PortalBoundary` there, which is where a scope is
|
|
13
|
+
* applied. ComponentPreview's stage provides one: its colour scheme, its
|
|
14
|
+
* tokens and its direction. `null` everywhere else, which leaves a portal's
|
|
15
|
+
* contents exactly as they were.
|
|
16
|
+
*/
|
|
17
|
+
type PortalScope = {
|
|
18
|
+
className?: string;
|
|
19
|
+
style?: React.CSSProperties;
|
|
20
|
+
dir?: 'ltr' | 'rtl';
|
|
21
|
+
/** `data-*` attributes for the wrapping element. */
|
|
22
|
+
attributes?: Record<`data-${string}`, string | undefined>;
|
|
23
|
+
};
|
|
24
|
+
declare const PortalScopeContext: React.Context<PortalScope | null>;
|
|
25
|
+
/**
|
|
26
|
+
* The one child of every portal in this package. It does the two things a
|
|
27
|
+
* portal needs because React context crosses it and the DOM does not:
|
|
28
|
+
*
|
|
29
|
+
* - resets a ButtonGroup's context, so a Button inside the popup does not
|
|
30
|
+
* render as a segment of the group the popup was opened from (see
|
|
31
|
+
* `ButtonGroupBoundary`, which does only this);
|
|
32
|
+
* - applies the `PortalScope` the popup was opened in, if there is one, by
|
|
33
|
+
* wrapping the contents in one element that carries it.
|
|
34
|
+
*
|
|
35
|
+
* That element is `display: contents`, so it generates no box: the popup is
|
|
36
|
+
* positioned and stacked as before, and only inheritance and ancestor
|
|
37
|
+
* selectors see it. Outside a scope there is no element at all.
|
|
38
|
+
*
|
|
39
|
+
* Wrap the portalled contents of an overlay from another library in this to
|
|
40
|
+
* get both. `check:portal-boundary` requires it of every portal here.
|
|
41
|
+
*/
|
|
42
|
+
declare function PortalBoundary({ children }: {
|
|
43
|
+
children: React.ReactNode;
|
|
44
|
+
}): React.JSX.Element;
|
|
45
|
+
|
|
46
|
+
export { PortalBoundary, PortalScopeContext };
|
|
47
|
+
export type { PortalScope };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { ButtonGroupBoundary } from './button-group-context.js';
|
|
5
|
+
|
|
6
|
+
const PortalScopeContext = React.createContext(null);
|
|
7
|
+
function PortalBoundary({ children }) {
|
|
8
|
+
const scope = React.useContext(PortalScopeContext);
|
|
9
|
+
return /* @__PURE__ */ jsx(ButtonGroupBoundary, { children: scope ? /* @__PURE__ */ jsx(
|
|
10
|
+
"div",
|
|
11
|
+
{
|
|
12
|
+
...scope.attributes,
|
|
13
|
+
"data-slot": "portal-scope",
|
|
14
|
+
dir: scope.dir,
|
|
15
|
+
className: scope.className ? `contents ${scope.className}` : "contents",
|
|
16
|
+
style: scope.style,
|
|
17
|
+
children
|
|
18
|
+
}
|
|
19
|
+
) : children });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { PortalBoundary, PortalScopeContext };
|
|
23
|
+
//# sourceMappingURL=portal-boundary.js.map
|
|
24
|
+
//# sourceMappingURL=portal-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/portal-boundary.tsx"],"names":[],"mappings":";;;;AA4BA,MAAM,kBAAA,GAAqB,KAAA,CAAM,aAAA,CAAkC,IAAI;AAmBvE,SAAS,cAAA,CAAe,EAAE,QAAA,EAAS,EAAkC;AACnE,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,UAAA,CAAW,kBAAkB,CAAA;AAEjD,EAAA,uBACE,GAAA,CAAC,uBACE,QAAA,EAAA,KAAA,mBACC,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACE,GAAG,KAAA,CAAM,UAAA;AAAA,MACV,WAAA,EAAU,cAAA;AAAA,MACV,KAAK,KAAA,CAAM,GAAA;AAAA,MACX,WAAW,KAAA,CAAM,SAAA,GAAY,CAAA,SAAA,EAAY,KAAA,CAAM,SAAS,CAAA,CAAA,GAAK,UAAA;AAAA,MAC7D,OAAO,KAAA,CAAM,KAAA;AAAA,MAEZ;AAAA;AAAA,MAGH,QAAA,EAEJ,CAAA;AAEJ","file":"portal-boundary.js","sourcesContent":["'use client'\n\nimport * as React from 'react'\n\nimport { ButtonGroupBoundary } from './button-group-context.js'\n\n/**\n * What a region of the page hands the popups opened from inside it, so they\n * look as though they were still inside it: a class, a text direction,\n * attributes and custom properties for an element wrapped around the popup's\n * portalled contents.\n *\n * A popup portals to the end of the page, so nothing set on an ancestor of its\n * trigger reaches it through the DOM: not a custom property, not the `dark`\n * class, not `dir`. React context does cross a portal, and every popup in this\n * package passes through `PortalBoundary` there, which is where a scope is\n * applied. ComponentPreview's stage provides one: its colour scheme, its\n * tokens and its direction. `null` everywhere else, which leaves a portal's\n * contents exactly as they were.\n */\ntype PortalScope = {\n className?: string\n style?: React.CSSProperties\n dir?: 'ltr' | 'rtl'\n /** `data-*` attributes for the wrapping element. */\n attributes?: Record<`data-${string}`, string | undefined>\n}\n\nconst PortalScopeContext = React.createContext<PortalScope | null>(null)\n\n/**\n * The one child of every portal in this package. It does the two things a\n * portal needs because React context crosses it and the DOM does not:\n *\n * - resets a ButtonGroup's context, so a Button inside the popup does not\n * render as a segment of the group the popup was opened from (see\n * `ButtonGroupBoundary`, which does only this);\n * - applies the `PortalScope` the popup was opened in, if there is one, by\n * wrapping the contents in one element that carries it.\n *\n * That element is `display: contents`, so it generates no box: the popup is\n * positioned and stacked as before, and only inheritance and ancestor\n * selectors see it. Outside a scope there is no element at all.\n *\n * Wrap the portalled contents of an overlay from another library in this to\n * get both. `check:portal-boundary` requires it of every portal here.\n */\nfunction PortalBoundary({ children }: { children: React.ReactNode }) {\n const scope = React.useContext(PortalScopeContext)\n\n return (\n <ButtonGroupBoundary>\n {scope ? (\n <div\n {...scope.attributes}\n data-slot='portal-scope'\n dir={scope.dir}\n className={scope.className ? `contents ${scope.className}` : 'contents'}\n style={scope.style}\n >\n {children}\n </div>\n ) : (\n children\n )}\n </ButtonGroupBoundary>\n )\n}\n\nexport { PortalBoundary, PortalScopeContext }\nexport type { PortalScope }\n"]}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The custom properties ComponentPreview writes onto a stage so one region of
|
|
3
|
+
* a page can render in another colour scheme, or another brand palette, than
|
|
4
|
+
* the page around it.
|
|
5
|
+
*
|
|
6
|
+
* Why a stage needs them at all: a custom property whose value is `var(...)`
|
|
7
|
+
* is resolved on the element that DECLARES it and inherited as the result.
|
|
8
|
+
* The stylesheet declares the shadcn tokens (`--background`, `--primary`, and
|
|
9
|
+
* so on) and the palette bridges (the `--color-primary-*` family) on `:root`,
|
|
10
|
+
* so they are fixed to the page's values before a nested element is reached.
|
|
11
|
+
* Redeclaring them on the stage makes them resolve again, against the stage.
|
|
12
|
+
* The bridges are redeclared only when a palette is chosen; otherwise they are
|
|
13
|
+
* the page's own, which a rebrand may have set directly.
|
|
14
|
+
*
|
|
15
|
+
* Every value here is a reference to a token, never a colour. The three maps
|
|
16
|
+
* are copies of maps owned elsewhere, and `scripts/preview-theme.test.mjs`
|
|
17
|
+
* fails when a copy drifts from its owner:
|
|
18
|
+
* - `LIGHT_ROLES` / `DARK_ROLES` mirror the semantic layers of the tokens
|
|
19
|
+
* package (each role there is one palette step);
|
|
20
|
+
* - `SHADCN_TOKENS` mirrors the `:root` block of `styles/theme.css`.
|
|
21
|
+
*
|
|
22
|
+
* Dependency-free on purpose: the test imports this file directly, and
|
|
23
|
+
* registry consumers receive it as `lib/preview-theme.ts`.
|
|
24
|
+
*/
|
|
25
|
+
type PreviewScheme = 'light' | 'dark';
|
|
26
|
+
/** The palettes of the NSW brand colour set, masterbrand's two first. */
|
|
27
|
+
declare const BRAND_PALETTES: readonly ["blue", "red", "green", "teal", "purple", "fuchsia", "orange", "yellow", "brown"];
|
|
28
|
+
/** The palettes of the NSW Aboriginal colour set. */
|
|
29
|
+
declare const ABORIGINAL_PALETTES: readonly ["aboriginal-red", "aboriginal-orange", "aboriginal-brown", "aboriginal-yellow", "aboriginal-green", "aboriginal-blue", "aboriginal-purple"];
|
|
30
|
+
type PreviewPalette = (typeof BRAND_PALETTES)[number] | (typeof ABORIGINAL_PALETTES)[number];
|
|
31
|
+
/** The steps every palette and both theme ramps carry. */
|
|
32
|
+
declare const PALETTE_STEPS: readonly [50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950];
|
|
33
|
+
/**
|
|
34
|
+
* The light role tokens as palette steps. `primary` stands for the brand ramp:
|
|
35
|
+
* the tokens package names NSW blue there, which is what masterbrand's primary
|
|
36
|
+
* ramp is, so writing the ramp lets a chosen palette reach the action and link
|
|
37
|
+
* roles too.
|
|
38
|
+
*/
|
|
39
|
+
declare const LIGHT_ROLES: {
|
|
40
|
+
readonly 'background-default': "nsw-grey-50";
|
|
41
|
+
readonly 'background-subtle': "nsw-grey-100";
|
|
42
|
+
readonly 'surface-default': "white";
|
|
43
|
+
readonly 'surface-raised': "white";
|
|
44
|
+
readonly 'surface-sunken': "nsw-grey-100";
|
|
45
|
+
readonly 'text-default': "nsw-grey-900";
|
|
46
|
+
readonly 'text-muted': "nsw-grey-600";
|
|
47
|
+
readonly 'text-subtle': "nsw-grey-500";
|
|
48
|
+
readonly 'text-inverse': "white";
|
|
49
|
+
readonly 'text-link': "primary-800";
|
|
50
|
+
readonly 'border-default': "nsw-grey-300";
|
|
51
|
+
readonly 'border-subtle': "nsw-grey-200";
|
|
52
|
+
readonly 'border-strong': "nsw-grey-500";
|
|
53
|
+
readonly 'action-default': "primary-800";
|
|
54
|
+
readonly 'action-hover': "primary-900";
|
|
55
|
+
readonly 'action-subtle': "primary-50";
|
|
56
|
+
readonly 'success-surface': "success-50";
|
|
57
|
+
readonly 'success-text': "success-700";
|
|
58
|
+
readonly 'success-border': "success-300";
|
|
59
|
+
readonly 'success-solid': "success-600";
|
|
60
|
+
readonly 'warning-surface': "warning-50";
|
|
61
|
+
readonly 'warning-text': "warning-700";
|
|
62
|
+
readonly 'warning-border': "warning-300";
|
|
63
|
+
readonly 'warning-solid': "warning-600";
|
|
64
|
+
readonly 'danger-surface': "danger-50";
|
|
65
|
+
readonly 'danger-text': "danger-700";
|
|
66
|
+
readonly 'danger-border': "danger-300";
|
|
67
|
+
readonly 'danger-solid': "danger-600";
|
|
68
|
+
readonly 'info-surface': "info-50";
|
|
69
|
+
readonly 'info-text': "info-700";
|
|
70
|
+
readonly 'info-border': "info-300";
|
|
71
|
+
readonly 'info-solid': "info-600";
|
|
72
|
+
};
|
|
73
|
+
/** The dark role tokens as palette steps; see `LIGHT_ROLES`. */
|
|
74
|
+
declare const DARK_ROLES: {
|
|
75
|
+
readonly 'background-default': "nsw-grey-950";
|
|
76
|
+
readonly 'background-subtle': "nsw-grey-900";
|
|
77
|
+
readonly 'surface-default': "nsw-grey-900";
|
|
78
|
+
readonly 'surface-raised': "nsw-grey-800";
|
|
79
|
+
readonly 'surface-sunken': "nsw-grey-950";
|
|
80
|
+
readonly 'text-default': "nsw-grey-100";
|
|
81
|
+
readonly 'text-muted': "nsw-grey-400";
|
|
82
|
+
readonly 'text-subtle': "nsw-grey-500";
|
|
83
|
+
readonly 'text-inverse': "nsw-grey-950";
|
|
84
|
+
readonly 'text-link': "primary-400";
|
|
85
|
+
readonly 'border-default': "nsw-grey-700";
|
|
86
|
+
readonly 'border-subtle': "nsw-grey-800";
|
|
87
|
+
readonly 'border-strong': "nsw-grey-500";
|
|
88
|
+
readonly 'action-default': "primary-500";
|
|
89
|
+
readonly 'action-hover': "primary-400";
|
|
90
|
+
readonly 'action-subtle': "primary-900";
|
|
91
|
+
readonly 'success-surface': "success-900";
|
|
92
|
+
readonly 'success-text': "success-300";
|
|
93
|
+
readonly 'success-border': "success-700";
|
|
94
|
+
readonly 'success-solid': "success-500";
|
|
95
|
+
readonly 'warning-surface': "warning-900";
|
|
96
|
+
readonly 'warning-text': "warning-300";
|
|
97
|
+
readonly 'warning-border': "warning-700";
|
|
98
|
+
readonly 'warning-solid': "warning-500";
|
|
99
|
+
readonly 'danger-surface': "danger-900";
|
|
100
|
+
readonly 'danger-text': "danger-300";
|
|
101
|
+
readonly 'danger-border': "danger-700";
|
|
102
|
+
readonly 'danger-solid': "danger-500";
|
|
103
|
+
readonly 'info-surface': "info-900";
|
|
104
|
+
readonly 'info-text': "info-300";
|
|
105
|
+
readonly 'info-border': "info-700";
|
|
106
|
+
readonly 'info-solid': "info-500";
|
|
107
|
+
};
|
|
108
|
+
/** The shadcn tokens and the role each one maps onto, as in `theme.css`. */
|
|
109
|
+
declare const SHADCN_TOKENS: {
|
|
110
|
+
readonly background: "surface-default";
|
|
111
|
+
readonly foreground: "text-default";
|
|
112
|
+
readonly card: "surface-raised";
|
|
113
|
+
readonly 'card-foreground': "text-default";
|
|
114
|
+
readonly popover: "surface-raised";
|
|
115
|
+
readonly 'popover-foreground': "text-default";
|
|
116
|
+
readonly primary: "action-default";
|
|
117
|
+
readonly 'primary-foreground': "text-inverse";
|
|
118
|
+
readonly secondary: "surface-sunken";
|
|
119
|
+
readonly 'secondary-foreground': "text-default";
|
|
120
|
+
readonly muted: "background-subtle";
|
|
121
|
+
readonly 'muted-foreground': "text-muted";
|
|
122
|
+
readonly accent: "background-subtle";
|
|
123
|
+
readonly 'accent-foreground': "text-default";
|
|
124
|
+
readonly destructive: "danger-solid";
|
|
125
|
+
readonly border: "border-default";
|
|
126
|
+
readonly input: "border-default";
|
|
127
|
+
readonly ring: "border-strong";
|
|
128
|
+
readonly 'input-border': "border-strong";
|
|
129
|
+
readonly 'input-foreground': "text-default";
|
|
130
|
+
readonly 'input-placeholder': "text-muted";
|
|
131
|
+
readonly 'input-surface': "surface-default";
|
|
132
|
+
readonly 'input-surface-hover': "surface-sunken";
|
|
133
|
+
readonly 'input-ring': "border-strong";
|
|
134
|
+
readonly 'input-invalid-border': "danger-solid";
|
|
135
|
+
readonly 'input-invalid-surface-hover': "danger-surface";
|
|
136
|
+
readonly 'input-invalid-ring': "danger-solid";
|
|
137
|
+
readonly 'chart-1': "primary-450";
|
|
138
|
+
readonly 'chart-2': "primary-550";
|
|
139
|
+
readonly 'chart-3': "primary-600";
|
|
140
|
+
readonly 'chart-4': "primary-650";
|
|
141
|
+
readonly 'chart-5': "primary-700";
|
|
142
|
+
readonly sidebar: "background-subtle";
|
|
143
|
+
readonly 'sidebar-foreground': "text-default";
|
|
144
|
+
readonly 'sidebar-primary': "action-default";
|
|
145
|
+
readonly 'sidebar-primary-foreground': "text-inverse";
|
|
146
|
+
readonly 'sidebar-accent': "background-subtle";
|
|
147
|
+
readonly 'sidebar-accent-foreground': "text-default";
|
|
148
|
+
readonly 'sidebar-border': "border-default";
|
|
149
|
+
readonly 'sidebar-ring': "border-strong";
|
|
150
|
+
};
|
|
151
|
+
type PreviewThemeOptions = {
|
|
152
|
+
/** The colour scheme the stage renders in. */
|
|
153
|
+
scheme: PreviewScheme;
|
|
154
|
+
/** The palette that becomes the primary ramp. Omit to keep the page's. */
|
|
155
|
+
primary?: PreviewPalette;
|
|
156
|
+
/** The palette that becomes the accent ramp. Omit to keep the page's. */
|
|
157
|
+
accent?: PreviewPalette;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* The custom properties for one stage, as a `style` object. Order matters only
|
|
161
|
+
* to a reader: palette first, then the roles that read it, then the shadcn
|
|
162
|
+
* tokens that read the roles.
|
|
163
|
+
*/
|
|
164
|
+
declare function previewThemeStyle({ scheme, primary, accent, }: PreviewThemeOptions): Record<`--${string}`, string>;
|
|
165
|
+
|
|
166
|
+
export { ABORIGINAL_PALETTES, BRAND_PALETTES, DARK_ROLES, LIGHT_ROLES, PALETTE_STEPS, SHADCN_TOKENS, previewThemeStyle };
|
|
167
|
+
export type { PreviewPalette, PreviewScheme, PreviewThemeOptions };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
const BRAND_PALETTES = [
|
|
2
|
+
"blue",
|
|
3
|
+
"red",
|
|
4
|
+
"green",
|
|
5
|
+
"teal",
|
|
6
|
+
"purple",
|
|
7
|
+
"fuchsia",
|
|
8
|
+
"orange",
|
|
9
|
+
"yellow",
|
|
10
|
+
"brown"
|
|
11
|
+
];
|
|
12
|
+
const ABORIGINAL_PALETTES = [
|
|
13
|
+
"aboriginal-red",
|
|
14
|
+
"aboriginal-orange",
|
|
15
|
+
"aboriginal-brown",
|
|
16
|
+
"aboriginal-yellow",
|
|
17
|
+
"aboriginal-green",
|
|
18
|
+
"aboriginal-blue",
|
|
19
|
+
"aboriginal-purple"
|
|
20
|
+
];
|
|
21
|
+
const PALETTE_STEPS = [
|
|
22
|
+
50,
|
|
23
|
+
100,
|
|
24
|
+
150,
|
|
25
|
+
200,
|
|
26
|
+
250,
|
|
27
|
+
300,
|
|
28
|
+
350,
|
|
29
|
+
400,
|
|
30
|
+
450,
|
|
31
|
+
500,
|
|
32
|
+
550,
|
|
33
|
+
600,
|
|
34
|
+
650,
|
|
35
|
+
700,
|
|
36
|
+
750,
|
|
37
|
+
800,
|
|
38
|
+
850,
|
|
39
|
+
900,
|
|
40
|
+
950
|
|
41
|
+
];
|
|
42
|
+
const LIGHT_ROLES = {
|
|
43
|
+
"background-default": "nsw-grey-50",
|
|
44
|
+
"background-subtle": "nsw-grey-100",
|
|
45
|
+
"surface-default": "white",
|
|
46
|
+
"surface-raised": "white",
|
|
47
|
+
"surface-sunken": "nsw-grey-100",
|
|
48
|
+
"text-default": "nsw-grey-900",
|
|
49
|
+
"text-muted": "nsw-grey-600",
|
|
50
|
+
"text-subtle": "nsw-grey-500",
|
|
51
|
+
"text-inverse": "white",
|
|
52
|
+
"text-link": "primary-800",
|
|
53
|
+
"border-default": "nsw-grey-300",
|
|
54
|
+
"border-subtle": "nsw-grey-200",
|
|
55
|
+
"border-strong": "nsw-grey-500",
|
|
56
|
+
"action-default": "primary-800",
|
|
57
|
+
"action-hover": "primary-900",
|
|
58
|
+
"action-subtle": "primary-50",
|
|
59
|
+
"success-surface": "success-50",
|
|
60
|
+
"success-text": "success-700",
|
|
61
|
+
"success-border": "success-300",
|
|
62
|
+
"success-solid": "success-600",
|
|
63
|
+
"warning-surface": "warning-50",
|
|
64
|
+
"warning-text": "warning-700",
|
|
65
|
+
"warning-border": "warning-300",
|
|
66
|
+
"warning-solid": "warning-600",
|
|
67
|
+
"danger-surface": "danger-50",
|
|
68
|
+
"danger-text": "danger-700",
|
|
69
|
+
"danger-border": "danger-300",
|
|
70
|
+
"danger-solid": "danger-600",
|
|
71
|
+
"info-surface": "info-50",
|
|
72
|
+
"info-text": "info-700",
|
|
73
|
+
"info-border": "info-300",
|
|
74
|
+
"info-solid": "info-600"
|
|
75
|
+
};
|
|
76
|
+
const DARK_ROLES = {
|
|
77
|
+
"background-default": "nsw-grey-950",
|
|
78
|
+
"background-subtle": "nsw-grey-900",
|
|
79
|
+
"surface-default": "nsw-grey-900",
|
|
80
|
+
"surface-raised": "nsw-grey-800",
|
|
81
|
+
"surface-sunken": "nsw-grey-950",
|
|
82
|
+
"text-default": "nsw-grey-100",
|
|
83
|
+
"text-muted": "nsw-grey-400",
|
|
84
|
+
"text-subtle": "nsw-grey-500",
|
|
85
|
+
"text-inverse": "nsw-grey-950",
|
|
86
|
+
"text-link": "primary-400",
|
|
87
|
+
"border-default": "nsw-grey-700",
|
|
88
|
+
"border-subtle": "nsw-grey-800",
|
|
89
|
+
"border-strong": "nsw-grey-500",
|
|
90
|
+
"action-default": "primary-500",
|
|
91
|
+
"action-hover": "primary-400",
|
|
92
|
+
"action-subtle": "primary-900",
|
|
93
|
+
"success-surface": "success-900",
|
|
94
|
+
"success-text": "success-300",
|
|
95
|
+
"success-border": "success-700",
|
|
96
|
+
"success-solid": "success-500",
|
|
97
|
+
"warning-surface": "warning-900",
|
|
98
|
+
"warning-text": "warning-300",
|
|
99
|
+
"warning-border": "warning-700",
|
|
100
|
+
"warning-solid": "warning-500",
|
|
101
|
+
"danger-surface": "danger-900",
|
|
102
|
+
"danger-text": "danger-300",
|
|
103
|
+
"danger-border": "danger-700",
|
|
104
|
+
"danger-solid": "danger-500",
|
|
105
|
+
"info-surface": "info-900",
|
|
106
|
+
"info-text": "info-300",
|
|
107
|
+
"info-border": "info-700",
|
|
108
|
+
"info-solid": "info-500"
|
|
109
|
+
};
|
|
110
|
+
const SHADCN_TOKENS = {
|
|
111
|
+
background: "surface-default",
|
|
112
|
+
foreground: "text-default",
|
|
113
|
+
card: "surface-raised",
|
|
114
|
+
"card-foreground": "text-default",
|
|
115
|
+
popover: "surface-raised",
|
|
116
|
+
"popover-foreground": "text-default",
|
|
117
|
+
primary: "action-default",
|
|
118
|
+
"primary-foreground": "text-inverse",
|
|
119
|
+
secondary: "surface-sunken",
|
|
120
|
+
"secondary-foreground": "text-default",
|
|
121
|
+
muted: "background-subtle",
|
|
122
|
+
"muted-foreground": "text-muted",
|
|
123
|
+
accent: "background-subtle",
|
|
124
|
+
"accent-foreground": "text-default",
|
|
125
|
+
destructive: "danger-solid",
|
|
126
|
+
border: "border-default",
|
|
127
|
+
input: "border-default",
|
|
128
|
+
ring: "border-strong",
|
|
129
|
+
"input-border": "border-strong",
|
|
130
|
+
"input-foreground": "text-default",
|
|
131
|
+
"input-placeholder": "text-muted",
|
|
132
|
+
"input-surface": "surface-default",
|
|
133
|
+
"input-surface-hover": "surface-sunken",
|
|
134
|
+
"input-ring": "border-strong",
|
|
135
|
+
"input-invalid-border": "danger-solid",
|
|
136
|
+
"input-invalid-surface-hover": "danger-surface",
|
|
137
|
+
"input-invalid-ring": "danger-solid",
|
|
138
|
+
"chart-1": "primary-450",
|
|
139
|
+
"chart-2": "primary-550",
|
|
140
|
+
"chart-3": "primary-600",
|
|
141
|
+
"chart-4": "primary-650",
|
|
142
|
+
"chart-5": "primary-700",
|
|
143
|
+
sidebar: "background-subtle",
|
|
144
|
+
"sidebar-foreground": "text-default",
|
|
145
|
+
"sidebar-primary": "action-default",
|
|
146
|
+
"sidebar-primary-foreground": "text-inverse",
|
|
147
|
+
"sidebar-accent": "background-subtle",
|
|
148
|
+
"sidebar-accent-foreground": "text-default",
|
|
149
|
+
"sidebar-border": "border-default",
|
|
150
|
+
"sidebar-ring": "border-strong"
|
|
151
|
+
};
|
|
152
|
+
function previewThemeStyle({
|
|
153
|
+
scheme,
|
|
154
|
+
primary,
|
|
155
|
+
accent
|
|
156
|
+
}) {
|
|
157
|
+
const style = {};
|
|
158
|
+
for (const [ramp, palette] of [
|
|
159
|
+
["primary", primary],
|
|
160
|
+
["accent", accent]
|
|
161
|
+
]) {
|
|
162
|
+
if (!palette) continue;
|
|
163
|
+
for (const step of PALETTE_STEPS) {
|
|
164
|
+
style[`--${ramp}-${step}`] = `var(--nsw-${palette}-${step})`;
|
|
165
|
+
style[`--color-${ramp}-${step}`] = `var(--${ramp}-${step})`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const roles = scheme === "dark" ? DARK_ROLES : LIGHT_ROLES;
|
|
169
|
+
for (const [role, step] of Object.entries(roles)) style[`--${role}`] = `var(--${step})`;
|
|
170
|
+
for (const [token, role] of Object.entries(SHADCN_TOKENS)) style[`--${token}`] = `var(--${role})`;
|
|
171
|
+
return style;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export { ABORIGINAL_PALETTES, BRAND_PALETTES, DARK_ROLES, LIGHT_ROLES, PALETTE_STEPS, SHADCN_TOKENS, previewThemeStyle };
|
|
175
|
+
//# sourceMappingURL=preview-theme.js.map
|
|
176
|
+
//# sourceMappingURL=preview-theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/preview-theme.ts"],"names":[],"mappings":"AA4BA,MAAM,cAAA,GAAiB;AAAA,EACrB,MAAA;AAAA,EACA,KAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAA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CAAA,EAAG,KAAA,CAAM,CAAA,EAAA,EAAK,KAAK,CAAA,CAAE,CAAA,GAAI,SAAS,IAAI,CAAA,CAAA,CAAA;AAE9F,EAAA,OAAO,KAAA;AACT","file":"preview-theme.js","sourcesContent":["/**\n * The custom properties ComponentPreview writes onto a stage so one region of\n * a page can render in another colour scheme, or another brand palette, than\n * the page around it.\n *\n * Why a stage needs them at all: a custom property whose value is `var(...)`\n * is resolved on the element that DECLARES it and inherited as the result.\n * The stylesheet declares the shadcn tokens (`--background`, `--primary`, and\n * so on) and the palette bridges (the `--color-primary-*` family) on `:root`,\n * so they are fixed to the page's values before a nested element is reached.\n * Redeclaring them on the stage makes them resolve again, against the stage.\n * The bridges are redeclared only when a palette is chosen; otherwise they are\n * the page's own, which a rebrand may have set directly.\n *\n * Every value here is a reference to a token, never a colour. The three maps\n * are copies of maps owned elsewhere, and `scripts/preview-theme.test.mjs`\n * fails when a copy drifts from its owner:\n * - `LIGHT_ROLES` / `DARK_ROLES` mirror the semantic layers of the tokens\n * package (each role there is one palette step);\n * - `SHADCN_TOKENS` mirrors the `:root` block of `styles/theme.css`.\n *\n * Dependency-free on purpose: the test imports this file directly, and\n * registry consumers receive it as `lib/preview-theme.ts`.\n */\n\ntype PreviewScheme = 'light' | 'dark'\n\n/** The palettes of the NSW brand colour set, masterbrand's two first. */\nconst BRAND_PALETTES = [\n 'blue',\n 'red',\n 'green',\n 'teal',\n 'purple',\n 'fuchsia',\n 'orange',\n 'yellow',\n 'brown',\n] as const\n\n/** The palettes of the NSW Aboriginal colour set. */\nconst ABORIGINAL_PALETTES = [\n 'aboriginal-red',\n 'aboriginal-orange',\n 'aboriginal-brown',\n 'aboriginal-yellow',\n 'aboriginal-green',\n 'aboriginal-blue',\n 'aboriginal-purple',\n] as const\n\ntype PreviewPalette = (typeof BRAND_PALETTES)[number] | (typeof ABORIGINAL_PALETTES)[number]\n\n/** The steps every palette and both theme ramps carry. */\nconst PALETTE_STEPS = [\n 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950,\n] as const\n\n/**\n * The light role tokens as palette steps. `primary` stands for the brand ramp:\n * the tokens package names NSW blue there, which is what masterbrand's primary\n * ramp is, so writing the ramp lets a chosen palette reach the action and link\n * roles too.\n */\nconst LIGHT_ROLES = {\n 'background-default': 'nsw-grey-50',\n 'background-subtle': 'nsw-grey-100',\n 'surface-default': 'white',\n 'surface-raised': 'white',\n 'surface-sunken': 'nsw-grey-100',\n 'text-default': 'nsw-grey-900',\n 'text-muted': 'nsw-grey-600',\n 'text-subtle': 'nsw-grey-500',\n 'text-inverse': 'white',\n 'text-link': 'primary-800',\n 'border-default': 'nsw-grey-300',\n 'border-subtle': 'nsw-grey-200',\n 'border-strong': 'nsw-grey-500',\n 'action-default': 'primary-800',\n 'action-hover': 'primary-900',\n 'action-subtle': 'primary-50',\n 'success-surface': 'success-50',\n 'success-text': 'success-700',\n 'success-border': 'success-300',\n 'success-solid': 'success-600',\n 'warning-surface': 'warning-50',\n 'warning-text': 'warning-700',\n 'warning-border': 'warning-300',\n 'warning-solid': 'warning-600',\n 'danger-surface': 'danger-50',\n 'danger-text': 'danger-700',\n 'danger-border': 'danger-300',\n 'danger-solid': 'danger-600',\n 'info-surface': 'info-50',\n 'info-text': 'info-700',\n 'info-border': 'info-300',\n 'info-solid': 'info-600',\n} as const\n\n/** The dark role tokens as palette steps; see `LIGHT_ROLES`. */\nconst DARK_ROLES = {\n 'background-default': 'nsw-grey-950',\n 'background-subtle': 'nsw-grey-900',\n 'surface-default': 'nsw-grey-900',\n 'surface-raised': 'nsw-grey-800',\n 'surface-sunken': 'nsw-grey-950',\n 'text-default': 'nsw-grey-100',\n 'text-muted': 'nsw-grey-400',\n 'text-subtle': 'nsw-grey-500',\n 'text-inverse': 'nsw-grey-950',\n 'text-link': 'primary-400',\n 'border-default': 'nsw-grey-700',\n 'border-subtle': 'nsw-grey-800',\n 'border-strong': 'nsw-grey-500',\n 'action-default': 'primary-500',\n 'action-hover': 'primary-400',\n 'action-subtle': 'primary-900',\n 'success-surface': 'success-900',\n 'success-text': 'success-300',\n 'success-border': 'success-700',\n 'success-solid': 'success-500',\n 'warning-surface': 'warning-900',\n 'warning-text': 'warning-300',\n 'warning-border': 'warning-700',\n 'warning-solid': 'warning-500',\n 'danger-surface': 'danger-900',\n 'danger-text': 'danger-300',\n 'danger-border': 'danger-700',\n 'danger-solid': 'danger-500',\n 'info-surface': 'info-900',\n 'info-text': 'info-300',\n 'info-border': 'info-700',\n 'info-solid': 'info-500',\n} as const\n\n/** The shadcn tokens and the role each one maps onto, as in `theme.css`. */\nconst SHADCN_TOKENS = {\n background: 'surface-default',\n foreground: 'text-default',\n card: 'surface-raised',\n 'card-foreground': 'text-default',\n popover: 'surface-raised',\n 'popover-foreground': 'text-default',\n primary: 'action-default',\n 'primary-foreground': 'text-inverse',\n secondary: 'surface-sunken',\n 'secondary-foreground': 'text-default',\n muted: 'background-subtle',\n 'muted-foreground': 'text-muted',\n accent: 'background-subtle',\n 'accent-foreground': 'text-default',\n destructive: 'danger-solid',\n border: 'border-default',\n input: 'border-default',\n ring: 'border-strong',\n 'input-border': 'border-strong',\n 'input-foreground': 'text-default',\n 'input-placeholder': 'text-muted',\n 'input-surface': 'surface-default',\n 'input-surface-hover': 'surface-sunken',\n 'input-ring': 'border-strong',\n 'input-invalid-border': 'danger-solid',\n 'input-invalid-surface-hover': 'danger-surface',\n 'input-invalid-ring': 'danger-solid',\n 'chart-1': 'primary-450',\n 'chart-2': 'primary-550',\n 'chart-3': 'primary-600',\n 'chart-4': 'primary-650',\n 'chart-5': 'primary-700',\n sidebar: 'background-subtle',\n 'sidebar-foreground': 'text-default',\n 'sidebar-primary': 'action-default',\n 'sidebar-primary-foreground': 'text-inverse',\n 'sidebar-accent': 'background-subtle',\n 'sidebar-accent-foreground': 'text-default',\n 'sidebar-border': 'border-default',\n 'sidebar-ring': 'border-strong',\n} as const\n\ntype PreviewThemeOptions = {\n /** The colour scheme the stage renders in. */\n scheme: PreviewScheme\n /** The palette that becomes the primary ramp. Omit to keep the page's. */\n primary?: PreviewPalette\n /** The palette that becomes the accent ramp. Omit to keep the page's. */\n accent?: PreviewPalette\n}\n\n/**\n * The custom properties for one stage, as a `style` object. Order matters only\n * to a reader: palette first, then the roles that read it, then the shadcn\n * tokens that read the roles.\n */\nfunction previewThemeStyle({\n scheme,\n primary,\n accent,\n}: PreviewThemeOptions): Record<`--${string}`, string> {\n const style: Record<`--${string}`, string> = {}\n\n for (const [ramp, palette] of [\n ['primary', primary],\n ['accent', accent],\n ] as const) {\n // Without a chosen palette the ramp is the page's own, and so is its\n // bridge: a rebrand may set the bridge itself (`--color-primary-800`) on\n // the page or on a wrapper, and redeclaring it here would undo that.\n if (!palette) continue\n for (const step of PALETTE_STEPS) {\n style[`--${ramp}-${step}`] = `var(--nsw-${palette}-${step})`\n style[`--color-${ramp}-${step}`] = `var(--${ramp}-${step})`\n }\n }\n\n const roles = scheme === 'dark' ? DARK_ROLES : LIGHT_ROLES\n for (const [role, step] of Object.entries(roles)) style[`--${role}`] = `var(--${step})`\n for (const [token, role] of Object.entries(SHADCN_TOKENS)) style[`--${token}`] = `var(--${role})`\n\n return style\n}\n\nexport {\n ABORIGINAL_PALETTES,\n BRAND_PALETTES,\n DARK_ROLES,\n LIGHT_ROLES,\n PALETTE_STEPS,\n SHADCN_TOKENS,\n previewThemeStyle,\n}\nexport type { PreviewPalette, PreviewScheme, PreviewThemeOptions }\n"]}
|