@storybook/addon-ondevice-backgrounds 9.0.9 → 9.0.14
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/dist/useGlobals.d.ts +2 -0
- package/dist/useGlobals.js +43 -0
- package/package.json +4 -4
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useGlobals = useGlobals;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const core_events_1 = require("storybook/internal/core-events");
|
|
6
|
+
const preview_api_1 = require("storybook/internal/preview-api");
|
|
7
|
+
const global_1 = require("@storybook/global");
|
|
8
|
+
// export const useGlobals = (story?: PreparedStory): [Globals, (globals: Globals) => void] => {
|
|
9
|
+
// const [globals, setGlobals] = useState(story?.storyGlobals);
|
|
10
|
+
// useEffect(() => {
|
|
11
|
+
// const channel = addons.getChannel();
|
|
12
|
+
// const onGlobalsUpdated = (changed: { globals: Globals }) => {
|
|
13
|
+
// setGlobals(changed.globals);
|
|
14
|
+
// };
|
|
15
|
+
// channel.on(GLOBALS_UPDATED, onGlobalsUpdated);
|
|
16
|
+
// return () => channel.off(GLOBALS_UPDATED, onGlobalsUpdated);
|
|
17
|
+
// }, []);
|
|
18
|
+
// const updateGlobals = (globals: Globals) => {
|
|
19
|
+
// console.log('updateGlobals', globals);
|
|
20
|
+
// addons.getChannel().emit(GLOBALS_UPDATED, { globals });
|
|
21
|
+
// };
|
|
22
|
+
// return [globals, updateGlobals];
|
|
23
|
+
// };
|
|
24
|
+
function useGlobals() {
|
|
25
|
+
const { currentContext } = global_1.global.STORYBOOK_HOOKS_CONTEXT;
|
|
26
|
+
const [globals, setGlobals] = (0, react_1.useState)(currentContext?.globals);
|
|
27
|
+
const channel = preview_api_1.addons.getChannel();
|
|
28
|
+
// const { globals } = useStoryContext();
|
|
29
|
+
(0, react_1.useEffect)(() => {
|
|
30
|
+
const channel = preview_api_1.addons.getChannel();
|
|
31
|
+
const onGlobalsUpdated = (changed) => {
|
|
32
|
+
setGlobals(changed.globals);
|
|
33
|
+
// global.STORYBOOK_HOOKS_CONTEXT!.currentContext!.globals = {
|
|
34
|
+
// ...global.STORYBOOK_HOOKS_CONTEXT!.currentContext!.globals,
|
|
35
|
+
// ...changed.globals,
|
|
36
|
+
// };
|
|
37
|
+
};
|
|
38
|
+
channel.on(core_events_1.GLOBALS_UPDATED, onGlobalsUpdated);
|
|
39
|
+
return () => channel.off(core_events_1.GLOBALS_UPDATED, onGlobalsUpdated);
|
|
40
|
+
}, []);
|
|
41
|
+
const updateGlobals = (0, react_1.useCallback)((newGlobals) => channel.emit(core_events_1.UPDATE_GLOBALS, { globals: newGlobals }), [channel]);
|
|
42
|
+
return [globals, updateGlobals];
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/addon-ondevice-backgrounds",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.14",
|
|
4
4
|
"description": "A react-native storybook addon to show different backgrounds for your preview",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"addon",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dev": "tsc --watch"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@storybook/react-native-theming": "^9.0.
|
|
35
|
+
"@storybook/react-native-theming": "^9.0.14"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"typescript": "~5.8.3"
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": "*",
|
|
42
42
|
"react-native": "*",
|
|
43
|
-
"storybook": "
|
|
43
|
+
"storybook": "9.0.14"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "19bb44781daef1f4bd1c5782c0a00d5b7fa5b943"
|
|
49
49
|
}
|