@fluentui-react-native/use-styling 0.13.12 → 0.14.0

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 (41) hide show
  1. package/CHANGELOG.json +1 -1
  2. package/CHANGELOG.md +39 -2
  3. package/README.md +1 -1
  4. package/lib/buildProps.d.ts +14 -6
  5. package/lib/buildProps.js +28 -24
  6. package/lib/buildProps.js.map +1 -1
  7. package/lib/buildProps.test.d.ts +1 -1
  8. package/lib/buildProps.test.js +28 -28
  9. package/lib/buildProps.test.js.map +1 -1
  10. package/lib/buildUseStyling.d.ts +30 -27
  11. package/lib/buildUseStyling.js +30 -31
  12. package/lib/buildUseStyling.js.map +1 -1
  13. package/lib/buildUseStyling.test.d.ts +1 -1
  14. package/lib/buildUseStyling.test.js +67 -64
  15. package/lib/buildUseStyling.test.js.map +1 -1
  16. package/lib/index.d.ts +1 -1
  17. package/lib/index.js +1 -1
  18. package/lib/useStyling.samples.test.d.ts +1 -1
  19. package/lib/useStyling.samples.test.js +171 -148
  20. package/lib/useStyling.samples.test.js.map +1 -1
  21. package/lib-commonjs/buildProps.d.ts +14 -6
  22. package/lib-commonjs/buildProps.js +32 -29
  23. package/lib-commonjs/buildProps.js.map +1 -1
  24. package/lib-commonjs/buildProps.test.d.ts +1 -1
  25. package/lib-commonjs/buildProps.test.js +32 -32
  26. package/lib-commonjs/buildProps.test.js.map +1 -1
  27. package/lib-commonjs/buildUseStyling.d.ts +30 -27
  28. package/lib-commonjs/buildUseStyling.js +35 -37
  29. package/lib-commonjs/buildUseStyling.js.map +1 -1
  30. package/lib-commonjs/buildUseStyling.test.d.ts +1 -1
  31. package/lib-commonjs/buildUseStyling.test.js +72 -69
  32. package/lib-commonjs/buildUseStyling.test.js.map +1 -1
  33. package/lib-commonjs/index.d.ts +1 -1
  34. package/lib-commonjs/index.js +30 -10
  35. package/lib-commonjs/index.js.map +1 -1
  36. package/lib-commonjs/useStyling.samples.test.d.ts +1 -1
  37. package/lib-commonjs/useStyling.samples.test.js +227 -177
  38. package/lib-commonjs/useStyling.samples.test.js.map +1 -1
  39. package/package.json +46 -46
  40. package/src/buildProps.ts +2 -2
  41. package/src/useStyling.samples.test.tsx +23 -14
@@ -1,4 +1,5 @@
1
- import * as React from 'react';
1
+ import { jsx as _jsx, jsxs as _jsxs } from 'react/jsx-runtime';
2
+ import { act } from 'react';
2
3
  import { Text, View } from 'react-native';
3
4
  import * as renderer from 'react-test-renderer';
4
5
  import { buildProps } from './buildProps';
@@ -7,14 +8,14 @@ import { buildUseStyling } from './buildUseStyling';
7
8
  * The default/base theme just contains base values
8
9
  */
9
10
  const baseTheme = {
10
- globals: {
11
- backgroundColor: 'white',
12
- color: 'black',
13
- borderColor: 'blue',
14
- fontFamily: 'Arial',
15
- fontSize: 12,
16
- },
17
- components: {},
11
+ globals: {
12
+ backgroundColor: 'white',
13
+ color: 'black',
14
+ borderColor: 'blue',
15
+ fontFamily: 'Arial',
16
+ fontSize: 12,
17
+ },
18
+ components: {},
18
19
  };
19
20
  const current = { theme: baseTheme };
20
21
  /**
@@ -23,156 +24,178 @@ const current = { theme: baseTheme };
23
24
  * whatever system they desire
24
25
  */
25
26
  const themeHelper = {
26
- useTheme: () => current.theme,
27
- getComponentInfo: (theme, name) => theme.components[name],
28
- setActive: (theme) => {
29
- current.theme = theme ? { ...baseTheme, ...theme } : baseTheme;
30
- },
27
+ useTheme: () => current.theme,
28
+ getComponentInfo: (theme, name) => theme.components[name],
29
+ setActive: (theme) => {
30
+ current.theme = theme ? { ...baseTheme, ...theme } : baseTheme;
31
+ },
31
32
  };
32
33
  describe('useStyling samples', () => {
34
+ /**
35
+ * Sample #1 - Themeable text element
36
+ *
37
+ * This adds some default opinions for how a text element should be styled but only allows for customization
38
+ * via theming
39
+ */
40
+ // now create the styling hook, first the options so they can be reused later
41
+ const sample1StylingOptions = {
33
42
  /**
34
- * Sample #1 - Themeable text element
35
- *
36
- * This adds some default opinions for how a text element should be styled but only allows for customization
37
- * via theming
43
+ * tell the styling hook how to build up the tokens
38
44
  */
39
- // now create the styling hook, first the options so they can be reused later
40
- const sample1StylingOptions = {
45
+ tokens: [
46
+ /** first the default values should come from the global theme section */
47
+ (t) => ({
48
+ color: t.globals.color,
49
+ fontFamily: t.globals.fontFamily,
50
+ fontSize: t.globals.fontSize,
51
+ }),
52
+ /** next we should look for a component reference to overlay */
53
+ 'Sample1',
54
+ ],
55
+ /**
56
+ * Now provide the recipe for how to build props for the sub-components given the tokens
57
+ */
58
+ slotProps: {
59
+ /** only one sub-component, a Text element called content, as a result this needs to build up TextProps */
60
+ content: buildProps(
41
61
  /**
42
- * tell the styling hook how to build up the tokens
62
+ * first input for buildProps is a function which takes tokens and a theme and returns props
43
63
  */
44
- tokens: [
45
- /** first the default values should come from the global theme section */
46
- (t) => ({
47
- color: t.globals.color,
48
- fontFamily: t.globals.fontFamily,
49
- fontSize: t.globals.fontSize,
50
- }),
51
- /** next we should look for a component reference to overlay */
52
- 'Sample1',
53
- ],
64
+ (tokens /*, theme: Theme */) => {
65
+ return {
66
+ style: { ...tokens },
67
+ };
68
+ },
54
69
  /**
55
- * Now provide the recipe for how to build props for the sub-components given the tokens
70
+ * The second input are the tokens used as inputs for the above function. This is similar to the way the useEffect hook
71
+ * works in react.
56
72
  */
57
- slotProps: {
58
- /** only one sub-component, a Text element called content, as a result this needs to build up TextProps */
59
- content: buildProps(
60
- /**
61
- * first input for buildProps is a function which takes tokens and a theme and returns props
62
- */
63
- (tokens /*, theme: Theme */) => {
64
- return {
65
- style: { ...tokens },
66
- };
67
- },
68
- /**
69
- * The second input are the tokens used as inputs for the above function. This is similar to the way the useEffect hook
70
- * works in react.
71
- */
72
- ['color', 'fontFamily', 'fontSize']),
73
+ ['color', 'fontFamily', 'fontSize'],
74
+ ),
75
+ },
76
+ };
77
+ // now build the actual hook from the options and theme helper
78
+ const useStylingSample1 = buildUseStyling(sample1StylingOptions, themeHelper);
79
+ // now the sample 1 component becomes simple to build, just merge the styled props with the input props
80
+ const Sample1Text = (props) => {
81
+ const styledProps = useStylingSample1(props).content;
82
+ const merged = { ...props, ...styledProps };
83
+ return _jsx(Text, { ...merged, children: props.children });
84
+ };
85
+ /** first render the component with no updates */
86
+ it('Sample1Text rendering with no overrides', () => {
87
+ let component;
88
+ act(() => {
89
+ component = renderer.create(_jsx(Sample1Text, { children: 'Sample1a' }));
90
+ });
91
+ expect(component.toJSON()).toMatchSnapshot();
92
+ });
93
+ /** now re-theme the component via the components in the theme */
94
+ it('Sample1Text rendering with some custom settings in the theme', () => {
95
+ themeHelper.setActive({
96
+ components: {
97
+ Sample1: {
98
+ color: 'pink',
99
+ fontSize: 24,
73
100
  },
74
- };
75
- // now build the actual hook from the options and theme helper
76
- const useStylingSample1 = buildUseStyling(sample1StylingOptions, themeHelper);
77
- // now the sample 1 component becomes simple to build, just merge the styled props with the input props
78
- const Sample1Text = (props) => {
79
- const styledProps = useStylingSample1(props).content;
80
- const merged = { ...props, ...styledProps };
81
- return React.createElement(Text, { ...merged }, props.children);
82
- };
83
- /** first render the component with no updates */
84
- it('Sample1Text rendering with no overrides', () => {
85
- const tree = renderer.create(React.createElement(Sample1Text, null, "Sample1a")).toJSON();
86
- expect(tree).toMatchSnapshot();
101
+ },
87
102
  });
88
- /** now re-theme the component via the components in the theme */
89
- it('Sample1Text rendering with some custom settings in the theme', () => {
90
- themeHelper.setActive({
91
- components: {
92
- Sample1: {
93
- color: 'pink',
94
- fontSize: 24,
95
- },
96
- },
97
- });
98
- const tree = renderer.create(React.createElement(Sample1Text, null, "Sample1b")).toJSON();
99
- expect(tree).toMatchSnapshot();
103
+ let component;
104
+ act(() => {
105
+ component = renderer.create(_jsx(Sample1Text, { children: 'Sample1b' }));
100
106
  });
101
- /**
102
- * Build the styling hook for sample2. Because this isn't being recombined this is being specified inline rather
103
- * than using a separate options object. Both are fine.
104
- */
105
- const useStylingSample2 = buildUseStyling({
106
- /**
107
- * This just starts with the baseline styling from sample1, in particular we are using the recipes of how to turn
108
- * token values into the props for the internal sub-components. While this example is not super complex, for real-world
109
- * components, re-using these can be extremely valuable.
110
- *
111
- * With that in mind, this copies over the recipes for how to turn tokens into props, the customizations that
112
- * will be made are about how to ensure the tokens are set up correctly.
113
- */
114
- ...sample1StylingOptions,
115
- /**
116
- * In sample1 tokens are set to defaults from the global theme section, then patched with any values looked up with
117
- * the string 'Sample1'
118
- *
119
- * We want to maintain the logic of setting up the globals, but add an additional lookup for 'Sample2'. This might correspond
120
- * to saying that if we were making a variant of a 'Text' component called 'HeaderText', we might want to look up
121
- * customizations from 'Text' first, then override those customizations with those from 'HeaderText'
122
- *
123
- * If we didn't want to add the extra 'Sample2' lookup this line would be omitted. If we didn't want to look up 'Sample1' first
124
- * that could be filtered out of the array that is being copied
125
- */
126
- tokens: [...sample1StylingOptions.tokens, 'Sample2'],
127
- /**
128
- * This is the final bit of magic. The tokens will already have values set from the global theme, they will then be patched with
129
- * any customizations set into Sample1 and/or Sample2.
130
- *
131
- * If this value was omitted then the tokens would be passed to the slotProps recipies as is. To have those values patched from
132
- * the component props we add a list of the props which need to be passed into tokens. If all props should be spread into the
133
- * tokens then this value can be set to 'all'. If none should be passed it can be omitted or set to 'none'
134
- */
135
- tokensThatAreAlsoProps: ['color'],
136
- }, themeHelper);
137
- // the Sample2Text component is built the same way as sample1, just using the new hook that has been created
138
- const Sample2Text = (props) => {
139
- const styledProps = useStylingSample2(props).content;
140
- const merged = { ...props, ...styledProps };
141
- // delete the color key to not pass it through to the text props, could be done via destructuring, filtering, or any number of ways
142
- delete merged.color;
143
- // render the text
144
- return React.createElement(Text, { ...merged }, props.children);
145
- };
146
- /** rendering the Sample2 component with the base theme */
147
- it('Sample2Text rendering with defaults and a color override', () => {
148
- themeHelper.setActive();
149
- const tree = renderer
150
- .create(React.createElement(View, null,
151
- React.createElement(Sample2Text, null, "Sample2 with defaults"),
152
- React.createElement(Sample2Text, { color: "green" }, "Sample2 with color override via prop")))
153
- .toJSON();
154
- expect(tree).toMatchSnapshot();
107
+ expect(component.toJSON()).toMatchSnapshot();
108
+ });
109
+ /**
110
+ * Build the styling hook for sample2. Because this isn't being recombined this is being specified inline rather
111
+ * than using a separate options object. Both are fine.
112
+ */
113
+ const useStylingSample2 = buildUseStyling(
114
+ {
115
+ /**
116
+ * This just starts with the baseline styling from sample1, in particular we are using the recipes of how to turn
117
+ * token values into the props for the internal sub-components. While this example is not super complex, for real-world
118
+ * components, re-using these can be extremely valuable.
119
+ *
120
+ * With that in mind, this copies over the recipes for how to turn tokens into props, the customizations that
121
+ * will be made are about how to ensure the tokens are set up correctly.
122
+ */
123
+ ...sample1StylingOptions,
124
+ /**
125
+ * In sample1 tokens are set to defaults from the global theme section, then patched with any values looked up with
126
+ * the string 'Sample1'
127
+ *
128
+ * We want to maintain the logic of setting up the globals, but add an additional lookup for 'Sample2'. This might correspond
129
+ * to saying that if we were making a variant of a 'Text' component called 'HeaderText', we might want to look up
130
+ * customizations from 'Text' first, then override those customizations with those from 'HeaderText'
131
+ *
132
+ * If we didn't want to add the extra 'Sample2' lookup this line would be omitted. If we didn't want to look up 'Sample1' first
133
+ * that could be filtered out of the array that is being copied
134
+ */
135
+ tokens: [...sample1StylingOptions.tokens, 'Sample2'],
136
+ /**
137
+ * This is the final bit of magic. The tokens will already have values set from the global theme, they will then be patched with
138
+ * any customizations set into Sample1 and/or Sample2.
139
+ *
140
+ * If this value was omitted then the tokens would be passed to the slotProps recipies as is. To have those values patched from
141
+ * the component props we add a list of the props which need to be passed into tokens. If all props should be spread into the
142
+ * tokens then this value can be set to 'all'. If none should be passed it can be omitted or set to 'none'
143
+ */
144
+ tokensThatAreAlsoProps: ['color'],
145
+ },
146
+ themeHelper,
147
+ );
148
+ // the Sample2Text component is built the same way as sample1, just using the new hook that has been created
149
+ const Sample2Text = (props) => {
150
+ const styledProps = useStylingSample2(props).content;
151
+ const merged = { ...props, ...styledProps };
152
+ // delete the color key to not pass it through to the text props, could be done via destructuring, filtering, or any number of ways
153
+ delete merged.color;
154
+ // render the text
155
+ return _jsx(Text, { ...merged, children: props.children });
156
+ };
157
+ /** rendering the Sample2 component with the base theme */
158
+ it('Sample2Text rendering with defaults and a color override', () => {
159
+ themeHelper.setActive();
160
+ let component;
161
+ act(() => {
162
+ component = renderer.create(
163
+ _jsxs(View, {
164
+ children: [
165
+ _jsx(Sample2Text, { children: 'Sample2 with defaults' }),
166
+ _jsx(Sample2Text, { color: 'green', children: 'Sample2 with color override via prop' }),
167
+ ],
168
+ }),
169
+ );
170
+ });
171
+ expect(component.toJSON()).toMatchSnapshot();
172
+ });
173
+ /** now re-theme the component via the components in the theme */
174
+ it('Sample2Text rendering with some custom settings in the theme', () => {
175
+ themeHelper.setActive({
176
+ components: {
177
+ Sample1: {
178
+ color: 'pink',
179
+ fontSize: 24,
180
+ },
181
+ Sample2: {
182
+ fontSize: 18,
183
+ fontFamily: 'Helvetica',
184
+ },
185
+ },
155
186
  });
156
- /** now re-theme the component via the components in the theme */
157
- it('Sample2Text rendering with some custom settings in the theme', () => {
158
- themeHelper.setActive({
159
- components: {
160
- Sample1: {
161
- color: 'pink',
162
- fontSize: 24,
163
- },
164
- Sample2: {
165
- fontSize: 18,
166
- fontFamily: 'Helvetica',
167
- },
168
- },
169
- });
170
- const tree = renderer
171
- .create(React.createElement(View, null,
172
- React.createElement(Sample2Text, null, "Sample2 with theme overrides set"),
173
- React.createElement(Sample2Text, { color: "purple" }, "Sample2 with theme and color prop override")))
174
- .toJSON();
175
- expect(tree).toMatchSnapshot();
187
+ let component;
188
+ act(() => {
189
+ component = renderer.create(
190
+ _jsxs(View, {
191
+ children: [
192
+ _jsx(Sample2Text, { children: 'Sample2 with theme overrides set' }),
193
+ _jsx(Sample2Text, { color: 'purple', children: 'Sample2 with theme and color prop override' }),
194
+ ],
195
+ }),
196
+ );
176
197
  });
198
+ expect(component.toJSON()).toMatchSnapshot();
199
+ });
177
200
  });
178
- //# sourceMappingURL=useStyling.samples.test.js.map
201
+ //# sourceMappingURL=useStyling.samples.test.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AK,EAAC,QAAQ,2DAAyD;oBAC/E,CACR,CAAC;QAAA,CACH,CAAC,CAAC;QACH,MAAM,CAAC,SAAU,CAAC,MAAM,EAAE,CAAC,CAAC,eAAe,EAAE,CAAC;IAAA,CAC/C,CAAC,CAAC;AAAA,CACJ,CAAC,CAAC"}
@@ -21,18 +21,20 @@ export type BuildPropsBase<TProps, TTokens, TTheme> = (tokens: TTokens, theme: T
21
21
  * A refine function allows style functions to be updated based on tokens that are also props. Only those tokens that are also
22
22
  * props need to be considered as a key for caching
23
23
  */
24
- export type RefineFunctionBase<TProps, TTokens, TTheme> = (mask?: TokensThatAreAlsoProps<TTokens>) => BuildPropsBase<TProps, TTokens, TTheme>;
24
+ export type RefineFunctionBase<TProps, TTokens, TTheme> = (
25
+ mask?: TokensThatAreAlsoProps<TTokens>,
26
+ ) => BuildPropsBase<TProps, TTokens, TTheme>;
25
27
  /**
26
28
  * Signature for a style function which can be optionally refined by the styling hook if prop masks are provided
27
29
  */
28
30
  export type RefinableBuildPropsBase<TProps, TTokens, TTheme> = BuildPropsBase<TProps, TTokens, TTheme> & {
29
- refine?: RefineFunctionBase<TProps, TTokens, TTheme>;
31
+ refine?: RefineFunctionBase<TProps, TTokens, TTheme>;
30
32
  };
31
33
  /**
32
34
  * Style functions can be plain functions, refinable functions, or just raw props
33
35
  */
34
36
  export type BuildSlotProps<TSlotProps, TTokens, TTheme> = {
35
- [K in keyof TSlotProps]?: RefinableBuildPropsBase<TSlotProps[K], TTokens, TTheme> | TSlotProps[K];
37
+ [K in keyof TSlotProps]?: RefinableBuildPropsBase<TSlotProps[K], TTokens, TTheme> | TSlotProps[K];
36
38
  };
37
39
  /**
38
40
  * Standard wrapper for a function that provides props for a component based on tokens and theme.
@@ -40,12 +42,18 @@ export type BuildSlotProps<TSlotProps, TTokens, TTheme> = {
40
42
  * @param fn - function which does the work of producing props for the tokens and theme provided
41
43
  * @param keys - which token properties are used by this style, this determines the keys to use for caching
42
44
  */
43
- export declare function buildProps<TProps, TTokens, TTheme>(fn: (tokens: TTokens, theme: TTheme) => TProps, keys?: (keyof TTokens)[]): RefinableBuildPropsBase<TProps, TTokens, TTheme>;
45
+ export declare function buildProps<TProps, TTokens, TTheme>(
46
+ fn: (tokens: TTokens, theme: TTheme) => TProps,
47
+ keys?: (keyof TTokens)[],
48
+ ): RefinableBuildPropsBase<TProps, TTokens, TTheme>;
44
49
  /**
45
50
  * Utility function to check the type and refinement capabilities of a styleFunction and refine it if appropriate
46
51
  *
47
52
  * @param fn - function or props to potentially refine
48
53
  * @param mask - prop mask to use for refinement
49
54
  */
50
- export declare function refinePropsFunctions<TSlotProps, TTokens, TTheme>(styles: BuildSlotProps<TSlotProps, TTokens, TTheme>, mask: TokensThatAreAlsoProps<TTokens>): BuildSlotProps<TSlotProps, TTokens, TTheme>;
51
- //# sourceMappingURL=buildProps.d.ts.map
55
+ export declare function refinePropsFunctions<TSlotProps, TTokens, TTheme>(
56
+ styles: BuildSlotProps<TSlotProps, TTokens, TTheme>,
57
+ mask: TokensThatAreAlsoProps<TTokens>,
58
+ ): BuildSlotProps<TSlotProps, TTokens, TTheme>;
59
+ //# sourceMappingURL=buildProps.d.ts.map
@@ -1,15 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.refinePropsFunctions = exports.buildProps = void 0;
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.buildProps = buildProps;
4
+ exports.refinePropsFunctions = refinePropsFunctions;
4
5
  function cacheStyleClosure(fn, keys) {
5
- return (tokens, theme, cache) => cache(() => fn(tokens, theme), (keys || []).map((key) => tokens[key]))[0];
6
+ return (tokens, theme, cache) =>
7
+ cache(
8
+ () => fn(tokens, theme),
9
+ (keys || []).map((key) => tokens[key]),
10
+ )[0];
6
11
  }
7
12
  function refineKeys(keys, mask) {
8
- return typeof mask === 'object' && Array.isArray(mask)
9
- ? keys.filter((key) => mask.findIndex((val) => val === key) !== -1)
10
- : mask
11
- ? keys
12
- : [];
13
+ return typeof mask === 'object' && Array.isArray(mask)
14
+ ? keys.filter((key) => mask.findIndex((val) => val === key) !== -1)
15
+ : mask
16
+ ? keys
17
+ : [];
13
18
  }
14
19
  /**
15
20
  * Standard wrapper for a function that provides props for a component based on tokens and theme.
@@ -18,19 +23,18 @@ function refineKeys(keys, mask) {
18
23
  * @param keys - which token properties are used by this style, this determines the keys to use for caching
19
24
  */
20
25
  function buildProps(fn, keys) {
21
- // wrap the provided function in the standard caching layer, basing it upon the provided keys
22
- const result = cacheStyleClosure(fn, keys);
23
- // if results are being cached on keys, provide the ability to refine the function if a prop mask is specified
24
- result.refine =
25
- keys && keys.length > 0
26
- ? (mask) => {
27
- return cacheStyleClosure(fn, refineKeys(keys, mask));
28
- }
29
- : undefined;
30
- // return the style function decorated with the refine function
31
- return result;
26
+ // wrap the provided function in the standard caching layer, basing it upon the provided keys
27
+ const result = cacheStyleClosure(fn, keys);
28
+ // if results are being cached on keys, provide the ability to refine the function if a prop mask is specified
29
+ result.refine =
30
+ keys && keys.length > 0
31
+ ? (mask) => {
32
+ return cacheStyleClosure(fn, refineKeys(keys, mask));
33
+ }
34
+ : undefined;
35
+ // return the style function decorated with the refine function
36
+ return result;
32
37
  }
33
- exports.buildProps = buildProps;
34
38
  /**
35
39
  * Utility function to check the type and refinement capabilities of a styleFunction and refine it if appropriate
36
40
  *
@@ -38,12 +42,11 @@ exports.buildProps = buildProps;
38
42
  * @param mask - prop mask to use for refinement
39
43
  */
40
44
  function refinePropsFunctions(styles, mask) {
41
- const result = {};
42
- Object.keys(styles).forEach((key) => {
43
- const refine = typeof styles[key] === 'function' && styles[key].refine;
44
- result[key] = refine ? refine(mask) : styles[key];
45
- });
46
- return result;
45
+ const result = {};
46
+ for (const key of Object.keys(styles)) {
47
+ const refine = typeof styles[key] === 'function' && styles[key].refine;
48
+ result[key] = refine ? refine(mask) : styles[key];
49
+ }
50
+ return result;
47
51
  }
48
- exports.refinePropsFunctions = refinePropsFunctions;
49
- //# sourceMappingURL=buildProps.js.map
52
+ //# sourceMappingURL=buildProps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildProps.js","sourceRoot":"","sources":["../src/buildProps.ts"],"names":[],"mappings":";;;AA4CA,SAAS,iBAAiB,CACxB,EAA8C,EAC9C,IAAwB;IAExB,OAAO,CAAC,MAAe,EAAE,KAAa,EAAE,KAAmB,EAAE,EAAE,CAC7D,KAAK,CACH,GAAG,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EACvB,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CACvC,CAAC,CAAC,CAAC,CAAC;AACT,CAAC;AAED,SAAS,UAAU,CAAU,IAAuB,EAAE,IAAsC;IAC1F,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QACpD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;QACnE,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CACxB,EAA8C,EAC9C,IAAwB;IAExB,6FAA6F;IAC7F,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAE3C,8GAA8G;IAC9G,MAAM,CAAC,MAAM;QACX,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YACrB,CAAC,CAAC,CAAC,IAAsC,EAAE,EAAE;gBACzC,OAAO,iBAAiB,CAAC,EAAE,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;YACv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use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const framework_base_1 = require("@fluentui-react-native/framework-base");
4
- const buildProps_1 = require("./buildProps");
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ const framework_base_1 = require('@fluentui-react-native/framework-base');
4
+ const buildProps_1 = require('./buildProps');
5
5
  const theme = { foo: 'foo', bar: 'bar' };
6
6
  let instanceCount = 0;
7
7
  function munge(tokens, theme) {
8
- return {
9
- ...theme,
10
- ...tokens,
11
- instance: instanceCount++,
12
- };
8
+ return {
9
+ ...theme,
10
+ ...tokens,
11
+ instance: instanceCount++,
12
+ };
13
13
  }
14
14
  describe('props function tests', () => {
15
- test('basic build props function caches as expected', () => {
16
- const cache = (0, framework_base_1.getMemoCache)();
17
- const styleFn = (0, buildProps_1.buildProps)(munge, ['a', 'b']);
18
- const p1 = styleFn({ a: 'a', b: 'b', c: 'c' }, theme, cache);
19
- expect(styleFn({ a: 'a', b: 'b', c: 'foo' }, theme, cache)).toBe(p1);
20
- const p2 = styleFn({ a: 'b', b: 'b' }, theme, cache);
21
- expect(p2).not.toBe(p1);
22
- expect(styleFn({ a: 'b', b: 'b', c: 'bar' }, theme, cache)).toBe(p2);
23
- });
24
- test('build props function refinement works with explicit keys', () => {
25
- const cache = (0, framework_base_1.getMemoCache)();
26
- const styleFn = (0, buildProps_1.buildProps)(munge, ['a', 'b', 'c', 'd']);
27
- const refinedFn = styleFn.refine(['a', 'b']);
28
- const t1 = { a: 'a', b: 'b', c: 'c', d: 'd' };
29
- const t2 = { a: 'a', b: 'b', c: 'foo', d: 'bar' };
30
- const p1 = styleFn(t1, theme, cache);
31
- const p2 = styleFn(t2, theme, cache);
32
- expect(p2).not.toBe(p1);
33
- const rp1 = refinedFn(t1, theme, cache);
34
- const rp2 = refinedFn(t2, theme, cache);
35
- expect(rp2).toBe(rp1);
36
- });
15
+ test('basic build props function caches as expected', () => {
16
+ const cache = (0, framework_base_1.getMemoCache)();
17
+ const styleFn = (0, buildProps_1.buildProps)(munge, ['a', 'b']);
18
+ const p1 = styleFn({ a: 'a', b: 'b', c: 'c' }, theme, cache);
19
+ expect(styleFn({ a: 'a', b: 'b', c: 'foo' }, theme, cache)).toBe(p1);
20
+ const p2 = styleFn({ a: 'b', b: 'b' }, theme, cache);
21
+ expect(p2).not.toBe(p1);
22
+ expect(styleFn({ a: 'b', b: 'b', c: 'bar' }, theme, cache)).toBe(p2);
23
+ });
24
+ test('build props function refinement works with explicit keys', () => {
25
+ const cache = (0, framework_base_1.getMemoCache)();
26
+ const styleFn = (0, buildProps_1.buildProps)(munge, ['a', 'b', 'c', 'd']);
27
+ const refinedFn = styleFn.refine(['a', 'b']);
28
+ const t1 = { a: 'a', b: 'b', c: 'c', d: 'd' };
29
+ const t2 = { a: 'a', b: 'b', c: 'foo', d: 'bar' };
30
+ const p1 = styleFn(t1, theme, cache);
31
+ const p2 = styleFn(t2, theme, cache);
32
+ expect(p2).not.toBe(p1);
33
+ const rp1 = refinedFn(t1, theme, cache);
34
+ const rp2 = refinedFn(t2, theme, cache);
35
+ expect(rp2).toBe(rp1);
36
+ });
37
37
  });
38
- //# sourceMappingURL=buildProps.test.js.map
38
+ //# sourceMappingURL=buildProps.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildProps.test.js","sourceRoot":"","sources":["../src/buildProps.test.ts"],"names":[],"mappings":";;AAAA,0EAAqE;AAErE,6CAA0C;AAM1C,MAAM,KAAK,GAAW,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AAEjD,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB,SAAS,KAAK,CAAC,MAAe,EAAE,KAAa;IAC3C,OAAO;QACL,GAAG,KAAK;QACR,GAAG,MAAM;QACT,QAAQ,EAAE,aAAa,EAAE;KAC1B,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,IAAI,CAAC,+CAA+C,EAAE,GAAG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