@unpunnyfuns/swatchbook-blocks 1.1.0 → 1.2.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/README.md CHANGED
@@ -39,10 +39,7 @@ Block catalogue, props, and composition patterns live in the [blocks reference](
39
39
 
40
40
  ## Boundaries
41
41
 
42
- - Compose multiple blocks per page; each mounts independently.
43
- - ✅ Render outside Storybook with a hand-built or loaded `ProjectSnapshot`.
44
- - ❌ Don't import from `virtual:swatchbook/tokens`; it's the addon's internal wiring, not a public API. Use `SwatchbookProvider`.
45
- - ❌ Don't use `useGlobals` / `useArgs` from `storybook/preview-api` inside custom blocks; those hooks throw in docs context.
42
+ Blocks read from `SwatchbookProvider`, not the addon's internal `virtual:swatchbook/tokens` module; don't import that directly. And `useGlobals` / `useArgs` from `storybook/preview-api` throw in a docs context, so don't call them inside custom blocks.
46
43
 
47
44
  ## Credits
48
45
 
package/dist/index.d.mts CHANGED
@@ -111,6 +111,15 @@ interface ProjectSnapshot {
111
111
  tokenGraph?: VirtualTokenGraph;
112
112
  /** The default tuple — `{ axis: axis.default }` for every axis. */
113
113
  defaultTuple: Record<string, string>;
114
+ /**
115
+ * Starting color format for blocks that display color values:
116
+ * `config.defaultColorFormat` from core, passed through the wire
117
+ * snapshot. `useColorFormat()` falls back to this when neither a
118
+ * block's own `colorFormat` prop nor a `ColorFormatContext` override is
119
+ * active. Optional: hand-built snapshots (tests, MDX) that omit it fall
120
+ * through to the bare `'hex'` default.
121
+ */
122
+ defaultColorFormat?: ColorFormat;
114
123
  /**
115
124
  * Pre-built `resolveAt(tuple)` accessor. The addon's preview decorator
116
125
  * instantiates this once per iframe lifetime. When present, use-project
@@ -144,10 +153,17 @@ declare function useActiveTheme(): string;
144
153
  declare const AxesContext: _$react.Context<Readonly<Record<string, string>>>;
145
154
  declare function useActiveAxes(): Readonly<Record<string, string>>;
146
155
  /**
147
- * Active color-display format for the current story/docs render. Populated
148
- * by the addon's preview decorator from the `swatchbookColorFormat` global
149
- * (per-story `globals` or toolbar dropdown) and consumed by blocks that
150
- * render color-token values. Emitted CSS is unaffected.
156
+ * Active color-display format for the current story/docs render, consumed
157
+ * by blocks that render color-token values. Emitted CSS is unaffected.
158
+ *
159
+ * Sits in the middle of the precedence chain a block resolves via
160
+ * `colorFormat ?? useColorFormat()`: a block's own `colorFormat` prop wins
161
+ * over this context, which wins over the active snapshot's
162
+ * `defaultColorFormat` (from `Config.defaultColorFormat`). "Active
163
+ * snapshot" is whichever source is actually feeding the render:
164
+ * `SwatchbookProvider` when a story decorator mounted one, otherwise the
165
+ * channel-fed `TokenSnapshot` that MDX-embedded blocks (no `<Story/>`, no
166
+ * provider) read through `useProject()`'s fallback path.
151
167
  *
152
168
  * Runs through plain React context rather than Storybook's `useGlobals` so
153
169
  * per-story seeded globals flow through on first render and the same hook
@@ -155,6 +171,12 @@ declare function useActiveAxes(): Readonly<Record<string, string>>;
155
171
  * isn't available).
156
172
  */
157
173
  declare const ColorFormatContext: _$react.Context<ColorFormat | null>;
174
+ /**
175
+ * Resolves the color-display format from the context/snapshot/default
176
+ * chain: `ColorFormatContext` → active snapshot's `defaultColorFormat` →
177
+ * `'hex'`. Composing blocks read `colorFormat ?? useColorFormat()` to give
178
+ * their own `colorFormat` prop top precedence over this chain.
179
+ */
158
180
  declare function useColorFormat(): ColorFormat;
159
181
  //#endregion
160
182
  //#region src/internal/sort-tokens.d.ts
@@ -178,12 +200,19 @@ interface BorderPreviewProps {
178
200
  sortBy?: SortBy;
179
201
  /** `'asc'` (default) or `'desc'`. */
180
202
  sortDir?: SortDir;
203
+ /**
204
+ * Highest-precedence color format for this preview's values, overriding
205
+ * an outer `ColorFormatContext` and the project's `defaultColorFormat`.
206
+ * Omit to inherit the existing precedence chain (see `useColorFormat`).
207
+ */
208
+ colorFormat?: ColorFormat;
181
209
  }
182
210
  declare function BorderPreview({
183
211
  filter,
184
212
  caption,
185
213
  sortBy,
186
- sortDir
214
+ sortDir,
215
+ colorFormat
187
216
  }: BorderPreviewProps): ReactElement;
188
217
  //#endregion
189
218
  //#region src/border-preview/BorderSample.d.ts
@@ -227,13 +256,20 @@ interface ColorPaletteProps {
227
256
  sortBy?: SortBy;
228
257
  /** `'asc'` (default) or `'desc'`. */
229
258
  sortDir?: SortDir;
259
+ /**
260
+ * Highest-precedence color format for this palette's values, overriding
261
+ * an outer `ColorFormatContext` and the project's `defaultColorFormat`.
262
+ * Omit to inherit the existing precedence chain (see `useColorFormat`).
263
+ */
264
+ colorFormat?: ColorFormat;
230
265
  }
231
266
  declare function ColorPalette({
232
267
  filter,
233
268
  groupBy,
234
269
  caption,
235
270
  sortBy,
236
- sortDir
271
+ sortDir,
272
+ colorFormat
237
273
  }: ColorPaletteProps): ReactElement;
238
274
  //#endregion
239
275
  //#region src/indicators/resolve.d.ts
@@ -303,6 +339,12 @@ interface ColorTableProps {
303
339
  id?: string;
304
340
  /** Configure the per-row indicator strip. See `IndicatorsProp`. Gamut stays in the Value cell, so it is not part of this strip. */
305
341
  indicators?: IndicatorsProp;
342
+ /**
343
+ * Highest-precedence color format for this table's values, overriding
344
+ * an outer `ColorFormatContext` and the project's `defaultColorFormat`.
345
+ * Omit to inherit the existing precedence chain (see `useColorFormat`).
346
+ */
347
+ colorFormat?: ColorFormat;
306
348
  }
307
349
  /**
308
350
  * A grouped, searchable table of `$type: color` tokens. Suffix-matched
@@ -319,7 +361,8 @@ declare function ColorTable({
319
361
  onSelect,
320
362
  variants,
321
363
  id,
322
- indicators
364
+ indicators,
365
+ colorFormat
323
366
  }: ColorTableProps): ReactElement;
324
367
  //#endregion
325
368
  //#region src/Diagnostics.d.ts
@@ -471,12 +514,19 @@ interface GradientPaletteProps {
471
514
  sortBy?: SortBy;
472
515
  /** `'asc'` (default) or `'desc'`. */
473
516
  sortDir?: SortDir;
517
+ /**
518
+ * Highest-precedence color format for this palette's values, overriding
519
+ * an outer `ColorFormatContext` and the project's `defaultColorFormat`.
520
+ * Omit to inherit the existing precedence chain (see `useColorFormat`).
521
+ */
522
+ colorFormat?: ColorFormat;
474
523
  }
475
524
  declare function GradientPalette({
476
525
  filter,
477
526
  caption,
478
527
  sortBy,
479
- sortDir
528
+ sortDir,
529
+ colorFormat
480
530
  }: GradientPaletteProps): ReactElement;
481
531
  //#endregion
482
532
  //#region src/motion-preview/MotionSample.d.ts
@@ -690,6 +740,14 @@ interface TokenSnapshot {
690
740
  readonly listing: Readonly<Record<string, VirtualTokenListing>>;
691
741
  readonly tokenGraph: VirtualTokenGraph;
692
742
  readonly defaultTuple: Record<string, string>;
743
+ /**
744
+ * Starting color format for blocks that display color values:
745
+ * `config.defaultColorFormat` from core, forwarded from the addon's
746
+ * `registerTokenSource` call. `useColorFormat()` falls back to this on
747
+ * the provider-less (MDX/autodocs) path when no `ColorFormatContext`/
748
+ * channel-globals override is active.
749
+ */
750
+ readonly defaultColorFormat: ColorFormat;
693
751
  /** Monotonic counter, bumped on each update. Useful as a React key. */
694
752
  readonly version: number;
695
753
  }
@@ -728,12 +786,19 @@ interface ShadowPreviewProps {
728
786
  sortBy?: SortBy;
729
787
  /** `'asc'` (default) or `'desc'`. */
730
788
  sortDir?: SortDir;
789
+ /**
790
+ * Highest-precedence color format for this preview's values, overriding
791
+ * an outer `ColorFormatContext` and the project's `defaultColorFormat`.
792
+ * Omit to inherit the existing precedence chain (see `useColorFormat`).
793
+ */
794
+ colorFormat?: ColorFormat;
731
795
  }
732
796
  declare function ShadowPreview({
733
797
  filter,
734
798
  caption,
735
799
  sortBy,
736
- sortDir
800
+ sortDir,
801
+ colorFormat
737
802
  }: ShadowPreviewProps): ReactElement;
738
803
  //#endregion
739
804
  //#region src/shadow-preview/ShadowSample.d.ts
@@ -776,10 +841,18 @@ interface TokenDetailProps {
776
841
  path: string;
777
842
  /** Override the heading. Defaults to the path. */
778
843
  heading?: string;
844
+ /**
845
+ * Highest-precedence color format for this block's values, overriding
846
+ * an outer `ColorFormatContext` and the project's `defaultColorFormat`.
847
+ * Omit to inherit the existing precedence chain (see `useColorFormat`).
848
+ * Also governs the composed `CompositeBreakdown` / `AxisVariance` sub-parts.
849
+ */
850
+ colorFormat?: ColorFormat;
779
851
  }
780
852
  declare function TokenDetail({
781
853
  path,
782
- heading
854
+ heading,
855
+ colorFormat
783
856
  }: TokenDetailProps): ReactElement;
784
857
  //#endregion
785
858
  //#region src/token-detail/AliasChain.d.ts
@@ -804,18 +877,32 @@ declare function AliasedBy({
804
877
  interface AxisVarianceProps {
805
878
  /** Full dot-path of the token. */
806
879
  path: string;
880
+ /**
881
+ * Highest-precedence color format for this block's values, overriding
882
+ * an outer `ColorFormatContext` and the project's `defaultColorFormat`.
883
+ * Omit to inherit the existing precedence chain (see `useColorFormat`).
884
+ */
885
+ colorFormat?: ColorFormat;
807
886
  }
808
887
  declare function AxisVariance({
809
- path
888
+ path,
889
+ colorFormat
810
890
  }: AxisVarianceProps): ReactElement;
811
891
  //#endregion
812
892
  //#region src/token-detail/CompositeBreakdown.d.ts
813
893
  interface CompositeBreakdownProps {
814
894
  /** Full dot-path of the token. */
815
895
  path: string;
896
+ /**
897
+ * Highest-precedence color format for this block's values, overriding
898
+ * an outer `ColorFormatContext` and the project's `defaultColorFormat`.
899
+ * Omit to inherit the existing precedence chain (see `useColorFormat`).
900
+ */
901
+ colorFormat?: ColorFormat;
816
902
  }
817
903
  declare function CompositeBreakdown({
818
- path
904
+ path,
905
+ colorFormat
819
906
  }: CompositeBreakdownProps): ReactElement | null;
820
907
  //#endregion
821
908
  //#region src/token-detail/CompositePreview.d.ts
@@ -909,6 +996,13 @@ interface TokenNavigatorProps {
909
996
  id?: string;
910
997
  /** Configure the per-row indicator strip. See `IndicatorsProp`. */
911
998
  indicators?: IndicatorsProp;
999
+ /**
1000
+ * Highest-precedence color format for this tree's values, overriding
1001
+ * an outer `ColorFormatContext` and the project's `defaultColorFormat`.
1002
+ * Omit to inherit the existing precedence chain (see `useColorFormat`).
1003
+ * Also governs the composed row-detail `TokenDetail` slide-over.
1004
+ */
1005
+ colorFormat?: ColorFormat;
912
1006
  }
913
1007
  /**
914
1008
  * A collapsible, searchable tree of tokens with roving-tabindex keyboard
@@ -922,7 +1016,8 @@ declare function TokenNavigator({
922
1016
  searchable,
923
1017
  onSelect,
924
1018
  id,
925
- indicators
1019
+ indicators,
1020
+ colorFormat
926
1021
  }: TokenNavigatorProps): ReactElement;
927
1022
  //#endregion
928
1023
  //#region src/TokenTable.d.ts
@@ -967,6 +1062,13 @@ interface TokenTableProps {
967
1062
  id?: string;
968
1063
  /** Configure the per-row indicator strip. See `IndicatorsProp`. */
969
1064
  indicators?: IndicatorsProp;
1065
+ /**
1066
+ * Highest-precedence color format for this table's values, overriding
1067
+ * an outer `ColorFormatContext` and the project's `defaultColorFormat`.
1068
+ * Omit to inherit the existing precedence chain (see `useColorFormat`).
1069
+ * Also governs the composed row-detail `TokenDetail` slide-over.
1070
+ */
1071
+ colorFormat?: ColorFormat;
970
1072
  }
971
1073
  /**
972
1074
  * A sortable, searchable table of tokens. Click a row to inspect it in a
@@ -982,7 +1084,8 @@ declare function TokenTable({
982
1084
  searchable,
983
1085
  onSelect,
984
1086
  id,
985
- indicators
1087
+ indicators,
1088
+ colorFormat
986
1089
  }: TokenTableProps): ReactElement;
987
1090
  //#endregion
988
1091
  //#region src/TypographyScale.d.ts