@fluentui-react-native/storybook-desktop-runtime 0.2.1 → 0.3.1
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/.cache/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +48 -0
- package/README.md +18 -0
- package/config/metro.cjs +6 -1
- package/jest.config.cjs +1 -0
- package/lib/DesktopStoryRoot.d.ts.map +1 -1
- package/lib/DesktopStoryRoot.js +3 -2
- package/lib/DesktopStoryRoot.js.map +1 -1
- package/lib/StorybookTheme.d.ts +0 -1
- package/lib/StorybookTheme.d.ts.map +1 -1
- package/lib/StorybookTheme.js +29 -27
- package/lib/StorybookTheme.js.map +1 -1
- package/lib/StorybookTheme.test.d.ts +2 -0
- package/lib/StorybookTheme.test.d.ts.map +1 -0
- package/lib/StorybookTheme.test.js +131 -0
- package/lib/StorybookTheme.test.js.map +1 -0
- package/lib/StorybookUI.win32.js +3 -3
- package/lib/StorybookUI.win32.js.map +1 -1
- package/lib/ThemedStorybookUI.d.ts +3 -0
- package/lib/ThemedStorybookUI.d.ts.map +1 -0
- package/lib/ThemedStorybookUI.js +8 -0
- package/lib/ThemedStorybookUI.js.map +1 -0
- package/lib/Win32CalloutPortal.d.ts.map +1 -1
- package/lib/Win32CalloutPortal.js +3 -2
- package/lib/Win32CalloutPortal.js.map +1 -1
- package/lib/createDesktopStorybookApp.d.ts.map +1 -1
- package/lib/createDesktopStorybookApp.js +4 -14
- package/lib/createDesktopStorybookApp.js.map +1 -1
- package/lib/createDesktopStorybookPreview.d.ts.map +1 -1
- package/lib/createDesktopStorybookPreview.js +1 -2
- package/lib/createDesktopStorybookPreview.js.map +1 -1
- package/lib/useStorybookTheme.d.ts +3 -0
- package/lib/useStorybookTheme.d.ts.map +1 -0
- package/lib/useStorybookTheme.js +106 -0
- package/lib/useStorybookTheme.js.map +1 -0
- package/lib/useStorybookTheme.test.d.ts +2 -0
- package/lib/useStorybookTheme.test.d.ts.map +1 -0
- package/lib/useStorybookTheme.test.js +66 -0
- package/lib/useStorybookTheme.test.js.map +1 -0
- package/package.json +13 -6
- package/src/DesktopStoryRoot.tsx +3 -2
- package/src/StorybookTheme.test.tsx +164 -0
- package/src/StorybookTheme.tsx +91 -78
- package/src/StorybookUI.win32.tsx +3 -3
- package/src/ThemedStorybookUI.tsx +9 -0
- package/src/Win32CalloutPortal.tsx +4 -3
- package/src/createDesktopStorybookApp.tsx +6 -25
- package/src/createDesktopStorybookPreview.tsx +5 -8
- package/src/useStorybookTheme.test.tsx +92 -0
- package/src/useStorybookTheme.ts +113 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { StyleSheet, View as NativeView } from 'react-native';
|
|
3
2
|
import { DesktopDriverBridge } from './DesktopDriverBridge';
|
|
4
|
-
import { DesktopStorybookConfigProvider
|
|
3
|
+
import { DesktopStorybookConfigProvider } from './DesktopStorybookConfig';
|
|
5
4
|
import { StorybookThemeHost } from './StorybookTheme';
|
|
6
|
-
import {
|
|
5
|
+
import { ThemedStorybookUI } from './ThemedStorybookUI';
|
|
7
6
|
export function createDesktopStorybookApp(view, { enableWebsockets = true, host = '127.0.0.1', port, testIDPrefix = 'storybook-desktop' } = {}) {
|
|
8
7
|
const runtimeInstance = globalThis.__FURN_DESKTOP_STORYBOOK_INSTANCE__;
|
|
9
8
|
const memoryStore = {};
|
|
@@ -17,22 +16,13 @@ export function createDesktopStorybookApp(view, { enableWebsockets = true, host
|
|
|
17
16
|
enableWebsockets,
|
|
18
17
|
host,
|
|
19
18
|
port: port ?? runtimeInstance?.storybookPort ?? 7007,
|
|
20
|
-
CustomUIComponent:
|
|
19
|
+
CustomUIComponent: ThemedStorybookUI,
|
|
21
20
|
storage,
|
|
22
21
|
});
|
|
23
22
|
function DesktopStorybookApp() {
|
|
24
23
|
const resolvedTestIDPrefix = runtimeInstance?.testIDPrefix ?? testIDPrefix;
|
|
25
|
-
return (_jsx(DesktopStorybookConfigProvider, { runtimeInstance: runtimeInstance, testIDPrefix: resolvedTestIDPrefix, children: _jsxs(
|
|
24
|
+
return (_jsx(DesktopStorybookConfigProvider, { runtimeInstance: runtimeInstance, testIDPrefix: resolvedTestIDPrefix, children: _jsxs(StorybookThemeHost, { children: [_jsx(DesktopDriverBridge, {}), _jsx(StorybookUI, {})] }) }));
|
|
26
25
|
}
|
|
27
26
|
return DesktopStorybookApp;
|
|
28
27
|
}
|
|
29
|
-
function DesktopStorybookAppRoot({ children }) {
|
|
30
|
-
const testID = useDesktopStorybookTestID('app-root');
|
|
31
|
-
return (_jsx(NativeView, { style: styles.root, testID: testID, children: children }));
|
|
32
|
-
}
|
|
33
|
-
const styles = StyleSheet.create({
|
|
34
|
-
root: {
|
|
35
|
-
flex: 1,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
28
|
//# sourceMappingURL=createDesktopStorybookApp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDesktopStorybookApp.js","sourceRoot":"","sources":["../src/createDesktopStorybookApp.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"createDesktopStorybookApp.js","sourceRoot":"","sources":["../src/createDesktopStorybookApp.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AASxD,MAAM,UAAU,yBAAyB,CACvC,IAAkC,EAClC,EAAE,gBAAgB,GAAG,IAAI,EAAE,IAAI,GAAG,WAAW,EAAE,IAAI,EAAE,YAAY,GAAG,mBAAmB,EAAE,GAA4B,EAAE;IAEvH,MAAM,eAAe,GACnB,UAGD,CAAC,mCAAmC,CAAC;IACtC,MAAM,WAAW,GAA2B,EAAE,CAAC;IAC/C,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,KAAK,EAAE,GAAW,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC9E,OAAO,EAAE,KAAK,EAAE,GAAW,EAAE,KAAa,EAAE,EAAE;YAC5C,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC3B,CAAC;KACF,CAAC;IACF,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC;QACtC,gBAAgB;QAChB,IAAI;QACJ,IAAI,EAAE,IAAI,IAAI,eAAe,EAAE,aAAa,IAAI,IAAI;QACpD,iBAAiB,EAAE,iBAAiB;QACpC,OAAO;KACR,CAAC,CAAC;IAEH,SAAS,mBAAmB;QAC1B,MAAM,oBAAoB,GAAG,eAAe,EAAE,YAAY,IAAI,YAAY,CAAC;QAC3E,OAAO,CACL,KAAC,8BAA8B,IAAC,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,YAClG,MAAC,kBAAkB,eACjB,KAAC,mBAAmB,KAAG,EACvB,KAAC,WAAW,KAAG,IACI,GACU,CAClC,CAAC;IACJ,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDesktopStorybookPreview.d.ts","sourceRoot":"","sources":["../src/createDesktopStorybookPreview.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"createDesktopStorybookPreview.d.ts","sourceRoot":"","sources":["../src/createDesktopStorybookPreview.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAIvD,wBAAgB,6BAA6B,IAAI,OAAO,CAavD"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { StyleSheet, View } from 'react-native';
|
|
3
3
|
import { DesktopStoryRoot } from './DesktopStoryRoot';
|
|
4
|
-
import { StorybookThemeProvider } from './StorybookTheme';
|
|
5
4
|
export function createDesktopStorybookPreview() {
|
|
6
5
|
return {
|
|
7
6
|
decorators: [
|
|
8
|
-
(Story, context) => (_jsx(
|
|
7
|
+
(Story, context) => (_jsx(DesktopStoryRoot, { storyId: context.id, children: _jsx(View, { style: styles.story, children: _jsx(Story, {}) }) })),
|
|
9
8
|
],
|
|
10
9
|
parameters: {},
|
|
11
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDesktopStorybookPreview.js","sourceRoot":"","sources":["../src/createDesktopStorybookPreview.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"createDesktopStorybookPreview.js","sourceRoot":"","sources":["../src/createDesktopStorybookPreview.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,UAAU,6BAA6B;IAC3C,OAAO;QACL,UAAU,EAAE;YACV,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAClB,KAAC,gBAAgB,IAAC,OAAO,EAAE,OAAO,CAAC,EAAE,YACnC,KAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,KAAK,YACvB,KAAC,KAAK,KAAG,GACJ,GACU,CACpB;SACF;QACD,UAAU,EAAE,EAAE;KACf,CAAC;AACJ,CAAC;AAED,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,KAAK,EAAE;QACL,UAAU,EAAE,QAAQ;QACpB,IAAI,EAAE,CAAC;QACP,cAAc,EAAE,QAAQ;QACxB,OAAO,EAAE,EAAE;KACZ;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorybookTheme.d.ts","sourceRoot":"","sources":["../src/useStorybookTheme.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAE7D,wBAAgB,iBAAiB,IAAI,KAAK,CAWzC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useThemeState } from '@fluentui-react-native/design';
|
|
3
|
+
import { darkTheme, theme as lightTheme } from '@storybook/react-native-theming';
|
|
4
|
+
export function useStorybookTheme() {
|
|
5
|
+
const state = useThemeState();
|
|
6
|
+
const { theme, nativeColors } = React.useMemo(() => storybookThemeFromThemeState(state), [state]);
|
|
7
|
+
React.useEffect(() => {
|
|
8
|
+
if (nativeColors.length > 0) {
|
|
9
|
+
console.warn(`Storybook chrome cannot resolve native system colors; using fixed contrasting theme colors for: ${nativeColors.join(', ')}.`);
|
|
10
|
+
}
|
|
11
|
+
}, [nativeColors]);
|
|
12
|
+
return theme;
|
|
13
|
+
}
|
|
14
|
+
function storybookThemeFromThemeState({ appearance, highContrast, tokens }) {
|
|
15
|
+
const base = highContrast || appearance.colorScheme === 'dark' ? darkTheme : lightTheme;
|
|
16
|
+
const foreground = base.base === 'dark' ? 'fixedWhite' : 'fixedBlack';
|
|
17
|
+
const background = base.base === 'dark' ? 'fixedBlack' : 'fixedWhite';
|
|
18
|
+
const nativeColors = new Set();
|
|
19
|
+
const color = (name, role = 'foreground') => {
|
|
20
|
+
const value = tokens.color[name];
|
|
21
|
+
// Storybook also passes these colors to JS color utilities, not just native styles.
|
|
22
|
+
if (typeof value === 'string') {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
nativeColors.add(name);
|
|
26
|
+
const fallbackName = role === 'foreground' ? foreground : background;
|
|
27
|
+
const fallback = tokens.color[fallbackName];
|
|
28
|
+
if (typeof fallback !== 'string') {
|
|
29
|
+
throw new Error(`Storybook chrome requires a literal "${fallbackName}" fallback for the "${name}" theme token.`);
|
|
30
|
+
}
|
|
31
|
+
return fallback;
|
|
32
|
+
};
|
|
33
|
+
const theme = {
|
|
34
|
+
...base,
|
|
35
|
+
color: {
|
|
36
|
+
...base.color,
|
|
37
|
+
primary: color('foregroundBrandPrimary'),
|
|
38
|
+
secondary: color('backgroundBrandHeavy'),
|
|
39
|
+
secondaryLighter: color('backgroundBrandSoft', 'background'),
|
|
40
|
+
tertiary: color('foregroundSuccessPrimary'),
|
|
41
|
+
ancillary: color('foregroundBrandPrimary'),
|
|
42
|
+
orange: color('foregroundWarningPrimary'),
|
|
43
|
+
gold: color('foregroundWarningPrimary'),
|
|
44
|
+
green: color('foregroundSuccessPrimary'),
|
|
45
|
+
seafoam: color('foregroundSuccessPrimary'),
|
|
46
|
+
purple: color('foregroundBrandPrimary'),
|
|
47
|
+
ultraviolet: color('foregroundBrandPrimary'),
|
|
48
|
+
lightest: color('foregroundBrandOnloud', 'background'),
|
|
49
|
+
lighter: color('surfaceNeutralNear', 'background'),
|
|
50
|
+
light: color('backgroundNeutralSubtle', 'background'),
|
|
51
|
+
mediumlight: color('strokeNeutralSubtle'),
|
|
52
|
+
medium: color('strokeNeutralSoft'),
|
|
53
|
+
mediumdark: color('foregroundNeutralSecondary'),
|
|
54
|
+
dark: color('foregroundNeutralPrimary'),
|
|
55
|
+
darker: color('foregroundNeutralPrimary'),
|
|
56
|
+
darkest: color('foregroundNeutralPrimary'),
|
|
57
|
+
border: color('strokeNeutralSoft'),
|
|
58
|
+
positive: color('foregroundSuccessPrimary'),
|
|
59
|
+
negative: color('foregroundDangerPrimary'),
|
|
60
|
+
warning: color('foregroundWarningPrimary'),
|
|
61
|
+
critical: color('foregroundDangerPrimary'),
|
|
62
|
+
defaultText: color('foregroundNeutralPrimary'),
|
|
63
|
+
inverseText: color('foregroundNeutralOnloud', 'background'),
|
|
64
|
+
positiveText: color('foregroundSuccessPrimary'),
|
|
65
|
+
negativeText: color('foregroundDangerPrimary'),
|
|
66
|
+
warningText: color('foregroundWarningPrimary'),
|
|
67
|
+
},
|
|
68
|
+
background: {
|
|
69
|
+
...base.background,
|
|
70
|
+
app: color('surfaceNeutralFar', 'background'),
|
|
71
|
+
bar: color('backgroundNeutralSubtle', 'background'),
|
|
72
|
+
// LiteUI and StoryView paint the canvas with content rather than preview.
|
|
73
|
+
content: color('surfaceNeutralFar', 'background'),
|
|
74
|
+
preview: color('surfaceNeutralFar', 'background'),
|
|
75
|
+
hoverable: color('backgroundNeutralSoft', 'background'),
|
|
76
|
+
positive: color('backgroundSuccessSubtle', 'background'),
|
|
77
|
+
negative: color('backgroundDangerSubtle', 'background'),
|
|
78
|
+
warning: color('backgroundWarningSubtle', 'background'),
|
|
79
|
+
critical: color('backgroundDangerSubtle', 'background'),
|
|
80
|
+
},
|
|
81
|
+
textMutedColor: color('foregroundNeutralTertiary'),
|
|
82
|
+
input: {
|
|
83
|
+
...base.input,
|
|
84
|
+
border: color('strokeNeutralSoft'),
|
|
85
|
+
background: color('backgroundNeutralLoud', 'background'),
|
|
86
|
+
color: color('foregroundNeutralPrimary'),
|
|
87
|
+
},
|
|
88
|
+
button: {
|
|
89
|
+
...base.button,
|
|
90
|
+
background: color('backgroundNeutralLoud', 'background'),
|
|
91
|
+
border: color('strokeNeutralSoft'),
|
|
92
|
+
},
|
|
93
|
+
boolean: {
|
|
94
|
+
...base.boolean,
|
|
95
|
+
background: color('backgroundNeutralSoft', 'background'),
|
|
96
|
+
selectedBackground: color('backgroundBrandHeavy'),
|
|
97
|
+
},
|
|
98
|
+
appBorderColor: color('strokeNeutralSubtle'),
|
|
99
|
+
barTextColor: color('foregroundNeutralPrimary'),
|
|
100
|
+
barHoverColor: color('foregroundBrandPrimary'),
|
|
101
|
+
barSelectedColor: color('foregroundBrandPrimary'),
|
|
102
|
+
barBg: color('backgroundNeutralSubtle', 'background'),
|
|
103
|
+
};
|
|
104
|
+
return { theme, nativeColors: [...nativeColors] };
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=useStorybookTheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorybookTheme.js","sourceRoot":"","sources":["../src/useStorybookTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAGjF,MAAM,UAAU,iBAAiB;IAC/B,MAAM,KAAK,GAAG,aAAa,EAAE,CAAC;IAC9B,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,4BAA4B,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAClG,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO,CAAC,IAAI,CACV,mGAAmG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC9H,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IACnB,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,4BAA4B,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAc;IACpF,MAAM,IAAI,GAAG,YAAY,IAAI,UAAU,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;IACxF,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY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C;IACF,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorybookTheme.test.d.ts","sourceRoot":"","sources":["../src/useStorybookTheme.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { PlatformColor } from 'react-native';
|
|
3
|
+
import { act, render } from '@testing-library/react-native';
|
|
4
|
+
import { FlexThemeReference, ThemedRoot, useThemeState } from '@fluentui-react-native/design';
|
|
5
|
+
import { useStorybookTheme } from './useStorybookTheme';
|
|
6
|
+
function Probe({ themes, states }) {
|
|
7
|
+
themes.push(useStorybookTheme());
|
|
8
|
+
const state = useThemeState();
|
|
9
|
+
states?.push(state);
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
describe('Storybook theme palette', () => {
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
jest.restoreAllMocks();
|
|
15
|
+
});
|
|
16
|
+
it('derives colors from the current tokens and updates after source invalidation', async () => {
|
|
17
|
+
const themes = [];
|
|
18
|
+
const states = [];
|
|
19
|
+
const source = new FlexThemeReference({
|
|
20
|
+
base: { color: { surfaceNeutralFar: '#123456', foregroundNeutralPrimary: '#abcdef' } },
|
|
21
|
+
});
|
|
22
|
+
const scene = await render(_jsx(ThemedRoot, { theme: source, children: _jsx(Probe, { themes: themes, states: states }) }));
|
|
23
|
+
expect(themes[0].background.app).toBe('#123456');
|
|
24
|
+
expect(themes[0].background.content).toBe('#123456');
|
|
25
|
+
expect(themes[0].background.preview).toBe('#123456');
|
|
26
|
+
expect(themes[0].color.defaultText).toBe('#abcdef');
|
|
27
|
+
await scene.rerender(_jsx(ThemedRoot, { theme: source, children: _jsx(Probe, { themes: themes, states: states }) }));
|
|
28
|
+
expect(themes[themes.length - 1]).toBe(themes[0]);
|
|
29
|
+
await act(() => source.update({ color: { surfaceNeutralFar: '#654321' } }));
|
|
30
|
+
expect(themes[themes.length - 1].background.app).toBe('#654321');
|
|
31
|
+
expect(themes[themes.length - 1].background.content).toBe('#654321');
|
|
32
|
+
expect(themes[themes.length - 1].background.preview).toBe('#654321');
|
|
33
|
+
expect(themes[themes.length - 1]).not.toBe(themes[0]);
|
|
34
|
+
expect(themes[themes.length - 1].appBorderColor).toBe(states[states.length - 1].tokens.color.strokeNeutralSubtle);
|
|
35
|
+
});
|
|
36
|
+
it('warns and substitutes a contrasting theme color for native opaque colors', async () => {
|
|
37
|
+
const warn = jest.spyOn(console, 'warn').mockImplementation();
|
|
38
|
+
const themes = [];
|
|
39
|
+
const states = [];
|
|
40
|
+
const source = new FlexThemeReference({ base: { color: { foregroundBrandPrimary: PlatformColor('labelColor') } } });
|
|
41
|
+
await render(_jsx(ThemedRoot, { theme: source, children: _jsx(Probe, { themes: themes, states: states }) }));
|
|
42
|
+
expect(themes[0].color.primary).toBe(states[0].tokens.color.fixedBlack);
|
|
43
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
44
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('foregroundBrandPrimary'));
|
|
45
|
+
});
|
|
46
|
+
it.each([
|
|
47
|
+
['light', 'standard', 'fixedWhite'],
|
|
48
|
+
['dark', 'standard', 'fixedBlack'],
|
|
49
|
+
['light', 'highContrast', 'fixedBlack'],
|
|
50
|
+
['dark', 'highContrast', 'fixedBlack'],
|
|
51
|
+
])('retains the native canvas fallback for %s/%s', async (colorScheme, contrast, fallback) => {
|
|
52
|
+
const warn = jest.spyOn(console, 'warn').mockImplementation();
|
|
53
|
+
const themes = [];
|
|
54
|
+
const states = [];
|
|
55
|
+
const source = new FlexThemeReference({
|
|
56
|
+
appearance: { colorScheme, contrast },
|
|
57
|
+
base: { color: { surfaceNeutralFar: PlatformColor('windowBackgroundColor') } },
|
|
58
|
+
});
|
|
59
|
+
await render(_jsx(ThemedRoot, { theme: source, children: _jsx(Probe, { themes: themes, states: states }) }));
|
|
60
|
+
expect(themes[0].background.content).toBe(states[0].tokens.color[fallback]);
|
|
61
|
+
expect(themes[0].background.preview).toBe(states[0].tokens.color[fallback]);
|
|
62
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
63
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('surfaceNeutralFar'));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=useStorybookTheme.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorybookTheme.test.js","sourceRoot":"","sources":["../src/useStorybookTheme.test.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAI9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,SAAS,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,EAA8C;IAC3E,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACjC,MAAM,KAAK,GAAG,aAAa,EAAE,CAAC;IAC9B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACpB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,eAAe,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8EAA8E,EAAE,KAAK,IAAI,EAAE;QAC5F,MAAM,MAAM,GAAY,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAiB,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,IAAI,kBAAkB,CAAC;YACpC,IAAI,EAAE,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AC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC5E,MAAM,CAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACtC,MAAM,CAAC,IAAI,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAClF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui-react-native/storybook-desktop-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "React Native runtime and Metro services for desktop Storybook applications",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "",
|
|
@@ -27,12 +27,13 @@
|
|
|
27
27
|
"build": "tsc -b",
|
|
28
28
|
"clean": "fluentui-scripts clean",
|
|
29
29
|
"format": "fluentui-scripts format",
|
|
30
|
-
"lint": "fluentui-scripts lint"
|
|
30
|
+
"lint": "fluentui-scripts lint",
|
|
31
|
+
"test": "fluentui-scripts jest"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@fluentui-react-native/callout": "0.29.
|
|
34
|
-
"@fluentui-react-native/default-theme": "0.27.
|
|
35
|
-
"@fluentui-react-native/design": "0.
|
|
34
|
+
"@fluentui-react-native/callout": "0.29.6",
|
|
35
|
+
"@fluentui-react-native/default-theme": "0.27.14",
|
|
36
|
+
"@fluentui-react-native/design": "0.5.1",
|
|
36
37
|
"@rnx-kit/metro-config": "^2.2.4",
|
|
37
38
|
"@rnx-kit/metro-resolver-symlinks": "^0.3.1",
|
|
38
39
|
"@storybook/react-native": "^10.4.7",
|
|
@@ -46,12 +47,17 @@
|
|
|
46
47
|
"@babel/core": "^7.20.0",
|
|
47
48
|
"@fluentui-react-native/scripts": "0.1.0",
|
|
48
49
|
"@office-iss/react-native-win32": "^0.81.0",
|
|
50
|
+
"@react-native-community/cli": "^20.0.0",
|
|
51
|
+
"@react-native-community/cli-platform-android": "^20.0.0",
|
|
52
|
+
"@react-native-community/cli-platform-ios": "^20.0.0",
|
|
49
53
|
"@react-native/babel-preset": "^0.81.0",
|
|
54
|
+
"@testing-library/react-native": "^14.0.1",
|
|
50
55
|
"@types/react": "~19.1.4",
|
|
51
56
|
"react": "19.1.4",
|
|
52
57
|
"react-native": "^0.81.6",
|
|
53
58
|
"react-native-macos": "^0.81.0",
|
|
54
|
-
"react-native-windows": "^0.81.0"
|
|
59
|
+
"react-native-windows": "^0.81.0",
|
|
60
|
+
"test-renderer": "1.1.0"
|
|
55
61
|
},
|
|
56
62
|
"peerDependencies": {
|
|
57
63
|
"@office-iss/react-native-win32": "^0.81.0",
|
|
@@ -76,6 +82,7 @@
|
|
|
76
82
|
}
|
|
77
83
|
},
|
|
78
84
|
"furn": {
|
|
85
|
+
"jestPlatform": "macos",
|
|
79
86
|
"knip": {
|
|
80
87
|
"ignoreDependencies": [
|
|
81
88
|
"@fluentui-react-native/callout"
|
package/src/DesktopStoryRoot.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { StyleSheet, View } from 'react-native';
|
|
2
|
+
import { Platform, StyleSheet, View } from 'react-native';
|
|
3
3
|
import { addons } from 'storybook/preview-api';
|
|
4
4
|
|
|
5
5
|
import { desktopStoryErrorEvent, desktopStoryReadyEvent } from './DesktopDriverBridge';
|
|
@@ -13,6 +13,7 @@ type DesktopStoryRootProps = {
|
|
|
13
13
|
export function DesktopStoryRoot({ children, storyId }: DesktopStoryRootProps) {
|
|
14
14
|
const { runtimeInstance, selection } = useDesktopStorybookConfig();
|
|
15
15
|
const testID = useDesktopStorybookTestID('story-root');
|
|
16
|
+
const exposeNativeMarker = Platform.OS === 'macos' || Platform.OS === 'windows' || Platform.OS === ('win32' as any);
|
|
16
17
|
const activeSelection = selection?.storyId === storyId ? selection : undefined;
|
|
17
18
|
|
|
18
19
|
React.useEffect(() => {
|
|
@@ -49,7 +50,7 @@ export function DesktopStoryRoot({ children, storyId }: DesktopStoryRootProps) {
|
|
|
49
50
|
}
|
|
50
51
|
}}
|
|
51
52
|
>
|
|
52
|
-
<View accessibilityLabel={marker} style={styles.root} testID={testID}>
|
|
53
|
+
<View accessibilityLabel={marker} accessible={exposeNativeMarker || undefined} style={styles.root} testID={testID}>
|
|
53
54
|
{children}
|
|
54
55
|
</View>
|
|
55
56
|
</StoryRenderErrorBoundary>
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { StyleSheet, Text } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { fireEvent, render } from '@testing-library/react-native';
|
|
5
|
+
import { useRootSettings, useThemeState } from '@fluentui-react-native/design';
|
|
6
|
+
import type { RootSettings, ThemeState } from '@fluentui-react-native/design';
|
|
7
|
+
import { defaultFlexTokens } from '@fluentui-react-native/design/testing';
|
|
8
|
+
import type { View as StorybookView } from '@storybook/react-native';
|
|
9
|
+
import { theme as lightTheme } from '@storybook/react-native-theming';
|
|
10
|
+
|
|
11
|
+
import { createDesktopStorybookApp } from './createDesktopStorybookApp';
|
|
12
|
+
import { DesktopDriverBridge } from './DesktopDriverBridge';
|
|
13
|
+
import { StorybookUIComponent } from './StorybookUI';
|
|
14
|
+
|
|
15
|
+
jest.mock('./DesktopDriverBridge', () => ({ DesktopDriverBridge: jest.fn(() => null) }));
|
|
16
|
+
jest.mock('./StorybookUI', () => ({ StorybookUIComponent: jest.fn(() => null) }));
|
|
17
|
+
|
|
18
|
+
function createTestApp(storyBackgroundColor?: string) {
|
|
19
|
+
const roots: RootSettings[] = [];
|
|
20
|
+
const bridgeRoots: RootSettings[] = [];
|
|
21
|
+
const themes: ThemeState[] = [];
|
|
22
|
+
const mounted = jest.fn();
|
|
23
|
+
const unmounted = jest.fn();
|
|
24
|
+
|
|
25
|
+
function Story() {
|
|
26
|
+
roots.push(useRootSettings());
|
|
27
|
+
themes.push(useThemeState());
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
mounted();
|
|
30
|
+
return unmounted;
|
|
31
|
+
}, []);
|
|
32
|
+
return <Text testID="selected-story">Selected story</Text>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
jest.mocked(DesktopDriverBridge).mockImplementation(() => {
|
|
36
|
+
bridgeRoots.push(useRootSettings());
|
|
37
|
+
return null;
|
|
38
|
+
});
|
|
39
|
+
jest.mocked(StorybookUIComponent).mockImplementation(({ children }) => <>{children}</>);
|
|
40
|
+
|
|
41
|
+
const getStorybookUI = jest.fn<ReturnType<StorybookView['getStorybookUI']>, Parameters<StorybookView['getStorybookUI']>>((params) => {
|
|
42
|
+
const UI = params?.CustomUIComponent;
|
|
43
|
+
if (!UI) {
|
|
44
|
+
throw new Error('Expected the app factory to configure the themed UI.');
|
|
45
|
+
}
|
|
46
|
+
return () => (
|
|
47
|
+
<UI
|
|
48
|
+
storyBackgroundColor={storyBackgroundColor}
|
|
49
|
+
storyHash={{}}
|
|
50
|
+
setStory={jest.fn()}
|
|
51
|
+
storage={{ getItem: () => null, setItem: () => undefined }}
|
|
52
|
+
theme={lightTheme}
|
|
53
|
+
>
|
|
54
|
+
<Story />
|
|
55
|
+
</UI>
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
const App = createDesktopStorybookApp({ getStorybookUI }, { enableWebsockets: false, testIDPrefix: 'test' });
|
|
59
|
+
return { App, roots, bridgeRoots, themes, mounted, unmounted, getStorybookUI };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
afterEach(() => {
|
|
63
|
+
jest.clearAllMocks();
|
|
64
|
+
jest.restoreAllMocks();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('Storybook app theme root', () => {
|
|
68
|
+
it('places the toolbar, UI, story, and runtime bridge in the same default Flex scene', async () => {
|
|
69
|
+
const { App, roots, bridgeRoots, themes } = createTestApp();
|
|
70
|
+
const scene = await render(<App />);
|
|
71
|
+
|
|
72
|
+
expect(scene.getByTestId('test-app-root')).toBeOnTheScreen();
|
|
73
|
+
expect(scene.getByTestId('test-theme-toolbar')).toBeOnTheScreen();
|
|
74
|
+
expect(scene.getByTestId('selected-story')).toBeOnTheScreen();
|
|
75
|
+
expect(scene.getByRole('button', { name: 'Default Flex' })).toBeOnTheScreen();
|
|
76
|
+
expect(themes[0].tokens).toEqual(defaultFlexTokens);
|
|
77
|
+
expect(bridgeRoots.every((root) => root === roots[0])).toBe(true);
|
|
78
|
+
expect(roots[0].inputModality).toBe('pointer');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('observes app-root input without rerendering the story', async () => {
|
|
82
|
+
const { App, roots, bridgeRoots } = createTestApp();
|
|
83
|
+
const scene = await render(<App />);
|
|
84
|
+
const renderCount = roots.length;
|
|
85
|
+
const root = scene.getByTestId('test-app-root');
|
|
86
|
+
|
|
87
|
+
await fireEvent(root, 'keyDownCapture', { nativeEvent: { key: 'Tab' } });
|
|
88
|
+
expect(roots[0].inputModality).toBe('keyboard');
|
|
89
|
+
expect(bridgeRoots[0].inputModality).toBe('keyboard');
|
|
90
|
+
await fireEvent(root, 'pointerDownCapture', {});
|
|
91
|
+
expect(roots[0].inputModality).toBe('pointer');
|
|
92
|
+
await fireEvent(root, 'keyDownCapture', { nativeEvent: { key: 'ArrowRight' } });
|
|
93
|
+
await fireEvent(root, 'startShouldSetResponderCapture', {});
|
|
94
|
+
expect(roots[0].inputModality).toBe('pointer');
|
|
95
|
+
expect(roots).toHaveLength(renderCount);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it.each(['none', 'light', 'dark'])('keeps the %s canvas distinct from the Secondary Button fill', async (choice) => {
|
|
99
|
+
const { App, themes } = createTestApp();
|
|
100
|
+
const scene = await render(<App />);
|
|
101
|
+
|
|
102
|
+
await fireEvent.press(scene.getByTestId(`test-theme-${choice}`));
|
|
103
|
+
|
|
104
|
+
const state = themes[themes.length - 1];
|
|
105
|
+
const calls = jest.mocked(StorybookUIComponent).mock.calls;
|
|
106
|
+
const theme = calls[calls.length - 1][0].theme;
|
|
107
|
+
expect(theme.background.content).toBe(state.tokens.color.surfaceNeutralFar);
|
|
108
|
+
expect(theme.background.content).toBe(theme.background.preview);
|
|
109
|
+
expect(theme.background.content).not.toBe(state.tokens.color.backgroundNeutralSubtle);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it.each(['#ffeedd', 'transparent'])('preserves the explicit %s story background across theme changes', async (storyBackgroundColor) => {
|
|
113
|
+
const { App } = createTestApp(storyBackgroundColor);
|
|
114
|
+
const scene = await render(<App />);
|
|
115
|
+
|
|
116
|
+
for (const choice of ['none', 'dark', 'light']) {
|
|
117
|
+
await fireEvent.press(scene.getByTestId(`test-theme-${choice}`));
|
|
118
|
+
const calls = jest.mocked(StorybookUIComponent).mock.calls;
|
|
119
|
+
expect(calls[calls.length - 1][0].storyBackgroundColor).toBe(storyBackgroundColor);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('switches chrome and story colors together without recreating Storybook or resetting the scene', async () => {
|
|
124
|
+
const warn = jest.spyOn(console, 'warn').mockImplementation();
|
|
125
|
+
const { App, roots, themes, mounted, unmounted, getStorybookUI } = createTestApp();
|
|
126
|
+
const scene = await render(<App />);
|
|
127
|
+
const root = roots[0];
|
|
128
|
+
const defaultBackground = themes[0].tokens.color.surfaceNeutralFar;
|
|
129
|
+
const backgrounds: Record<string, unknown> = {};
|
|
130
|
+
await fireEvent(scene.getByTestId('test-app-root'), 'keyDownCapture', { nativeEvent: { key: 'Tab' } });
|
|
131
|
+
|
|
132
|
+
for (const choice of ['dark', 'highContrast', 'light', 'none']) {
|
|
133
|
+
await fireEvent.press(scene.getByTestId(`test-theme-${choice}`));
|
|
134
|
+
const state = themes[themes.length - 1];
|
|
135
|
+
const calls = jest.mocked(StorybookUIComponent).mock.calls;
|
|
136
|
+
const theme = calls[calls.length - 1][0].theme;
|
|
137
|
+
backgrounds[choice] = theme.background.app;
|
|
138
|
+
|
|
139
|
+
expect(scene.getByTestId(`test-theme-${choice}`).props.accessibilityState.selected).toBe(true);
|
|
140
|
+
expect(StyleSheet.flatten(scene.getByTestId('test-theme-toolbar').props.style).backgroundColor).toBe(
|
|
141
|
+
state.tokens.color.backgroundNeutralSubtle,
|
|
142
|
+
);
|
|
143
|
+
expect(StyleSheet.flatten(scene.getByText('Theme').props.style).color).toBe(state.tokens.color.foregroundNeutralPrimary);
|
|
144
|
+
const foreground = theme.base === 'dark' ? state.tokens.color.fixedWhite : state.tokens.color.fixedBlack;
|
|
145
|
+
const background = theme.base === 'dark' ? state.tokens.color.fixedBlack : state.tokens.color.fixedWhite;
|
|
146
|
+
const literal = (value: unknown, fallback: unknown) => (typeof value === 'string' ? value : fallback);
|
|
147
|
+
expect(theme.background.app).toBe(literal(state.tokens.color.surfaceNeutralFar, background));
|
|
148
|
+
expect(theme.background.content).toBe(literal(state.tokens.color.surfaceNeutralFar, background));
|
|
149
|
+
expect(theme.background.preview).toBe(literal(state.tokens.color.surfaceNeutralFar, background));
|
|
150
|
+
expect(theme.color.defaultText).toBe(literal(state.tokens.color.foregroundNeutralPrimary, foreground));
|
|
151
|
+
expect(theme.input.color).toBe(literal(state.tokens.color.foregroundNeutralPrimary, foreground));
|
|
152
|
+
expect(theme.button.background).toBe(literal(state.tokens.color.backgroundNeutralLoud, background));
|
|
153
|
+
expect(root.inputModality).toBe('keyboard');
|
|
154
|
+
expect(roots.every((settings) => settings === root)).toBe(true);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
expect(backgrounds.dark).not.toBe(backgrounds.light);
|
|
158
|
+
expect(backgrounds.none).toBe(defaultBackground);
|
|
159
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('Storybook chrome cannot resolve native system colors'));
|
|
160
|
+
expect(getStorybookUI).toHaveBeenCalledTimes(1);
|
|
161
|
+
expect(mounted).toHaveBeenCalledTimes(1);
|
|
162
|
+
expect(unmounted).not.toHaveBeenCalled();
|
|
163
|
+
});
|
|
164
|
+
});
|