@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.
Files changed (46) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/lib/applyPropsToTokens.d.ts +2 -7
  3. package/lib/applyPropsToTokens.js +7 -7
  4. package/lib/applyPropsToTokens.test.d.ts +1 -1
  5. package/lib/applyPropsToTokens.test.js +19 -19
  6. package/lib/applyTokenLayers.d.ts +2 -7
  7. package/lib/applyTokenLayers.js +13 -16
  8. package/lib/applyTokenLayers.test.d.ts +1 -1
  9. package/lib/applyTokenLayers.test.js +42 -42
  10. package/lib/buildUseTokens.d.ts +3 -6
  11. package/lib/buildUseTokens.js +22 -22
  12. package/lib/buildUseTokens.test.d.ts +1 -1
  13. package/lib/buildUseTokens.test.js +68 -68
  14. package/lib/customizable.d.ts +3 -6
  15. package/lib/customizable.js +7 -7
  16. package/lib/index.d.ts +1 -1
  17. package/lib/index.js +1 -1
  18. package/lib/patchTokens.d.ts +2 -6
  19. package/lib/patchTokens.js +12 -12
  20. package/lib/patchTokens.test.d.ts +1 -1
  21. package/lib/patchTokens.test.js +32 -32
  22. package/lib/useTokens.samples.test.d.ts +1 -1
  23. package/lib/useTokens.samples.test.js +119 -133
  24. package/lib-commonjs/applyPropsToTokens.d.ts +2 -7
  25. package/lib-commonjs/applyPropsToTokens.js +9 -9
  26. package/lib-commonjs/applyPropsToTokens.test.d.ts +1 -1
  27. package/lib-commonjs/applyPropsToTokens.test.js +23 -23
  28. package/lib-commonjs/applyTokenLayers.d.ts +2 -7
  29. package/lib-commonjs/applyTokenLayers.js +16 -19
  30. package/lib-commonjs/applyTokenLayers.test.d.ts +1 -1
  31. package/lib-commonjs/applyTokenLayers.test.js +46 -46
  32. package/lib-commonjs/buildUseTokens.d.ts +3 -6
  33. package/lib-commonjs/buildUseTokens.js +26 -29
  34. package/lib-commonjs/buildUseTokens.test.d.ts +1 -1
  35. package/lib-commonjs/buildUseTokens.test.js +71 -71
  36. package/lib-commonjs/customizable.d.ts +3 -6
  37. package/lib-commonjs/customizable.js +9 -9
  38. package/lib-commonjs/index.d.ts +1 -1
  39. package/lib-commonjs/index.js +13 -38
  40. package/lib-commonjs/patchTokens.d.ts +2 -6
  41. package/lib-commonjs/patchTokens.js +14 -14
  42. package/lib-commonjs/patchTokens.test.d.ts +1 -1
  43. package/lib-commonjs/patchTokens.test.js +36 -36
  44. package/lib-commonjs/useTokens.samples.test.d.ts +1 -1
  45. package/lib-commonjs/useTokens.samples.test.js +156 -191
  46. package/package.json +14 -13
@@ -1,38 +1,38 @@
1
1
  import { getMemoCache } from '@fluentui-react-native/framework-base';
2
2
  import { patchTokens } from './patchTokens';
3
3
  const themeTokens = {
4
- uno: 'uno',
5
- dos: 'dos',
6
- tres: 3,
7
- quatro: 4,
8
- cinco: true,
4
+ uno: 'uno',
5
+ dos: 'dos',
6
+ tres: 3,
7
+ quatro: 4,
8
+ cinco: true,
9
9
  };
10
10
  describe('patchTokens tests', () => {
11
- test('props get copied', () => {
12
- const cache = getMemoCache();
13
- const patchValues = { uno: 'one', quatro: 'quatro' };
14
- const [tokens] = patchTokens(themeTokens, cache, patchValues);
15
- expect(tokens).not.toBe(themeTokens);
16
- for (const key in patchValues) {
17
- expect(tokens[key]).toEqual(patchValues[key]);
18
- }
19
- });
20
- test('no copied props does not change tokens', () => {
21
- const cache = getMemoCache();
22
- const patchValues1 = {};
23
- const [tokens] = patchTokens(themeTokens, cache, patchValues1);
24
- expect(tokens).toBe(themeTokens);
25
- const patchValues2 = { tres: undefined };
26
- const [tokens2] = patchTokens(themeTokens, cache, patchValues2);
27
- expect(tokens2).toBe(themeTokens);
28
- });
29
- test('patching tokens cache independent of order', () => {
30
- const cache = getMemoCache();
31
- const patch1 = { uno: 'one', cinco: false };
32
- const patch2 = { cinco: false, uno: 'one' };
33
- const [tokens1] = patchTokens(themeTokens, cache, patch1);
34
- const [tokens2] = patchTokens(themeTokens, cache, patch2);
35
- expect(tokens1).toBe(tokens2);
36
- });
11
+ test('props get copied', () => {
12
+ const cache = getMemoCache();
13
+ const patchValues = { uno: 'one', quatro: 'quatro' };
14
+ const [tokens] = patchTokens(themeTokens, cache, patchValues);
15
+ expect(tokens).not.toBe(themeTokens);
16
+ for (const key in patchValues) {
17
+ expect(tokens[key]).toEqual(patchValues[key]);
18
+ }
19
+ });
20
+ test('no copied props does not change tokens', () => {
21
+ const cache = getMemoCache();
22
+ const patchValues1 = {};
23
+ const [tokens] = patchTokens(themeTokens, cache, patchValues1);
24
+ expect(tokens).toBe(themeTokens);
25
+ const patchValues2 = { tres: undefined };
26
+ const [tokens2] = patchTokens(themeTokens, cache, patchValues2);
27
+ expect(tokens2).toBe(themeTokens);
28
+ });
29
+ test('patching tokens cache independent of order', () => {
30
+ const cache = getMemoCache();
31
+ const patch1 = { uno: 'one', cinco: false };
32
+ const patch2 = { cinco: false, uno: 'one' };
33
+ const [tokens1] = patchTokens(themeTokens, cache, patch1);
34
+ const [tokens2] = patchTokens(themeTokens, cache, patch2);
35
+ expect(tokens1).toBe(tokens2);
36
+ });
37
37
  });
38
- //# sourceMappingURL=patchTokens.test.js.map
38
+ //# 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
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from 'react/jsx-runtime';
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { act } from 'react';
3
3
  import { Text, View } from 'react-native';
4
4
  import { immutableMerge } from '@fluentui-react-native/framework-base';
@@ -9,19 +9,19 @@ import { buildUseTokens } from './buildUseTokens';
9
9
  * The default/base theme just contains base values
10
10
  */
11
11
  const baseTheme = {
12
- globals: {
13
- backgroundColor: 'white',
14
- color: 'black',
15
- borderColor: 'blue',
16
- fontFamily: 'Arial',
17
- fontSize: 12,
18
- },
19
- components: {},
12
+ globals: {
13
+ backgroundColor: 'white',
14
+ color: 'black',
15
+ borderColor: 'blue',
16
+ fontFamily: 'Arial',
17
+ fontSize: 12,
18
+ },
19
+ components: {},
20
20
  };
21
21
  const current = { theme: baseTheme };
22
22
  const useTheme = () => current.theme;
23
23
  const setActiveTheme = (theme) => {
24
- current.theme = (theme && immutableMerge(baseTheme, theme)) || baseTheme;
24
+ current.theme = (theme && immutableMerge(baseTheme, theme)) || baseTheme;
25
25
  };
26
26
  /**
27
27
  * 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
@@ -29,135 +29,121 @@ const setActiveTheme = (theme) => {
29
29
  */
30
30
  const getComponentInfo = (theme, name) => theme.components[name];
31
31
  describe('useTokens samples', () => {
32
- /**
33
- * Sample #1 - Themeable text element
34
- *
35
- * This adds some default opinions for how a text element should be styled but only allows for customization
36
- * via theming
37
- */
38
- const useTokensSample1 = buildUseTokens(
39
- getComponentInfo,
32
+ /**
33
+ * Sample #1 - Themeable text element
34
+ *
35
+ * This adds some default opinions for how a text element should be styled but only allows for customization
36
+ * via theming
37
+ */
38
+ const useTokensSample1 = buildUseTokens(getComponentInfo,
40
39
  /** first the default values should come from the global theme section */
41
40
  (t) => ({
42
- color: t.globals.color,
43
- fontFamily: t.globals.fontFamily,
44
- fontSize: t.globals.fontSize,
45
- }),
41
+ color: t.globals.color,
42
+ fontFamily: t.globals.fontFamily,
43
+ fontSize: t.globals.fontSize,
44
+ }),
46
45
  /** next we should look for a component reference to overlay */
47
- 'SampleText',
48
- );
49
- const SampleText1 = (props) => {
50
- // standard props splitting
51
- const { style, children, ...rest } = props;
52
- // typically this would start with a call to retrieve the theme from the context via whatever method is appropriate
53
- const theme = useTheme();
54
- // next the tokens are resolved from the theme, a cache specific to this theme is returned as well to allow for
55
- // style objects to not be rebuilt unnecessarily
56
- const [tokens, cache] = useTokensSample1(theme);
57
- // build up the text style, or the full props as appropriate
58
- const [styleFromTokens] = cache(
59
- /**
60
- * first build the style object
61
- * - this executes once for every unique set of keys.
62
- * - The cache is already unique for this theme
63
- */
64
- () => ({ ...tokens }),
65
- /**
66
- * now specify the keys
67
- * - because the only changing variable is the theme
68
- * - ...and all the style properties are either constant or come from the tokens
69
- * - ...no keys need to be specified
70
- * - this means that only one style object will be created per component + theme pair
71
- */
72
- [],
73
- );
74
- // merge the props from the tokens with anything passed in via style. This is internally cached via object identity
75
- // so the merged style object won't change identity unless one of the two inputs changes identity.
76
- const mergedStyle = mergeStyles(styleFromTokens, style);
77
- // now just render the element, forwarding the props, setting the merged style, then passing the children as appropriate
78
- return _jsx(Text, { ...rest, style: mergedStyle, children: children });
79
- };
80
- beforeEach(() => {
81
- setActiveTheme();
82
- });
83
- /** first render the component with no updates */
84
- it('Sample1Text rendering with no overrides', () => {
85
- let component;
86
- act(() => {
87
- component = renderer.create(_jsx(SampleText1, { children: 'Sample1a' }));
46
+ 'SampleText');
47
+ const SampleText1 = (props) => {
48
+ // standard props splitting
49
+ const { style, children, ...rest } = props;
50
+ // typically this would start with a call to retrieve the theme from the context via whatever method is appropriate
51
+ const theme = useTheme();
52
+ // next the tokens are resolved from the theme, a cache specific to this theme is returned as well to allow for
53
+ // style objects to not be rebuilt unnecessarily
54
+ const [tokens, cache] = useTokensSample1(theme);
55
+ // build up the text style, or the full props as appropriate
56
+ const [styleFromTokens] = cache(
57
+ /**
58
+ * first build the style object
59
+ * - this executes once for every unique set of keys.
60
+ * - The cache is already unique for this theme
61
+ */
62
+ () => ({ ...tokens }),
63
+ /**
64
+ * now specify the keys
65
+ * - because the only changing variable is the theme
66
+ * - ...and all the style properties are either constant or come from the tokens
67
+ * - ...no keys need to be specified
68
+ * - this means that only one style object will be created per component + theme pair
69
+ */
70
+ []);
71
+ // merge the props from the tokens with anything passed in via style. This is internally cached via object identity
72
+ // so the merged style object won't change identity unless one of the two inputs changes identity.
73
+ const mergedStyle = mergeStyles(styleFromTokens, style);
74
+ // now just render the element, forwarding the props, setting the merged style, then passing the children as appropriate
75
+ return (_jsx(Text, { ...rest, style: mergedStyle, children: children }));
76
+ };
77
+ beforeEach(() => {
78
+ setActiveTheme();
88
79
  });
89
- expect(component.toJSON()).toMatchSnapshot();
90
- });
91
- /** now re-theme the component via the components in the theme */
92
- it('Sample1Text rendering with some custom settings in the theme', () => {
93
- setActiveTheme({
94
- components: {
95
- SampleText: {
96
- color: 'pink',
97
- fontSize: 24,
98
- },
99
- },
80
+ /** first render the component with no updates */
81
+ it('Sample1Text rendering with no overrides', () => {
82
+ let component;
83
+ act(() => {
84
+ component = renderer.create(_jsx(SampleText1, { children: "Sample1a" }));
85
+ });
86
+ expect(component.toJSON()).toMatchSnapshot();
100
87
  });
101
- let component;
102
- act(() => {
103
- component = renderer.create(_jsx(SampleText1, { children: 'Sample1b' }));
88
+ /** now re-theme the component via the components in the theme */
89
+ it('Sample1Text rendering with some custom settings in the theme', () => {
90
+ setActiveTheme({
91
+ components: {
92
+ SampleText: {
93
+ color: 'pink',
94
+ fontSize: 24,
95
+ },
96
+ },
97
+ });
98
+ let component;
99
+ act(() => {
100
+ component = renderer.create(_jsx(SampleText1, { children: "Sample1b" }));
101
+ });
102
+ expect(component.toJSON()).toMatchSnapshot();
104
103
  });
105
- expect(component.toJSON()).toMatchSnapshot();
106
- });
107
- // the Sample2Text component is built the same way as sample1, just using the new hook that has been created
108
- const SampleText2 = (props) => {
109
- const { color, style, children, ...rest } = props;
110
- const theme = useTheme();
111
- // this starts the same as sample1, extract tokens from the theme and get a theme specific cache object
112
- const [tokens, cache] = useTokensSample1(theme);
113
- // now when building up the style this time, the resulting style object is based upon both the theme and the passed
114
- // in value of colors. Because the theme is already part of the cache definition, only color needs to be a key
115
- const styleFromTokens = cache(
116
- /** build the style, only patch the color if it has a value, otherwise the theme value would get stomped if color was undefined */
117
- () => ({ ...tokens, ...(color && { color }) }),
118
- /** use color as an additional key for the style */
119
- [color],
120
- );
121
- // now just render, this time merging styles inline to make it a bit shorter
122
- return _jsx(Text, { ...rest, style: mergeStyles(styleFromTokens, style), children: children });
123
- };
124
- /** rendering the Sample2 component with the base theme */
125
- it('Sample2Text rendering with defaults and a color override', () => {
126
- let component;
127
- act(() => {
128
- component = renderer.create(
129
- _jsxs(View, {
130
- children: [
131
- _jsx(SampleText2, { children: 'Sample2 with defaults' }),
132
- _jsx(SampleText2, { color: 'green', children: 'Sample2 with color override via prop' }),
133
- ],
134
- }),
135
- );
104
+ // the Sample2Text component is built the same way as sample1, just using the new hook that has been created
105
+ const SampleText2 = (props) => {
106
+ const { color, style, children, ...rest } = props;
107
+ const theme = useTheme();
108
+ // this starts the same as sample1, extract tokens from the theme and get a theme specific cache object
109
+ const [tokens, cache] = useTokensSample1(theme);
110
+ // now when building up the style this time, the resulting style object is based upon both the theme and the passed
111
+ // in value of colors. Because the theme is already part of the cache definition, only color needs to be a key
112
+ const styleFromTokens = cache(
113
+ /** build the style, only patch the color if it has a value, otherwise the theme value would get stomped if color was undefined */
114
+ () => ({ ...tokens, ...(color && { color }) }),
115
+ /** use color as an additional key for the style */
116
+ [color]);
117
+ // now just render, this time merging styles inline to make it a bit shorter
118
+ return (_jsx(Text, { ...rest, style: mergeStyles(styleFromTokens, style), children: children }));
119
+ };
120
+ /** rendering the Sample2 component with the base theme */
121
+ it('Sample2Text rendering with defaults and a color override', () => {
122
+ let component;
123
+ act(() => {
124
+ component = renderer.create(_jsxs(View, { children: [
125
+ _jsx(SampleText2, { children: "Sample2 with defaults" }), _jsx(SampleText2, { color: "green", children: "Sample2 with color override via prop" })
126
+ ] }));
127
+ });
128
+ expect(component.toJSON()).toMatchSnapshot();
136
129
  });
137
- expect(component.toJSON()).toMatchSnapshot();
138
- });
139
- /** now re-theme the component via the components in the theme */
140
- it('Sample2Text rendering with some custom settings in the theme', () => {
141
- setActiveTheme({
142
- components: {
143
- SampleText: {
144
- fontSize: 18,
145
- fontFamily: 'Helvetica',
146
- },
147
- },
130
+ /** now re-theme the component via the components in the theme */
131
+ it('Sample2Text rendering with some custom settings in the theme', () => {
132
+ setActiveTheme({
133
+ components: {
134
+ SampleText: {
135
+ fontSize: 18,
136
+ fontFamily: 'Helvetica',
137
+ },
138
+ },
139
+ });
140
+ let component;
141
+ act(() => {
142
+ component = renderer.create(_jsxs(View, { children: [
143
+ _jsx(SampleText2, { children: "Sample2 with theme overrides set" }), _jsx(SampleText2, { color: "purple", children: "Sample2 with theme and color prop override" })
144
+ ] }));
145
+ });
146
+ expect(component.toJSON()).toMatchSnapshot();
148
147
  });
149
- let component;
150
- act(() => {
151
- component = renderer.create(
152
- _jsxs(View, {
153
- children: [
154
- _jsx(SampleText2, { children: 'Sample2 with theme overrides set' }),
155
- _jsx(SampleText2, { color: 'purple', children: 'Sample2 with theme and color prop override' }),
156
- ],
157
- }),
158
- );
159
- });
160
- expect(component.toJSON()).toMatchSnapshot();
161
- });
162
148
  });
163
- //# sourceMappingURL=useTokens.samples.test.js.map
149
+ //# sourceMappingURL=useTokens.samples.test.js.map
@@ -1,8 +1,3 @@
1
1
  import type { GetTypedMemoValue } from '@fluentui-react-native/framework-base';
2
- export declare function applyPropsToTokens<TProps, TTokens>(
3
- props: TProps,
4
- tokens: TTokens,
5
- cache: GetTypedMemoValue<TTokens>,
6
- keys: (keyof TTokens)[],
7
- ): [TTokens, GetTypedMemoValue<TTokens>];
8
- //# sourceMappingURL=applyPropsToTokens.d.ts.map
2
+ export declare function applyPropsToTokens<TProps, TTokens>(props: TProps, tokens: TTokens, cache: GetTypedMemoValue<TTokens>, keys: (keyof TTokens)[]): [TTokens, GetTypedMemoValue<TTokens>];
3
+ //# sourceMappingURL=applyPropsToTokens.d.ts.map
@@ -1,12 +1,12 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyPropsToTokens = applyPropsToTokens;
4
4
  function applyPropsToTokens(props, tokens, cache, keys) {
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]);
9
- }
10
- return [tokens, cache];
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]);
9
+ }
10
+ return [tokens, cache];
11
11
  }
12
- //# sourceMappingURL=applyPropsToTokens.js.map
12
+ //# sourceMappingURL=applyPropsToTokens.js.map
@@ -1,2 +1,2 @@
1
1
  export {};
2
- //# sourceMappingURL=applyPropsToTokens.test.d.ts.map
2
+ //# sourceMappingURL=applyPropsToTokens.test.d.ts.map
@@ -1,31 +1,31 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- const framework_base_1 = require('@fluentui-react-native/framework-base');
4
- const applyPropsToTokens_1 = require('./applyPropsToTokens');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const framework_base_1 = require("@fluentui-react-native/framework-base");
4
+ const applyPropsToTokens_1 = require("./applyPropsToTokens");
5
5
  const tokenProps = ['dos', 'quatro', 'cinco'];
6
6
  const themeTokens = {
7
- uno: 'uno',
8
- dos: 'dos',
9
- tres: 3,
10
- quatro: 4,
11
- cinco: true,
7
+ uno: 'uno',
8
+ dos: 'dos',
9
+ tres: 3,
10
+ quatro: 4,
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
16
  describe('applyPropsToTokens tests', () => {
17
- test('props get copied', () => {
18
- const cache = (0, framework_base_1.getTypedMemoCache)();
19
- const [tokens] = (0, applyPropsToTokens_1.applyPropsToTokens)(props1, themeTokens, cache, tokenProps);
20
- expect(tokens).not.toBe(themeTokens);
21
- for (const key of tokenProps) {
22
- expect(tokens[key]).toEqual(props1[key]);
23
- }
24
- });
25
- test('no copied props does not change tokens', () => {
26
- const cache = (0, framework_base_1.getTypedMemoCache)();
27
- const [tokens] = (0, applyPropsToTokens_1.applyPropsToTokens)({}, themeTokens, cache, tokenProps);
28
- expect(tokens).toBe(themeTokens);
29
- });
17
+ test('props get copied', () => {
18
+ const cache = (0, framework_base_1.getTypedMemoCache)();
19
+ const [tokens] = (0, applyPropsToTokens_1.applyPropsToTokens)(props1, themeTokens, cache, tokenProps);
20
+ expect(tokens).not.toBe(themeTokens);
21
+ for (const key of tokenProps) {
22
+ expect(tokens[key]).toEqual(props1[key]);
23
+ }
24
+ });
25
+ test('no copied props does not change tokens', () => {
26
+ const cache = (0, framework_base_1.getTypedMemoCache)();
27
+ const [tokens] = (0, applyPropsToTokens_1.applyPropsToTokens)({}, themeTokens, cache, tokenProps);
28
+ expect(tokens).toBe(themeTokens);
29
+ });
30
30
  });
31
- //# sourceMappingURL=applyPropsToTokens.test.js.map
31
+ //# sourceMappingURL=applyPropsToTokens.test.js.map
@@ -12,10 +12,5 @@ export type HasLayer = (name: string) => boolean;
12
12
  * @param subCache - cache scoped to the root object with no layers applied
13
13
  * @param hasLayer - a function which returns whether a given layer should be applied
14
14
  */
15
- export declare function applyTokenLayers<TTokens>(
16
- tokens: TTokens,
17
- states: string[],
18
- subCache: GetTypedMemoValue<TTokens>,
19
- hasLayer: HasLayer,
20
- ): [TTokens, GetTypedMemoValue<TTokens>];
21
- //# sourceMappingURL=applyTokenLayers.d.ts.map
15
+ export declare function applyTokenLayers<TTokens>(tokens: TTokens, states: string[], subCache: GetTypedMemoValue<TTokens>, hasLayer: HasLayer): [TTokens, GetTypedMemoValue<TTokens>];
16
+ //# sourceMappingURL=applyTokenLayers.d.ts.map
@@ -1,7 +1,7 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyTokenLayers = applyTokenLayers;
4
- const framework_base_1 = require('@fluentui-react-native/framework-base');
4
+ const framework_base_1 = require("@fluentui-react-native/framework-base");
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,20 +12,17 @@ const framework_base_1 = require('@fluentui-react-native/framework-base');
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
- let final = { tokens, subCache };
16
- if (states && states.length > 0) {
17
- // now walk the overrides that are set, merging in props, caching results, and getting a new sub cache
18
- final = states
19
- .filter((val) => hasLayer(val))
20
- .reduce((previous, layerName) => {
21
- const layer = previous.tokens[layerName];
22
- const [tokens, subCache] = previous.subCache(
23
- () => (layer && typeof layer === 'object' ? (0, framework_base_1.immutableMerge)(previous.tokens, layer) : previous.tokens),
24
- [layer],
25
- );
26
- return { tokens, subCache };
27
- }, final);
28
- }
29
- return [final.tokens, final.subCache];
15
+ let final = { tokens, subCache };
16
+ if (states && states.length > 0) {
17
+ // now walk the overrides that are set, merging in props, caching results, and getting a new sub cache
18
+ final = states
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, framework_base_1.immutableMerge)(previous.tokens, layer) : previous.tokens), [layer]);
23
+ return { tokens, subCache };
24
+ }, final);
25
+ }
26
+ return [final.tokens, final.subCache];
30
27
  }
31
- //# sourceMappingURL=applyTokenLayers.js.map
28
+ //# sourceMappingURL=applyTokenLayers.js.map
@@ -1,2 +1,2 @@
1
1
  export {};
2
- //# sourceMappingURL=applyTokenLayers.test.d.ts.map
2
+ //# sourceMappingURL=applyTokenLayers.test.d.ts.map
@@ -1,55 +1,55 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- const framework_base_1 = require('@fluentui-react-native/framework-base');
4
- const applyTokenLayers_1 = require('./applyTokenLayers');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const framework_base_1 = require("@fluentui-react-native/framework-base");
4
+ const applyTokenLayers_1 = require("./applyTokenLayers");
5
5
  const stateOrder = ['hover', 'press', 'disabled'];
6
6
  const tokens1 = {
7
- a: 'a',
8
- b: 'b',
9
- c: 'c',
10
- hover: {
11
- a: 'a-hover',
12
- b: 'b-hover',
7
+ a: 'a',
8
+ b: 'b',
9
+ c: 'c',
10
+ hover: {
11
+ a: 'a-hover',
12
+ b: 'b-hover',
13
+ press: {
14
+ a: 'a-hover-press',
15
+ },
16
+ },
13
17
  press: {
14
- a: 'a-hover-press',
18
+ a: 'a-press',
19
+ b: 'b-press',
20
+ },
21
+ disabled: {
22
+ a: 'disabled',
23
+ b: 'disabled',
24
+ c: 'disabled',
15
25
  },
16
- },
17
- press: {
18
- a: 'a-press',
19
- b: 'b-press',
20
- },
21
- disabled: {
22
- a: 'disabled',
23
- b: 'disabled',
24
- c: 'disabled',
25
- },
26
26
  };
27
27
  function stripLayers(tokens) {
28
- const t = { ...tokens };
29
- delete t.hover;
30
- delete t.press;
31
- delete t.disabled;
32
- return t;
28
+ const t = { ...tokens };
29
+ delete t.hover;
30
+ delete t.press;
31
+ delete t.disabled;
32
+ return t;
33
33
  }
34
34
  describe('applyLayers tests', () => {
35
- test('no layers returns tokens', () => {
36
- const cache = (0, framework_base_1.getMemoCache)();
37
- const tokens = (0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, () => false)[0];
38
- expect(tokens).toBe(tokens1);
39
- });
40
- test('apply hover works', () => {
41
- const cache = (0, framework_base_1.getMemoCache)();
42
- const lookup = (layer) => layer === 'hover';
43
- const result1 = (0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0];
44
- expect((0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0]).toBe(result1);
45
- expect(stripLayers(result1)).toEqual({ a: 'a-hover', b: 'b-hover', c: 'c' });
46
- });
47
- test('apply hover and press layer correctly', () => {
48
- const cache = (0, framework_base_1.getMemoCache)();
49
- const lookup = (layer) => layer === 'hover' || layer === 'press';
50
- const result1 = (0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0];
51
- expect((0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0]).toBe(result1);
52
- expect(stripLayers(result1)).toEqual({ a: 'a-hover-press', b: 'b-press', c: 'c' });
53
- });
35
+ test('no layers returns tokens', () => {
36
+ const cache = (0, framework_base_1.getMemoCache)();
37
+ const tokens = (0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, () => false)[0];
38
+ expect(tokens).toBe(tokens1);
39
+ });
40
+ test('apply hover works', () => {
41
+ const cache = (0, framework_base_1.getMemoCache)();
42
+ const lookup = (layer) => layer === 'hover';
43
+ const result1 = (0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0];
44
+ expect((0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0]).toBe(result1);
45
+ expect(stripLayers(result1)).toEqual({ a: 'a-hover', b: 'b-hover', c: 'c' });
46
+ });
47
+ test('apply hover and press layer correctly', () => {
48
+ const cache = (0, framework_base_1.getMemoCache)();
49
+ const lookup = (layer) => layer === 'hover' || layer === 'press';
50
+ const result1 = (0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0];
51
+ expect((0, applyTokenLayers_1.applyTokenLayers)(tokens1, stateOrder, cache, lookup)[0]).toBe(result1);
52
+ expect(stripLayers(result1)).toEqual({ a: 'a-hover-press', b: 'b-press', c: 'c' });
53
+ });
54
54
  });
55
- //# sourceMappingURL=applyTokenLayers.test.js.map
55
+ //# sourceMappingURL=applyTokenLayers.test.js.map