@unpunnyfuns/swatchbook-switcher 0.10.2 → 0.11.2

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +60 -0
  3. package/package.json +11 -11
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Unpunny Funs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # swatchbook-switcher
2
+
3
+ Published as `@unpunnyfuns/swatchbook-switcher`. Framework-agnostic theme-switcher UI for swatchbook — axis pills, preset pills, color-format selector. Consumed by the Storybook addon toolbar and by any React host that knows how to set `data-*` attributes on the document to drive per-theme CSS.
4
+
5
+ > **Documentation:** [unpunnyfuns.github.io/swatchbook](https://unpunnyfuns.github.io/swatchbook/). Token parsing powered by [Terrazzo](https://terrazzo.app/) by the [Terrazzo team](https://github.com/terrazzoapp) via `@unpunnyfuns/swatchbook-core`.
6
+
7
+ ## Install
8
+
9
+ Most consumers pick this up transitively via `@unpunnyfuns/swatchbook-addon` — the addon re-exports the full switcher API, so `import { ThemeSwitcher } from '@unpunnyfuns/swatchbook-addon'` works and you don't need a second install line. Reach for this package directly when you want the switcher *without* the Storybook addon (a docs-site navbar, a standalone React app using swatchbook tokens):
10
+
11
+ ```sh
12
+ npm install @unpunnyfuns/swatchbook-switcher
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ import { ThemeSwitcher } from '@unpunnyfuns/swatchbook-switcher';
19
+
20
+ function SiteHeader({ axes, presets, themes }) {
21
+ return (
22
+ <ThemeSwitcher
23
+ axes={axes}
24
+ presets={presets}
25
+ themes={themes}
26
+ activeAxes={{ mode: 'Dark' }}
27
+ colorFormat="oklch"
28
+ onAxisChange={(axis, context) => {
29
+ document.documentElement.setAttribute(`data-sb-${axis}`, context);
30
+ }}
31
+ onColorFormatChange={(format) => {
32
+ document.documentElement.setAttribute('data-sb-color-format', format);
33
+ }}
34
+ />
35
+ );
36
+ }
37
+ ```
38
+
39
+ The component is pure — it doesn't read or write to storage, and it doesn't bake in any particular way of applying the active tuple. The caller decides how to translate `onAxisChange` into DOM updates, routing changes, or global state.
40
+
41
+ ## Exports
42
+
43
+ | Name | Shape |
44
+ | --- | --- |
45
+ | `ThemeSwitcher` | The popover component. |
46
+ | `ThemeSwitcherProps` | Prop types — axes, presets, themes, active axis tuple, color format, change callbacks, optional `className`. |
47
+ | `SwitcherAxis` / `SwitcherPreset` / `SwitcherTheme` | JSON-friendly shapes the component accepts. Cross-compatible with `@unpunnyfuns/swatchbook-core`'s `Project.axes` / `.presets` / `.themes` — pass them through directly. |
48
+
49
+ ## Where it's used inside this repo
50
+
51
+ - The Storybook addon's toolbar popover (`packages/addon/src/manager/toolbar.ts`).
52
+ - The docs site's navbar (`apps/docs/src/theme/Navbar/SwatchbookSwitcher/index.tsx`).
53
+
54
+ Both cases feed `ThemeSwitcher` a snapshot of the active `Project` and wire the callbacks to `document.documentElement.setAttribute` calls. If you're rendering swatchbook tokens on a site that isn't Storybook, mirror that pattern.
55
+
56
+ ## See also
57
+
58
+ - [`@unpunnyfuns/swatchbook-addon`](../addon) — Storybook addon. Re-exports `ThemeSwitcher` along with the full blocks surface.
59
+ - [`@unpunnyfuns/swatchbook-blocks`](../blocks) — MDX doc blocks that the switcher-driven axis changes propagate to.
60
+ - [`@unpunnyfuns/swatchbook-core`](../core) — the DTCG loader whose output feeds this component.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unpunnyfuns/swatchbook-switcher",
3
- "version": "0.10.2",
3
+ "version": "0.11.2",
4
4
  "description": "Framework-agnostic theme-switcher UI for swatchbook — axis pills, preset pills, color-format selector. Consumed by the Storybook addon toolbar and any React host that knows how to set data-attributes on the document.",
5
5
  "license": "MIT",
6
6
  "author": "unpunnyfuns <unpunnyfuns@gmail.com>",
@@ -43,15 +43,6 @@
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  },
46
- "scripts": {
47
- "build": "tsdown",
48
- "typecheck": "tsc --noEmit",
49
- "test": "vitest run",
50
- "test:watch": "vitest",
51
- "lint": "oxlint --deny-warnings -c ../../.oxlintrc.json src test",
52
- "format": "oxfmt -c ../../.oxfmtrc.json src test",
53
- "format:check": "oxfmt --check -c ../../.oxfmtrc.json src test"
54
- },
55
46
  "peerDependencies": {
56
47
  "react": ">=18"
57
48
  },
@@ -69,5 +60,14 @@
69
60
  },
70
61
  "dependencies": {
71
62
  "clsx": "^2.1.1"
63
+ },
64
+ "scripts": {
65
+ "build": "tsdown",
66
+ "typecheck": "tsc --noEmit",
67
+ "test": "vitest run",
68
+ "test:watch": "vitest",
69
+ "lint": "oxlint --deny-warnings -c ../../.oxlintrc.json src test",
70
+ "format": "oxfmt -c ../../.oxfmtrc.json src test",
71
+ "format:check": "oxfmt --check -c ../../.oxfmtrc.json src test"
72
72
  }
73
- }
73
+ }