@fluentui-react-native/win32-theme 0.39.8 → 0.39.11
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 +36 -0
- package/lib/NativeModule/getThemingModule.native.d.ts.map +1 -1
- package/lib/NativeModule/getThemingModule.native.js +7 -2
- package/lib/NativeModule/getThemingModule.native.js.map +1 -1
- package/lib/NativeModule/hostThemeSetting.d.ts +8 -1
- package/lib/NativeModule/hostThemeSetting.d.ts.map +1 -1
- package/lib/NativeModule/hostThemeSetting.js +7 -14
- package/lib/NativeModule/hostThemeSetting.js.map +1 -1
- package/lib/NativeModule/index.d.ts +1 -1
- package/lib/NativeModule/index.d.ts.map +1 -1
- package/lib/NativeModule/officeThemingModule.d.ts +13 -8
- package/lib/NativeModule/officeThemingModule.d.ts.map +1 -1
- package/lib/__tests__/win32-theme.test.js +3 -0
- package/lib/__tests__/win32-theme.test.js.map +1 -1
- package/lib/createBrandedThemeWithAlias.js +1 -1
- package/lib/createBrandedThemeWithAlias.js.map +1 -1
- package/lib/createFontAliasTokens.js +1 -1
- package/lib/createFontAliasTokens.js.map +1 -1
- package/lib/createOfficeAliasTokens.js +1 -1
- package/lib/createOfficeAliasTokens.js.map +1 -1
- package/lib/createOfficeTheme.d.ts.map +1 -1
- package/lib/createOfficeTheme.js +108 -40
- package/lib/createOfficeTheme.js.map +1 -1
- package/lib/getOfficeTokens.d.ts +404 -1
- package/lib/getOfficeTokens.d.ts.map +1 -1
- package/lib/getOfficeTokens.js +1 -1
- package/lib/getOfficeTokens.js.map +1 -1
- package/package.json +4 -6
- package/src/NativeModule/getThemingModule.native.ts +8 -2
- package/src/NativeModule/hostThemeSetting.ts +15 -5
- package/src/NativeModule/index.ts +1 -0
- package/src/NativeModule/officeThemingModule.ts +17 -9
- package/src/__tests__/win32-theme.test.ts +4 -0
- package/src/createBrandedThemeWithAlias.ts +1 -1
- package/src/createFontAliasTokens.ts +1 -1
- package/src/createOfficeAliasTokens.ts +1 -1
- package/src/createOfficeTheme.ts +136 -51
- package/src/getOfficeTokens.ts +1 -2
- package/lib/highContrast/tokens-alias.d.ts +0 -2
- package/lib/highContrast/tokens-alias.d.ts.map +0 -1
- package/lib/highContrast/tokens-alias.js +0 -17
- package/lib/highContrast/tokens-alias.js.map +0 -1
- package/src/highContrast/tokens-alias.ts +0 -20
package/src/createOfficeTheme.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { createDefaultTheme } from '@fluentui-react-native/default-theme';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
appearanceOptionFromResolved,
|
|
4
|
+
appearanceOptionsFromLegacy,
|
|
5
|
+
createThemeAppearanceSource,
|
|
6
|
+
ThemeReference,
|
|
7
|
+
} from '@fluentui-react-native/design/theming';
|
|
8
|
+
import type {
|
|
9
|
+
OfficePalette,
|
|
10
|
+
Theme,
|
|
11
|
+
ThemeAppearanceSource,
|
|
12
|
+
ThemeAppearanceSourceSnapshot,
|
|
13
|
+
ThemeOptions,
|
|
14
|
+
} from '@fluentui-react-native/design/theming';
|
|
4
15
|
|
|
5
16
|
import { createAliasesFromPalette } from './createAliasesFromPalette';
|
|
6
17
|
import { createBrandedThemeWithAlias } from './createBrandedThemeWithAlias';
|
|
@@ -8,7 +19,7 @@ import { createOfficeColorAliasTokens, createOfficeShadowAliasTokens } from './c
|
|
|
8
19
|
import { createPartialOfficeTheme } from './createPartialOfficeTheme';
|
|
9
20
|
import { win32Typography } from './getThemeTypography';
|
|
10
21
|
import { getThemingModule } from './NativeModule/getThemingModule';
|
|
11
|
-
import {
|
|
22
|
+
import { getCurrentHostThemeState, setCurrentHostThemeState } from './NativeModule/hostThemeSetting';
|
|
12
23
|
import type { CxxException, PlatformDefaultsChangedArgs } from './NativeModule/officeThemingModule';
|
|
13
24
|
|
|
14
25
|
function handlePaletteCall(palette: OfficePalette | CxxException): OfficePalette | undefined {
|
|
@@ -27,59 +38,133 @@ function handlePaletteCall(palette: OfficePalette | CxxException): OfficePalette
|
|
|
27
38
|
*/
|
|
28
39
|
export function createOfficeTheme(options: ThemeOptions = {}): ThemeReference {
|
|
29
40
|
const [module, emitter] = getThemingModule();
|
|
30
|
-
const
|
|
41
|
+
const currentHostState = getCurrentHostThemeState();
|
|
42
|
+
const ref = { module, emitter, themeName: currentHostState.hostThemeSetting || '' };
|
|
31
43
|
const { paletteName } = options;
|
|
44
|
+
const constants = module.getConstants();
|
|
45
|
+
let colorScheme = currentHostState.hostThemeSetting ? currentHostState.colorScheme : constants.initialColorScheme;
|
|
46
|
+
let isHighContrast = currentHostState.hostThemeSetting ? currentHostState.isHighContrast : constants.initialIsHighContrast;
|
|
47
|
+
const themeRefHolder: { current?: ThemeReference } = {};
|
|
48
|
+
const updateOfficeState = (
|
|
49
|
+
themeName: string | undefined,
|
|
50
|
+
nextColorScheme: ThemeAppearanceSourceSnapshot['colorScheme'],
|
|
51
|
+
nextIsHighContrast: boolean | undefined,
|
|
52
|
+
) => {
|
|
53
|
+
const nextThemeName = themeName || ref.themeName;
|
|
54
|
+
const changed = nextThemeName !== ref.themeName || nextColorScheme !== colorScheme || nextIsHighContrast !== isHighContrast;
|
|
55
|
+
ref.themeName = nextThemeName;
|
|
56
|
+
colorScheme = nextColorScheme;
|
|
57
|
+
isHighContrast = nextIsHighContrast;
|
|
58
|
+
setCurrentHostThemeState({
|
|
59
|
+
hostThemeSetting: ref.themeName,
|
|
60
|
+
colorScheme,
|
|
61
|
+
isHighContrast,
|
|
62
|
+
});
|
|
63
|
+
return changed;
|
|
64
|
+
};
|
|
65
|
+
const appearanceSource: ThemeAppearanceSource = createThemeAppearanceSource(
|
|
66
|
+
() => getOfficeAppearance(ref.themeName, colorScheme, isHighContrast),
|
|
67
|
+
emitter
|
|
68
|
+
? (listener) => {
|
|
69
|
+
const subscription = emitter.addListener('onPlatformDefaultsChanged', (args: PlatformDefaultsChangedArgs) => {
|
|
70
|
+
updateOfficeState(args?.hostThemeSetting, args?.colorScheme, args?.isHighContrast);
|
|
71
|
+
themeRefHolder.current?.invalidate();
|
|
72
|
+
listener();
|
|
73
|
+
});
|
|
74
|
+
const currentState = getCurrentHostThemeState();
|
|
75
|
+
if (updateOfficeState(currentState.hostThemeSetting, currentState.colorScheme, currentState.isHighContrast)) {
|
|
76
|
+
themeRefHolder.current?.invalidate();
|
|
77
|
+
}
|
|
78
|
+
listener();
|
|
79
|
+
return () => subscription.remove();
|
|
80
|
+
}
|
|
81
|
+
: undefined,
|
|
82
|
+
);
|
|
32
83
|
|
|
33
|
-
const themeRef = new ThemeReference(
|
|
34
|
-
createDefaultTheme(options),
|
|
35
|
-
() =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!ref.themeName || ref.themeName === '') {
|
|
52
|
-
return {};
|
|
53
|
-
}
|
|
84
|
+
const themeRef = new ThemeReference({
|
|
85
|
+
base: createDefaultTheme(options),
|
|
86
|
+
getAppearance: () =>
|
|
87
|
+
options.appearance
|
|
88
|
+
? appearanceOptionsFromLegacy(options.appearance)
|
|
89
|
+
: { colorScheme: 'system', contrast: 'system', interfaceLevel: 'base' },
|
|
90
|
+
appearanceSource,
|
|
91
|
+
alwaysSubscribeToAppearanceSource: true,
|
|
92
|
+
recipes: [
|
|
93
|
+
() => {
|
|
94
|
+
const name = paletteName || 'WhiteColors';
|
|
95
|
+
const palette = handlePaletteCall(ref.module.getPalette(name));
|
|
96
|
+
return createPartialOfficeTheme(module, ref.themeName, palette);
|
|
97
|
+
},
|
|
98
|
+
() => {
|
|
99
|
+
if (!ref.themeName || ref.themeName === '') {
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
54
102
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!theme.host.palette) {
|
|
65
|
-
return {};
|
|
66
|
-
}
|
|
103
|
+
return {
|
|
104
|
+
shadows: { ...createOfficeShadowAliasTokens(ref.themeName) },
|
|
105
|
+
typography: win32Typography(),
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
() => {
|
|
109
|
+
if (!ref.themeName || ref.themeName === '') {
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
67
112
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
113
|
+
return {
|
|
114
|
+
colors: { ...createOfficeColorAliasTokens(ref.themeName) },
|
|
115
|
+
typography: win32Typography(),
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
(theme: Theme) => {
|
|
119
|
+
return createBrandedThemeWithAlias(ref.themeName, theme);
|
|
120
|
+
},
|
|
121
|
+
(theme: Theme) => {
|
|
122
|
+
if (!theme.host.palette) {
|
|
123
|
+
return {};
|
|
124
|
+
}
|
|
74
125
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
126
|
+
return {
|
|
127
|
+
...(paletteName !== undefined && { colors: createAliasesFromPalette(theme.host.palette, ref.themeName === 'HighContrast') }),
|
|
128
|
+
typography: win32Typography(),
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
(_theme, appearance) => ({
|
|
132
|
+
host: {
|
|
133
|
+
appearance: appearance ? appearanceOptionFromResolved(appearance) : undefined,
|
|
134
|
+
},
|
|
135
|
+
}),
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
themeRefHolder.current = themeRef;
|
|
82
139
|
|
|
83
|
-
// now return the theme reference
|
|
84
140
|
return themeRef;
|
|
85
141
|
}
|
|
142
|
+
|
|
143
|
+
function getOfficeAppearance(
|
|
144
|
+
themeName: string,
|
|
145
|
+
colorScheme?: ThemeAppearanceSourceSnapshot['colorScheme'],
|
|
146
|
+
isHighContrast?: boolean,
|
|
147
|
+
): ThemeAppearanceSourceSnapshot {
|
|
148
|
+
if (colorScheme || isHighContrast !== undefined) {
|
|
149
|
+
return {
|
|
150
|
+
colorScheme,
|
|
151
|
+
contrast: isHighContrast ? 'highContrast' : 'standard',
|
|
152
|
+
interfaceLevel: 'base',
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
switch (themeName) {
|
|
157
|
+
case 'Black':
|
|
158
|
+
case 'DarkGray':
|
|
159
|
+
return { colorScheme: 'dark', contrast: 'standard', interfaceLevel: 'base' };
|
|
160
|
+
case 'HighContrast':
|
|
161
|
+
// Transitional until the native contract exposes scheme and contrast as
|
|
162
|
+
// separate fields rather than one host-theme name.
|
|
163
|
+
return { contrast: 'highContrast', interfaceLevel: 'base' };
|
|
164
|
+
case 'Colorful':
|
|
165
|
+
case 'White':
|
|
166
|
+
return { colorScheme: 'light', contrast: 'standard', interfaceLevel: 'base' };
|
|
167
|
+
default:
|
|
168
|
+
return { interfaceLevel: 'base' };
|
|
169
|
+
}
|
|
170
|
+
}
|
package/src/getOfficeTokens.ts
CHANGED
|
@@ -5,8 +5,7 @@ import colorfulShadowTokens from '@fluentui-react-native/design-tokens-win32/col
|
|
|
5
5
|
import darkGrayAliasTokens from '@fluentui-react-native/design-tokens-win32/darkgray/tokens-aliases.json';
|
|
6
6
|
import darkGrayShadowTokens from '@fluentui-react-native/design-tokens-win32/darkgray/tokens-shadow.json';
|
|
7
7
|
import hcShadowTokens from '@fluentui-react-native/design-tokens-win32/hc/tokens-shadow.json';
|
|
8
|
-
|
|
9
|
-
import { hcAliasTokens } from './highContrast/tokens-alias';
|
|
8
|
+
import { hcAliasTokens } from '@fluentui-react-native/design/tokens/legacy';
|
|
10
9
|
|
|
11
10
|
export function getOfficeAliasTokens(officeTheme: string) {
|
|
12
11
|
if (officeTheme === 'White' || officeTheme === 'Colorful') {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens-alias.d.ts","sourceRoot":"","sources":["../../src/highContrast/tokens-alias.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,KAAkC,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { PlatformColor } from 'react-native';
|
|
2
|
-
import aliasTokens from '@fluentui-react-native/design-tokens-win32/hc/tokens-aliases.json';
|
|
3
|
-
export const hcAliasTokens = processAliasTokens(aliasTokens);
|
|
4
|
-
function processAliasTokens(aliasTokens) {
|
|
5
|
-
for (const key in aliasTokens) {
|
|
6
|
-
for (const innerKey in aliasTokens[key]) {
|
|
7
|
-
const entry = aliasTokens[key][innerKey];
|
|
8
|
-
if (typeof entry === 'string' && entry.includes('PlatformColor')) {
|
|
9
|
-
const color = entry.substring(14, entry.length - 1);
|
|
10
|
-
// eslint-disable-next-line @react-native/platform-colors
|
|
11
|
-
aliasTokens[key][innerKey] = PlatformColor(color);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return aliasTokens;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=tokens-alias.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens-alias.js","sourceRoot":"","sources":["../../src/highContrast/tokens-alias.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,WAAW,MAAM,mEAAmE,CAAC;AAE5F,MAAM,CAAC,MAAM,aAAa,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;AAE7D,SAAS,kBAAkB,CAAC,WAAgB;IAC1C,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,KAAK,MAAM,QAAQ,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;YACxC,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;YACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;gBACjE,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;gBACpD,yDAAyD;gBACzD,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { PlatformColor } from 'react-native';
|
|
2
|
-
|
|
3
|
-
import aliasTokens from '@fluentui-react-native/design-tokens-win32/hc/tokens-aliases.json';
|
|
4
|
-
|
|
5
|
-
export const hcAliasTokens = processAliasTokens(aliasTokens);
|
|
6
|
-
|
|
7
|
-
function processAliasTokens(aliasTokens: any) {
|
|
8
|
-
for (const key in aliasTokens) {
|
|
9
|
-
for (const innerKey in aliasTokens[key]) {
|
|
10
|
-
const entry = aliasTokens[key][innerKey];
|
|
11
|
-
if (typeof entry === 'string' && entry.includes('PlatformColor')) {
|
|
12
|
-
const color = entry.substring(14, entry.length - 1);
|
|
13
|
-
// eslint-disable-next-line @react-native/platform-colors
|
|
14
|
-
aliasTokens[key][innerKey] = PlatformColor(color);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return aliasTokens;
|
|
20
|
-
}
|