preview.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { sans } from "@pythnetwork/fonts";
  2. import { withThemeByClassName } from "@storybook/addon-themes";
  3. import type { Preview, Decorator } from "@storybook/react";
  4. import { useEffect } from "react";
  5. import "./tailwind.css";
  6. const preview = {
  7. parameters: {
  8. backgrounds: { disable: true },
  9. actions: { argTypesRegex: "^on[A-Z].*" },
  10. },
  11. } satisfies Preview;
  12. export default preview;
  13. const withRootClasses =
  14. (...classes: string[]): Decorator =>
  15. (storyFn) => {
  16. useEffect(() => {
  17. const root = document.querySelector("html");
  18. const classList = classes
  19. .flatMap((cls) => cls.split(" "))
  20. .filter(Boolean);
  21. if (root) {
  22. root.classList.add(...classList);
  23. return () => {
  24. root.classList.remove(...classList);
  25. };
  26. } else {
  27. return;
  28. }
  29. }, []);
  30. return storyFn();
  31. };
  32. export const decorators: Decorator[] = [
  33. withRootClasses("font-sans antialiased", sans.variable),
  34. withThemeByClassName({
  35. themes: {
  36. white: "light bg-white text-steel-900",
  37. light: "light bg-beige-100 text-steel-900",
  38. dark: "dark bg-steel-800 text-steel-50",
  39. darker: "dark bg-steel-900 text-steel-50",
  40. },
  41. defaultTheme: "light",
  42. }),
  43. ];