@dxos/storybook-utils 0.7.5-labs.071a3e2
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/LICENSE +8 -0
- package/README.md +9 -0
- package/README.yml +1 -0
- package/dist/lib/browser/index.mjs +82 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/types/src/decorators/index.d.ts +4 -0
- package/dist/types/src/decorators/index.d.ts.map +1 -0
- package/dist/types/src/decorators/withLayout.d.ts +14 -0
- package/dist/types/src/decorators/withLayout.d.ts.map +1 -0
- package/dist/types/src/decorators/withSignals.d.ts +6 -0
- package/dist/types/src/decorators/withSignals.d.ts.map +1 -0
- package/dist/types/src/decorators/withTheme.d.ts +6 -0
- package/dist/types/src/decorators/withTheme.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +6 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +47 -0
- package/src/decorators/index.ts +7 -0
- package/src/decorators/withLayout.tsx +52 -0
- package/src/decorators/withSignals.tsx +16 -0
- package/src/decorators/withTheme.tsx +37 -0
- package/src/index.ts +12 -0
- package/src/util.tsx +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 DXOS
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @dxos/storybook-utils
|
|
2
|
+
|
|
3
|
+
Utilities for DXOS UI Storybooks.
|
|
4
|
+
|
|
5
|
+
## Contributions
|
|
6
|
+
|
|
7
|
+
Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
|
|
8
|
+
|
|
9
|
+
License: [MIT](./LICENSE) Copyright 2022 © DXOS
|
package/README.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
guideUrl: https://docs.dxos.org/guide/react/aurora/
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// packages/common/storybook-utils/src/index.ts
|
|
2
|
+
import { registerSignalsRuntime as registerSignalsRuntime2 } from "@dxos/echo-signals/react";
|
|
3
|
+
|
|
4
|
+
// packages/common/storybook-utils/src/decorators/withLayout.tsx
|
|
5
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { DensityProvider } from "@dxos/react-ui";
|
|
8
|
+
import { Tooltip } from "@dxos/react-ui";
|
|
9
|
+
import { mx } from "@dxos/react-ui-theme";
|
|
10
|
+
var defaultOptions = {
|
|
11
|
+
density: "fine"
|
|
12
|
+
};
|
|
13
|
+
var providers = [
|
|
14
|
+
(children, options) => {
|
|
15
|
+
return options.tooltips ? /* @__PURE__ */ React.createElement(Tooltip.Provider, null, children) : children;
|
|
16
|
+
},
|
|
17
|
+
(children, options) => {
|
|
18
|
+
return options?.density ? /* @__PURE__ */ React.createElement(DensityProvider, {
|
|
19
|
+
density: options.density
|
|
20
|
+
}, children) : children;
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
var withLayout = ({ classNames, fullscreen, ..._options } = {}) => {
|
|
24
|
+
return (Story, _context) => {
|
|
25
|
+
const options = defaultsDeep({}, _options, defaultOptions);
|
|
26
|
+
const children = (
|
|
27
|
+
// NOTE: Do not change the flex direction to flex-col by default.
|
|
28
|
+
/* @__PURE__ */ React.createElement("div", {
|
|
29
|
+
role: "none",
|
|
30
|
+
className: mx(fullscreen && "fixed inset-0 flex overflow-hidden", classNames)
|
|
31
|
+
}, /* @__PURE__ */ React.createElement(Story, null))
|
|
32
|
+
);
|
|
33
|
+
return providers.reduceRight((acc, provider) => provider(acc, options), children);
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// packages/common/storybook-utils/src/decorators/withSignals.tsx
|
|
38
|
+
import React2 from "react";
|
|
39
|
+
import { registerSignalsRuntime } from "@dxos/echo-signals/react";
|
|
40
|
+
var withSignals = (Story) => {
|
|
41
|
+
registerSignalsRuntime();
|
|
42
|
+
return /* @__PURE__ */ React2.createElement(Story, null);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// packages/common/storybook-utils/src/decorators/withTheme.tsx
|
|
46
|
+
import { addons } from "@storybook/preview-api";
|
|
47
|
+
import React3, { memo, useEffect, useState } from "react";
|
|
48
|
+
import { DARK_MODE_EVENT_NAME } from "storybook-dark-mode";
|
|
49
|
+
import { ThemeProvider } from "@dxos/react-ui";
|
|
50
|
+
import { defaultTx } from "@dxos/react-ui-theme";
|
|
51
|
+
var channel = addons.getChannel();
|
|
52
|
+
var withTheme = (Story, context) => {
|
|
53
|
+
const MemoizedStory = /* @__PURE__ */ memo(Story);
|
|
54
|
+
const [themeMode, setThemeMode] = useState("dark");
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const handleUpdate = (darkMode) => setThemeMode(darkMode ? "dark" : "light");
|
|
57
|
+
channel.on(DARK_MODE_EVENT_NAME, handleUpdate);
|
|
58
|
+
return () => channel.off(DARK_MODE_EVENT_NAME, handleUpdate);
|
|
59
|
+
}, [
|
|
60
|
+
channel
|
|
61
|
+
]);
|
|
62
|
+
return /* @__PURE__ */ React3.createElement(ThemeProvider, {
|
|
63
|
+
tx: defaultTx,
|
|
64
|
+
themeMode,
|
|
65
|
+
resourceExtensions: context?.parameters?.translations,
|
|
66
|
+
noCache: true
|
|
67
|
+
}, /* @__PURE__ */ React3.createElement(MemoizedStory, null));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// packages/common/storybook-utils/src/util.tsx
|
|
71
|
+
import React4 from "react";
|
|
72
|
+
var render = (r) => (args) => /* @__PURE__ */ React4.createElement(React4.Fragment, null, r(args) ?? /* @__PURE__ */ React4.createElement("div", null));
|
|
73
|
+
|
|
74
|
+
// packages/common/storybook-utils/src/index.ts
|
|
75
|
+
registerSignalsRuntime2();
|
|
76
|
+
export {
|
|
77
|
+
render,
|
|
78
|
+
withLayout,
|
|
79
|
+
withSignals,
|
|
80
|
+
withTheme
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/decorators/withLayout.tsx", "../../../src/decorators/withSignals.tsx", "../../../src/decorators/withTheme.tsx", "../../../src/util.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { registerSignalsRuntime } from '@dxos/echo-signals/react';\n\nexport { type Meta } from '@storybook/react';\n\nexport * from './decorators';\nexport * from './util';\n\nregisterSignalsRuntime();\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Decorator } from '@storybook/react';\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport React, { type JSX } from 'react';\n\nimport { type Density, DensityProvider, type ThemedClassName } from '@dxos/react-ui';\nimport { Tooltip } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\ntype ProviderOptions = {\n fullscreen?: boolean;\n density?: Density;\n tooltips?: boolean;\n};\n\nconst defaultOptions: ProviderOptions = {\n density: 'fine',\n};\n\ntype Provider = (children: JSX.Element, options: ProviderOptions) => JSX.Element;\n\nconst providers: Provider[] = [\n (children, options) => {\n return options.tooltips ? <Tooltip.Provider>{children}</Tooltip.Provider> : children;\n },\n (children, options) => {\n return options?.density ? <DensityProvider density={options.density}>{children}</DensityProvider> : children;\n },\n];\n\nexport type WithFullscreenProps = ThemedClassName<ProviderOptions>;\n\n/**\n * Decorator to layout the story container, adding optional providers.\n */\nexport const withLayout = ({ classNames, fullscreen, ..._options }: WithFullscreenProps = {}): Decorator => {\n // TODO(burdon): Inspect \"fullscreen\" parameter in context.\n return (Story, _context) => {\n const options = defaultsDeep({}, _options, defaultOptions);\n const children = (\n // NOTE: Do not change the flex direction to flex-col by default.\n <div role='none' className={mx(fullscreen && 'fixed inset-0 flex overflow-hidden', classNames)}>\n <Story />\n </div>\n );\n\n return providers.reduceRight((acc, provider) => provider(acc, options), children);\n };\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Decorator } from '@storybook/react';\nimport React from 'react';\n\nimport { registerSignalsRuntime } from '@dxos/echo-signals/react';\n\n/**\n * Make objects created using @dxos/echo-schema `create` reactive.\n */\nexport const withSignals: Decorator = (Story) => {\n registerSignalsRuntime();\n return <Story />;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { addons } from '@storybook/preview-api';\nimport { type Decorator } from '@storybook/react';\nimport React, { memo, useEffect, useState } from 'react';\nimport { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';\n\nimport { type ThemeMode, ThemeProvider } from '@dxos/react-ui';\nimport { defaultTx } from '@dxos/react-ui-theme';\n\nconst channel = addons.getChannel();\n\n/**\n * Changes theme based on storybook toolbar toggle.\n */\nexport const withTheme: Decorator = (Story, context) => {\n // Prevent re-rendering of the story.\n const MemoizedStory = memo(Story);\n const [themeMode, setThemeMode] = useState<ThemeMode>('dark');\n\n // https://www.npmjs.com/package/storybook-dark-mode\n // NOTE: The `useDarkMode` hook causes the story to continually re-render.\n // NOTE: Changing the theme will cause the story to remount.\n useEffect(() => {\n const handleUpdate = (darkMode: boolean) => setThemeMode(darkMode ? 'dark' : 'light');\n channel.on(DARK_MODE_EVENT_NAME, handleUpdate);\n return () => channel.off(DARK_MODE_EVENT_NAME, handleUpdate);\n }, [channel]);\n\n return (\n <ThemeProvider tx={defaultTx} themeMode={themeMode} resourceExtensions={context?.parameters?.translations} noCache>\n <MemoizedStory />\n </ThemeProvider>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { type FC } from 'react';\n\n/**\n * Story renderer wrapper.\n */\nexport const render =\n <T,>(r: FC<T>) =>\n (args: T) => <>{r(args) ?? <div />}</>;\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,0BAAAA,+BAA8B;;;ACCvC,OAAOC,kBAAkB;AACzB,OAAOC,WAAyB;AAEhC,SAAuBC,uBAA6C;AACpE,SAASC,eAAe;AACxB,SAASC,UAAU;AAQnB,IAAMC,iBAAkC;EACtCC,SAAS;AACX;AAIA,IAAMC,YAAwB;EAC5B,CAACC,UAAUC,YAAAA;AACT,WAAOA,QAAQC,WAAW,sBAAA,cAACC,QAAQC,UAAQ,MAAEJ,QAAAA,IAA+BA;EAC9E;EACA,CAACA,UAAUC,YAAAA;AACT,WAAOA,SAASH,UAAU,sBAAA,cAACO,iBAAAA;MAAgBP,SAASG,QAAQH;OAAUE,QAAAA,IAA8BA;EACtG;;AAQK,IAAMM,aAAa,CAAC,EAAEC,YAAYC,YAAY,GAAGC,SAAAA,IAAkC,CAAC,MAAC;AAE1F,SAAO,CAACC,OAAOC,aAAAA;AACb,UAAMV,UAAUW,aAAa,CAAC,GAAGH,UAAUZ,cAAAA;AAC3C,UAAMG;;MAEJ,sBAAA,cAACa,OAAAA;QAAIC,MAAK;QAAOC,WAAWC,GAAGR,cAAc,sCAAsCD,UAAAA;SACjF,sBAAA,cAACG,OAAAA,IAAAA,CAAAA;;AAIL,WAAOX,UAAUkB,YAAY,CAACC,KAAKC,aAAaA,SAASD,KAAKjB,OAAAA,GAAUD,QAAAA;EAC1E;AACF;;;AC9CA,OAAOoB,YAAW;AAElB,SAASC,8BAA8B;AAKhC,IAAMC,cAAyB,CAACC,UAAAA;AACrCC,yBAAAA;AACA,SAAO,gBAAAC,OAAA,cAACF,OAAAA,IAAAA;AACV;;;ACXA,SAASG,cAAc;AAEvB,OAAOC,UAASC,MAAMC,WAAWC,gBAAgB;AACjD,SAASC,4BAA4B;AAErC,SAAyBC,qBAAqB;AAC9C,SAASC,iBAAiB;AAE1B,IAAMC,UAAUC,OAAOC,WAAU;AAK1B,IAAMC,YAAuB,CAACC,OAAOC,YAAAA;AAE1C,QAAMC,gBAAgBC,qBAAKH,KAAAA;AAC3B,QAAM,CAACI,WAAWC,YAAAA,IAAgBC,SAAoB,MAAA;AAKtDC,YAAU,MAAA;AACR,UAAMC,eAAe,CAACC,aAAsBJ,aAAaI,WAAW,SAAS,OAAA;AAC7Eb,YAAQc,GAAGC,sBAAsBH,YAAAA;AACjC,WAAO,MAAMZ,QAAQgB,IAAID,sBAAsBH,YAAAA;EACjD,GAAG;IAACZ;GAAQ;AAEZ,SACE,gBAAAiB,OAAA,cAACC,eAAAA;IAAcC,IAAIC;IAAWZ;IAAsBa,oBAAoBhB,SAASiB,YAAYC;IAAcC,SAAAA;KACzG,gBAAAP,OAAA,cAACX,eAAAA,IAAAA,CAAAA;AAGP;;;AChCA,OAAOmB,YAAwB;AAKxB,IAAMC,SACX,CAAKC,MACL,CAACC,SAAY,gBAAAC,OAAA,cAAAA,OAAA,UAAA,MAAGF,EAAEC,IAAAA,KAAS,gBAAAC,OAAA,cAACC,OAAAA,IAAAA,CAAAA;;;AJA9BC,wBAAAA;",
|
|
6
|
+
"names": ["registerSignalsRuntime", "defaultsDeep", "React", "DensityProvider", "Tooltip", "mx", "defaultOptions", "density", "providers", "children", "options", "tooltips", "Tooltip", "Provider", "DensityProvider", "withLayout", "classNames", "fullscreen", "_options", "Story", "_context", "defaultsDeep", "div", "role", "className", "mx", "reduceRight", "acc", "provider", "React", "registerSignalsRuntime", "withSignals", "Story", "registerSignalsRuntime", "React", "addons", "React", "memo", "useEffect", "useState", "DARK_MODE_EVENT_NAME", "ThemeProvider", "defaultTx", "channel", "addons", "getChannel", "withTheme", "Story", "context", "MemoizedStory", "memo", "themeMode", "setThemeMode", "useState", "useEffect", "handleUpdate", "darkMode", "on", "DARK_MODE_EVENT_NAME", "off", "React", "ThemeProvider", "tx", "defaultTx", "resourceExtensions", "parameters", "translations", "noCache", "React", "render", "r", "args", "React", "div", "registerSignalsRuntime"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/common/storybook-utils/src/decorators/withLayout.tsx":{"bytes":5343,"imports":[{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"packages/common/storybook-utils/src/decorators/withSignals.tsx":{"bytes":1440,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/echo-signals/react","kind":"import-statement","external":true}],"format":"esm"},"packages/common/storybook-utils/src/decorators/withTheme.tsx":{"bytes":4710,"imports":[{"path":"@storybook/preview-api","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"storybook-dark-mode","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"packages/common/storybook-utils/src/decorators/index.ts":{"bytes":708,"imports":[{"path":"packages/common/storybook-utils/src/decorators/withLayout.tsx","kind":"import-statement","original":"./withLayout"},{"path":"packages/common/storybook-utils/src/decorators/withSignals.tsx","kind":"import-statement","original":"./withSignals"},{"path":"packages/common/storybook-utils/src/decorators/withTheme.tsx","kind":"import-statement","original":"./withTheme"}],"format":"esm"},"packages/common/storybook-utils/src/util.tsx":{"bytes":1048,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"packages/common/storybook-utils/src/index.ts":{"bytes":962,"imports":[{"path":"@dxos/echo-signals/react","kind":"import-statement","external":true},{"path":"packages/common/storybook-utils/src/decorators/index.ts","kind":"import-statement","original":"./decorators"},{"path":"packages/common/storybook-utils/src/util.tsx","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"packages/common/storybook-utils/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6666},"packages/common/storybook-utils/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/echo-signals/react","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/echo-signals/react","kind":"import-statement","external":true},{"path":"@storybook/preview-api","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"storybook-dark-mode","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["render","withLayout","withSignals","withTheme"],"entryPoint":"packages/common/storybook-utils/src/index.ts","inputs":{"packages/common/storybook-utils/src/index.ts":{"bytesInOutput":121},"packages/common/storybook-utils/src/decorators/withLayout.tsx":{"bytesInOutput":1175},"packages/common/storybook-utils/src/decorators/index.ts":{"bytesInOutput":0},"packages/common/storybook-utils/src/decorators/withSignals.tsx":{"bytesInOutput":217},"packages/common/storybook-utils/src/decorators/withTheme.tsx":{"bytesInOutput":933},"packages/common/storybook-utils/src/util.tsx":{"bytesInOutput":181}},"bytes":3069}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/decorators/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Decorator } from '@storybook/react';
|
|
2
|
+
import { type Density, type ThemedClassName } from '@dxos/react-ui';
|
|
3
|
+
type ProviderOptions = {
|
|
4
|
+
fullscreen?: boolean;
|
|
5
|
+
density?: Density;
|
|
6
|
+
tooltips?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type WithFullscreenProps = ThemedClassName<ProviderOptions>;
|
|
9
|
+
/**
|
|
10
|
+
* Decorator to layout the story container, adding optional providers.
|
|
11
|
+
*/
|
|
12
|
+
export declare const withLayout: ({ classNames, fullscreen, ..._options }?: WithFullscreenProps) => Decorator;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=withLayout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withLayout.d.ts","sourceRoot":"","sources":["../../../../src/decorators/withLayout.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAIlD,OAAO,EAAE,KAAK,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAIrF,KAAK,eAAe,GAAG;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAiBF,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC;AAEnE;;GAEG;AACH,eAAO,MAAM,UAAU,6CAA6C,mBAAmB,KAAQ,SAa9F,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withSignals.d.ts","sourceRoot":"","sources":["../../../../src/decorators/withSignals.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,SAGzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withTheme.d.ts","sourceRoot":"","sources":["../../../../src/decorators/withTheme.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AASlD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,SAmBvB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,MAAM,GAChB,CAAC,KAAM,EAAE,CAAC,CAAC,CAAC,YACN,CAAC,sBAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.7.3"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/storybook-utils",
|
|
3
|
+
"version": "0.7.5-labs.071a3e2",
|
|
4
|
+
"description": "Utilities for DXOS UI Storybooks.",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "DXOS.org",
|
|
9
|
+
"sideEffects": true,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/types/src/index.d.ts",
|
|
13
|
+
"browser": "./dist/lib/browser/index.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"types": "dist/types/src/index.d.ts",
|
|
17
|
+
"typesVersions": {
|
|
18
|
+
"*": {}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"src"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@storybook/preview-api": "^8.3.6",
|
|
26
|
+
"lodash.defaultsdeep": "^4.6.1",
|
|
27
|
+
"storybook-dark-mode": "^4.0.2",
|
|
28
|
+
"@dxos/echo-signals": "0.7.5-labs.071a3e2",
|
|
29
|
+
"@dxos/log": "0.7.5-labs.071a3e2"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
33
|
+
"@types/react": "~18.2.0",
|
|
34
|
+
"@types/react-dom": "~18.2.0",
|
|
35
|
+
"react": "~18.2.0",
|
|
36
|
+
"react-dom": "~18.2.0",
|
|
37
|
+
"storybook": "^8.3.6",
|
|
38
|
+
"@dxos/react-ui": "0.7.5-labs.071a3e2",
|
|
39
|
+
"@dxos/react-ui-theme": "0.7.5-labs.071a3e2"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"react": "~18.2.0",
|
|
43
|
+
"react-dom": "~18.2.0",
|
|
44
|
+
"@dxos/react-ui": "0.7.5-labs.071a3e2",
|
|
45
|
+
"@dxos/react-ui-theme": "0.7.5-labs.071a3e2"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Decorator } from '@storybook/react';
|
|
6
|
+
import defaultsDeep from 'lodash.defaultsdeep';
|
|
7
|
+
import React, { type JSX } from 'react';
|
|
8
|
+
|
|
9
|
+
import { type Density, DensityProvider, type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
+
import { Tooltip } from '@dxos/react-ui';
|
|
11
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
12
|
+
|
|
13
|
+
type ProviderOptions = {
|
|
14
|
+
fullscreen?: boolean;
|
|
15
|
+
density?: Density;
|
|
16
|
+
tooltips?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const defaultOptions: ProviderOptions = {
|
|
20
|
+
density: 'fine',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type Provider = (children: JSX.Element, options: ProviderOptions) => JSX.Element;
|
|
24
|
+
|
|
25
|
+
const providers: Provider[] = [
|
|
26
|
+
(children, options) => {
|
|
27
|
+
return options.tooltips ? <Tooltip.Provider>{children}</Tooltip.Provider> : children;
|
|
28
|
+
},
|
|
29
|
+
(children, options) => {
|
|
30
|
+
return options?.density ? <DensityProvider density={options.density}>{children}</DensityProvider> : children;
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export type WithFullscreenProps = ThemedClassName<ProviderOptions>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Decorator to layout the story container, adding optional providers.
|
|
38
|
+
*/
|
|
39
|
+
export const withLayout = ({ classNames, fullscreen, ..._options }: WithFullscreenProps = {}): Decorator => {
|
|
40
|
+
// TODO(burdon): Inspect "fullscreen" parameter in context.
|
|
41
|
+
return (Story, _context) => {
|
|
42
|
+
const options = defaultsDeep({}, _options, defaultOptions);
|
|
43
|
+
const children = (
|
|
44
|
+
// NOTE: Do not change the flex direction to flex-col by default.
|
|
45
|
+
<div role='none' className={mx(fullscreen && 'fixed inset-0 flex overflow-hidden', classNames)}>
|
|
46
|
+
<Story />
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return providers.reduceRight((acc, provider) => provider(acc, options), children);
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Decorator } from '@storybook/react';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { registerSignalsRuntime } from '@dxos/echo-signals/react';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Make objects created using @dxos/echo-schema `create` reactive.
|
|
12
|
+
*/
|
|
13
|
+
export const withSignals: Decorator = (Story) => {
|
|
14
|
+
registerSignalsRuntime();
|
|
15
|
+
return <Story />;
|
|
16
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { addons } from '@storybook/preview-api';
|
|
6
|
+
import { type Decorator } from '@storybook/react';
|
|
7
|
+
import React, { memo, useEffect, useState } from 'react';
|
|
8
|
+
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';
|
|
9
|
+
|
|
10
|
+
import { type ThemeMode, ThemeProvider } from '@dxos/react-ui';
|
|
11
|
+
import { defaultTx } from '@dxos/react-ui-theme';
|
|
12
|
+
|
|
13
|
+
const channel = addons.getChannel();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Changes theme based on storybook toolbar toggle.
|
|
17
|
+
*/
|
|
18
|
+
export const withTheme: Decorator = (Story, context) => {
|
|
19
|
+
// Prevent re-rendering of the story.
|
|
20
|
+
const MemoizedStory = memo(Story);
|
|
21
|
+
const [themeMode, setThemeMode] = useState<ThemeMode>('dark');
|
|
22
|
+
|
|
23
|
+
// https://www.npmjs.com/package/storybook-dark-mode
|
|
24
|
+
// NOTE: The `useDarkMode` hook causes the story to continually re-render.
|
|
25
|
+
// NOTE: Changing the theme will cause the story to remount.
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const handleUpdate = (darkMode: boolean) => setThemeMode(darkMode ? 'dark' : 'light');
|
|
28
|
+
channel.on(DARK_MODE_EVENT_NAME, handleUpdate);
|
|
29
|
+
return () => channel.off(DARK_MODE_EVENT_NAME, handleUpdate);
|
|
30
|
+
}, [channel]);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<ThemeProvider tx={defaultTx} themeMode={themeMode} resourceExtensions={context?.parameters?.translations} noCache>
|
|
34
|
+
<MemoizedStory />
|
|
35
|
+
</ThemeProvider>
|
|
36
|
+
);
|
|
37
|
+
};
|
package/src/index.ts
ADDED