@multiplatform.one/storybook 7.16.0 → 7.17.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 +4 -1
- package/dist/cjs/CreatePreview.cjs +47 -3
- package/dist/cjs/CreatePreview.native.js +51 -3
- package/dist/cjs/CreatePreview.native.js.map +1 -1
- package/dist/esm/CreatePreview.mjs +48 -4
- package/dist/esm/CreatePreview.mjs.map +1 -1
- package/dist/esm/CreatePreview.native.js +52 -4
- package/dist/esm/CreatePreview.native.js.map +1 -1
- package/dist/esm/safeAction.native.js.map +1 -1
- package/dist/jsx/CreatePreview.mjs +48 -4
- package/dist/jsx/CreatePreview.mjs.map +1 -1
- package/dist/jsx/CreatePreview.native.js +51 -3
- package/dist/jsx/CreatePreview.native.js.map +1 -1
- package/package.json +4 -3
- package/src/CreatePreview.spec.tsx +130 -0
- package/src/CreatePreview.tsx +69 -1
- package/types/CreatePreview.d.ts +6 -0
- package/types/CreatePreview.d.ts.map +1 -1
package/src/CreatePreview.tsx
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
Space,
|
|
26
26
|
Size,
|
|
27
27
|
TextAccent,
|
|
28
|
+
activateThemeConfig,
|
|
28
29
|
getPreset,
|
|
29
30
|
getPresetNames,
|
|
30
31
|
useTheme,
|
|
@@ -76,6 +77,12 @@ export interface CreatePreviewI18n {
|
|
|
76
77
|
export interface CreatePreviewOptions {
|
|
77
78
|
/** ThemeConfig produced by createDefaultThemeConfig(). */
|
|
78
79
|
themeConfig: ThemeConfig;
|
|
80
|
+
/**
|
|
81
|
+
* More ThemeConfigs the `tamaguiConfig` toolbar global switches to, by
|
|
82
|
+
* name, e.g. `{ subset: subsetThemeConfig }`. Each must build a subset of
|
|
83
|
+
* `themeConfig`'s themes. `themeConfig` stays the default, listed as `full`.
|
|
84
|
+
*/
|
|
85
|
+
themeConfigs?: Record<string, ThemeConfig>;
|
|
79
86
|
/** i18n configuration for language switching via Storybook globals. */
|
|
80
87
|
i18n: CreatePreviewI18n;
|
|
81
88
|
/** AppProvider component produced by createApp(). */
|
|
@@ -92,6 +99,8 @@ export interface CreatePreviewOptions {
|
|
|
92
99
|
globalTypes?: Record<string, InputType>;
|
|
93
100
|
}
|
|
94
101
|
|
|
102
|
+
const defaultThemeConfigName = "full";
|
|
103
|
+
|
|
95
104
|
// ---------------------------------------------------------------------------
|
|
96
105
|
// Knob options map — enum values for Storybook controls
|
|
97
106
|
// ---------------------------------------------------------------------------
|
|
@@ -432,6 +441,38 @@ export function createPreview(options: CreatePreviewOptions): Preview {
|
|
|
432
441
|
globalTypes: extraGlobalTypes = {},
|
|
433
442
|
} = options;
|
|
434
443
|
|
|
444
|
+
// -- Tamagui config switch -------------------------------------------------
|
|
445
|
+
|
|
446
|
+
const themeConfigsByName: Record<string, ThemeConfig> = {
|
|
447
|
+
...options.themeConfigs,
|
|
448
|
+
[defaultThemeConfigName]: themeConfig,
|
|
449
|
+
};
|
|
450
|
+
const themeConfigNames = [
|
|
451
|
+
defaultThemeConfigName,
|
|
452
|
+
...Object.keys(themeConfigsByName).filter((name) => name !== defaultThemeConfigName),
|
|
453
|
+
];
|
|
454
|
+
const switchesThemeConfig = themeConfigNames.length > 1;
|
|
455
|
+
// Tamagui reads theme values from the themes of the config it first renders
|
|
456
|
+
// under, for good, so the preview boots on the default config and every
|
|
457
|
+
// alternate must build a subset of its themes.
|
|
458
|
+
if (switchesThemeConfig) activateThemeConfig(themeConfig);
|
|
459
|
+
let activeThemeConfigName = defaultThemeConfigName;
|
|
460
|
+
|
|
461
|
+
// Switching runs in a layout effect, not during render: dropping Tamagui's
|
|
462
|
+
// theme-name cache re-renders every mounted theme consumer. The keyed
|
|
463
|
+
// AppProvider then remounts the story under the new config before paint.
|
|
464
|
+
function useActiveThemeConfigName(requested: string): string {
|
|
465
|
+
const [active, setActive] = useState(activeThemeConfigName);
|
|
466
|
+
useLayoutEffect(() => {
|
|
467
|
+
if (requested !== activeThemeConfigName) {
|
|
468
|
+
activateThemeConfig(themeConfigsByName[requested]);
|
|
469
|
+
activeThemeConfigName = requested;
|
|
470
|
+
}
|
|
471
|
+
setActive(requested);
|
|
472
|
+
}, [requested]);
|
|
473
|
+
return active;
|
|
474
|
+
}
|
|
475
|
+
|
|
435
476
|
// -- globalTypes -----------------------------------------------------------
|
|
436
477
|
|
|
437
478
|
const enumKeys = Object.keys(knobOptions);
|
|
@@ -513,6 +554,21 @@ export function createPreview(options: CreatePreviewOptions): Preview {
|
|
|
513
554
|
},
|
|
514
555
|
};
|
|
515
556
|
|
|
557
|
+
if (switchesThemeConfig) {
|
|
558
|
+
generatedGlobalTypes.tamaguiConfig = {
|
|
559
|
+
name: "Tamagui config",
|
|
560
|
+
description: "Tamagui config the story renders under",
|
|
561
|
+
options: themeConfigNames,
|
|
562
|
+
control: { type: "select" },
|
|
563
|
+
toolbar: {
|
|
564
|
+
title: "Tamagui config",
|
|
565
|
+
icon: "paintbrush",
|
|
566
|
+
items: themeConfigNames.map((name) => ({ value: name, title: `${name} config` })),
|
|
567
|
+
dynamicTitle: true,
|
|
568
|
+
},
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
|
|
516
572
|
const globalTypes = { ...generatedGlobalTypes, ...extraGlobalTypes };
|
|
517
573
|
|
|
518
574
|
// -- initialGlobals --------------------------------------------------------
|
|
@@ -533,6 +589,7 @@ export function createPreview(options: CreatePreviewOptions): Preview {
|
|
|
533
589
|
__themeColors: themeColorNames,
|
|
534
590
|
__themeSwatches: themeSwatches,
|
|
535
591
|
preset: themeConfig.defaultPreset ?? "",
|
|
592
|
+
...(switchesThemeConfig && { tamaguiConfig: defaultThemeConfigName }),
|
|
536
593
|
};
|
|
537
594
|
// Register every knob key so Storybook allows setting them from the manager.
|
|
538
595
|
// Use empty string (not undefined) — JSON.stringify strips undefined values,
|
|
@@ -639,6 +696,13 @@ export function createPreview(options: CreatePreviewOptions): Preview {
|
|
|
639
696
|
// all Tamagui components pick it up implicitly through context.
|
|
640
697
|
const colorGlobal = (context.globals.color as string) || "";
|
|
641
698
|
|
|
699
|
+
const requestedThemeConfig = context.globals.tamaguiConfig as string | undefined;
|
|
700
|
+
const themeConfigName = useActiveThemeConfigName(
|
|
701
|
+
requestedThemeConfig && themeConfigNames.includes(requestedThemeConfig)
|
|
702
|
+
? requestedThemeConfig
|
|
703
|
+
: defaultThemeConfigName,
|
|
704
|
+
);
|
|
705
|
+
|
|
642
706
|
// Per-story theme overrides via `parameters.theme` (AC-5.4).
|
|
643
707
|
// Stories can specify e.g. `parameters: { theme: { padding: "large" } }`
|
|
644
708
|
// to pin a specific knob configuration for that story.
|
|
@@ -735,7 +799,11 @@ export function createPreview(options: CreatePreviewOptions): Preview {
|
|
|
735
799
|
|
|
736
800
|
return (
|
|
737
801
|
<PresetContext.Provider value={presetCtxValue}>
|
|
738
|
-
<AppProvider
|
|
802
|
+
<AppProvider
|
|
803
|
+
key={themeConfigName}
|
|
804
|
+
themeConfig={themeConfigsByName[themeConfigName]}
|
|
805
|
+
systemTheme={resolvedScheme}
|
|
806
|
+
>
|
|
739
807
|
{/* FontKnobStyles lives inside ThemeProvider / KnobBridge so
|
|
740
808
|
Storybook and shipped apps share one mount. A second copy
|
|
741
809
|
here would race the style-tag cleanup. */}
|
package/types/CreatePreview.d.ts
CHANGED
|
@@ -34,6 +34,12 @@ export interface CreatePreviewI18n {
|
|
|
34
34
|
export interface CreatePreviewOptions {
|
|
35
35
|
/** ThemeConfig produced by createDefaultThemeConfig(). */
|
|
36
36
|
themeConfig: ThemeConfig;
|
|
37
|
+
/**
|
|
38
|
+
* More ThemeConfigs the `tamaguiConfig` toolbar global switches to, by
|
|
39
|
+
* name, e.g. `{ subset: subsetThemeConfig }`. Each must build a subset of
|
|
40
|
+
* `themeConfig`'s themes. `themeConfig` stays the default, listed as `full`.
|
|
41
|
+
*/
|
|
42
|
+
themeConfigs?: Record<string, ThemeConfig>;
|
|
37
43
|
/** i18n configuration for language switching via Storybook globals. */
|
|
38
44
|
i18n: CreatePreviewI18n;
|
|
39
45
|
/** AppProvider component produced by createApp(). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreatePreview.d.ts","sourceRoot":"","sources":["../src/CreatePreview.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"CreatePreview.d.ts","sourceRoot":"","sources":["../src/CreatePreview.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,KAAK,WAAW,EAuBjB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAClE,eAAO,MAAM,+BAA+B,sCAAsC,CAAC;AACnF,eAAO,MAAM,2BAA2B,kCAAkC,CAAC;AAC3E,eAAO,MAAM,wBAAwB,qCAAqC,CAAC;AAC3E,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AACpE,eAAO,MAAM,0BAA0B,uCAAuC,CAAC;AAC/E,eAAO,MAAM,0BAA0B,gCAAgC,CAAC;AACxE,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAElE;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACxC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,UAAU,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC;CACvD;AAMD,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