@fluentui-react-native/use-tokens 0.6.2 → 0.6.4
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.json +66 -1
- package/CHANGELOG.md +18 -2
- package/eslint.config.js +3 -0
- package/lib/applyPropsToTokens.js +4 -13
- package/lib/applyPropsToTokens.js.map +1 -1
- package/lib/applyPropsToTokens.test.js +11 -12
- package/lib/applyPropsToTokens.test.js.map +1 -1
- package/lib/applyTokenLayers.js +6 -6
- package/lib/applyTokenLayers.js.map +1 -1
- package/lib/applyTokenLayers.test.js +15 -16
- package/lib/applyTokenLayers.test.js.map +1 -1
- package/lib/buildUseTokens.js +7 -16
- package/lib/buildUseTokens.js.map +1 -1
- package/lib/buildUseTokens.test.js +24 -25
- package/lib/buildUseTokens.test.js.map +1 -1
- package/lib/customizable.js +3 -7
- package/lib/customizable.js.map +1 -1
- package/lib/patchTokens.js +4 -13
- package/lib/patchTokens.js.map +1 -1
- package/lib/patchTokens.test.js +19 -19
- package/lib/patchTokens.test.js.map +1 -1
- package/lib/useTokens.samples.test.js +33 -34
- package/lib/useTokens.samples.test.js.map +1 -1
- package/lib-commonjs/applyPropsToTokens.js +4 -13
- package/lib-commonjs/applyPropsToTokens.js.map +1 -1
- package/lib-commonjs/applyPropsToTokens.test.js +13 -14
- package/lib-commonjs/applyPropsToTokens.test.js.map +1 -1
- package/lib-commonjs/applyTokenLayers.js +7 -7
- package/lib-commonjs/applyTokenLayers.js.map +1 -1
- package/lib-commonjs/applyTokenLayers.test.js +17 -18
- package/lib-commonjs/applyTokenLayers.test.js.map +1 -1
- package/lib-commonjs/buildUseTokens.js +9 -18
- package/lib-commonjs/buildUseTokens.js.map +1 -1
- package/lib-commonjs/buildUseTokens.test.js +25 -26
- package/lib-commonjs/buildUseTokens.test.js.map +1 -1
- package/lib-commonjs/customizable.js +3 -7
- package/lib-commonjs/customizable.js.map +1 -1
- package/lib-commonjs/patchTokens.js +4 -13
- package/lib-commonjs/patchTokens.js.map +1 -1
- package/lib-commonjs/patchTokens.test.js +21 -21
- package/lib-commonjs/patchTokens.test.js.map +1 -1
- package/lib-commonjs/useTokens.samples.test.js +40 -40
- package/lib-commonjs/useTokens.samples.test.js.map +1 -1
- package/package.json +25 -11
- package/.eslintrc.js +0 -3
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign, __rest } from "tslib";
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { Text, View } from 'react-native';
|
|
4
3
|
import { immutableMerge } from '@fluentui-react-native/immutable-merge';
|
|
@@ -8,7 +7,7 @@ import { buildUseTokens } from './buildUseTokens';
|
|
|
8
7
|
/**
|
|
9
8
|
* The default/base theme just contains base values
|
|
10
9
|
*/
|
|
11
|
-
|
|
10
|
+
const baseTheme = {
|
|
12
11
|
globals: {
|
|
13
12
|
backgroundColor: 'white',
|
|
14
13
|
color: 'black',
|
|
@@ -18,48 +17,48 @@ var baseTheme = {
|
|
|
18
17
|
},
|
|
19
18
|
components: {},
|
|
20
19
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const current = { theme: baseTheme };
|
|
21
|
+
const useTheme = () => current.theme;
|
|
22
|
+
const setActiveTheme = (theme) => {
|
|
24
23
|
current.theme = (theme && immutableMerge(baseTheme, theme)) || baseTheme;
|
|
25
24
|
};
|
|
26
25
|
/**
|
|
27
26
|
* Helper function used to look up a component in the theme. Having this injected allows this module to not be dependent on the shape of
|
|
28
27
|
* the theme used.
|
|
29
28
|
*/
|
|
30
|
-
|
|
31
|
-
describe('useTokens samples',
|
|
29
|
+
const getComponentInfo = (theme, name) => theme.components[name];
|
|
30
|
+
describe('useTokens samples', () => {
|
|
32
31
|
/**
|
|
33
32
|
* Sample #1 - Themeable text element
|
|
34
33
|
*
|
|
35
34
|
* This adds some default opinions for how a text element should be styled but only allows for customization
|
|
36
35
|
* via theming
|
|
37
36
|
*/
|
|
38
|
-
|
|
37
|
+
const useTokensSample1 = buildUseTokens(getComponentInfo,
|
|
39
38
|
/** first the default values should come from the global theme section */
|
|
40
|
-
|
|
39
|
+
(t) => ({
|
|
41
40
|
color: t.globals.color,
|
|
42
41
|
fontFamily: t.globals.fontFamily,
|
|
43
42
|
fontSize: t.globals.fontSize,
|
|
44
|
-
})
|
|
43
|
+
}),
|
|
45
44
|
/** next we should look for a component reference to overlay */
|
|
46
45
|
'SampleText');
|
|
47
|
-
|
|
46
|
+
const SampleText1 = (props) => {
|
|
48
47
|
// standard props splitting
|
|
49
|
-
|
|
48
|
+
const { style, children, ...rest } = props;
|
|
50
49
|
// typically this would start with a call to retrieve the theme from the context via whatever method is appropriate
|
|
51
|
-
|
|
50
|
+
const theme = useTheme();
|
|
52
51
|
// next the tokens are resolved from the theme, a cache specific to this theme is returned as well to allow for
|
|
53
52
|
// style objects to not be rebuilt unnecessarily
|
|
54
|
-
|
|
53
|
+
const [tokens, cache] = useTokensSample1(theme);
|
|
55
54
|
// build up the text style, or the full props as appropriate
|
|
56
|
-
|
|
55
|
+
const styleFromTokens = cache(
|
|
57
56
|
/**
|
|
58
57
|
* first build the style object
|
|
59
58
|
* - this executes once for every unique set of keys.
|
|
60
59
|
* - The cache is already unique for this theme
|
|
61
60
|
*/
|
|
62
|
-
|
|
61
|
+
() => ({ ...tokens }),
|
|
63
62
|
/**
|
|
64
63
|
* now specify the keys
|
|
65
64
|
* - because the only changing variable is the theme
|
|
@@ -70,20 +69,20 @@ describe('useTokens samples', function () {
|
|
|
70
69
|
[]);
|
|
71
70
|
// merge the props from the tokens with anything passed in via style. This is internally cached via object identity
|
|
72
71
|
// so the merged style object won't change identity unless one of the two inputs changes identity.
|
|
73
|
-
|
|
72
|
+
const mergedStyle = mergeStyles(styleFromTokens, style);
|
|
74
73
|
// now just render the element, forwarding the props, setting the merged style, then passing the children as appropriate
|
|
75
|
-
return (React.createElement(Text,
|
|
74
|
+
return (React.createElement(Text, { ...rest, style: mergedStyle }, children));
|
|
76
75
|
};
|
|
77
|
-
beforeEach(
|
|
76
|
+
beforeEach(() => {
|
|
78
77
|
setActiveTheme();
|
|
79
78
|
});
|
|
80
79
|
/** first render the component with no updates */
|
|
81
|
-
it('Sample1Text rendering with no overrides',
|
|
82
|
-
|
|
80
|
+
it('Sample1Text rendering with no overrides', () => {
|
|
81
|
+
const tree = renderer.create(React.createElement(SampleText1, null, "Sample1a")).toJSON();
|
|
83
82
|
expect(tree).toMatchSnapshot();
|
|
84
83
|
});
|
|
85
84
|
/** now re-theme the component via the components in the theme */
|
|
86
|
-
it('Sample1Text rendering with some custom settings in the theme',
|
|
85
|
+
it('Sample1Text rendering with some custom settings in the theme', () => {
|
|
87
86
|
setActiveTheme({
|
|
88
87
|
components: {
|
|
89
88
|
SampleText: {
|
|
@@ -92,28 +91,28 @@ describe('useTokens samples', function () {
|
|
|
92
91
|
},
|
|
93
92
|
},
|
|
94
93
|
});
|
|
95
|
-
|
|
94
|
+
const tree = renderer.create(React.createElement(SampleText1, null, "Sample1b")).toJSON();
|
|
96
95
|
expect(tree).toMatchSnapshot();
|
|
97
96
|
});
|
|
98
97
|
// the Sample2Text component is built the same way as sample1, just using the new hook that has been created
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
const SampleText2 = (props) => {
|
|
99
|
+
const { color, style, children, ...rest } = props;
|
|
100
|
+
const theme = useTheme();
|
|
102
101
|
// this starts the same as sample1, extract tokens from the theme and get a theme specific cache object
|
|
103
|
-
|
|
102
|
+
const [tokens, cache] = useTokensSample1(theme);
|
|
104
103
|
// now when building up the style this time, the resulting style object is based upon both the theme and the passed
|
|
105
104
|
// in value of colors. Because the theme is already part of the cache definition, only color needs to be a key
|
|
106
|
-
|
|
105
|
+
const styleFromTokens = cache(
|
|
107
106
|
/** build the style, only patch the color if it has a value, otherwise the theme value would get stomped if color was undefined */
|
|
108
|
-
|
|
107
|
+
() => ({ ...tokens, ...(color && { color }) }),
|
|
109
108
|
/** use color as an additional key for the style */
|
|
110
109
|
[color]);
|
|
111
110
|
// now just render, this time merging styles inline to make it a bit shorter
|
|
112
|
-
return (React.createElement(Text,
|
|
111
|
+
return (React.createElement(Text, { ...rest, style: mergeStyles(styleFromTokens, style) }, children));
|
|
113
112
|
};
|
|
114
113
|
/** rendering the Sample2 component with the base theme */
|
|
115
|
-
it('Sample2Text rendering with defaults and a color override',
|
|
116
|
-
|
|
114
|
+
it('Sample2Text rendering with defaults and a color override', () => {
|
|
115
|
+
const tree = renderer
|
|
117
116
|
.create(React.createElement(View, null,
|
|
118
117
|
React.createElement(SampleText2, null, "Sample2 with defaults"),
|
|
119
118
|
React.createElement(SampleText2, { color: "green" }, "Sample2 with color override via prop")))
|
|
@@ -121,7 +120,7 @@ describe('useTokens samples', function () {
|
|
|
121
120
|
expect(tree).toMatchSnapshot();
|
|
122
121
|
});
|
|
123
122
|
/** now re-theme the component via the components in the theme */
|
|
124
|
-
it('Sample2Text rendering with some custom settings in the theme',
|
|
123
|
+
it('Sample2Text rendering with some custom settings in the theme', () => {
|
|
125
124
|
setActiveTheme({
|
|
126
125
|
components: {
|
|
127
126
|
SampleText: {
|
|
@@ -130,7 +129,7 @@ describe('useTokens samples', function () {
|
|
|
130
129
|
},
|
|
131
130
|
},
|
|
132
131
|
});
|
|
133
|
-
|
|
132
|
+
const tree = renderer
|
|
134
133
|
.create(React.createElement(View, null,
|
|
135
134
|
React.createElement(SampleText2, null, "Sample2 with theme overrides set"),
|
|
136
135
|
React.createElement(SampleText2, { color: "purple" }, "Sample2 with theme and color prop override")))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTokens.samples.test.js","sourceRoot":"","sources":["../src/useTokens.samples.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTokens.samples.test.js","sourceRoot":"","sources":["../src/useTokens.samples.test.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,c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UAAU,EAAE;gBACV,UAAU,EAAE;oBACV,QAAQ,EAAE,EAAE;oBACZ,UAAU,EAAE,WAAW;iBACxB;aACF;SACF,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,QAAQ;aAClB,MAAM,CACL,oBAAC,IAAI;YACH,oBAAC,WAAW,2CAA+C;YAC3D,oBAAC,WAAW,IAAC,KAAK,EAAC,QAAQ,iDAAyD,CAC/E,CACR;aACA,MAAM,EAAE,CAAC;QACZ,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyPropsToTokens = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
4
|
function applyPropsToTokens(props, tokens, cache, keys) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
_a = cache(function () {
|
|
11
|
-
var _a;
|
|
12
|
-
return (setValue === undefined ? tokens : tslib_1.__assign(tslib_1.__assign({}, tokens), (_a = {}, _a[key] = setValue, _a)));
|
|
13
|
-
}, [setValue]), tokens = _a[0], cache = _a[1];
|
|
14
|
-
};
|
|
15
|
-
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
16
|
-
var key = keys_1[_i];
|
|
17
|
-
_loop_1(key);
|
|
5
|
+
for (const key of keys) {
|
|
6
|
+
const sourceValue = props[key];
|
|
7
|
+
const setValue = sourceValue === tokens[key] ? undefined : sourceValue;
|
|
8
|
+
[tokens, cache] = cache(() => (setValue === undefined ? tokens : { ...tokens, [key]: setValue }), [setValue]);
|
|
18
9
|
}
|
|
19
10
|
return [tokens, cache];
|
|
20
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyPropsToTokens.js","sourceRoot":"","sources":["../src/applyPropsToTokens.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"applyPropsToTokens.js","sourceRoot":"","sources":["../src/applyPropsToTokens.ts"],"names":[],"mappings":";;;AAEA,SAAgB,kBAAkB,CAChC,KAAa,EACb,MAAe,EACf,KAA4B,EAC5B,IAAuB;IAEvB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;QACtB,MAAM,WAAW,GAAG,KAAK,CAAC,GAAa,CAAC,CAAC;QACzC,MAAM,QAAQ,GAAG,WAAW,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;QACvE,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;KAC/G;IACD,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACzB,CAAC;AAZD,gDAYC"}
|
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const memo_cache_1 = require("@fluentui-react-native/memo-cache");
|
|
4
|
+
const applyPropsToTokens_1 = require("./applyPropsToTokens");
|
|
5
|
+
const tokenProps = ['dos', 'quatro', 'cinco'];
|
|
6
|
+
const themeTokens = {
|
|
7
7
|
uno: 'uno',
|
|
8
8
|
dos: 'dos',
|
|
9
9
|
tres: 3,
|
|
10
10
|
quatro: 4,
|
|
11
11
|
cinco: true,
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
const props1 = { dos: 'two', quatro: 'four', cinco: false, foo: 'foo', bar: 'bar' };
|
|
14
14
|
// const props2: Props = { dos: 'two' };
|
|
15
15
|
// const props3: Props = { foo: 'foo', bar: 'bar' };
|
|
16
|
-
describe('applyPropsToTokens tests',
|
|
17
|
-
test('props get copied',
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
describe('applyPropsToTokens tests', () => {
|
|
17
|
+
test('props get copied', () => {
|
|
18
|
+
const cache = (0, memo_cache_1.getMemoCache)();
|
|
19
|
+
const [tokens] = (0, applyPropsToTokens_1.applyPropsToTokens)(props1, themeTokens, cache, tokenProps);
|
|
20
20
|
expect(tokens).not.toBe(themeTokens);
|
|
21
|
-
for (
|
|
22
|
-
var key = tokenProps_1[_i];
|
|
21
|
+
for (const key of tokenProps) {
|
|
23
22
|
expect(tokens[key]).toEqual(props1[key]);
|
|
24
23
|
}
|
|
25
24
|
});
|
|
26
|
-
test('no copied props does not change tokens',
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
test('no copied props does not change tokens', () => {
|
|
26
|
+
const cache = (0, memo_cache_1.getMemoCache)();
|
|
27
|
+
const [tokens] = (0, applyPropsToTokens_1.applyPropsToTokens)({}, themeTokens, cache, tokenProps);
|
|
29
28
|
expect(tokens).toBe(themeTokens);
|
|
30
29
|
});
|
|
31
30
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyPropsToTokens.test.js","sourceRoot":"","sources":["../src/applyPropsToTokens.test.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"applyPropsToTokens.test.js","sourceRoot":"","sources":["../src/applyPropsToTokens.test.ts"],"names":[],"mappings":";;AAAA,kEAAiE;AAEjE,6DAA0D;AAW1D,MAAM,UAAU,GAAyB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAOpE,MAAM,WAAW,GAAW;IAC1B,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,IAAI;CACZ,CAAC;AAEF,MAAM,MAAM,GAAU,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AAC3F,wCAAwC;AACxC,oDAAoD;AAEpD,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAI,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC5B,MAAM,KAAK,GAAG,IAAA,yBAAY,GAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,GAAG,IAAA,uCAAkB,EAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACrC,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE;YAC5B,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;SAC1C;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAClD,MAAM,KAAK,GAAG,IAAA,yBAAY,GAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,GAAG,IAAA,uCAAkB,EAAC,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;QACxE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyTokenLayers = void 0;
|
|
4
|
-
|
|
4
|
+
const immutable_merge_1 = require("@fluentui-react-native/immutable-merge");
|
|
5
5
|
/**
|
|
6
6
|
* Apply token layers, building them up applied layer by applied layer, using the cache to store intermediate
|
|
7
7
|
* values
|
|
@@ -12,15 +12,15 @@ var immutable_merge_1 = require("@fluentui-react-native/immutable-merge");
|
|
|
12
12
|
* @param hasLayer - a function which returns whether a given layer should be applied
|
|
13
13
|
*/
|
|
14
14
|
function applyTokenLayers(tokens, states, subCache, hasLayer) {
|
|
15
|
-
|
|
15
|
+
let final = { tokens, subCache };
|
|
16
16
|
if (states && states.length > 0) {
|
|
17
17
|
// now walk the overrides that are set, merging in props, caching results, and getting a new sub cache
|
|
18
18
|
final = states
|
|
19
|
-
.filter(
|
|
20
|
-
.reduce(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return { tokens
|
|
19
|
+
.filter((val) => hasLayer(val))
|
|
20
|
+
.reduce((previous, layerName) => {
|
|
21
|
+
const layer = previous.tokens[layerName];
|
|
22
|
+
const [tokens, subCache] = previous.subCache(() => (layer && typeof layer === 'object' ? (0, immutable_merge_1.immutableMerge)(previous.tokens, layer) : previous.tokens), [layer]);
|
|
23
|
+
return { tokens, subCache };
|
|
24
24
|
}, final);
|
|
25
25
|
}
|
|
26
26
|
return [final.tokens, final.subCache];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyTokenLayers.js","sourceRoot":"","sources":["../src/applyTokenLayers.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"applyTokenLayers.js","sourceRoot":"","sources":["../src/applyTokenLayers.ts"],"names":[],"mappings":";;;AAAA,4EAAwE;AAQxE;;;;;;;;GAQG;AACH,SAAgB,gBAAgB,CAC9B,MAAe,EACf,MAAgB,EAChB,QAA+B,EAC/B,QAAkB;IAGlB,IAAI,KAAK,GAAmB,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IACjD,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,sGAAsG;QACtG,KAAK,GAAG,MAAM;aACX,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;aAC9B,MAAM,CAAC,CAAC,QAAwB,EAAE,SAAiB,EAAE,EAAE;YACtD,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACzC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAC1C,GAAG,EAAE,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,gCAAc,EAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EACrG,CAAC,KAAK,CAAC,CACR,CAAC;YACF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QAC9B,CAAC,EAAE,KAAK,CAAC,CAAC;KACb;IACD,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC;AAtBD,4CAsBC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var tokens1 = {
|
|
3
|
+
const memo_cache_1 = require("@fluentui-react-native/memo-cache");
|
|
4
|
+
const applyTokenLayers_1 = require("./applyTokenLayers");
|
|
5
|
+
const stateOrder = ['hover', 'press', 'disabled'];
|
|
6
|
+
const tokens1 = {
|
|
8
7
|
a: 'a',
|
|
9
8
|
b: 'b',
|
|
10
9
|
c: 'c',
|
|
@@ -26,29 +25,29 @@ var tokens1 = {
|
|
|
26
25
|
},
|
|
27
26
|
};
|
|
28
27
|
function stripLayers(tokens) {
|
|
29
|
-
|
|
28
|
+
const t = { ...tokens };
|
|
30
29
|
delete t.hover;
|
|
31
30
|
delete t.press;
|
|
32
31
|
delete t.disabled;
|
|
33
32
|
return t;
|
|
34
33
|
}
|
|
35
|
-
describe('applyLayers tests',
|
|
36
|
-
test('no layers returns tokens',
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
describe('applyLayers tests', () => {
|
|
35
|
+
test('no layers returns tokens', () => {
|
|
36
|
+
const cache = (0, memo_cache_1.getMemoCache)();
|
|
37
|
+
const tokens = (0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, () => false)[0];
|
|
39
38
|
expect(tokens).toBe(tokens1);
|
|
40
39
|
});
|
|
41
|
-
test('apply hover works',
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
test('apply hover works', () => {
|
|
41
|
+
const cache = (0, memo_cache_1.getMemoCache)();
|
|
42
|
+
const lookup = (layer) => layer === 'hover';
|
|
43
|
+
const result1 = (0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0];
|
|
45
44
|
expect((0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0]).toBe(result1);
|
|
46
45
|
expect(stripLayers(result1)).toEqual({ a: 'a-hover', b: 'b-hover', c: 'c' });
|
|
47
46
|
});
|
|
48
|
-
test('apply hover and press layer correctly',
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
test('apply hover and press layer correctly', () => {
|
|
48
|
+
const cache = (0, memo_cache_1.getMemoCache)();
|
|
49
|
+
const lookup = (layer) => layer === 'hover' || layer === 'press';
|
|
50
|
+
const result1 = (0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0];
|
|
52
51
|
expect((0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0]).toBe(result1);
|
|
53
52
|
expect(stripLayers(result1)).toEqual({ a: 'a-hover-press', b: 'b-press', c: 'c' });
|
|
54
53
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyTokenLayers.test.js","sourceRoot":"","sources":["../src/applyTokenLayers.test.ts"],"names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AC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildUseTokens = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var memo_cache_1 = require("@fluentui-react-native/memo-cache");
|
|
4
|
+
const immutable_merge_1 = require("@fluentui-react-native/immutable-merge");
|
|
5
|
+
const memo_cache_1 = require("@fluentui-react-native/memo-cache");
|
|
7
6
|
/**
|
|
8
7
|
* Tokens are defined as either:
|
|
9
8
|
* TTokens - an object
|
|
@@ -32,27 +31,19 @@ function mapToTokens(tokenEntry, theme, getComponentInfo) {
|
|
|
32
31
|
* @param options - options which drive behavior for the generated styling hook
|
|
33
32
|
* @param themeHelper - injected theme functionality
|
|
34
33
|
*/
|
|
35
|
-
function buildUseTokens(getComponentInfo) {
|
|
36
|
-
var tokens = [];
|
|
37
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
38
|
-
tokens[_i - 1] = arguments[_i];
|
|
39
|
-
}
|
|
34
|
+
function buildUseTokens(getComponentInfo, ...tokens) {
|
|
40
35
|
// create a cache instance for use in this particular call to buildUseTokens
|
|
41
|
-
|
|
36
|
+
const cache = (0, memo_cache_1.getMemoCache)();
|
|
42
37
|
// the core function simply merges layers together, looking up component definitions in the theme as well as executing any
|
|
43
38
|
// theme functions. This turns the tokens into an array of token objects that then get merged together
|
|
44
|
-
|
|
39
|
+
const useTokensCore = (theme) => {
|
|
45
40
|
// get the base styles all merged together, these will only depend on internal tokens and theme
|
|
46
|
-
return cache(
|
|
41
|
+
return cache(() => (0, immutable_merge_1.immutableMerge)(...tokens.map((value) => mapToTokens(value, theme, getComponentInfo))), [theme]);
|
|
47
42
|
};
|
|
48
43
|
// attach a customize function to generate a new use
|
|
49
|
-
useTokensCore.customize =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
newTokens[_i] = arguments[_i];
|
|
53
|
-
}
|
|
54
|
-
var mergedTokens = tslib_1.__spreadArray(tslib_1.__spreadArray([], tokens, true), newTokens, true);
|
|
55
|
-
return buildUseTokens.apply(void 0, tslib_1.__spreadArray([getComponentInfo], mergedTokens, false));
|
|
44
|
+
useTokensCore.customize = (...newTokens) => {
|
|
45
|
+
const mergedTokens = [...tokens, ...newTokens];
|
|
46
|
+
return buildUseTokens(getComponentInfo, ...mergedTokens);
|
|
56
47
|
};
|
|
57
48
|
return useTokensCore;
|
|
58
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildUseTokens.js","sourceRoot":"","sources":["../src/buildUseTokens.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildUseTokens.js","sourceRoot":"","sources":["../src/buildUseTokens.ts"],"names":[],"mappings":";;;AAAA,4EAAwE;AAExE,kEAAiE;AAiCjE;;;;;;;;;;;;GAYG;AACH,SAAS,WAAW,CAClB,UAA+D,EAC/D,KAAa,EACb,gBAA+D;IAE/D,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;QAClC,UAAU,GAAG,CAAC,gBAAgB,IAAK,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAa,CAAC,IAAK,EAAc,CAAC;KACxG;IACD,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE;QACpC,UAAU,GAAI,UAA+C,CAAC,KAAK,CAAC,CAAC;KACtE;IACD,OAAO,UAA+B,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAC5B,gBAA+D,EAC/D,GAAG,MAAwC;IAE3C,4EAA4E;IAC5E,MAAM,KAAK,GAAG,IAAA,yBAAY,GAAE,CAAC;IAE7B,0HAA0H;IAC1H,sGAAsG;IACtG,MAAM,aAAa,GAAG,CAAC,KAAa,EAAE,EAAE;QACtC,+FAA+F;QAC/F,OAAO,KAAK,CAAC,GAAG,EAAE,CAAC,IAAA,gCAAc,EAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACrH,CAAC,CAAC;IAEF,oDAAoD;IACpD,aAAa,CAAC,SAAS,GAAG,CAAC,GAAG,SAA2C,EAAE,EAAE;QAC3E,MAAM,YAAY,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;QAC/C,OAAO,cAAc,CAAkB,gBAAgB,EAAE,GAAG,YAAY,CAAC,CAAC;IAC5E,CAAC,CAAC;IAEF,OAAO,aAAa,CAAC;AACvB,CAAC;AArBD,wCAqBC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var baseTokens = {
|
|
3
|
+
const buildUseTokens_1 = require("./buildUseTokens");
|
|
4
|
+
const baseTokens = {
|
|
6
5
|
a: 'a-base',
|
|
7
6
|
b: 'b-base',
|
|
8
7
|
c: 'c-base',
|
|
@@ -13,7 +12,7 @@ var baseTokens = {
|
|
|
13
12
|
c: 'c-base-press',
|
|
14
13
|
},
|
|
15
14
|
};
|
|
16
|
-
|
|
15
|
+
const defaultTheme = {
|
|
17
16
|
vals: {
|
|
18
17
|
foo: 'foo',
|
|
19
18
|
bar: 'bar',
|
|
@@ -29,15 +28,15 @@ var defaultTheme = {
|
|
|
29
28
|
},
|
|
30
29
|
},
|
|
31
30
|
};
|
|
32
|
-
|
|
31
|
+
const variantTheme = {
|
|
33
32
|
vals: {
|
|
34
33
|
foo: 'variant',
|
|
35
34
|
},
|
|
36
35
|
components: {},
|
|
37
36
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const getComponentInfo = (theme, name) => theme.components[name];
|
|
38
|
+
const componentTokens = [baseTokens, 'uno', (theme) => ({ b: theme.vals.foo })];
|
|
39
|
+
const resolvedTokens = {
|
|
41
40
|
a: 'uno-a',
|
|
42
41
|
b: 'foo',
|
|
43
42
|
c: 'uno-c',
|
|
@@ -48,7 +47,7 @@ var resolvedTokens = {
|
|
|
48
47
|
c: 'c-base-press',
|
|
49
48
|
},
|
|
50
49
|
};
|
|
51
|
-
|
|
50
|
+
const variantTokens = {
|
|
52
51
|
a: 'a-base',
|
|
53
52
|
b: 'variant',
|
|
54
53
|
c: 'c-base',
|
|
@@ -59,30 +58,30 @@ var variantTokens = {
|
|
|
59
58
|
c: 'c-base-press',
|
|
60
59
|
},
|
|
61
60
|
};
|
|
62
|
-
describe('buildUseTokens test suite',
|
|
63
|
-
test('basic built hook',
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
describe('buildUseTokens test suite', () => {
|
|
62
|
+
test('basic built hook', () => {
|
|
63
|
+
const useTokens = (0, buildUseTokens_1.buildUseTokens)(getComponentInfo, ...componentTokens);
|
|
64
|
+
const [tokens] = useTokens(defaultTheme);
|
|
66
65
|
expect(tokens).toEqual(resolvedTokens);
|
|
67
66
|
});
|
|
68
|
-
test('multiple calls return same object',
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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);
|
|
72
71
|
expect(tokens1).toBe(tokens2);
|
|
73
72
|
});
|
|
74
|
-
test('variant theme is separate',
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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);
|
|
78
77
|
expect(tokensVariant).not.toBe(tokensDefault);
|
|
79
78
|
expect(tokensVariant).toEqual(variantTokens);
|
|
80
79
|
});
|
|
81
|
-
test('simple customization layers on top',
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
expect(tokens).toEqual(
|
|
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' });
|
|
86
85
|
});
|
|
87
86
|
});
|
|
88
87
|
//# sourceMappingURL=buildUseTokens.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildUseTokens.test.js","sourceRoot":"","sources":["../src/buildUseTokens.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildUseTokens.test.js","sourceRoot":"","sources":["../src/buildUseTokens.test.ts"],"names":[],"mappings":";;AAAA,qDAAkD;AAUlD,MAAM,UAAU,GAAW;IACzB,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,QAAQ;IACX,KAAK,EAAE;QACL,CAAC,EAAE,cAAc;KAClB;IACD,KAAK,EAAE;QACL,CAAC,EAAE,cAAc;KAClB;CACF,CAAC;AAYF,MAAM,YAAY,GAAU;IAC1B,IAAI,EAAE;QACJ,GAAG,EAAE,KAAK;QACV,GAAG,EAAE,KAAK;KACX;IACD,UAAU,EAAE;QACV,GAAG,EAAE;YACH,CAAC,EAAE,OAAO;YACV,CAAC,EAAE,OAAO;SACX;QACD,GAAG,EAAE;YACH,CAAC,EAAE,OAAO;YACV,CAAC,EAAE,OAAO;SACX;KACF;CACF,CAAC;AAEF,MAAM,YAAY,GAAU;IAC1B,IAAI,EAAE;QACJ,GAAG,EAAE,SAAS;KACf;IACD,UAAU,EAAE,EAAE;CACf,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,KAAY,EA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AAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACrC,MAAM,SAAS,GAAG,IAAA,+BAAc,EAAC,gBAAgB,EAAE,GAAG,eAAe,CAAC,CAAC;QACvE,MAAM,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;QAChD,MAAM,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;QAChD,MAAM,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC9C,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC9C,MAAM,SAAS,GAAG,IAAA,+BAAc,EAAC,gBAAgB,EAAE,GAAG,eAAe,CAAC,CAAC;QACvE,MAAM,eAAe,GAAG,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC7D,MAAM,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;QAC/C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,cAAc,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -11,13 +11,9 @@ exports.customizable = void 0;
|
|
|
11
11
|
* new component (which can also be customized)
|
|
12
12
|
*/
|
|
13
13
|
function customizable(injectable, useTokens) {
|
|
14
|
-
|
|
15
|
-
component.customize =
|
|
16
|
-
|
|
17
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18
|
-
tokens[_i] = arguments[_i];
|
|
19
|
-
}
|
|
20
|
-
var useTokensNew = useTokens.customize.apply(useTokens, tokens);
|
|
14
|
+
const component = (props) => injectable(props, useTokens);
|
|
15
|
+
component.customize = (...tokens) => {
|
|
16
|
+
const useTokensNew = useTokens.customize(...tokens);
|
|
21
17
|
return customizable(injectable, useTokensNew);
|
|
22
18
|
};
|
|
23
19
|
return component;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customizable.js","sourceRoot":"","sources":["../src/customizable.ts"],"names":[],"mappings":";;;AAiBA;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAC1B,UAAwD,EACxD,SAAqC;IAErC,
|
|
1
|
+
{"version":3,"file":"customizable.js","sourceRoot":"","sources":["../src/customizable.ts"],"names":[],"mappings":";;;AAiBA;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAC1B,UAAwD,EACxD,SAAqC;IAErC,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAClE,SAAS,CAAC,SAAS,GAAG,CAAC,GAAG,MAAwC,EAAE,EAAE;QACpE,MAAM,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC;QACpD,OAAO,YAAY,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IAChD,CAAC,CAAC;IACF,OAAO,SAAS,CAAC;AACnB,CAAC;AAVD,oCAUC"}
|