-
Notifications
You must be signed in to change notification settings - Fork 708
/
preview.tsx
87 lines (79 loc) · 2.24 KB
/
preview.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import type { Preview } from "@storybook/react";
import * as React from "react";
import { useEffect } from "react";
import { TooltipProvider } from "@radix-ui/react-tooltip";
import { setEnv } from "../packages/feature-flags/src/index";
import { theme, globalCss } from "../packages/design-system/src/index";
import { color } from "../packages/design-system/src/__generated__/figma-design-tokens";
// this adds <style> tags to the <head> of the document
import "@fontsource-variable/inter";
import "@fontsource-variable/manrope";
import "@fontsource/roboto-mono";
const WaitForFonts = ({ children }) => {
const [isFontsLoaded, setIsFontsLoaded] = React.useState(false);
useEffect(() => {
let isUnsubscribed = false;
document.fonts.ready.then(() => {
if (isUnsubscribed === false) {
setIsFontsLoaded(true);
}
});
return () => {
isUnsubscribed = true;
};
}, []);
return isFontsLoaded ? (
children
) : (
<div>
Waiting for fonts to load ...
{/* not rendering children initially breaks backgrounds addon,
* so we always render it */}
<div style={{ display: "none" }}>{children}</div>
</div>
);
};
const globalStyles = globalCss({
body: {
color: theme.colors.foregroundMain,
fontFamily: theme.fonts.sans,
},
});
export const decorators: Preview["decorators"] = [
(Story) => {
globalStyles();
setEnv("*");
return (
// waiting for fonts makes screenshot tests more stable
<WaitForFonts>
<TooltipProvider>
<Story />
</TooltipProvider>
</WaitForFonts>
);
},
];
const parameters: Preview["parameters"] = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
backgrounds: {
default: "White",
values: [
{ name: "White", value: "#ffffff" },
{ name: "Black", value: "#000000" },
{ name: "Panel", value: color.backgroundPanel },
{ name: "Maintenance Dark", value: color.maintenanceDark },
{ name: "Maintenance Medium", value: color.maintenanceMedium },
{ name: "Maintenance Light", value: color.maintenanceLight },
],
},
};
export default {
decorators,
parameters,
} satisfies Preview;