@fluentui-react-native/use-styling 0.14.0 → 0.14.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.
@@ -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 * as renderer from 'react-test-renderer';
@@ -8,14 +8,14 @@ import { buildUseStyling } from './buildUseStyling';
8
8
  * The default/base theme just contains base values
9
9
  */
10
10
  const baseTheme = {
11
- globals: {
12
- backgroundColor: 'white',
13
- color: 'black',
14
- borderColor: 'blue',
15
- fontFamily: 'Arial',
16
- fontSize: 12,
17
- },
18
- components: {},
11
+ globals: {
12
+ backgroundColor: 'white',
13
+ color: 'black',
14
+ borderColor: 'blue',
15
+ fontFamily: 'Arial',
16
+ fontSize: 12,
17
+ },
18
+ components: {},
19
19
  };
20
20
  const current = { theme: baseTheme };
21
21
  /**
@@ -24,178 +24,164 @@ const current = { theme: baseTheme };
24
24
  * whatever system they desire
25
25
  */
26
26
  const themeHelper = {
27
- useTheme: () => current.theme,
28
- getComponentInfo: (theme, name) => theme.components[name],
29
- setActive: (theme) => {
30
- current.theme = theme ? { ...baseTheme, ...theme } : baseTheme;
31
- },
27
+ useTheme: () => current.theme,
28
+ getComponentInfo: (theme, name) => theme.components[name],
29
+ setActive: (theme) => {
30
+ current.theme = theme ? { ...baseTheme, ...theme } : baseTheme;
31
+ },
32
32
  };
33
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 = {
42
34
  /**
43
- * tell the styling hook how to build up the tokens
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
44
39
  */
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(
40
+ // now create the styling hook, first the options so they can be reused later
41
+ const sample1StylingOptions = {
61
42
  /**
62
- * first input for buildProps is a function which takes tokens and a theme and returns props
43
+ * tell the styling hook how to build up the tokens
63
44
  */
64
- (tokens /*, theme: Theme */) => {
65
- return {
66
- style: { ...tokens },
67
- };
68
- },
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
+ ],
69
55
  /**
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
+ * Now provide the recipe for how to build props for the sub-components given the tokens
72
57
  */
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,
58
+ slotProps: {
59
+ /** only one sub-component, a Text element called content, as a result this needs to build up TextProps */
60
+ content: buildProps(
61
+ /**
62
+ * first input for buildProps is a function which takes tokens and a theme and returns props
63
+ */
64
+ (tokens /*, theme: Theme */) => {
65
+ return {
66
+ style: { ...tokens },
67
+ };
68
+ },
69
+ /**
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.
72
+ */
73
+ ['color', 'fontFamily', 'fontSize']),
100
74
  },
101
- },
75
+ };
76
+ // now build the actual hook from the options and theme helper
77
+ const useStylingSample1 = buildUseStyling(sample1StylingOptions, themeHelper);
78
+ // now the sample 1 component becomes simple to build, just merge the styled props with the input props
79
+ const Sample1Text = (props) => {
80
+ const styledProps = useStylingSample1(props).content;
81
+ const merged = { ...props, ...styledProps };
82
+ return _jsx(Text, { ...merged, children: props.children });
83
+ };
84
+ /** first render the component with no updates */
85
+ it('Sample1Text rendering with no overrides', () => {
86
+ let component;
87
+ act(() => {
88
+ component = renderer.create(_jsx(Sample1Text, { children: "Sample1a" }));
89
+ });
90
+ expect(component.toJSON()).toMatchSnapshot();
102
91
  });
103
- let component;
104
- act(() => {
105
- component = renderer.create(_jsx(Sample1Text, { children: 'Sample1b' }));
92
+ /** now re-theme the component via the components in the theme */
93
+ it('Sample1Text rendering with some custom settings in the theme', () => {
94
+ themeHelper.setActive({
95
+ components: {
96
+ Sample1: {
97
+ color: 'pink',
98
+ fontSize: 24,
99
+ },
100
+ },
101
+ });
102
+ let component;
103
+ act(() => {
104
+ component = renderer.create(_jsx(Sample1Text, { children: "Sample1b" }));
105
+ });
106
+ expect(component.toJSON()).toMatchSnapshot();
106
107
  });
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
- },
108
+ /**
109
+ * Build the styling hook for sample2. Because this isn't being recombined this is being specified inline rather
110
+ * than using a separate options object. Both are fine.
111
+ */
112
+ const useStylingSample2 = buildUseStyling({
113
+ /**
114
+ * This just starts with the baseline styling from sample1, in particular we are using the recipes of how to turn
115
+ * token values into the props for the internal sub-components. While this example is not super complex, for real-world
116
+ * components, re-using these can be extremely valuable.
117
+ *
118
+ * With that in mind, this copies over the recipes for how to turn tokens into props, the customizations that
119
+ * will be made are about how to ensure the tokens are set up correctly.
120
+ */
121
+ ...sample1StylingOptions,
122
+ /**
123
+ * In sample1 tokens are set to defaults from the global theme section, then patched with any values looked up with
124
+ * the string 'Sample1'
125
+ *
126
+ * We want to maintain the logic of setting up the globals, but add an additional lookup for 'Sample2'. This might correspond
127
+ * to saying that if we were making a variant of a 'Text' component called 'HeaderText', we might want to look up
128
+ * customizations from 'Text' first, then override those customizations with those from 'HeaderText'
129
+ *
130
+ * 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
131
+ * that could be filtered out of the array that is being copied
132
+ */
133
+ tokens: [...sample1StylingOptions.tokens, 'Sample2'],
134
+ /**
135
+ * This is the final bit of magic. The tokens will already have values set from the global theme, they will then be patched with
136
+ * any customizations set into Sample1 and/or Sample2.
137
+ *
138
+ * If this value was omitted then the tokens would be passed to the slotProps recipies as is. To have those values patched from
139
+ * 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
140
+ * tokens then this value can be set to 'all'. If none should be passed it can be omitted or set to 'none'
141
+ */
142
+ tokensThatAreAlsoProps: ['color'],
143
+ }, themeHelper);
144
+ // the Sample2Text component is built the same way as sample1, just using the new hook that has been created
145
+ const Sample2Text = (props) => {
146
+ const styledProps = useStylingSample2(props).content;
147
+ const merged = { ...props, ...styledProps };
148
+ // delete the color key to not pass it through to the text props, could be done via destructuring, filtering, or any number of ways
149
+ delete merged.color;
150
+ // render the text
151
+ return _jsx(Text, { ...merged, children: props.children });
152
+ };
153
+ /** rendering the Sample2 component with the base theme */
154
+ it('Sample2Text rendering with defaults and a color override', () => {
155
+ themeHelper.setActive();
156
+ let component;
157
+ act(() => {
158
+ component = renderer.create(_jsxs(View, { children: [
159
+ _jsx(Sample2Text, { children: "Sample2 with defaults" }), _jsx(Sample2Text, { color: "green", children: "Sample2 with color override via prop" })
160
+ ] }));
161
+ });
162
+ expect(component.toJSON()).toMatchSnapshot();
186
163
  });
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
- );
164
+ /** now re-theme the component via the components in the theme */
165
+ it('Sample2Text rendering with some custom settings in the theme', () => {
166
+ themeHelper.setActive({
167
+ components: {
168
+ Sample1: {
169
+ color: 'pink',
170
+ fontSize: 24,
171
+ },
172
+ Sample2: {
173
+ fontSize: 18,
174
+ fontFamily: 'Helvetica',
175
+ },
176
+ },
177
+ });
178
+ let component;
179
+ act(() => {
180
+ component = renderer.create(_jsxs(View, { children: [
181
+ _jsx(Sample2Text, { children: "Sample2 with theme overrides set" }), _jsx(Sample2Text, { color: "purple", children: "Sample2 with theme and color prop override" })
182
+ ] }));
183
+ });
184
+ expect(component.toJSON()).toMatchSnapshot();
197
185
  });
198
- expect(component.toJSON()).toMatchSnapshot();
199
- });
200
186
  });
201
- //# sourceMappingURL=useStyling.samples.test.js.map
187
+ //# sourceMappingURL=useStyling.samples.test.js.map
@@ -21,20 +21,18 @@ 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> = (
25
- mask?: TokensThatAreAlsoProps<TTokens>,
26
- ) => BuildPropsBase<TProps, TTokens, TTheme>;
24
+ export type RefineFunctionBase<TProps, TTokens, TTheme> = (mask?: TokensThatAreAlsoProps<TTokens>) => BuildPropsBase<TProps, TTokens, TTheme>;
27
25
  /**
28
26
  * Signature for a style function which can be optionally refined by the styling hook if prop masks are provided
29
27
  */
30
28
  export type RefinableBuildPropsBase<TProps, TTokens, TTheme> = BuildPropsBase<TProps, TTokens, TTheme> & {
31
- refine?: RefineFunctionBase<TProps, TTokens, TTheme>;
29
+ refine?: RefineFunctionBase<TProps, TTokens, TTheme>;
32
30
  };
33
31
  /**
34
32
  * Style functions can be plain functions, refinable functions, or just raw props
35
33
  */
36
34
  export type BuildSlotProps<TSlotProps, TTokens, TTheme> = {
37
- [K in keyof TSlotProps]?: RefinableBuildPropsBase<TSlotProps[K], TTokens, TTheme> | TSlotProps[K];
35
+ [K in keyof TSlotProps]?: RefinableBuildPropsBase<TSlotProps[K], TTokens, TTheme> | TSlotProps[K];
38
36
  };
39
37
  /**
40
38
  * Standard wrapper for a function that provides props for a component based on tokens and theme.
@@ -42,18 +40,12 @@ export type BuildSlotProps<TSlotProps, TTokens, TTheme> = {
42
40
  * @param fn - function which does the work of producing props for the tokens and theme provided
43
41
  * @param keys - which token properties are used by this style, this determines the keys to use for caching
44
42
  */
45
- export declare function buildProps<TProps, TTokens, TTheme>(
46
- fn: (tokens: TTokens, theme: TTheme) => TProps,
47
- keys?: (keyof TTokens)[],
48
- ): RefinableBuildPropsBase<TProps, TTokens, TTheme>;
43
+ export declare function buildProps<TProps, TTokens, TTheme>(fn: (tokens: TTokens, theme: TTheme) => TProps, keys?: (keyof TTokens)[]): RefinableBuildPropsBase<TProps, TTokens, TTheme>;
49
44
  /**
50
45
  * Utility function to check the type and refinement capabilities of a styleFunction and refine it if appropriate
51
46
  *
52
47
  * @param fn - function or props to potentially refine
53
48
  * @param mask - prop mask to use for refinement
54
49
  */
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
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
@@ -1,20 +1,16 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildProps = buildProps;
4
4
  exports.refinePropsFunctions = refinePropsFunctions;
5
5
  function cacheStyleClosure(fn, keys) {
6
- return (tokens, theme, cache) =>
7
- cache(
8
- () => fn(tokens, theme),
9
- (keys || []).map((key) => tokens[key]),
10
- )[0];
6
+ return (tokens, theme, cache) => cache(() => fn(tokens, theme), (keys || []).map((key) => tokens[key]))[0];
11
7
  }
12
8
  function refineKeys(keys, mask) {
13
- return typeof mask === 'object' && Array.isArray(mask)
14
- ? keys.filter((key) => mask.findIndex((val) => val === key) !== -1)
15
- : mask
16
- ? keys
17
- : [];
9
+ return typeof mask === 'object' && Array.isArray(mask)
10
+ ? keys.filter((key) => mask.findIndex((val) => val === key) !== -1)
11
+ : mask
12
+ ? keys
13
+ : [];
18
14
  }
19
15
  /**
20
16
  * Standard wrapper for a function that provides props for a component based on tokens and theme.
@@ -23,17 +19,17 @@ function refineKeys(keys, mask) {
23
19
  * @param keys - which token properties are used by this style, this determines the keys to use for caching
24
20
  */
25
21
  function buildProps(fn, keys) {
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;
22
+ // wrap the provided function in the standard caching layer, basing it upon the provided keys
23
+ const result = cacheStyleClosure(fn, keys);
24
+ // if results are being cached on keys, provide the ability to refine the function if a prop mask is specified
25
+ result.refine =
26
+ keys && keys.length > 0
27
+ ? (mask) => {
28
+ return cacheStyleClosure(fn, refineKeys(keys, mask));
29
+ }
30
+ : undefined;
31
+ // return the style function decorated with the refine function
32
+ return result;
37
33
  }
38
34
  /**
39
35
  * Utility function to check the type and refinement capabilities of a styleFunction and refine it if appropriate
@@ -42,11 +38,11 @@ function buildProps(fn, keys) {
42
38
  * @param mask - prop mask to use for refinement
43
39
  */
44
40
  function refinePropsFunctions(styles, mask) {
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;
41
+ const result = {};
42
+ for (const key of Object.keys(styles)) {
43
+ const refine = typeof styles[key] === 'function' && styles[key].refine;
44
+ result[key] = refine ? refine(mask) : styles[key];
45
+ }
46
+ return result;
51
47
  }
52
- //# sourceMappingURL=buildProps.js.map
48
+ //# 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,EAC0B;IAClD,OAAO,CAAC,MAAe,EAAE,KAAa,EAAE,KAAmB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AiB,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,CAAC;gBAC1C,OAAO,iBAAiB,CAAC,EAAE,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;YAAA,CACtD;YACH,CAAC,CAAC,SAAS,CAAC;IAEhB,+DAA+D;IAC/D,OAAO,MAAM,CAAC;AAAA,CACf;AAED;;;;;GAKG;AACH,8BACE,MAAmD,EACnD,IAAqC,EACQ;IAC7C,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,MAAM,MAAM,GACV,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,UAAU,IAAK,MAAM,CAAC,GAAG,CAA4E,CAAC,MAAM,CAAC;QACtI,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,MAAM,CAAC;AAAA,CACf"}
@@ -1,2 +1,2 @@
1
1
  export {};
2
- //# sourceMappingURL=buildProps.test.d.ts.map
2
+ //# sourceMappingURL=buildProps.test.d.ts.map
@@ -1,38 +1,38 @@
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');
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