@storybook/react-native 6.5.0-rc.1 → 6.5.0-rc.10
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/constants.d.ts +5 -0
- package/dist/constants.js +5 -0
- package/dist/hooks.d.ts +44 -0
- package/dist/hooks.js +80 -5
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -0
- package/dist/preview/View.d.ts +10 -7
- package/dist/preview/View.js +12 -4
- package/dist/preview/components/OnDeviceUI/OnDeviceUI.d.ts +1 -2
- package/dist/preview/components/OnDeviceUI/OnDeviceUI.js +74 -46
- package/dist/preview/components/OnDeviceUI/Panel.d.ts +7 -5
- package/dist/preview/components/OnDeviceUI/Panel.js +13 -4
- package/dist/preview/components/OnDeviceUI/absolute-positioned-keyboard-aware-view.d.ts +1 -1
- package/dist/preview/components/OnDeviceUI/addons/Addons.d.ts +3 -2
- package/dist/preview/components/OnDeviceUI/addons/Addons.js +18 -23
- package/dist/preview/components/OnDeviceUI/addons/AddonsSkeleton.d.ts +14 -0
- package/dist/preview/components/OnDeviceUI/addons/AddonsSkeleton.js +59 -0
- package/dist/preview/components/OnDeviceUI/addons/List.js +6 -15
- package/dist/preview/components/OnDeviceUI/addons/Wrapper.js +13 -14
- package/dist/preview/components/OnDeviceUI/animation.d.ts +35 -12
- package/dist/preview/components/OnDeviceUI/animation.js +56 -25
- package/dist/preview/components/OnDeviceUI/navigation/Navigation.d.ts +5 -5
- package/dist/preview/components/OnDeviceUI/navigation/Navigation.js +24 -10
- package/dist/preview/components/OnDeviceUI/navigation/NavigationBar.d.ts +8 -0
- package/dist/preview/components/OnDeviceUI/navigation/NavigationBar.js +14 -0
- package/dist/preview/components/OnDeviceUI/navigation/NavigationButton.d.ts +3 -0
- package/dist/preview/components/OnDeviceUI/navigation/NavigationButton.js +20 -0
- package/dist/preview/components/OnDeviceUI/navigation/constants.d.ts +2 -2
- package/dist/preview/components/OnDeviceUI/navigation/constants.js +2 -2
- package/dist/preview/components/Shared/icons.d.ts +35 -6
- package/dist/preview/components/Shared/icons.js +44 -31
- package/dist/preview/components/Shared/layout.d.ts +12 -0
- package/dist/preview/components/Shared/layout.js +27 -0
- package/dist/preview/components/Shared/tabs.d.ts +20 -0
- package/dist/preview/components/Shared/tabs.js +35 -0
- package/dist/preview/components/Shared/theme.d.ts +187 -13
- package/dist/preview/components/Shared/theme.js +316 -13
- package/dist/preview/components/StoryListView/StoryListView.js +62 -70
- package/dist/preview/components/StoryView/StoryView.js +22 -15
- package/dist/preview/start.d.ts +2 -2
- package/dist/preview/start.js +4 -4
- package/dist/types/emotion-native.d.js +4 -0
- package/dist/types/types-6.0.d.ts +10 -10
- package/dist/types/types.d.ts +3 -3
- package/package.json +6 -6
- package/readme.md +146 -168
- package/scripts/__snapshots__/loader.test.js.snap +35 -35
- package/scripts/loader.js +6 -1
- package/dist/preview/components/OnDeviceUI/navigation/Bar.d.ts +0 -9
- package/dist/preview/components/OnDeviceUI/navigation/Bar.js +0 -17
- package/dist/preview/components/OnDeviceUI/navigation/Button.d.ts +0 -10
- package/dist/preview/components/OnDeviceUI/navigation/Button.js +0 -17
- package/dist/preview/components/OnDeviceUI/navigation/VisibilityButton.d.ts +0 -8
- package/dist/preview/components/OnDeviceUI/navigation/VisibilityButton.js +0 -45
- package/dist/preview/components/Shared/text.d.ts +0 -3
- package/dist/preview/components/Shared/text.js +0 -18
package/dist/hooks.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { StoryContext } from '@storybook/csf';
|
|
2
|
+
import type { Theme } from './preview/components/Shared/theme';
|
|
2
3
|
import type { ReactNativeFramework } from './types/types-6.0';
|
|
3
4
|
/**
|
|
4
5
|
* Hook that returns a function to set the current story context.
|
|
@@ -20,3 +21,46 @@ export declare function useIsStorySelected(storyId: string): boolean;
|
|
|
20
21
|
* Hook that indicates if `title` is the currently selected story section.
|
|
21
22
|
*/
|
|
22
23
|
export declare function useIsStorySectionSelected(title: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Hook that causes a re-render when the currently selected story is changed.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useUpdateOnStoryChanged(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Hook that gets the current theme values.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useTheme(): Theme;
|
|
32
|
+
/**
|
|
33
|
+
* A boolean atom creator for an atom that can only be toggled between
|
|
34
|
+
* true/false.
|
|
35
|
+
*
|
|
36
|
+
* @see {@link https://jotai.org/docs/recipes/atom-creators#atomwithtoggle}
|
|
37
|
+
*/
|
|
38
|
+
export declare function atomWithToggle(initialValue?: boolean): import("jotai").WritableAtom<boolean, [nextValue?: boolean], void> & {
|
|
39
|
+
init: boolean;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Hook that retrieves the current state, and a setter, for the `isUIVisible`
|
|
43
|
+
* atom.
|
|
44
|
+
*/
|
|
45
|
+
export declare function useIsUIVisible(): [boolean, (nextValue?: boolean) => void];
|
|
46
|
+
/**
|
|
47
|
+
* Hook that retrieves the current state, and a setter, for the
|
|
48
|
+
* `isSplitPanelVisibleAtom` atom.
|
|
49
|
+
*/
|
|
50
|
+
export declare function useIsSplitPanelVisible(): [boolean, (nextValue?: boolean) => void];
|
|
51
|
+
interface SyncExternalUIParams {
|
|
52
|
+
isUIVisible?: boolean;
|
|
53
|
+
isSplitPanelVisible?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sync the UI atom states with external values, such as from Story parameters.
|
|
57
|
+
*/
|
|
58
|
+
export declare function syncExternalUI({ isUIVisible, isSplitPanelVisible }: SyncExternalUIParams): void;
|
|
59
|
+
/**
|
|
60
|
+
* Hook that manages the state for the currently selected addon.
|
|
61
|
+
*
|
|
62
|
+
* This value persists across stories, so that the same addon will be selected
|
|
63
|
+
* when switching stories.
|
|
64
|
+
*/
|
|
65
|
+
export declare function useSelectedAddon(initialValue?: string): [string, (args_0: string | ((prev: string) => string)) => void];
|
|
66
|
+
export {};
|
package/dist/hooks.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { atom, useAtom, useAtomValue, useSetAtom, getDefaultStore } from 'jotai';
|
|
3
|
+
import { useTheme as useEmotionTheme } from 'emotion-theming';
|
|
3
4
|
const storyContextAtom = atom(null);
|
|
4
5
|
/**
|
|
5
6
|
* Hook that returns a function to set the current story context.
|
|
@@ -18,18 +19,92 @@ export function useStoryContext() {
|
|
|
18
19
|
*/
|
|
19
20
|
export function useStoryContextParam(name, defaultValue) {
|
|
20
21
|
var _a;
|
|
21
|
-
const paramAtom = useMemo(() => atom(get => { var _a, _b; return (_b = (_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.parameters) === null || _b === void 0 ? void 0 : _b[name]; }), [name]);
|
|
22
|
+
const paramAtom = useMemo(() => atom((get) => { var _a, _b; return (_b = (_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.parameters) === null || _b === void 0 ? void 0 : _b[name]; }), [name]);
|
|
22
23
|
return (_a = useAtomValue(paramAtom)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Hook that indicates if `storyId` is the currently selected story.
|
|
26
27
|
*/
|
|
27
28
|
export function useIsStorySelected(storyId) {
|
|
28
|
-
return useAtomValue(useMemo(() => atom(get => { var _a; return ((_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.id) === storyId; }), [storyId]));
|
|
29
|
+
return useAtomValue(useMemo(() => atom((get) => { var _a; return ((_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.id) === storyId; }), [storyId]));
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* Hook that indicates if `title` is the currently selected story section.
|
|
32
33
|
*/
|
|
33
34
|
export function useIsStorySectionSelected(title) {
|
|
34
|
-
return useAtomValue(useMemo(() => atom(get => { var _a; return ((_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.title) === title; }), [title]));
|
|
35
|
+
return useAtomValue(useMemo(() => atom((get) => { var _a; return ((_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.title) === title; }), [title]));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Hook that causes a re-render when the currently selected story is changed.
|
|
39
|
+
*/
|
|
40
|
+
export function useUpdateOnStoryChanged() {
|
|
41
|
+
useAtomValue(useMemo(() => atom((get) => { var _a; return (_a = get(storyContextAtom)) === null || _a === void 0 ? void 0 : _a.id; }), []));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Hook that gets the current theme values.
|
|
45
|
+
*/
|
|
46
|
+
export function useTheme() {
|
|
47
|
+
return useEmotionTheme();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A boolean atom creator for an atom that can only be toggled between
|
|
51
|
+
* true/false.
|
|
52
|
+
*
|
|
53
|
+
* @see {@link https://jotai.org/docs/recipes/atom-creators#atomwithtoggle}
|
|
54
|
+
*/
|
|
55
|
+
export function atomWithToggle(initialValue) {
|
|
56
|
+
const anAtom = atom(initialValue, (get, set, nextValue) => {
|
|
57
|
+
const update = nextValue !== null && nextValue !== void 0 ? nextValue : !get(anAtom);
|
|
58
|
+
set(anAtom, update);
|
|
59
|
+
});
|
|
60
|
+
return anAtom;
|
|
61
|
+
}
|
|
62
|
+
const isUIVisibleAtom = atomWithToggle(true);
|
|
63
|
+
/**
|
|
64
|
+
* Hook that retrieves the current state, and a setter, for the `isUIVisible`
|
|
65
|
+
* atom.
|
|
66
|
+
*/
|
|
67
|
+
export function useIsUIVisible() {
|
|
68
|
+
return useAtom(isUIVisibleAtom);
|
|
69
|
+
}
|
|
70
|
+
const isSplitPanelVisibleAtom = atomWithToggle(false);
|
|
71
|
+
/**
|
|
72
|
+
* Hook that retrieves the current state, and a setter, for the
|
|
73
|
+
* `isSplitPanelVisibleAtom` atom.
|
|
74
|
+
*/
|
|
75
|
+
export function useIsSplitPanelVisible() {
|
|
76
|
+
return useAtom(isSplitPanelVisibleAtom);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Sync the UI atom states with external values, such as from Story parameters.
|
|
80
|
+
*/
|
|
81
|
+
export function syncExternalUI({ isUIVisible, isSplitPanelVisible }) {
|
|
82
|
+
const jotaiStore = getDefaultStore();
|
|
83
|
+
if (isUIVisible !== undefined) {
|
|
84
|
+
jotaiStore.set(isUIVisibleAtom, isUIVisible);
|
|
85
|
+
}
|
|
86
|
+
if (isSplitPanelVisible !== undefined) {
|
|
87
|
+
jotaiStore.set(isSplitPanelVisibleAtom, isSplitPanelVisible);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const selectedAddonAtom = atom(undefined);
|
|
91
|
+
/**
|
|
92
|
+
* Hook that manages the state for the currently selected addon.
|
|
93
|
+
*
|
|
94
|
+
* This value persists across stories, so that the same addon will be selected
|
|
95
|
+
* when switching stories.
|
|
96
|
+
*/
|
|
97
|
+
export function useSelectedAddon(initialValue) {
|
|
98
|
+
const result = useAtom(selectedAddonAtom);
|
|
99
|
+
const set = result[1];
|
|
100
|
+
React.useEffect(() => {
|
|
101
|
+
const jotaiStore = getDefaultStore();
|
|
102
|
+
// Only apply the initial value once, and only if the atom doesn't have a
|
|
103
|
+
// value yet.
|
|
104
|
+
if (jotaiStore.get(selectedAddonAtom) === undefined) {
|
|
105
|
+
set(initialValue);
|
|
106
|
+
}
|
|
107
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
108
|
+
}, []);
|
|
109
|
+
return result;
|
|
35
110
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ReactNode } from 'react';
|
|
|
6
6
|
import type { ReactNativeFramework } from './types/types-6.0';
|
|
7
7
|
declare const configure: (loadable: import("@storybook/core-client").Loadable, m: NodeModule) => void;
|
|
8
8
|
export { configure };
|
|
9
|
-
|
|
9
|
+
type C = ClientApi<ReactNativeFramework>;
|
|
10
10
|
export declare const setAddon: C['setAddon'];
|
|
11
11
|
export declare const addDecorator: C['addDecorator'];
|
|
12
12
|
export declare const addParameters: C['addParameters'];
|
|
@@ -18,3 +18,4 @@ export declare const raw: C['raw'];
|
|
|
18
18
|
export declare const storiesOf: (kind: string, _module: NodeModule) => StoryApi<ReactNode>;
|
|
19
19
|
export declare const getStorybookUI: (params?: Partial<import("./preview/View").Params>) => () => JSX.Element;
|
|
20
20
|
export * from './types/types-6.0';
|
|
21
|
+
export { theme, darkTheme } from './preview/components/Shared/theme';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _a;
|
|
1
2
|
import { start } from './preview/start';
|
|
2
3
|
const { clientApi, configure, view } = start();
|
|
3
4
|
export { configure };
|
|
@@ -15,3 +16,8 @@ export const storiesOf = (kind, _module) => rawStoriesOf(kind, { hot: () => { }
|
|
|
15
16
|
});
|
|
16
17
|
export const getStorybookUI = view.getStorybookUI;
|
|
17
18
|
export * from './types/types-6.0';
|
|
19
|
+
// @storybook/addon-storyshots v6 needs global.__STORYBOOK_STORY_STORE__.initializationPromise
|
|
20
|
+
global.__STORYBOOK_STORY_STORE__ = {
|
|
21
|
+
initializationPromise: (_a = clientApi.storyStore) === null || _a === void 0 ? void 0 : _a.initializationPromise,
|
|
22
|
+
};
|
|
23
|
+
export { theme, darkTheme } from './preview/components/Shared/theme';
|
package/dist/preview/View.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { StoryIndex, SelectionSpecifier } from '@storybook/store';
|
|
3
3
|
import { StoryContext } from '@storybook/csf';
|
|
4
|
-
import {
|
|
4
|
+
import { Theme } from './components/Shared/theme';
|
|
5
5
|
import type { ReactNativeFramework } from '../types/types-6.0';
|
|
6
6
|
import { PreviewWeb } from '@storybook/preview-web';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
type StoryKind = string;
|
|
8
|
+
type StoryName = string;
|
|
9
|
+
type InitialSelection = `${StoryKind}--${StoryName}` | {
|
|
10
10
|
/**
|
|
11
11
|
* Kind is the default export name or the storiesOf("name") name
|
|
12
12
|
*/
|
|
@@ -16,7 +16,10 @@ declare type InitialSelection = `${StoryKind}--${StoryName}` | {
|
|
|
16
16
|
*/
|
|
17
17
|
name: StoryName;
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
type DeepPartial<T> = T extends object ? {
|
|
20
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
21
|
+
} : T;
|
|
22
|
+
export type Params = {
|
|
20
23
|
onDeviceUI?: boolean;
|
|
21
24
|
enableWebsockets?: boolean;
|
|
22
25
|
query?: string;
|
|
@@ -27,10 +30,10 @@ export declare type Params = {
|
|
|
27
30
|
shouldPersistSelection?: boolean;
|
|
28
31
|
tabOpen?: number;
|
|
29
32
|
isUIHidden?: boolean;
|
|
33
|
+
isSplitPanelVisible?: boolean;
|
|
30
34
|
shouldDisableKeyboardAvoidingView?: boolean;
|
|
31
35
|
keyboardAvoidingViewVerticalOffset?: number;
|
|
32
|
-
|
|
33
|
-
theme?: typeof theme;
|
|
36
|
+
theme: DeepPartial<Theme>;
|
|
34
37
|
};
|
|
35
38
|
export declare class View {
|
|
36
39
|
_storyIndex: StoryIndex;
|
package/dist/preview/View.js
CHANGED
|
@@ -13,13 +13,15 @@ import { toId } from '@storybook/csf';
|
|
|
13
13
|
import { addons } from '@storybook/addons';
|
|
14
14
|
import { ThemeProvider } from 'emotion-theming';
|
|
15
15
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
16
|
-
import { useSetStoryContext } from '../hooks';
|
|
16
|
+
import { useSetStoryContext, syncExternalUI } from '../hooks';
|
|
17
17
|
import OnDeviceUI from './components/OnDeviceUI';
|
|
18
|
-
import { theme } from './components/Shared/theme';
|
|
18
|
+
import { darkTheme, theme } from './components/Shared/theme';
|
|
19
19
|
import StoryView from './components/StoryView';
|
|
20
20
|
import createChannel from '@storybook/channel-websocket';
|
|
21
21
|
import getHost from './rn-host-detect';
|
|
22
22
|
import events from '@storybook/core-events';
|
|
23
|
+
import { Appearance } from 'react-native';
|
|
24
|
+
import deepmerge from 'deepmerge';
|
|
23
25
|
const STORAGE_KEY = 'lastOpenedStory';
|
|
24
26
|
export class View {
|
|
25
27
|
constructor(preview) {
|
|
@@ -65,6 +67,7 @@ export class View {
|
|
|
65
67
|
});
|
|
66
68
|
};
|
|
67
69
|
this.getStorybookUI = (params = {}) => {
|
|
70
|
+
var _a;
|
|
68
71
|
const { shouldPersistSelection = true, onDeviceUI = true, enableWebsockets = false } = params;
|
|
69
72
|
const initialStory = this._getInitialStory(params);
|
|
70
73
|
if (enableWebsockets) {
|
|
@@ -87,7 +90,12 @@ export class View {
|
|
|
87
90
|
});
|
|
88
91
|
// eslint-disable-next-line consistent-this
|
|
89
92
|
const self = this;
|
|
90
|
-
const appliedTheme =
|
|
93
|
+
const appliedTheme = deepmerge(Appearance.getColorScheme() === 'dark' ? darkTheme : theme, (_a = params.theme) !== null && _a !== void 0 ? _a : {});
|
|
94
|
+
// Sync the Storybook parameters (external) with app UI state (internal), to initialise them.
|
|
95
|
+
syncExternalUI({
|
|
96
|
+
isUIVisible: params.isUIHidden !== undefined ? !params.isUIHidden : undefined,
|
|
97
|
+
isSplitPanelVisible: params.isSplitPanelVisible,
|
|
98
|
+
});
|
|
91
99
|
return () => {
|
|
92
100
|
const setContext = useSetStoryContext();
|
|
93
101
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
@@ -110,7 +118,7 @@ export class View {
|
|
|
110
118
|
if (onDeviceUI) {
|
|
111
119
|
return (React.createElement(SafeAreaProvider, null,
|
|
112
120
|
React.createElement(ThemeProvider, { theme: appliedTheme },
|
|
113
|
-
React.createElement(OnDeviceUI, { storyIndex: self._storyIndex,
|
|
121
|
+
React.createElement(OnDeviceUI, { storyIndex: self._storyIndex, tabOpen: params.tabOpen, shouldDisableKeyboardAvoidingView: params.shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset: params.keyboardAvoidingViewVerticalOffset }))));
|
|
114
122
|
}
|
|
115
123
|
else {
|
|
116
124
|
return React.createElement(StoryView, null);
|
|
@@ -5,9 +5,8 @@ interface OnDeviceUIProps {
|
|
|
5
5
|
storyIndex: StoryIndex;
|
|
6
6
|
url?: string;
|
|
7
7
|
tabOpen?: number;
|
|
8
|
-
isUIHidden?: boolean;
|
|
9
8
|
shouldDisableKeyboardAvoidingView?: boolean;
|
|
10
9
|
keyboardAvoidingViewVerticalOffset?: number;
|
|
11
10
|
}
|
|
12
|
-
declare const _default: React.MemoExoticComponent<({ storyIndex,
|
|
11
|
+
declare const _default: React.MemoExoticComponent<({ storyIndex, shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset, tabOpen: initialTabOpen, }: OnDeviceUIProps) => JSX.Element>;
|
|
13
12
|
export default _default;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import styled from '@emotion/native';
|
|
2
2
|
import React, { useState, useRef } from 'react';
|
|
3
|
-
import { Animated, Dimensions, Keyboard, KeyboardAvoidingView, Platform,
|
|
4
|
-
import { useStoryContextParam } from '../../../hooks';
|
|
3
|
+
import { Animated, Dimensions, Easing, Keyboard, KeyboardAvoidingView, Platform, TouchableOpacity, StatusBar, StyleSheet, View, } from 'react-native';
|
|
4
|
+
import { useIsSplitPanelVisible, useIsUIVisible, useStoryContextParam, useTheme, } from '../../../hooks';
|
|
5
|
+
import { ANIMATION_DURATION_TRANSITION } from '../../../constants';
|
|
5
6
|
import StoryListView from '../StoryListView';
|
|
6
7
|
import StoryView from '../StoryView';
|
|
7
8
|
import AbsolutePositionedKeyboardAwareView from './absolute-positioned-keyboard-aware-view';
|
|
8
9
|
import Addons from './addons/Addons';
|
|
9
|
-
import {
|
|
10
|
+
import { AddonsSkeleton } from './addons/AddonsSkeleton';
|
|
11
|
+
import { getAddonPanelPosition, getSidebarPanelPosition, getPreviewShadowStyle, getPreviewStyle, } from './animation';
|
|
10
12
|
import Navigation from './navigation';
|
|
11
|
-
import {
|
|
13
|
+
import { CANVAS, ADDONS } from './navigation/constants';
|
|
12
14
|
import Panel from './Panel';
|
|
13
15
|
import { useWindowDimensions } from 'react-native';
|
|
14
16
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
15
|
-
const ANIMATION_DURATION = 300;
|
|
16
17
|
const IS_IOS = Platform.OS === 'ios';
|
|
17
18
|
// @ts-ignore: Property 'Expo' does not exist on type 'Global'
|
|
18
19
|
const getExpoRoot = () => global.Expo || global.__expo || global.__exponent;
|
|
@@ -20,28 +21,22 @@ export const IS_EXPO = getExpoRoot() !== undefined;
|
|
|
20
21
|
const IS_ANDROID = Platform.OS === 'android';
|
|
21
22
|
const BREAKPOINT = 1024;
|
|
22
23
|
const flex = { flex: 1 };
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
const absolutePosition = {
|
|
33
|
-
position: 'absolute',
|
|
34
|
-
top: 0,
|
|
35
|
-
bottom: 0,
|
|
36
|
-
left: 0,
|
|
37
|
-
right: 0,
|
|
38
|
-
};
|
|
24
|
+
/**
|
|
25
|
+
* Story preview container.
|
|
26
|
+
*/
|
|
27
|
+
function Preview({ animatedValue, style, children }) {
|
|
28
|
+
const theme = useTheme();
|
|
29
|
+
const containerStyle = Object.assign({ backgroundColor: theme.preview.backgroundColor }, getPreviewShadowStyle(animatedValue));
|
|
30
|
+
return (React.createElement(Animated.View, { style: [flex, containerStyle] },
|
|
31
|
+
React.createElement(View, { style: [flex, style] }, children)));
|
|
32
|
+
}
|
|
39
33
|
const styles = StyleSheet.create({
|
|
40
34
|
expoAndroidContainer: { paddingTop: StatusBar.currentHeight },
|
|
41
35
|
});
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const [
|
|
36
|
+
const Container = styled.View(({ theme }) => (Object.assign(Object.assign({ flex: 1, backgroundColor: theme.preview.containerBackgroundColor }, (IS_ANDROID && IS_EXPO ? styles.expoAndroidContainer : undefined)), Platform.select({ web: { overflow: 'hidden' } }))));
|
|
37
|
+
const OnDeviceUI = ({ storyIndex, shouldDisableKeyboardAvoidingView, keyboardAvoidingViewVerticalOffset, tabOpen: initialTabOpen, }) => {
|
|
38
|
+
const [tabOpen, setTabOpen] = useState(initialTabOpen || CANVAS);
|
|
39
|
+
const lastTabOpen = React.useRef(tabOpen);
|
|
45
40
|
const [previewDimensions, setPreviewDimensions] = useState(() => ({
|
|
46
41
|
width: Dimensions.get('window').width,
|
|
47
42
|
height: Dimensions.get('window').height,
|
|
@@ -49,56 +44,89 @@ const OnDeviceUI = ({ storyIndex, isUIHidden, shouldDisableKeyboardAvoidingView,
|
|
|
49
44
|
const animatedValue = useRef(new Animated.Value(tabOpen));
|
|
50
45
|
const wide = useWindowDimensions().width >= BREAKPOINT;
|
|
51
46
|
const insets = useSafeAreaInsets();
|
|
52
|
-
const [isUIVisible, setIsUIVisible] = useState(isUIHidden !== undefined ? !isUIHidden : true);
|
|
53
47
|
const handleToggleTab = React.useCallback((newTabOpen) => {
|
|
54
48
|
if (newTabOpen === tabOpen) {
|
|
55
49
|
return;
|
|
56
50
|
}
|
|
51
|
+
lastTabOpen.current = tabOpen;
|
|
57
52
|
Animated.timing(animatedValue.current, {
|
|
58
53
|
toValue: newTabOpen,
|
|
59
|
-
duration:
|
|
54
|
+
duration: ANIMATION_DURATION_TRANSITION,
|
|
55
|
+
easing: Easing.inOut(Easing.cubic),
|
|
60
56
|
useNativeDriver: true,
|
|
61
57
|
}).start();
|
|
62
58
|
setTabOpen(newTabOpen);
|
|
63
|
-
const isSwipingBetweenNavigatorAndAddons = tabOpen + newTabOpen === PREVIEW;
|
|
64
|
-
setSlideBetweenAnimation(isSwipingBetweenNavigatorAndAddons);
|
|
65
59
|
// close the keyboard opened from a TextInput from story list or knobs
|
|
66
|
-
if (newTabOpen ===
|
|
60
|
+
if (newTabOpen === CANVAS) {
|
|
67
61
|
Keyboard.dismiss();
|
|
68
62
|
}
|
|
69
63
|
}, [tabOpen]);
|
|
70
64
|
const noSafeArea = useStoryContextParam('noSafeArea', false);
|
|
71
65
|
const previewWrapperStyles = [
|
|
72
66
|
flex,
|
|
73
|
-
|
|
67
|
+
getPreviewStyle({
|
|
74
68
|
animatedValue: animatedValue.current,
|
|
75
69
|
previewDimensions,
|
|
76
|
-
slideBetweenAnimation,
|
|
77
70
|
wide,
|
|
78
|
-
noSafeArea,
|
|
79
71
|
insets,
|
|
72
|
+
tabOpen,
|
|
73
|
+
lastTabOpen: lastTabOpen.current,
|
|
80
74
|
}),
|
|
81
75
|
];
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
const
|
|
76
|
+
const [isUIVisible] = useIsUIVisible();
|
|
77
|
+
// The initial value is just a guess until the layout calculation has been done.
|
|
78
|
+
const [navBarHeight, setNavBarHeight] = React.useState(insets.bottom + 40);
|
|
79
|
+
const measureNavigation = React.useCallback(({ nativeEvent }) => {
|
|
80
|
+
const inset = insets.bottom;
|
|
81
|
+
setNavBarHeight(isUIVisible ? nativeEvent.layout.height - inset : 0);
|
|
82
|
+
}, [isUIVisible, insets]);
|
|
83
|
+
// There are 4 cases for the additional UI margin:
|
|
84
|
+
// 1. Storybook UI is visible, and `noSafeArea` is false: Include top and
|
|
85
|
+
// bottom safe area insets, and also include the navigation bar height.
|
|
86
|
+
//
|
|
87
|
+
// 2. Storybook UI is not visible, and `noSafeArea` is false: Include top
|
|
88
|
+
// and bottom safe area insets.
|
|
89
|
+
//
|
|
90
|
+
// 3. Storybook UI is visible, and `noSafeArea` is true: Include only the
|
|
91
|
+
// bottom safe area inset and the navigation bar height.
|
|
92
|
+
//
|
|
93
|
+
// 4. Storybook UI is not visible, and `noSafeArea` is true: No margin.
|
|
94
|
+
const safeAreaMargins = {
|
|
95
|
+
paddingBottom: isUIVisible ? insets.bottom + navBarHeight : noSafeArea ? 0 : insets.bottom,
|
|
96
|
+
paddingTop: !noSafeArea ? insets.top : 0,
|
|
97
|
+
overflow: 'hidden',
|
|
98
|
+
};
|
|
99
|
+
// The panels always apply the safe area, regardless of the story parameters.
|
|
100
|
+
const panelSafeAreaMargins = {
|
|
101
|
+
paddingBottom: insets.bottom + navBarHeight,
|
|
102
|
+
paddingTop: insets.top,
|
|
103
|
+
};
|
|
104
|
+
// Adjust the keyboard offset (possibly in a negative direction) to account
|
|
105
|
+
// for the safe area and navigation bar.
|
|
106
|
+
const keyboardVerticalOffset = -panelSafeAreaMargins.paddingBottom + (keyboardAvoidingViewVerticalOffset !== null && keyboardAvoidingViewVerticalOffset !== void 0 ? keyboardAvoidingViewVerticalOffset : 0);
|
|
107
|
+
const [isSplitPanelVisible] = useIsSplitPanelVisible();
|
|
108
|
+
const isPreviewInactive = tabOpen !== CANVAS;
|
|
85
109
|
return (React.createElement(React.Fragment, null,
|
|
86
|
-
React.createElement(
|
|
87
|
-
React.createElement(KeyboardAvoidingView, { enabled: !shouldDisableKeyboardAvoidingView ||
|
|
110
|
+
React.createElement(Container, null,
|
|
111
|
+
React.createElement(KeyboardAvoidingView, { enabled: !shouldDisableKeyboardAvoidingView || isPreviewInactive, behavior: IS_IOS ? 'padding' : null, keyboardVerticalOffset: keyboardVerticalOffset, style: flex },
|
|
88
112
|
React.createElement(AbsolutePositionedKeyboardAwareView, { onLayout: setPreviewDimensions, previewDimensions: previewDimensions },
|
|
89
113
|
React.createElement(Animated.View, { style: previewWrapperStyles },
|
|
90
|
-
React.createElement(
|
|
91
|
-
React.createElement(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
114
|
+
React.createElement(Preview, { style: safeAreaMargins, animatedValue: animatedValue.current },
|
|
115
|
+
React.createElement(StoryView, null),
|
|
116
|
+
isSplitPanelVisible ? (React.createElement(Panel, { edge: "top", style: { flex: 1 } },
|
|
117
|
+
React.createElement(Addons, { active: true }),
|
|
118
|
+
React.createElement(AddonsSkeleton, { visible: isPreviewInactive }))) : null),
|
|
119
|
+
isPreviewInactive ? (React.createElement(TouchableOpacity, { style: StyleSheet.absoluteFillObject, onPress: () => handleToggleTab(CANVAS) })) : null),
|
|
120
|
+
React.createElement(Panel, { edge: "right", style: [
|
|
121
|
+
getSidebarPanelPosition(animatedValue.current, previewDimensions.width, wide),
|
|
122
|
+
panelSafeAreaMargins,
|
|
123
|
+
] },
|
|
96
124
|
React.createElement(StoryListView, { storyIndex: storyIndex })),
|
|
97
|
-
React.createElement(Panel, { style: [
|
|
125
|
+
React.createElement(Panel, { edge: "left", style: [
|
|
98
126
|
getAddonPanelPosition(animatedValue.current, previewDimensions.width, wide),
|
|
99
|
-
|
|
127
|
+
panelSafeAreaMargins,
|
|
100
128
|
] },
|
|
101
129
|
React.createElement(Addons, { active: tabOpen === ADDONS })))),
|
|
102
|
-
React.createElement(Navigation, { tabOpen: tabOpen, onChangeTab: handleToggleTab
|
|
130
|
+
React.createElement(Navigation, { onLayout: measureNavigation, tabOpen: tabOpen, onChangeTab: handleToggleTab }))));
|
|
103
131
|
};
|
|
104
132
|
export default React.memo(OnDeviceUI);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import React
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Animated, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
interface PanelProps {
|
|
4
|
+
edge: 'left' | 'right' | 'top';
|
|
5
|
+
style: StyleProp<Animated.AnimatedProps<ViewStyle>>;
|
|
6
|
+
children: React.ReactNode;
|
|
5
7
|
}
|
|
6
|
-
declare const _default: React.MemoExoticComponent<({ children, style }:
|
|
8
|
+
declare const _default: React.MemoExoticComponent<({ edge, children, style }: PanelProps) => JSX.Element>;
|
|
7
9
|
export default _default;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { StyleSheet, Animated } from 'react-native';
|
|
3
3
|
import styled from '@emotion/native';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const Container = styled(Animated.View)(({ theme, edge }) => ({
|
|
5
|
+
backgroundColor: theme.panel.backgroundColor,
|
|
6
|
+
borderTopWidth: edge === 'top' ? theme.panel.borderWidth : undefined,
|
|
7
|
+
borderStartWidth: edge === 'left' ? theme.panel.borderWidth : undefined,
|
|
8
|
+
borderEndWidth: edge === 'right' ? theme.panel.borderWidth : undefined,
|
|
9
|
+
borderColor: theme.panel.borderColor,
|
|
7
10
|
}));
|
|
8
|
-
const Panel = ({ children, style }) =>
|
|
11
|
+
const Panel = ({ edge, children, style }) => {
|
|
12
|
+
const containerStyle = StyleSheet.flatten([
|
|
13
|
+
edge === 'top' ? undefined : StyleSheet.absoluteFillObject,
|
|
14
|
+
style,
|
|
15
|
+
]);
|
|
16
|
+
return (React.createElement(Container, { edge: edge, style: containerStyle }, children));
|
|
17
|
+
};
|
|
9
18
|
export default React.memo(Panel);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
interface AddonsProps {
|
|
3
3
|
active: boolean;
|
|
4
|
-
}
|
|
4
|
+
}
|
|
5
|
+
declare const _default: React.MemoExoticComponent<({ active }: AddonsProps) => JSX.Element>;
|
|
5
6
|
export default _default;
|
|
@@ -1,33 +1,28 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { SafeAreaView, StyleSheet } from 'react-native';
|
|
3
|
-
import styled from '@emotion/native';
|
|
1
|
+
import React from 'react';
|
|
4
2
|
import { addons } from '@storybook/addons';
|
|
3
|
+
import { useSelectedAddon, useStoryContext } from '../../../../hooks';
|
|
5
4
|
import AddonsList from './List';
|
|
6
5
|
import AddonWrapper from './Wrapper';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
justifyContent: 'center',
|
|
12
|
-
});
|
|
13
|
-
const Container = styled.View(({ theme }) => ({
|
|
14
|
-
flex: 1,
|
|
15
|
-
backgroundColor: theme.backgroundColor,
|
|
6
|
+
import { Box } from '../../Shared/layout';
|
|
7
|
+
import styled from '@emotion/native';
|
|
8
|
+
const Text = styled.Text(({ theme }) => ({
|
|
9
|
+
marginTop: theme.tokens.spacing4,
|
|
16
10
|
}));
|
|
17
11
|
const Addons = ({ active }) => {
|
|
18
12
|
const panels = addons.getElements('panel');
|
|
19
|
-
const [addonSelected, setAddonSelected] =
|
|
13
|
+
const [addonSelected, setAddonSelected] = useSelectedAddon(Object.keys(panels)[0]);
|
|
14
|
+
const context = useStoryContext();
|
|
15
|
+
const id = context === null || context === void 0 ? void 0 : context.id;
|
|
16
|
+
if (!id) {
|
|
17
|
+
return (React.createElement(Box, { alignItems: "center", justifyContent: "center" },
|
|
18
|
+
React.createElement(Text, null, "No Story Selected")));
|
|
19
|
+
}
|
|
20
20
|
if (Object.keys(panels).length === 0) {
|
|
21
|
-
return (React.createElement(
|
|
22
|
-
React.createElement(
|
|
23
|
-
React.createElement(Label, null, "No addons loaded."))));
|
|
21
|
+
return (React.createElement(Box, { alignItems: "center", justifyContent: "center" },
|
|
22
|
+
React.createElement(Text, null, "No addons loaded.")));
|
|
24
23
|
}
|
|
25
|
-
return (React.createElement(
|
|
26
|
-
React.createElement(
|
|
27
|
-
|
|
28
|
-
React.createElement(AddonWrapper, { addonSelected: active ? addonSelected : null, panels: panels }))));
|
|
24
|
+
return (React.createElement(Box, { flex: true },
|
|
25
|
+
React.createElement(AddonsList, { onPressAddon: setAddonSelected, panels: panels, addonSelected: active ? addonSelected : null }),
|
|
26
|
+
React.createElement(AddonWrapper, { addonSelected: active ? addonSelected : null, panels: panels })));
|
|
29
27
|
};
|
|
30
|
-
const styles = StyleSheet.create({
|
|
31
|
-
container: { flex: 1 },
|
|
32
|
-
});
|
|
33
28
|
export default React.memo(Addons);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Component that mimics the addons panel.
|
|
4
|
+
*
|
|
5
|
+
* The main reason this exists is that the scaled addons view feels more
|
|
6
|
+
* cluttered than a more abstract skeleton view, which allows users to focus
|
|
7
|
+
* on the story content rather than become distracted by the addons UI in an
|
|
8
|
+
* already small view.
|
|
9
|
+
*/
|
|
10
|
+
export declare const AddonsSkeleton: React.NamedExoticComponent<AddonsSkeletonProps>;
|
|
11
|
+
interface AddonsSkeletonProps {
|
|
12
|
+
visible: boolean;
|
|
13
|
+
}
|
|
14
|
+
export {};
|