@fluentui-react-native/use-tokens 0.7.0 → 0.7.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/CHANGELOG.md +10 -0
- package/lib/applyPropsToTokens.d.ts +2 -7
- package/lib/applyPropsToTokens.js +7 -7
- package/lib/applyPropsToTokens.test.d.ts +1 -1
- package/lib/applyPropsToTokens.test.js +19 -19
- package/lib/applyTokenLayers.d.ts +2 -7
- package/lib/applyTokenLayers.js +13 -16
- package/lib/applyTokenLayers.test.d.ts +1 -1
- package/lib/applyTokenLayers.test.js +42 -42
- package/lib/buildUseTokens.d.ts +3 -6
- package/lib/buildUseTokens.js +22 -22
- package/lib/buildUseTokens.test.d.ts +1 -1
- package/lib/buildUseTokens.test.js +68 -68
- package/lib/customizable.d.ts +3 -6
- package/lib/customizable.js +7 -7
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/patchTokens.d.ts +2 -6
- package/lib/patchTokens.js +12 -12
- package/lib/patchTokens.test.d.ts +1 -1
- package/lib/patchTokens.test.js +32 -32
- package/lib/useTokens.samples.test.d.ts +1 -1
- package/lib/useTokens.samples.test.js +119 -133
- package/lib-commonjs/applyPropsToTokens.d.ts +2 -7
- package/lib-commonjs/applyPropsToTokens.js +9 -9
- package/lib-commonjs/applyPropsToTokens.test.d.ts +1 -1
- package/lib-commonjs/applyPropsToTokens.test.js +23 -23
- package/lib-commonjs/applyTokenLayers.d.ts +2 -7
- package/lib-commonjs/applyTokenLayers.js +16 -19
- package/lib-commonjs/applyTokenLayers.test.d.ts +1 -1
- package/lib-commonjs/applyTokenLayers.test.js +46 -46
- package/lib-commonjs/buildUseTokens.d.ts +3 -6
- package/lib-commonjs/buildUseTokens.js +26 -29
- package/lib-commonjs/buildUseTokens.test.d.ts +1 -1
- package/lib-commonjs/buildUseTokens.test.js +71 -71
- package/lib-commonjs/customizable.d.ts +3 -6
- package/lib-commonjs/customizable.js +9 -9
- package/lib-commonjs/index.d.ts +1 -1
- package/lib-commonjs/index.js +13 -38
- package/lib-commonjs/patchTokens.d.ts +2 -6
- package/lib-commonjs/patchTokens.js +14 -14
- package/lib-commonjs/patchTokens.test.d.ts +1 -1
- package/lib-commonjs/patchTokens.test.js +36 -36
- package/lib-commonjs/useTokens.samples.test.d.ts +1 -1
- package/lib-commonjs/useTokens.samples.test.js +156 -191
- package/package.json +14 -13
|
@@ -19,7 +19,7 @@ export type UseTokensCore<TTokens, TTheme> = (theme: TTheme) => [TTokens, GetTyp
|
|
|
19
19
|
* that captures both the previous values, and layers in the new values specified
|
|
20
20
|
*/
|
|
21
21
|
export type UseTokens<TTokens, TTheme> = UseTokensCore<TTokens, TTheme> & {
|
|
22
|
-
|
|
22
|
+
customize: (...tokens: TokenSettings<TTokens, TTheme>[]) => UseTokens<TTokens, TTheme>;
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Helper function that knows how to try to look up token information from the theme
|
|
@@ -31,8 +31,5 @@ export type GetComponentInfo<TTokens, TTheme> = (theme: TTheme, name: string) =>
|
|
|
31
31
|
* @param options - options which drive behavior for the generated styling hook
|
|
32
32
|
* @param themeHelper - injected theme functionality
|
|
33
33
|
*/
|
|
34
|
-
export declare function buildUseTokens<TTokens, TTheme>(
|
|
35
|
-
|
|
36
|
-
...tokens: TokenSettings<TTokens, TTheme>[]
|
|
37
|
-
): UseTokens<TTokens, TTheme>;
|
|
38
|
-
//# sourceMappingURL=buildUseTokens.d.ts.map
|
|
34
|
+
export declare function buildUseTokens<TTokens, TTheme>(getComponentInfo: GetComponentInfo<TTokens, TTheme> | undefined, ...tokens: TokenSettings<TTokens, TTheme>[]): UseTokens<TTokens, TTheme>;
|
|
35
|
+
//# sourceMappingURL=buildUseTokens.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildUseTokens = buildUseTokens;
|
|
4
|
-
const framework_base_1 = require(
|
|
5
|
-
const framework_base_2 = require(
|
|
4
|
+
const framework_base_1 = require("@fluentui-react-native/framework-base");
|
|
5
|
+
const framework_base_2 = require("@fluentui-react-native/framework-base");
|
|
6
6
|
/**
|
|
7
7
|
* Tokens are defined as either:
|
|
8
8
|
* TTokens - an object
|
|
@@ -17,13 +17,13 @@ const framework_base_2 = require('@fluentui-react-native/framework-base');
|
|
|
17
17
|
* @param getComponentInfo - helper to use to lookup the component in the theme
|
|
18
18
|
*/
|
|
19
19
|
function mapToTokens(tokenEntry, theme, getComponentInfo) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
if (typeof tokenEntry === 'string') {
|
|
21
|
+
tokenEntry = (getComponentInfo && getComponentInfo(theme, tokenEntry)) || {};
|
|
22
|
+
}
|
|
23
|
+
if (typeof tokenEntry === 'function') {
|
|
24
|
+
tokenEntry = tokenEntry(theme);
|
|
25
|
+
}
|
|
26
|
+
return tokenEntry;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Construct a useStyling hook which returns styled slot props based on props and tokens defined in options and in the theme
|
|
@@ -32,22 +32,19 @@ function mapToTokens(tokenEntry, theme, getComponentInfo) {
|
|
|
32
32
|
* @param themeHelper - injected theme functionality
|
|
33
33
|
*/
|
|
34
34
|
function buildUseTokens(getComponentInfo, ...tokens) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return buildUseTokens(getComponentInfo, ...mergedTokens);
|
|
50
|
-
};
|
|
51
|
-
return useTokensCore;
|
|
35
|
+
// create a cache instance for use in this particular call to buildUseTokens
|
|
36
|
+
const cache = (0, framework_base_2.getMemoCache)();
|
|
37
|
+
// the core function simply merges layers together, looking up component definitions in the theme as well as executing any
|
|
38
|
+
// theme functions. This turns the tokens into an array of token objects that then get merged together
|
|
39
|
+
const useTokensCore = (theme) => {
|
|
40
|
+
// get the base styles all merged together, these will only depend on internal tokens and theme
|
|
41
|
+
return cache(() => (0, framework_base_1.immutableMerge)(...tokens.map((value) => mapToTokens(value, theme, getComponentInfo))), [theme]);
|
|
42
|
+
};
|
|
43
|
+
// attach a customize function to generate a new use
|
|
44
|
+
useTokensCore.customize = (...newTokens) => {
|
|
45
|
+
const mergedTokens = [...tokens, ...newTokens];
|
|
46
|
+
return buildUseTokens(getComponentInfo, ...mergedTokens);
|
|
47
|
+
};
|
|
48
|
+
return useTokensCore;
|
|
52
49
|
}
|
|
53
|
-
//# sourceMappingURL=buildUseTokens.js.map
|
|
50
|
+
//# sourceMappingURL=buildUseTokens.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=buildUseTokens.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=buildUseTokens.test.d.ts.map
|
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const buildUseTokens_1 = require(
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const buildUseTokens_1 = require("./buildUseTokens");
|
|
4
4
|
const baseTokens = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
a: 'a-base',
|
|
6
|
+
b: 'b-base',
|
|
7
|
+
c: 'c-base',
|
|
8
|
+
hover: {
|
|
9
|
+
c: 'c-base-hover',
|
|
10
|
+
},
|
|
11
|
+
press: {
|
|
12
|
+
c: 'c-base-press',
|
|
13
|
+
},
|
|
14
14
|
};
|
|
15
15
|
const defaultTheme = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
components: {
|
|
21
|
-
uno: {
|
|
22
|
-
a: 'uno-a',
|
|
23
|
-
c: 'uno-c',
|
|
16
|
+
vals: {
|
|
17
|
+
foo: 'foo',
|
|
18
|
+
bar: 'bar',
|
|
24
19
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
components: {
|
|
21
|
+
uno: {
|
|
22
|
+
a: 'uno-a',
|
|
23
|
+
c: 'uno-c',
|
|
24
|
+
},
|
|
25
|
+
dos: {
|
|
26
|
+
b: 'dos-b',
|
|
27
|
+
c: 'dos-c',
|
|
28
|
+
},
|
|
28
29
|
},
|
|
29
|
-
},
|
|
30
30
|
};
|
|
31
31
|
const variantTheme = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
vals: {
|
|
33
|
+
foo: 'variant',
|
|
34
|
+
},
|
|
35
|
+
components: {},
|
|
36
36
|
};
|
|
37
37
|
const getComponentInfo = (theme, name) => theme.components[name];
|
|
38
38
|
const componentTokens = [baseTokens, 'uno', (theme) => ({ b: theme.vals.foo })];
|
|
39
39
|
const resolvedTokens = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
a: 'uno-a',
|
|
41
|
+
b: 'foo',
|
|
42
|
+
c: 'uno-c',
|
|
43
|
+
hover: {
|
|
44
|
+
c: 'c-base-hover',
|
|
45
|
+
},
|
|
46
|
+
press: {
|
|
47
|
+
c: 'c-base-press',
|
|
48
|
+
},
|
|
49
49
|
};
|
|
50
50
|
const variantTokens = {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
a: 'a-base',
|
|
52
|
+
b: 'variant',
|
|
53
|
+
c: 'c-base',
|
|
54
|
+
hover: {
|
|
55
|
+
c: 'c-base-hover',
|
|
56
|
+
},
|
|
57
|
+
press: {
|
|
58
|
+
c: 'c-base-press',
|
|
59
|
+
},
|
|
60
60
|
};
|
|
61
61
|
describe('buildUseTokens test suite', () => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
62
|
+
test('basic built hook', () => {
|
|
63
|
+
const useTokens = (0, buildUseTokens_1.buildUseTokens)(getComponentInfo, ...componentTokens);
|
|
64
|
+
const [tokens] = useTokens(defaultTheme);
|
|
65
|
+
expect(tokens).toEqual(resolvedTokens);
|
|
66
|
+
});
|
|
67
|
+
test('multiple calls return same object', () => {
|
|
68
|
+
const useTokens = (0, buildUseTokens_1.buildUseTokens)(getComponentInfo, ...componentTokens);
|
|
69
|
+
const [tokens1] = useTokens(defaultTheme);
|
|
70
|
+
const [tokens2] = useTokens(defaultTheme);
|
|
71
|
+
expect(tokens1).toBe(tokens2);
|
|
72
|
+
});
|
|
73
|
+
test('variant theme is separate', () => {
|
|
74
|
+
const useTokens = (0, buildUseTokens_1.buildUseTokens)(getComponentInfo, ...componentTokens);
|
|
75
|
+
const [tokensDefault] = useTokens(defaultTheme);
|
|
76
|
+
const [tokensVariant] = useTokens(variantTheme);
|
|
77
|
+
expect(tokensVariant).not.toBe(tokensDefault);
|
|
78
|
+
expect(tokensVariant).toEqual(variantTokens);
|
|
79
|
+
});
|
|
80
|
+
test('simple customization layers on top', () => {
|
|
81
|
+
const useTokens = (0, buildUseTokens_1.buildUseTokens)(getComponentInfo, ...componentTokens);
|
|
82
|
+
const useTokensCustom = useTokens.customize({ a: 'custom' });
|
|
83
|
+
const [tokens] = useTokensCustom(defaultTheme);
|
|
84
|
+
expect(tokens).toEqual({ ...resolvedTokens, a: 'custom' });
|
|
85
|
+
});
|
|
86
86
|
});
|
|
87
|
-
//# sourceMappingURL=buildUseTokens.test.js.map
|
|
87
|
+
//# sourceMappingURL=buildUseTokens.test.js.map
|
|
@@ -10,7 +10,7 @@ export type InjectableComponent<TProps, TTokens, TTheme> = (props: TProps, useTo
|
|
|
10
10
|
* A component with an attached customize function, used to create alternatively styled versions of the component
|
|
11
11
|
*/
|
|
12
12
|
export type CustomizableComponent<TProps, TTokens, TTheme> = React.FunctionComponent<TProps> & {
|
|
13
|
-
|
|
13
|
+
customize: (...tokens: TokenSettings<TTokens, TTheme>[]) => CustomizableComponent<TProps, TTokens, TTheme>;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Function helper for easily creating a customizable component based on the useTokens hook
|
|
@@ -21,8 +21,5 @@ export type CustomizableComponent<TProps, TTokens, TTheme> = React.FunctionCompo
|
|
|
21
21
|
* @returns - a function component that has a static function called customize attached. Customize will return a
|
|
22
22
|
* new component (which can also be customized)
|
|
23
23
|
*/
|
|
24
|
-
export declare function customizable<TProps, TTokens, TTheme>(
|
|
25
|
-
|
|
26
|
-
useTokens: UseTokens<TTokens, TTheme>,
|
|
27
|
-
): CustomizableComponent<TProps, TTokens, TTheme>;
|
|
28
|
-
//# sourceMappingURL=customizable.d.ts.map
|
|
24
|
+
export declare function customizable<TProps, TTokens, TTheme>(injectable: InjectableComponent<TProps, TTokens, TTheme>, useTokens: UseTokens<TTokens, TTheme>): CustomizableComponent<TProps, TTokens, TTheme>;
|
|
25
|
+
//# sourceMappingURL=customizable.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.customizable = customizable;
|
|
4
4
|
/**
|
|
5
5
|
* Function helper for easily creating a customizable component based on the useTokens hook
|
|
@@ -11,11 +11,11 @@ exports.customizable = customizable;
|
|
|
11
11
|
* new component (which can also be customized)
|
|
12
12
|
*/
|
|
13
13
|
function customizable(injectable, useTokens) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const component = (props) => injectable(props, useTokens);
|
|
15
|
+
component.customize = (...tokens) => {
|
|
16
|
+
const useTokensNew = useTokens.customize(...tokens);
|
|
17
|
+
return customizable(injectable, useTokensNew);
|
|
18
|
+
};
|
|
19
|
+
return component;
|
|
20
20
|
}
|
|
21
|
-
//# sourceMappingURL=customizable.js.map
|
|
21
|
+
//# sourceMappingURL=customizable.js.map
|
package/lib-commonjs/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export type { GetComponentInfo, TokenSettings, TokensFromTheme, UseTokens, UseTo
|
|
|
6
6
|
export { customizable } from './customizable';
|
|
7
7
|
export type { CustomizableComponent, InjectableComponent } from './customizable';
|
|
8
8
|
export { patchTokens } from './patchTokens';
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
package/lib-commonjs/index.js
CHANGED
|
@@ -1,39 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.patchTokens = exports.customizable = exports.buildUseTokens = exports.applyTokenLayers = exports.applyPropsToTokens = void 0;
|
|
4
|
-
const applyPropsToTokens_1 = require(
|
|
5
|
-
Object.defineProperty(exports,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return applyTokenLayers_1.applyTokenLayers;
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
const buildUseTokens_1 = require('./buildUseTokens');
|
|
19
|
-
Object.defineProperty(exports, 'buildUseTokens', {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return buildUseTokens_1.buildUseTokens;
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
const customizable_1 = require('./customizable');
|
|
26
|
-
Object.defineProperty(exports, 'customizable', {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () {
|
|
29
|
-
return customizable_1.customizable;
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
const patchTokens_1 = require('./patchTokens');
|
|
33
|
-
Object.defineProperty(exports, 'patchTokens', {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function () {
|
|
36
|
-
return patchTokens_1.patchTokens;
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
//# sourceMappingURL=index.js.map
|
|
4
|
+
const applyPropsToTokens_1 = require("./applyPropsToTokens");
|
|
5
|
+
Object.defineProperty(exports, "applyPropsToTokens", { enumerable: true, get: function () { return applyPropsToTokens_1.applyPropsToTokens; } });
|
|
6
|
+
const applyTokenLayers_1 = require("./applyTokenLayers");
|
|
7
|
+
Object.defineProperty(exports, "applyTokenLayers", { enumerable: true, get: function () { return applyTokenLayers_1.applyTokenLayers; } });
|
|
8
|
+
const buildUseTokens_1 = require("./buildUseTokens");
|
|
9
|
+
Object.defineProperty(exports, "buildUseTokens", { enumerable: true, get: function () { return buildUseTokens_1.buildUseTokens; } });
|
|
10
|
+
const customizable_1 = require("./customizable");
|
|
11
|
+
Object.defineProperty(exports, "customizable", { enumerable: true, get: function () { return customizable_1.customizable; } });
|
|
12
|
+
const patchTokens_1 = require("./patchTokens");
|
|
13
|
+
Object.defineProperty(exports, "patchTokens", { enumerable: true, get: function () { return patchTokens_1.patchTokens; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -8,9 +8,5 @@ import type { GetTypedMemoValue } from '@fluentui-react-native/framework-base';
|
|
|
8
8
|
* @param patchValues - new values to apply, values will be obtained via keys in the object
|
|
9
9
|
* @returns - a tuple consisting of a new tokens object and a new memo-cache
|
|
10
10
|
*/
|
|
11
|
-
export declare function patchTokens<TTokens>(
|
|
12
|
-
|
|
13
|
-
cache: GetTypedMemoValue<TTokens>,
|
|
14
|
-
patchValues: TTokens,
|
|
15
|
-
): [TTokens, GetTypedMemoValue<TTokens>];
|
|
16
|
-
//# sourceMappingURL=patchTokens.d.ts.map
|
|
11
|
+
export declare function patchTokens<TTokens>(tokens: TTokens, cache: GetTypedMemoValue<TTokens>, patchValues: TTokens): [TTokens, GetTypedMemoValue<TTokens>];
|
|
12
|
+
//# sourceMappingURL=patchTokens.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.patchTokens = patchTokens;
|
|
4
4
|
/**
|
|
5
5
|
* Take a set of tokens (and a memo-cache) and apply changes to those tokens from an additional set of tokens. Only keys which are
|
|
@@ -11,16 +11,16 @@ exports.patchTokens = patchTokens;
|
|
|
11
11
|
* @returns - a tuple consisting of a new tokens object and a new memo-cache
|
|
12
12
|
*/
|
|
13
13
|
function patchTokens(tokens, cache, patchValues) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
// reduce the patch values to the set of keys that are defined, and sort them to ensure consistent ordering
|
|
15
|
+
const keys = Object.keys(patchValues)
|
|
16
|
+
.filter((v) => patchValues[v] !== undefined)
|
|
17
|
+
.sort();
|
|
18
|
+
// for each key get an updated tokens collection based on key + value. Value alone isn't sufficient as the values
|
|
19
|
+
// are not necessarily unique. i.e. { a: 'blue' } and { b: 'blue' } would cache to the same without the key
|
|
20
|
+
for (const key of keys) {
|
|
21
|
+
[tokens, cache] = cache(() => ({ ...tokens, [key]: patchValues[key] }), [key, patchValues[key]]);
|
|
22
|
+
}
|
|
23
|
+
// return the updated tokens and cache (if there were any keys applied)
|
|
24
|
+
return [tokens, cache];
|
|
25
25
|
}
|
|
26
|
-
//# sourceMappingURL=patchTokens.js.map
|
|
26
|
+
//# sourceMappingURL=patchTokens.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=patchTokens.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=patchTokens.test.d.ts.map
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const framework_base_1 = require(
|
|
4
|
-
const patchTokens_1 = require(
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const framework_base_1 = require("@fluentui-react-native/framework-base");
|
|
4
|
+
const patchTokens_1 = require("./patchTokens");
|
|
5
5
|
const themeTokens = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
uno: 'uno',
|
|
7
|
+
dos: 'dos',
|
|
8
|
+
tres: 3,
|
|
9
|
+
quatro: 4,
|
|
10
|
+
cinco: true,
|
|
11
11
|
};
|
|
12
12
|
describe('patchTokens tests', () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
13
|
+
test('props get copied', () => {
|
|
14
|
+
const cache = (0, framework_base_1.getMemoCache)();
|
|
15
|
+
const patchValues = { uno: 'one', quatro: 'quatro' };
|
|
16
|
+
const [tokens] = (0, patchTokens_1.patchTokens)(themeTokens, cache, patchValues);
|
|
17
|
+
expect(tokens).not.toBe(themeTokens);
|
|
18
|
+
for (const key in patchValues) {
|
|
19
|
+
expect(tokens[key]).toEqual(patchValues[key]);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
test('no copied props does not change tokens', () => {
|
|
23
|
+
const cache = (0, framework_base_1.getMemoCache)();
|
|
24
|
+
const patchValues1 = {};
|
|
25
|
+
const [tokens] = (0, patchTokens_1.patchTokens)(themeTokens, cache, patchValues1);
|
|
26
|
+
expect(tokens).toBe(themeTokens);
|
|
27
|
+
const patchValues2 = { tres: undefined };
|
|
28
|
+
const [tokens2] = (0, patchTokens_1.patchTokens)(themeTokens, cache, patchValues2);
|
|
29
|
+
expect(tokens2).toBe(themeTokens);
|
|
30
|
+
});
|
|
31
|
+
test('patching tokens cache independent of order', () => {
|
|
32
|
+
const cache = (0, framework_base_1.getMemoCache)();
|
|
33
|
+
const patch1 = { uno: 'one', cinco: false };
|
|
34
|
+
const patch2 = { cinco: false, uno: 'one' };
|
|
35
|
+
const [tokens1] = (0, patchTokens_1.patchTokens)(themeTokens, cache, patch1);
|
|
36
|
+
const [tokens2] = (0, patchTokens_1.patchTokens)(themeTokens, cache, patch2);
|
|
37
|
+
expect(tokens1).toBe(tokens2);
|
|
38
|
+
});
|
|
39
39
|
});
|
|
40
|
-
//# sourceMappingURL=patchTokens.test.js.map
|
|
40
|
+
//# sourceMappingURL=patchTokens.test.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=useTokens.samples.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=useTokens.samples.test.d.ts.map
|