@saas-ui/storybook-addon 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/CHANGELOG.md +497 -0
  2. package/README.md +97 -0
  3. package/dist/chunk-E3MMX4DM.js +4973 -0
  4. package/dist/chunk-GII4NPN2.js +81 -0
  5. package/dist/chunk-HSBRF2QZ.js +18 -0
  6. package/dist/chunk-N4JZ67DU.js +26 -0
  7. package/dist/chunk-NOGSFSIA.js +52 -0
  8. package/dist/chunk-QNOLFHPG.js +63 -0
  9. package/dist/chunk-SGM3YTWS.js +82 -0
  10. package/dist/chunk-SVHNULTN.js +24 -0
  11. package/dist/chunk-UK7U2PBM.js +70 -0
  12. package/dist/constants.cjs +46 -0
  13. package/dist/constants.d.ts +11 -0
  14. package/dist/constants.js +15 -0
  15. package/dist/feature/arg-types.cjs +76 -0
  16. package/dist/feature/arg-types.d.ts +46 -0
  17. package/dist/feature/arg-types.js +7 -0
  18. package/dist/feature/color-mode/ColorModeSync.cjs +57 -0
  19. package/dist/feature/color-mode/ColorModeSync.d.ts +6 -0
  20. package/dist/feature/color-mode/ColorModeSync.js +8 -0
  21. package/dist/feature/color-mode/ColorModeTool.cjs +95 -0
  22. package/dist/feature/color-mode/ColorModeTool.d.ts +6 -0
  23. package/dist/feature/color-mode/ColorModeTool.js +8 -0
  24. package/dist/feature/color-mode/ThemeTool.cjs +5038 -0
  25. package/dist/feature/color-mode/ThemeTool.d.ts +6 -0
  26. package/dist/feature/color-mode/ThemeTool.js +8 -0
  27. package/dist/feature/decorator/ChakraProviderDecorator.cjs +168 -0
  28. package/dist/feature/decorator/ChakraProviderDecorator.d.ts +5 -0
  29. package/dist/feature/decorator/ChakraProviderDecorator.js +10 -0
  30. package/dist/feature/direction/DirectionTool.cjs +127 -0
  31. package/dist/feature/direction/DirectionTool.d.ts +6 -0
  32. package/dist/feature/direction/DirectionTool.js +8 -0
  33. package/dist/feature/direction/useDirection.cjs +59 -0
  34. package/dist/feature/direction/useDirection.d.ts +6 -0
  35. package/dist/feature/direction/useDirection.js +8 -0
  36. package/dist/index.cjs +99 -0
  37. package/dist/index.d.ts +4 -0
  38. package/dist/index.js +19 -0
  39. package/dist/preset/decorators.cjs +173 -0
  40. package/dist/preset/decorators.d.ts +3 -0
  41. package/dist/preset/decorators.js +13 -0
  42. package/dist/preset/index.cjs +60 -0
  43. package/dist/preset/index.d.ts +5 -0
  44. package/dist/preset/index.js +27 -0
  45. package/dist/preset/register.cjs +5175 -0
  46. package/dist/preset/register.d.ts +2 -0
  47. package/dist/preset/register.js +40 -0
  48. package/package.json +120 -0
  49. package/theming-arg-types.png +0 -0
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+
47
+ // src/preset/decorators.ts
48
+ var decorators_exports = {};
49
+ __export(decorators_exports, {
50
+ decorators: () => decorators
51
+ });
52
+ module.exports = __toCommonJS(decorators_exports);
53
+
54
+ // src/feature/decorator/ChakraProviderDecorator.tsx
55
+ var import_react4 = __toESM(require("react"), 1);
56
+ var import_addons3 = require("@storybook/addons");
57
+ var import_react5 = require("@chakra-ui/react");
58
+ var import_react6 = require("@saas-ui/react");
59
+
60
+ // src/feature/color-mode/ColorModeSync.tsx
61
+ var import_react = require("react");
62
+ var import_react2 = require("@chakra-ui/react");
63
+ var import_addons = require("@storybook/addons");
64
+
65
+ // src/constants.ts
66
+ var ADDON_ID = "@saas-ui/storybook-addon";
67
+ var COLOR_MODE_TOOL_ID = `${ADDON_ID}/color-mode-tool`;
68
+ var DIRECTION_TOOL_ID = `${ADDON_ID}/direction-tool`;
69
+ var THEME_TOOL_ID = `${ADDON_ID}/theme-tool`;
70
+ var EVENTS = {
71
+ TOGGLE_COLOR_MODE: `${ADDON_ID}/toggleColorMode`,
72
+ TOGGLE_DIRECTION: `${ADDON_ID}/toggleDirection`,
73
+ SET_THEME: `${ADDON_ID}/setTheme`
74
+ };
75
+
76
+ // src/feature/color-mode/ColorModeSync.tsx
77
+ function ColorModeSync() {
78
+ const { setColorMode } = (0, import_react2.useColorMode)();
79
+ (0, import_react.useEffect)(() => {
80
+ const channel = import_addons.addons.getChannel();
81
+ const colorModeToolCallback = (value) => setColorMode(value);
82
+ channel.on(EVENTS.TOGGLE_COLOR_MODE, colorModeToolCallback);
83
+ return () => {
84
+ channel.removeListener(EVENTS.TOGGLE_COLOR_MODE, colorModeToolCallback);
85
+ };
86
+ }, [setColorMode]);
87
+ return null;
88
+ }
89
+
90
+ // src/feature/direction/useDirection.tsx
91
+ var import_react3 = require("react");
92
+ var import_addons2 = require("@storybook/addons");
93
+ var useDirection = (initialDirection = "ltr") => {
94
+ const [direction, setDirection] = (0, import_react3.useState)(initialDirection.toLowerCase());
95
+ (0, import_react3.useEffect)(() => {
96
+ document.documentElement.dir = direction;
97
+ }, [direction]);
98
+ (0, import_react3.useEffect)(() => {
99
+ const channel = import_addons2.addons.getChannel();
100
+ const callback = (value) => setDirection(value);
101
+ channel.on(EVENTS.TOGGLE_DIRECTION, callback);
102
+ return () => {
103
+ channel.removeListener(EVENTS.TOGGLE_DIRECTION, callback);
104
+ };
105
+ }, [setDirection]);
106
+ return direction;
107
+ };
108
+
109
+ // src/feature/decorator/ChakraProviderDecorator.tsx
110
+ var import_theme = require("@saas-ui/theme");
111
+ var import_theme_glass = require("@saas-ui/theme-glass");
112
+ var import_jsx_runtime = require("react/jsx-runtime");
113
+ var glassTheme = (0, import_react5.extendTheme)(import_theme_glass.theme, import_theme.theme);
114
+ var useThemeSync = () => {
115
+ const [themeId, setTheme] = (0, import_react6.useLocalStorage)("storybook.theme", "0");
116
+ import_react4.default.useEffect(() => {
117
+ const channel = import_addons3.addons.getChannel();
118
+ const themeCallback = (value) => setTheme(value);
119
+ channel.on(EVENTS.SET_THEME, themeCallback);
120
+ return () => {
121
+ channel.removeListener(EVENTS.SET_THEME, themeCallback);
122
+ };
123
+ }, [setTheme]);
124
+ return themeId;
125
+ };
126
+ function ChakraProviderDecorator(Story, context) {
127
+ const {
128
+ parameters: { saasui: saasuiParams },
129
+ globals: { [DIRECTION_TOOL_ID]: globalDirection }
130
+ } = context;
131
+ const themeId = useThemeSync();
132
+ const getTheme = import_react4.default.useCallback(() => {
133
+ switch (themeId) {
134
+ case "1":
135
+ return import_theme.theme;
136
+ case "2":
137
+ return glassTheme;
138
+ default:
139
+ return import_theme.baseTheme;
140
+ }
141
+ }, [themeId]);
142
+ const theme = (saasuiParams == null ? void 0 : saasuiParams.theme) || getTheme();
143
+ const themeOverride = !!(saasuiParams == null ? void 0 : saasuiParams.theme);
144
+ const chakraTheme = (saasuiParams == null ? void 0 : saasuiParams.theme) ? typeof saasuiParams.theme === "function" ? saasuiParams.theme(context) : saasuiParams.theme : theme;
145
+ const direction = useDirection(globalDirection || (chakraTheme == null ? void 0 : chakraTheme.direction));
146
+ const themeWithDirectionOverride = (0, import_react4.useMemo)(
147
+ () => (0, import_react5.extendTheme)(
148
+ {
149
+ direction,
150
+ styles: {
151
+ global: {
152
+ body: {
153
+ minHeight: "var(--chakra-vh)"
154
+ }
155
+ }
156
+ }
157
+ },
158
+ chakraTheme
159
+ ),
160
+ [chakraTheme, direction]
161
+ );
162
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react6.SaasProvider, __spreadProps(__spreadValues({}, saasuiParams), { theme: themeWithDirectionOverride, children: [
163
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ColorModeSync, {}),
164
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Story, __spreadValues({}, context))
165
+ ] }));
166
+ }
167
+
168
+ // src/preset/decorators.ts
169
+ var decorators = [ChakraProviderDecorator];
170
+ // Annotate the CommonJS export names for ESM import in node:
171
+ 0 && (module.exports = {
172
+ decorators
173
+ });
@@ -0,0 +1,3 @@
1
+ declare const decorators: any[];
2
+
3
+ export { decorators };
@@ -0,0 +1,13 @@
1
+ import {
2
+ ChakraProviderDecorator
3
+ } from "../chunk-GII4NPN2.js";
4
+ import "../chunk-N4JZ67DU.js";
5
+ import "../chunk-SVHNULTN.js";
6
+ import "../chunk-HSBRF2QZ.js";
7
+ import "../chunk-UK7U2PBM.js";
8
+
9
+ // src/preset/decorators.ts
10
+ var decorators = [ChakraProviderDecorator];
11
+ export {
12
+ decorators
13
+ };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/preset/index.ts
31
+ var preset_exports = {};
32
+ __export(preset_exports, {
33
+ config: () => config,
34
+ managerEntries: () => managerEntries,
35
+ webpackFinal: () => webpackFinal
36
+ });
37
+ module.exports = __toCommonJS(preset_exports);
38
+ function config(entry = []) {
39
+ return [
40
+ ...entry,
41
+ require.resolve("@saas-ui/storybook-addon/preset/decorators")
42
+ ];
43
+ }
44
+ function managerEntries(entry = []) {
45
+ return [...entry, require.resolve("@saas-ui/storybook-addon/preset/register")];
46
+ }
47
+ function webpackFinal(config2) {
48
+ config2.module.rules.push({
49
+ test: /\.mjs$/,
50
+ include: /node_modules/,
51
+ type: "javascript/auto"
52
+ });
53
+ return config2;
54
+ }
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ config,
58
+ managerEntries,
59
+ webpackFinal
60
+ });
@@ -0,0 +1,5 @@
1
+ declare function config(entry?: never[]): string[];
2
+ declare function managerEntries(entry?: never[]): string[];
3
+ declare function webpackFinal(config: any): any;
4
+
5
+ export { config, managerEntries, webpackFinal };
@@ -0,0 +1,27 @@
1
+ import {
2
+ __require
3
+ } from "../chunk-UK7U2PBM.js";
4
+
5
+ // src/preset/index.ts
6
+ function config(entry = []) {
7
+ return [
8
+ ...entry,
9
+ __require.resolve("@saas-ui/storybook-addon/preset/decorators")
10
+ ];
11
+ }
12
+ function managerEntries(entry = []) {
13
+ return [...entry, __require.resolve("@saas-ui/storybook-addon/preset/register")];
14
+ }
15
+ function webpackFinal(config2) {
16
+ config2.module.rules.push({
17
+ test: /\.mjs$/,
18
+ include: /node_modules/,
19
+ type: "javascript/auto"
20
+ });
21
+ return config2;
22
+ }
23
+ export {
24
+ config,
25
+ managerEntries,
26
+ webpackFinal
27
+ };