@multiplatform.one/storybook 7.34.4 → 7.36.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.
@@ -14,25 +14,26 @@ import {
14
14
  BorderRadius,
15
15
  BorderWidth,
16
16
  CornerSmoothing,
17
- Density,
18
17
  DisabledStyle,
19
18
  Elevation,
20
19
  FillStyle,
21
20
  FontWeight,
22
21
  HeadingFont,
23
22
  PageTitleScale,
24
- animationNames,
25
- Space,
26
- Size,
23
+ motionStops,
24
+ normalizeAnimationKnob,
25
+ animationDurations,
27
26
  TableZebra,
28
27
  TextAccent,
29
28
  activateThemeConfig,
30
29
  getPreset,
31
30
  getPresetNames,
31
+ useActiveScale,
32
32
  useTheme,
33
33
  PresetContext,
34
34
  defaultPreset,
35
35
  defaultKnobs,
36
+ defaultScaleInputs,
36
37
  } from "@multiplatform.one/theme";
37
38
  import { config } from "@multiplatform.one/platform";
38
39
  import { CookiesProvider } from "react-cookie";
@@ -117,11 +118,6 @@ const knobOptions: Record<string, readonly string[]> = {
117
118
  cornerSmoothing: Object.values(CornerSmoothing),
118
119
  borderWidth: Object.values(BorderWidth),
119
120
  elevation: Object.values(Elevation),
120
- space: Object.values(Space),
121
- size: Object.values(Size),
122
- // LC-76 TWO-AXES: density is its own dial (compact steps space only), so
123
- // the size × density matrix is sweepable from the toolbar / URL globals.
124
- density: Object.values(Density),
125
121
  textAccent: Object.values(TextAccent),
126
122
  headingFont: Object.values(HeadingFont),
127
123
  bodyFont: Object.values(BodyFont),
@@ -129,7 +125,7 @@ const knobOptions: Record<string, readonly string[]> = {
129
125
  // D-11 hero-H1 dial: the page-title step is sweepable so the VERIFY probes
130
126
  // (and humans) can flip moderate/display from the toolbar or URL globals.
131
127
  pageTitleScale: Object.values(PageTitleScale),
132
- animation: ["none", ...animationNames],
128
+ animation: ["none", ...motionStops],
133
129
  // LC-40 DISABLED-VISIBLE: the disabled-treatment dial is sweepable so the
134
130
  // VERIFY probes (and humans) can flip keepLabel/dimWhole from the toolbar
135
131
  // or via URL globals.
@@ -143,8 +139,6 @@ const stateKnobFields = [
143
139
  "borderRadius",
144
140
  "borderWidth",
145
141
  "elevation",
146
- "space",
147
- "size",
148
142
  "textAccent",
149
143
  "headingFont",
150
144
  "bodyFont",
@@ -245,7 +239,7 @@ function AnimationNamesEmitter() {
245
239
  useEffect(() => {
246
240
  if (emittedRef.current) return;
247
241
  emittedRef.current = true;
248
- getChannelEmit()?.(animationNamesChannelEvent, animationNames as string[]);
242
+ getChannelEmit()?.(animationNamesChannelEvent, [...motionStops]);
249
243
  }, []);
250
244
  return null;
251
245
  }
@@ -593,6 +587,14 @@ export function createPreview(options: CreatePreviewOptions): Preview {
593
587
  // Publish registered preset names so the manager-side ThemePanel can
594
588
  // render a preset selector without importing the theme package.
595
589
  __presetNames: getPresetNames(),
590
+ // Each preset's token scale (control / type px), so the picker can say
591
+ // what a switch does to sizes and spacing.
592
+ __presetScales: Object.fromEntries(
593
+ getPresetNames().map((name) => {
594
+ const scale = getPreset(name)?.scale ?? defaultScaleInputs;
595
+ return [name, { control: scale.control, type: scale.type }];
596
+ }),
597
+ ),
596
598
  // Publish available theme color names so the ThemePanel can show only
597
599
  // colors that actually have registered Tamagui sub-themes.
598
600
  __themeColors: themeColorNames,
@@ -625,6 +627,12 @@ export function createPreview(options: CreatePreviewOptions): Preview {
625
627
  schemes: ["light", "dark"],
626
628
  themeColors: themeColorNames,
627
629
  presets: ["", ...getPresetNames()],
630
+ presetThemes: Object.fromEntries(
631
+ getPresetNames().flatMap((name) => {
632
+ const theme = getPreset(name)?.theme;
633
+ return theme ? [[name, theme]] : [];
634
+ }),
635
+ ),
628
636
  };
629
637
 
630
638
  // -- parameters ------------------------------------------------------------
@@ -711,20 +719,24 @@ export function createPreview(options: CreatePreviewOptions): Preview {
711
719
  const colorGlobal = (context.globals.color as string) || "";
712
720
 
713
721
  const requestedThemeConfig = context.globals.tamaguiConfig as string | undefined;
714
- const themeConfigName = useActiveThemeConfigName(
722
+ const requestedThemeConfigName =
715
723
  requestedThemeConfig && themeConfigNames.includes(requestedThemeConfig)
716
724
  ? requestedThemeConfig
717
- : defaultThemeConfigName,
718
- );
725
+ : defaultThemeConfigName;
726
+ const themeConfigName = useActiveThemeConfigName(requestedThemeConfigName);
719
727
 
720
728
  // Per-story theme overrides via `parameters.theme` (AC-5.4).
721
729
  // Stories can specify e.g. `parameters: { theme: { padding: "large" } }`
722
730
  // to pin a specific knob configuration for that story.
723
731
  const storyThemeParams = context.parameters?.theme as Partial<Knobs> | undefined;
724
732
 
725
- // Resolve the active preset (if any) from the `preset` global.
726
- const activePresetName = context.globals.preset as string | undefined;
733
+ // Resolve the active preset (if any) from the `preset` global. Its token
734
+ // scale is installed for the active Tamagui config before the story
735
+ // renders; the CSS repaint itself rides ThemeProvider's ScaleStyles.
736
+ const activePresetName = (context.globals.preset as string | undefined) || undefined;
727
737
  const activePreset = activePresetName ? getPreset(activePresetName) : undefined;
738
+ const presetTheme = (colorGlobal || activePreset?.theme || defaultPreset.theme) as ThemeName;
739
+ const scaleId = useActiveScale(themeConfigsByName[requestedThemeConfigName], activePresetName);
728
740
 
729
741
  const knobUpdate = useMemo(() => {
730
742
  const result: Partial<Knobs> = {};
@@ -745,6 +757,7 @@ export function createPreview(options: CreatePreviewOptions): Preview {
745
757
  (result as Record<string, unknown>)[key] = defaultKnobs[key];
746
758
  }
747
759
  }
760
+ result.animation = normalizeAnimationKnob(result.animation) ?? defaultKnobs.animation;
748
761
  for (const state of stateKeys) {
749
762
  const stateObj: Record<string, string> = {};
750
763
  let hasValues = false;
@@ -778,28 +791,19 @@ export function createPreview(options: CreatePreviewOptions): Preview {
778
791
  () => ({
779
792
  preset: {
780
793
  ...defaultPreset,
781
- theme: (colorGlobal || defaultPreset.theme) as ThemeName,
794
+ theme: presetTheme,
782
795
  knobs: { ...defaultKnobs, ...knobUpdate } as Knobs,
783
796
  },
784
797
  overrides: undefined,
798
+ presetName: activePresetName,
799
+ scaleId,
785
800
  }),
786
- [knobUpdate, colorGlobal],
801
+ [knobUpdate, presetTheme, activePresetName, scaleId],
787
802
  );
788
803
 
789
804
  const animationValue = presetCtxValue.preset.knobs.animation;
790
805
  useEffect(() => {
791
- const ms =
792
- animationValue === "none"
793
- ? "0ms"
794
- : animationValue === "quick"
795
- ? "100ms"
796
- : animationValue === "medium"
797
- ? "200ms"
798
- : animationValue === "slow" || animationValue === "lazy"
799
- ? "350ms"
800
- : animationValue === "bouncy"
801
- ? "300ms"
802
- : "200ms";
806
+ const ms = `${animationValue === "none" ? 0 : animationDurations[animationValue]}ms`;
803
807
  document.documentElement.style.setProperty("--mp-transition", ms);
804
808
  }, [animationValue]);
805
809
 
@@ -814,7 +818,7 @@ export function createPreview(options: CreatePreviewOptions): Preview {
814
818
  return (
815
819
  <PresetContext.Provider value={presetCtxValue}>
816
820
  <AppProvider
817
- key={themeConfigName}
821
+ key={`${themeConfigName}:${scaleId}`}
818
822
  themeConfig={themeConfigsByName[themeConfigName]}
819
823
  systemTheme={resolvedScheme}
820
824
  >
@@ -825,9 +829,9 @@ export function createPreview(options: CreatePreviewOptions): Preview {
825
829
  <FrappeDebugEmitter />
826
830
  <BaseThemeColorEmitter />
827
831
  {/* Always wrap in Theme so the host node exists on the default
828
- colour cell too. An empty colour global keeps the scheme
832
+ colour cell too. An empty preset theme keeps the scheme
829
833
  theme; a named colour is the Tamagui subtheme. */}
830
- <Theme name={(colorGlobal || resolvedScheme) as ThemeName}>
834
+ <Theme name={(presetTheme || resolvedScheme) as ThemeName}>
831
835
  <ThemeColorEmitter />
832
836
  <ColorChannelEmitter event={accentColorsChannelEvent} prefix="accent" />
833
837
  {storyContent}
@@ -835,8 +839,8 @@ export function createPreview(options: CreatePreviewOptions): Preview {
835
839
  {/* Opposite scheme emitters */}
836
840
  <Theme name={oppositeScheme as ThemeName}>
837
841
  <OppositeThemeColorEmitter />
838
- {colorGlobal ? (
839
- <Theme name={colorGlobal as ThemeName}>
842
+ {presetTheme ? (
843
+ <Theme name={presetTheme}>
840
844
  <ColorChannelEmitter event={baseOppositeChannelEvent} />
841
845
  <ColorChannelEmitter event={accentOppositeChannelEvent} prefix="accent" />
842
846
  </Theme>
@@ -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,EAwBjB,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,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,QAAQ,EAAE;QAAE,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;I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