Skip to content

Commit 7a8a091

Browse files
committed
Better storybook setup
1 parent 0f3a26d commit 7a8a091

File tree

4 files changed

+28
-59
lines changed

4 files changed

+28
-59
lines changed

.storybook/DocsContainer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export const DocsContainer = ({ children, context }) => {
2020
.docs-story {
2121
background-color: ${backgroundColor};
2222
}
23+
[id^=story--] .container {
24+
border: 1px dashed #e8e8e8;
25+
}
2326
`}</style>
2427
<BaseContainer
2528
context={{

docs/Alert.stories.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import { Alert } from "../dist/Alert";
2+
import type { AlertProps } from "../dist/Alert";
23
import { sectionName } from "./sectionName";
34
import { getStoryFactory } from "./getStory";
5+
import { assert } from "tsafe/assert";
6+
import type { Equals } from "tsafe";
7+
8+
const severities = ["success", "warning", "info", "error"] as const;
9+
10+
assert<Equals<typeof severities[number], AlertProps["severity"]>>();
411

512
const { meta, getStory } = getStoryFactory({
613
sectionName,
714
"wrappedComponent": { Alert },
8-
"defaultWidth": 500
15+
"argTypes": {
16+
"severity": {
17+
"options": severities,
18+
"control": { "type": "radio" }
19+
}
20+
}
921
});
1022

1123
export default meta;

docs/getStory.tsx

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import type { Meta, Story } from "@storybook/react";
33
import type { ArgType } from "@storybook/addons";
44
import { symToStr } from "tsafe/symToStr";
55
import { id } from "tsafe/id";
6-
import { GlobalStyles } from "tss-react";
76
import "../dist/dsfr/dsfr.css";
8-
import { startDsfrReact, useIsDark, useColors } from "../dist";
7+
import { startDsfrReact, useIsDark } from "../dist";
98

109
startDsfrReact({ "defaultColorScheme": "system" });
1110

@@ -14,32 +13,28 @@ export function getStoryFactory<Props extends Record<string, any>>(params: {
1413
wrappedComponent: Record<string, (props: Props) => JSX.Element | null>;
1514
/** https://storybook.js.org/docs/react/essentials/controls */
1615
argTypes?: Partial<Record<keyof Props, ArgType>>;
17-
defaultWidth?: number;
16+
defaultContainerWidth?: number;
1817
}) {
19-
const { sectionName, wrappedComponent, argTypes = {}, defaultWidth } = params;
18+
const { sectionName, wrappedComponent, argTypes = {}, defaultContainerWidth } = params;
2019

2120
const Component: any = Object.entries(wrappedComponent).map(([, component]) => component)[0];
2221

2322
const Template: Story<
2423
Props & {
2524
darkMode: boolean;
26-
width: number;
25+
containerWidth: number;
2726
}
28-
> = ({ darkMode, width, ...props }) => {
27+
> = ({ darkMode, containerWidth, ...props }) => {
2928
const { setIsDark } = useIsDark();
3029

3130
useEffect(() => {
3231
setIsDark(darkMode);
3332
}, [darkMode]);
3433

35-
return (
36-
<div
37-
style={{
38-
"width": width || undefined,
39-
"border": "1px dashed #e8e8e8",
40-
"display": "inline-block"
41-
}}
42-
>
34+
return containerWidth === 0 ? (
35+
<Component {...props} />
36+
) : (
37+
<div className="container" style={{ "width": containerWidth }}>
4338
<Component {...props} />
4439
</div>
4540
);
@@ -50,7 +45,7 @@ export function getStoryFactory<Props extends Record<string, any>>(params: {
5045

5146
out.args = {
5247
"darkMode": window.matchMedia("(prefers-color-scheme: dark)").matches,
53-
"width": defaultWidth ?? 0,
48+
"containerWidth": defaultContainerWidth ?? 0,
5449
...props
5550
};
5651

@@ -62,7 +57,7 @@ export function getStoryFactory<Props extends Record<string, any>>(params: {
6257
"title": `${sectionName}/${symToStr(wrappedComponent)}`,
6358
"component": Component,
6459
"argTypes": {
65-
"width": {
60+
"containerWidth": {
6661
"control": {
6762
"type": "range",
6863
"min": 0,

yarn.lock

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,17 +1248,6 @@
12481248
source-map "^0.5.7"
12491249
stylis "4.0.13"
12501250

1251-
"@emotion/cache@*":
1252-
version "11.10.5"
1253-
resolved "https://registry.yarnpkg.com/@emotion/cache/-/cache-11.10.5.tgz#c142da9351f94e47527ed458f7bbbbe40bb13c12"
1254-
integrity sha512-dGYHWyzTdmK+f2+EnIGBpkz1lKc4Zbj2KHd4cX3Wi8/OWr5pKslNjc3yABKH4adRGCvSX4VDC0i04mrrq0aiRA==
1255-
dependencies:
1256-
"@emotion/memoize" "^0.8.0"
1257-
"@emotion/sheet" "^1.2.1"
1258-
"@emotion/utils" "^1.2.0"
1259-
"@emotion/weak-memoize" "^0.3.0"
1260-
stylis "4.1.3"
1261-
12621251
"@emotion/cache@^11.10.0", "@emotion/cache@^11.10.3":
12631252
version "11.10.3"
12641253
resolved "https://registry.yarnpkg.com/@emotion/cache/-/cache-11.10.3.tgz#c4f67904fad10c945fea5165c3a5a0583c164b87"
@@ -1301,17 +1290,6 @@
13011290
"@emotion/weak-memoize" "^0.3.0"
13021291
hoist-non-react-statics "^3.3.1"
13031292

1304-
"@emotion/serialize@*":
1305-
version "1.1.1"
1306-
resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-1.1.1.tgz#0595701b1902feded8a96d293b26be3f5c1a5cf0"
1307-
integrity sha512-Zl/0LFggN7+L1liljxXdsVSVlg6E/Z/olVWpfxUTxOAmi8NU7YoeWeLfi1RmnB2TATHoaWwIBRoL+FvAJiTUQA==
1308-
dependencies:
1309-
"@emotion/hash" "^0.9.0"
1310-
"@emotion/memoize" "^0.8.0"
1311-
"@emotion/unitless" "^0.8.0"
1312-
"@emotion/utils" "^1.2.0"
1313-
csstype "^3.0.2"
1314-
13151293
"@emotion/serialize@^1.1.0":
13161294
version "1.1.0"
13171295
resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-1.1.0.tgz#b1f97b1011b09346a40e9796c37a3397b4ea8ea8"
@@ -1328,11 +1306,6 @@
13281306
resolved "https://registry.yarnpkg.com/@emotion/sheet/-/sheet-1.2.0.tgz#771b1987855839e214fc1741bde43089397f7be5"
13291307
integrity sha512-OiTkRgpxescko+M51tZsMq7Puu/KP55wMT8BgpcXVG2hqXc0Vo0mfymJ/Uj24Hp0i083ji/o0aLddh08UEjq8w==
13301308

1331-
"@emotion/sheet@^1.2.1":
1332-
version "1.2.1"
1333-
resolved "https://registry.yarnpkg.com/@emotion/sheet/-/sheet-1.2.1.tgz#0767e0305230e894897cadb6c8df2c51e61a6c2c"
1334-
integrity sha512-zxRBwl93sHMsOj4zs+OslQKg/uhF38MB+OMKoCrVuS0nyTkqnau+BM3WGEoOptg9Oz45T/aIGs1qbVAsEFo3nA==
1335-
13361309
"@emotion/styled@^11.10.4":
13371310
version "11.10.4"
13381311
resolved "https://registry.yarnpkg.com/@emotion/styled/-/styled-11.10.4.tgz#e93f84a4d54003c2acbde178c3f97b421fce1cd4"
@@ -1355,7 +1328,7 @@
13551328
resolved "https://registry.yarnpkg.com/@emotion/use-insertion-effect-with-fallbacks/-/use-insertion-effect-with-fallbacks-1.0.0.tgz#ffadaec35dbb7885bd54de3fa267ab2f860294df"
13561329
integrity sha512-1eEgUGmkaljiBnRMTdksDV1W4kUnmwgp7X9G8B++9GYwl1lUdqSndSriIrTJ0N7LQaoauY9JJ2yhiOYK5+NI4A==
13571330

1358-
"@emotion/utils@*", "@emotion/utils@^1.2.0":
1331+
"@emotion/utils@^1.2.0":
13591332
version "1.2.0"
13601333
resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-1.2.0.tgz#9716eaccbc6b5ded2ea5a90d65562609aab0f561"
13611334
integrity sha512-sn3WH53Kzpw8oQ5mgMmIzzyAaH2ZqFEbozVVBSYp538E06OSE6ytOp7pRAjNQR+Q/orwqdQYJSe2m3hCOeznkw==
@@ -10855,11 +10828,6 @@ stylis@4.0.13:
1085510828
resolved "https://registry.yarnpkg.com/stylis/-/stylis-4.0.13.tgz#f5db332e376d13cc84ecfe5dace9a2a51d954c91"
1085610829
integrity sha512-xGPXiFVl4YED9Jh7Euv2V220mriG9u4B2TA6Ybjc1catrstKD2PpIdU3U0RKpkVBC2EhmL/F0sPCr9vrFTNRag==
1085710830

10858-
stylis@4.1.3:
10859-
version "4.1.3"
10860-
resolved "https://registry.yarnpkg.com/stylis/-/stylis-4.1.3.tgz#fd2fbe79f5fed17c55269e16ed8da14c84d069f7"
10861-
integrity sha512-GP6WDNWf+o403jrEp9c5jibKavrtLW+/qYGhFxFrG8maXhwTBI7gLLhiBb0o7uFccWN+EOS9aMO6cGHWAO07OA==
10862-
1086310831
supports-color@8.1.1, supports-color@^8.0.0:
1086410832
version "8.1.1"
1086510833
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c"
@@ -11221,15 +11189,6 @@ tslib@^2.1.0, tslib@^2.4.0:
1122111189
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
1122211190
integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==
1122311191

11224-
tss-react@^4.4.4:
11225-
version "4.4.4"
11226-
resolved "https://registry.yarnpkg.com/tss-react/-/tss-react-4.4.4.tgz#12207842dfc58676a9f4d0f532741257428a78e7"
11227-
integrity sha512-Bzyg99bIQq3Lk4Rwc5XMOps58c1biw1rghCkApIX5XkAB+/VjGCIFSl63PePhmiRNvKRxJRpawGPPxHytiw1TA==
11228-
dependencies:
11229-
"@emotion/cache" "*"
11230-
"@emotion/serialize" "*"
11231-
"@emotion/utils" "*"
11232-
1123311192
tsutils@^3.21.0:
1123411193
version "3.21.0"
1123511194
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"

0 commit comments

Comments
 (0)