@fluentui-react-native/use-tokens 0.1.6

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 (106) hide show
  1. package/CHANGELOG.json +200 -0
  2. package/CHANGELOG.md +53 -0
  3. package/README.md +85 -0
  4. package/babel.config.js +1 -0
  5. package/just.config.js +3 -0
  6. package/lib/applyPropsToTokens.d.ts +3 -0
  7. package/lib/applyPropsToTokens.d.ts.map +1 -0
  8. package/lib/applyPropsToTokens.js +28 -0
  9. package/lib/applyPropsToTokens.js.map +1 -0
  10. package/lib/applyPropsToTokens.test.d.ts +2 -0
  11. package/lib/applyPropsToTokens.test.d.ts.map +1 -0
  12. package/lib/applyPropsToTokens.test.js +30 -0
  13. package/lib/applyPropsToTokens.test.js.map +1 -0
  14. package/lib/applyTokenLayers.d.ts +16 -0
  15. package/lib/applyTokenLayers.d.ts.map +1 -0
  16. package/lib/applyTokenLayers.js +25 -0
  17. package/lib/applyTokenLayers.js.map +1 -0
  18. package/lib/applyTokenLayers.test.d.ts +2 -0
  19. package/lib/applyTokenLayers.test.d.ts.map +1 -0
  20. package/lib/applyTokenLayers.test.js +64 -0
  21. package/lib/applyTokenLayers.test.js.map +1 -0
  22. package/lib/buildUseTokens.d.ts +35 -0
  23. package/lib/buildUseTokens.d.ts.map +1 -0
  24. package/lib/buildUseTokens.js +62 -0
  25. package/lib/buildUseTokens.js.map +1 -0
  26. package/lib/buildUseTokens.test.d.ts +2 -0
  27. package/lib/buildUseTokens.test.d.ts.map +1 -0
  28. package/lib/buildUseTokens.test.js +103 -0
  29. package/lib/buildUseTokens.test.js.map +1 -0
  30. package/lib/customizable.d.ts +24 -0
  31. package/lib/customizable.d.ts.map +1 -0
  32. package/lib/customizable.js +22 -0
  33. package/lib/customizable.js.map +1 -0
  34. package/lib/index.d.ts +6 -0
  35. package/lib/index.d.ts.map +1 -0
  36. package/lib/index.js +6 -0
  37. package/lib/index.js.map +1 -0
  38. package/lib/patchTokens.d.ts +12 -0
  39. package/lib/patchTokens.d.ts.map +1 -0
  40. package/lib/patchTokens.js +42 -0
  41. package/lib/patchTokens.js.map +1 -0
  42. package/lib/patchTokens.test.d.ts +2 -0
  43. package/lib/patchTokens.test.d.ts.map +1 -0
  44. package/lib/patchTokens.test.js +38 -0
  45. package/lib/patchTokens.test.js.map +1 -0
  46. package/lib/useTokens.samples.test.d.ts +2 -0
  47. package/lib/useTokens.samples.test.d.ts.map +1 -0
  48. package/lib/useTokens.samples.test.js +165 -0
  49. package/lib/useTokens.samples.test.js.map +1 -0
  50. package/lib-commonjs/applyPropsToTokens.d.ts +3 -0
  51. package/lib-commonjs/applyPropsToTokens.d.ts.map +1 -0
  52. package/lib-commonjs/applyPropsToTokens.js +31 -0
  53. package/lib-commonjs/applyPropsToTokens.js.map +1 -0
  54. package/lib-commonjs/applyPropsToTokens.test.d.ts +2 -0
  55. package/lib-commonjs/applyPropsToTokens.test.d.ts.map +1 -0
  56. package/lib-commonjs/applyPropsToTokens.test.js +32 -0
  57. package/lib-commonjs/applyPropsToTokens.test.js.map +1 -0
  58. package/lib-commonjs/applyTokenLayers.d.ts +16 -0
  59. package/lib-commonjs/applyTokenLayers.d.ts.map +1 -0
  60. package/lib-commonjs/applyTokenLayers.js +28 -0
  61. package/lib-commonjs/applyTokenLayers.js.map +1 -0
  62. package/lib-commonjs/applyTokenLayers.test.d.ts +2 -0
  63. package/lib-commonjs/applyTokenLayers.test.d.ts.map +1 -0
  64. package/lib-commonjs/applyTokenLayers.test.js +66 -0
  65. package/lib-commonjs/applyTokenLayers.test.js.map +1 -0
  66. package/lib-commonjs/buildUseTokens.d.ts +35 -0
  67. package/lib-commonjs/buildUseTokens.d.ts.map +1 -0
  68. package/lib-commonjs/buildUseTokens.js +65 -0
  69. package/lib-commonjs/buildUseTokens.js.map +1 -0
  70. package/lib-commonjs/buildUseTokens.test.d.ts +2 -0
  71. package/lib-commonjs/buildUseTokens.test.d.ts.map +1 -0
  72. package/lib-commonjs/buildUseTokens.test.js +105 -0
  73. package/lib-commonjs/buildUseTokens.test.js.map +1 -0
  74. package/lib-commonjs/customizable.d.ts +24 -0
  75. package/lib-commonjs/customizable.d.ts.map +1 -0
  76. package/lib-commonjs/customizable.js +25 -0
  77. package/lib-commonjs/customizable.js.map +1 -0
  78. package/lib-commonjs/index.d.ts +6 -0
  79. package/lib-commonjs/index.d.ts.map +1 -0
  80. package/lib-commonjs/index.js +11 -0
  81. package/lib-commonjs/index.js.map +1 -0
  82. package/lib-commonjs/patchTokens.d.ts +12 -0
  83. package/lib-commonjs/patchTokens.d.ts.map +1 -0
  84. package/lib-commonjs/patchTokens.js +45 -0
  85. package/lib-commonjs/patchTokens.js.map +1 -0
  86. package/lib-commonjs/patchTokens.test.d.ts +2 -0
  87. package/lib-commonjs/patchTokens.test.d.ts.map +1 -0
  88. package/lib-commonjs/patchTokens.test.js +40 -0
  89. package/lib-commonjs/patchTokens.test.js.map +1 -0
  90. package/lib-commonjs/useTokens.samples.test.d.ts +2 -0
  91. package/lib-commonjs/useTokens.samples.test.d.ts.map +1 -0
  92. package/lib-commonjs/useTokens.samples.test.js +177 -0
  93. package/lib-commonjs/useTokens.samples.test.js.map +1 -0
  94. package/package.json +41 -0
  95. package/src/__snapshots__/useTokens.samples.test.tsx.snap +163 -0
  96. package/src/applyPropsToTokens.test.ts +47 -0
  97. package/src/applyPropsToTokens.ts +15 -0
  98. package/src/applyTokenLayers.test.ts +67 -0
  99. package/src/applyTokenLayers.ts +40 -0
  100. package/src/buildUseTokens.test.ts +113 -0
  101. package/src/buildUseTokens.ts +89 -0
  102. package/src/customizable.ts +36 -0
  103. package/src/index.ts +5 -0
  104. package/src/patchTokens.test.ts +50 -0
  105. package/src/patchTokens.ts +30 -0
  106. package/src/useTokens.samples.test.tsx +219 -0
package/CHANGELOG.json ADDED
@@ -0,0 +1,200 @@
1
+ {
2
+ "name": "@fluentui-react-native/use-tokens",
3
+ "entries": [
4
+ {
5
+ "date": "Tue, 28 Sep 2021 21:06:18 GMT",
6
+ "tag": "@fluentui-react-native/use-tokens_v0.1.6",
7
+ "version": "0.1.6",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "comment": "Delete NativeButton",
12
+ "author": "67026167+chiuam@users.noreply.github.com",
13
+ "commit": "335503904094894a91e53c6de328bf13e13bcc1c",
14
+ "package": "@fluentui-react-native/use-tokens"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Tue, 21 Sep 2021 19:08:16 GMT",
21
+ "tag": "@fluentui-react-native/use-tokens_v0.1.5",
22
+ "version": "0.1.5",
23
+ "comments": {
24
+ "none": [
25
+ {
26
+ "comment": "Run prettier",
27
+ "author": "ruaraki@microsoft.com",
28
+ "commit": "e52c9b3d031599af4f43c261cb0a0327bc68a5ab",
29
+ "package": "@fluentui-react-native/use-tokens"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Tue, 14 Sep 2021 19:31:04 GMT",
36
+ "tag": "@fluentui-react-native/use-tokens_v0.1.5",
37
+ "version": "0.1.5",
38
+ "comments": {
39
+ "none": [
40
+ {
41
+ "comment": "Revert \"Bump Prettier and run it (#997)\"",
42
+ "author": "ruaraki@microsoft.com",
43
+ "commit": "c3eefc2cd6e8e23d64ca72460586f33120edc336",
44
+ "package": "@fluentui-react-native/use-tokens"
45
+ }
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ "date": "Fri, 10 Sep 2021 21:30:12 GMT",
51
+ "tag": "@fluentui-react-native/use-tokens_v0.1.5",
52
+ "version": "0.1.5",
53
+ "comments": {
54
+ "none": [
55
+ {
56
+ "comment": "Run the prettier",
57
+ "author": "ruaraki@microsoft.com",
58
+ "commit": "7ac71c6add6f05230c649dad60b5f7442f08cbb3",
59
+ "package": "@fluentui-react-native/use-tokens"
60
+ }
61
+ ]
62
+ }
63
+ },
64
+ {
65
+ "date": "Sat, 07 Aug 2021 00:40:04 GMT",
66
+ "tag": "@fluentui-react-native/use-tokens_v0.1.5",
67
+ "version": "0.1.5",
68
+ "comments": {
69
+ "none": [
70
+ {
71
+ "comment": "enable usePressableState with stock Pressable component",
72
+ "author": "jasonmo@microsoft.com",
73
+ "commit": "e506337e109ef24e675c2ac794179db86fcb7e86",
74
+ "package": "@fluentui-react-native/use-tokens"
75
+ }
76
+ ]
77
+ }
78
+ },
79
+ {
80
+ "date": "Fri, 06 Aug 2021 00:36:02 GMT",
81
+ "tag": "@fluentui-react-native/use-tokens_v0.1.5",
82
+ "version": "0.1.5",
83
+ "comments": {
84
+ "none": [
85
+ {
86
+ "comment": "Remove api-extractor related files",
87
+ "author": "ruaraki@microsoft.com",
88
+ "commit": "56ccce452d0dbbd5c24f53ebdd467f2d01dda694",
89
+ "package": "@fluentui-react-native/use-tokens"
90
+ }
91
+ ]
92
+ }
93
+ },
94
+ {
95
+ "date": "Wed, 04 Aug 2021 16:54:20 GMT",
96
+ "tag": "@fluentui-react-native/use-tokens_v0.1.5",
97
+ "version": "0.1.5",
98
+ "comments": {
99
+ "patch": [
100
+ {
101
+ "comment": "add patchTokens helper to make conversion easier",
102
+ "author": "jasonmo@microsoft.com",
103
+ "commit": "4136f64930de10457a984863998c4a553b0b0efc",
104
+ "package": "@fluentui-react-native/use-tokens"
105
+ }
106
+ ]
107
+ }
108
+ },
109
+ {
110
+ "date": "Wed, 04 Aug 2021 06:26:25 GMT",
111
+ "tag": "@fluentui-react-native/use-tokens_v0.1.4",
112
+ "version": "0.1.4",
113
+ "comments": {
114
+ "patch": [
115
+ {
116
+ "comment": "add comment back",
117
+ "author": "67026167+chiuam@users.noreply.github.com",
118
+ "commit": "68dd61bd45ca8ffacc1580e468f3c01810e3093e",
119
+ "package": "@fluentui-react-native/use-tokens"
120
+ }
121
+ ]
122
+ }
123
+ },
124
+ {
125
+ "date": "Tue, 03 Aug 2021 22:33:17 GMT",
126
+ "tag": "@fluentui-react-native/use-tokens_v0.1.3",
127
+ "version": "0.1.3",
128
+ "comments": {
129
+ "patch": [
130
+ {
131
+ "comment": "add patchTokens utility to use-tokens package",
132
+ "author": "jasonmo@microsoft.com",
133
+ "commit": "317097b2f51d04d33bfc2b14b2850a2774e0acbc",
134
+ "package": "@fluentui-react-native/use-tokens"
135
+ }
136
+ ]
137
+ }
138
+ },
139
+ {
140
+ "date": "Fri, 30 Jul 2021 06:26:34 GMT",
141
+ "tag": "@fluentui-react-native/use-tokens_v0.1.2",
142
+ "version": "0.1.2",
143
+ "comments": {
144
+ "none": [
145
+ {
146
+ "comment": "Bumped Jest to 27.0.6",
147
+ "author": "4123478+tido64@users.noreply.github.com",
148
+ "commit": "925cf4eb5fe6bfadf20208b5b3d3a4454fc5c9fa",
149
+ "package": "@fluentui-react-native/use-tokens"
150
+ }
151
+ ]
152
+ }
153
+ },
154
+ {
155
+ "date": "Tue, 27 Jul 2021 22:17:20 GMT",
156
+ "tag": "@fluentui-react-native/use-tokens_v0.1.2",
157
+ "version": "0.1.2",
158
+ "comments": {
159
+ "patch": [
160
+ {
161
+ "comment": "add compressible utility and a snapshot test / demo to framework",
162
+ "author": "jasonmo@microsoft.com",
163
+ "commit": "1cd8611e1e88848ab66f7c0e9113c946f968260c",
164
+ "package": "@fluentui-react-native/use-tokens"
165
+ }
166
+ ]
167
+ }
168
+ },
169
+ {
170
+ "date": "Tue, 27 Jul 2021 18:55:58 GMT",
171
+ "tag": "@fluentui-react-native/use-tokens_v0.1.1",
172
+ "version": "0.1.1",
173
+ "comments": {
174
+ "none": [
175
+ {
176
+ "comment": "Bump @fluentui-react-native/immutable-merge to v1.1.2",
177
+ "author": "4123478+tido64@users.noreply.github.com",
178
+ "commit": "07d04d166b13ff79e07a8c4cbc2e06afb1e4c3e6",
179
+ "package": "@fluentui-react-native/use-tokens"
180
+ }
181
+ ]
182
+ }
183
+ },
184
+ {
185
+ "date": "Wed, 21 Jul 2021 22:55:40 GMT",
186
+ "tag": "@fluentui-react-native/use-tokens_v0.1.1",
187
+ "version": "0.1.1",
188
+ "comments": {
189
+ "patch": [
190
+ {
191
+ "comment": "expose use-tokens in framework package",
192
+ "author": "jasonmo@microsoft.com",
193
+ "commit": "af44164cf47abb856e567e9976043aafe414ade6",
194
+ "package": "@fluentui-react-native/use-tokens"
195
+ }
196
+ ]
197
+ }
198
+ }
199
+ ]
200
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,53 @@
1
+ # Change Log - @fluentui-react-native/use-tokens
2
+
3
+ This log was last generated on Tue, 28 Sep 2021 21:06:18 GMT and should not be manually modified.
4
+
5
+ <!-- Start content -->
6
+
7
+ ## 0.1.6
8
+
9
+ Tue, 28 Sep 2021 21:06:18 GMT
10
+
11
+ ### Patches
12
+
13
+ - Delete NativeButton (67026167+chiuam@users.noreply.github.com)
14
+
15
+ ## 0.1.5
16
+
17
+ Wed, 04 Aug 2021 16:54:20 GMT
18
+
19
+ ### Patches
20
+
21
+ - add patchTokens helper to make conversion easier (jasonmo@microsoft.com)
22
+
23
+ ## 0.1.4
24
+
25
+ Wed, 04 Aug 2021 06:26:25 GMT
26
+
27
+ ### Patches
28
+
29
+ - add comment back (67026167+chiuam@users.noreply.github.com)
30
+
31
+ ## 0.1.3
32
+
33
+ Tue, 03 Aug 2021 22:33:17 GMT
34
+
35
+ ### Patches
36
+
37
+ - add patchTokens utility to use-tokens package (jasonmo@microsoft.com)
38
+
39
+ ## 0.1.2
40
+
41
+ Tue, 27 Jul 2021 22:17:20 GMT
42
+
43
+ ### Patches
44
+
45
+ - add compressible utility and a snapshot test / demo to framework (jasonmo@microsoft.com)
46
+
47
+ ## 0.1.1
48
+
49
+ Wed, 21 Jul 2021 22:55:40 GMT
50
+
51
+ ### Patches
52
+
53
+ - expose use-tokens in framework package (jasonmo@microsoft.com)
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # @fluentui-react-native/use-tokens
2
+
3
+ This package provides the means to create a hook function to build a set of tokens from a passed in theme as well as a cache object unique to the pairing of the given hook function and theme. These resolved tokens should then be used to build the styles for your component. This way the look and feel of a component can be built up from constants, theme globals, and even component specific overrides.
4
+
5
+ ## Tokens
6
+
7
+ A token is simply a setting that informs the styling of the component. These can be thought of as an additional set of component props that are automatically built-up by the framework. Typically these are set at component creation time or overriden by a theme but can can come from a variety of sources:
8
+
9
+ - **Objects** - this is a set of values contained within an object. These values are assumed to be unchanging over the lifetime of the object.
10
+ - **Theme Functions** - this allows values to be set in relation to values in a theme. An example would be a color being set to a particular entry in a color palette in the theme.
11
+ - **Name Lookup** - this will query the theme for a token object or theme function for this component.
12
+
13
+ ## Examples
14
+
15
+ At the core of this system is the idea that: **`Tokens + Theme ==> Styles`**. This can be thought of as:
16
+
17
+ - Your styles are produced via a recipe, ideally memoized via the returned cache or by the use of a `useMemo` hook or its equivalent
18
+ - The tokens are the ingredients for your recipe
19
+ - Some of those tokens come from constants
20
+ - Some of those tokens come from the theme
21
+
22
+ The overall signature of the method is as follows:
23
+
24
+ ```ts
25
+ export type StyledTextTokens = Pick<TextProps[style], 'color', 'fontFamily', 'fontWeight', 'fontSize'>;
26
+
27
+ const useTokens = buildUseTokens<StyledTextTokens, Theme>(
28
+ /* function for looking up a component in a theme, allows this to be used independently of the shape of the theme */
29
+ getComponentInfoFromTheme,
30
+
31
+ /* Start of tokens, these are applied in order */
32
+ /* object, these are effectively constants to be used as defaults */
33
+ { token1: 'foo', token2: 400 },
34
+ /* theme function */
35
+ (theme: Theme) => ({ token3: theme.colors.backgroundColor }),
36
+ /* name to lookup */
37
+ 'NameToLookup',
38
+ );
39
+ ```
40
+
41
+ This `useTokens` hook can then be used to build styles for the component as follows:
42
+
43
+ ```tsx
44
+ const StyledText: React.FunctionComponent<TextProps> = (props) => {
45
+ // split the props
46
+ const { style, children, ...rest } = props;
47
+
48
+ // left out of the hook to allow theme to be obtained in whatever way is appropriate. Generally from a context.
49
+ const theme = useTheme();
50
+
51
+ // get a set of tokens from the theme
52
+ const [tokens, cache] = useTokens(theme);
53
+
54
+ // create a style object from the tokens using the cache. Note that if all the tokens are actually directly styles the tokens could be used
55
+ // directly. This is just to illustrate the pattern for a more complex component
56
+ const [tokenStyle] = cache(() => ({ ...tokens }), []);
57
+
58
+ // now merge any styles coming from the props in on top as they should override
59
+ const mergedStyles = mergeStyles(tokenStyle, style);
60
+
61
+ // now just render the text element
62
+ return (
63
+ <Text {...rest} style={mergedStyles}>
64
+ {children}
65
+ </Text>
66
+ );
67
+ };
68
+ ```
69
+
70
+ ### Layering
71
+
72
+ These tokens will be deeply merged in the order they appear in the array.
73
+
74
+ ```js
75
+ const mergedTokens = merge(
76
+ ...options.tokens.map(entry => {
77
+ // string gets converted to object or function (or empty object)
78
+ if (typeof entry === 'string') {
79
+ entry = themeHelper.getComponentInfo(entry) || {};
80
+ }
81
+ // return either the function call (which will produce an object) or the object
82
+ return typeof entry === 'function' ? entry(theme) : entry;
83
+ });
84
+ );
85
+ ```
@@ -0,0 +1 @@
1
+ module.exports = require('@uifabricshared/build-native/babel.config');
package/just.config.js ADDED
@@ -0,0 +1,3 @@
1
+ const { preset } = require('@uifabricshared/build-native');
2
+
3
+ preset();
@@ -0,0 +1,3 @@
1
+ import { GetMemoValue } from '@fluentui-react-native/memo-cache';
2
+ export declare function applyPropsToTokens<TProps, TTokens>(props: TProps, tokens: TTokens, cache: GetMemoValue<TTokens>, keys: (keyof TTokens)[]): [TTokens, GetMemoValue<TTokens>];
3
+ //# sourceMappingURL=applyPropsToTokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyPropsToTokens.d.ts","sourceRoot":"","sources":["../src/applyPropsToTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAChD,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,EAC5B,IAAI,EAAE,CAAC,MAAM,OAAO,CAAC,EAAE,GACtB,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAOlC"}
@@ -0,0 +1,28 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ export function applyPropsToTokens(props, tokens, cache, keys) {
13
+ var _loop_1 = function (key) {
14
+ var _a;
15
+ var sourceValue = props[key];
16
+ var setValue = sourceValue === tokens[key] ? undefined : sourceValue;
17
+ _a = cache(function () {
18
+ var _a;
19
+ return (setValue === undefined ? tokens : __assign(__assign({}, tokens), (_a = {}, _a[key] = setValue, _a)));
20
+ }, [setValue]), tokens = _a[0], cache = _a[1];
21
+ };
22
+ for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
23
+ var key = keys_1[_i];
24
+ _loop_1(key);
25
+ }
26
+ return [tokens, cache];
27
+ }
28
+ //# sourceMappingURL=applyPropsToTokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyPropsToTokens.js","sourceRoot":"","sources":["../src/applyPropsToTokens.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,MAAM,UAAU,kBAAkB,CAChC,KAAa,EACb,MAAe,EACf,KAA4B,EAC5B,IAAuB;4BAEZ,GAAG;;QACZ,IAAM,WAAW,GAAG,KAAK,CAAC,GAAa,CAAC,CAAC;QACzC,IAAM,QAAQ,GAAG,WAAW,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;QACvE;;;sBAA6G,EAA5G,cAAM,EAAE,aAAK,CAAgG;;IAHhH,KAAkB,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI;QAAjB,IAAM,GAAG,aAAA;gBAAH,GAAG;KAIb;IACD,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=applyPropsToTokens.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyPropsToTokens.test.d.ts","sourceRoot":"","sources":["../src/applyPropsToTokens.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,30 @@
1
+ import { applyPropsToTokens } from './applyPropsToTokens';
2
+ import { getMemoCache } from '@fluentui-react-native/memo-cache';
3
+ var tokenProps = ['dos', 'quatro', 'cinco'];
4
+ var themeTokens = {
5
+ uno: 'uno',
6
+ dos: 'dos',
7
+ tres: 3,
8
+ quatro: 4,
9
+ cinco: true,
10
+ };
11
+ var props1 = { dos: 'two', quatro: 'four', cinco: false, foo: 'foo', bar: 'bar' };
12
+ // const props2: Props = { dos: 'two' };
13
+ // const props3: Props = { foo: 'foo', bar: 'bar' };
14
+ describe('applyPropsToTokens tests', function () {
15
+ test('props get copied', function () {
16
+ var cache = getMemoCache();
17
+ var tokens = applyPropsToTokens(props1, themeTokens, cache, tokenProps)[0];
18
+ expect(tokens).not.toBe(themeTokens);
19
+ for (var _i = 0, tokenProps_1 = tokenProps; _i < tokenProps_1.length; _i++) {
20
+ var key = tokenProps_1[_i];
21
+ expect(tokens[key]).toEqual(props1[key]);
22
+ }
23
+ });
24
+ test('no copied props does not change tokens', function () {
25
+ var cache = getMemoCache();
26
+ var tokens = applyPropsToTokens({}, themeTokens, cache, tokenProps)[0];
27
+ expect(tokens).toBe(themeTokens);
28
+ });
29
+ });
30
+ //# sourceMappingURL=applyPropsToTokens.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyPropsToTokens.test.js","sourceRoot":"","sources":["../src/applyPropsToTokens.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAWjE,IAAM,UAAU,GAAyB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAOpE,IAAM,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,IAAM,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;IACnC,IAAI,CAAC,kBAAkB,EAAE;QACvB,IAAM,KAAK,GAAG,YAAY,EAAE,CAAC;QACtB,IAAA,sEAAM,CAA+D;QAC5E,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACrC,KAAkB,UAAU,EAAV,yBAAU,EAAV,wBAAU,EAAV,IAAU,EAAE;YAAzB,IAAM,GAAG,mBAAA;YACZ,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;QAC7C,IAAM,KAAK,GAAG,YAAY,EAAE,CAAC;QACtB,IAAA,kEAAM,CAA2D;QACxE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { GetMemoValue } from '@fluentui-react-native/memo-cache';
2
+ /**
3
+ * alternatively look them up with a passed in function
4
+ */
5
+ export declare type HasLayer = (name: string) => boolean;
6
+ /**
7
+ * Apply token layers, building them up applied layer by applied layer, using the cache to store intermediate
8
+ * values
9
+ *
10
+ * @param tokens - input tokens which may have layers to apply
11
+ * @param states - array of states to check for, ordered by precedence
12
+ * @param subCache - cache scoped to the root object with no layers applied
13
+ * @param hasLayer - a function which returns whether a given layer should be applied
14
+ */
15
+ export declare function applyTokenLayers<TTokens>(tokens: TTokens, states: string[], subCache: GetMemoValue<TTokens>, hasLayer: HasLayer): [TTokens, GetMemoValue<TTokens>];
16
+ //# sourceMappingURL=applyTokenLayers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyTokenLayers.d.ts","sourceRoot":"","sources":["../src/applyTokenLayers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAGjE;;GAEG;AACH,oBAAY,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAEjD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EACtC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EAAE,EAChB,QAAQ,EAAE,YAAY,CAAC,OAAO,CAAC,EAC/B,QAAQ,EAAE,QAAQ,GACjB,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAiBlC"}
@@ -0,0 +1,25 @@
1
+ import { immutableMerge } from '@fluentui-react-native/immutable-merge';
2
+ /**
3
+ * Apply token layers, building them up applied layer by applied layer, using the cache to store intermediate
4
+ * values
5
+ *
6
+ * @param tokens - input tokens which may have layers to apply
7
+ * @param states - array of states to check for, ordered by precedence
8
+ * @param subCache - cache scoped to the root object with no layers applied
9
+ * @param hasLayer - a function which returns whether a given layer should be applied
10
+ */
11
+ export function applyTokenLayers(tokens, states, subCache, hasLayer) {
12
+ var final = { tokens: tokens, subCache: subCache };
13
+ if (states && states.length > 0) {
14
+ // now walk the overrides that are set, merging in props, caching results, and getting a new sub cache
15
+ final = states
16
+ .filter(function (val) { return hasLayer(val); })
17
+ .reduce(function (previous, layerName) {
18
+ var layer = previous.tokens[layerName];
19
+ var _a = previous.subCache(function () { return (layer && typeof layer === 'object' ? immutableMerge(previous.tokens, layer) : previous.tokens); }, [layer]), tokens = _a[0], subCache = _a[1];
20
+ return { tokens: tokens, subCache: subCache };
21
+ }, final);
22
+ }
23
+ return [final.tokens, final.subCache];
24
+ }
25
+ //# sourceMappingURL=applyTokenLayers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyTokenLayers.js","sourceRoot":"","sources":["../src/applyTokenLayers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAOxE;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAe,EACf,MAAgB,EAChB,QAA+B,EAC/B,QAAkB;IAGlB,IAAI,KAAK,GAAmB,EAAE,MAAM,QAAA,EAAE,QAAQ,UAAA,EAAE,CAAC;IACjD,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,sGAAsG;QACtG,KAAK,GAAG,MAAM;aACX,MAAM,CAAC,UAAC,GAAG,IAAK,OAAA,QAAQ,CAAC,GAAG,CAAC,EAAb,CAAa,CAAC;aAC9B,MAAM,CAAC,UAAC,QAAwB,EAAE,SAAiB;YAClD,IAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACnC,IAAA,wJAGL,EAHM,cAAM,EAAE,gBAGd,CAAC;YACF,OAAO,EAAE,MAAM,QAAA,EAAE,QAAQ,UAAA,EAAE,CAAC;QAC9B,CAAC,EAAE,KAAK,CAAC,CAAC;KACb;IACD,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=applyTokenLayers.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyTokenLayers.test.d.ts","sourceRoot":"","sources":["../src/applyTokenLayers.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,64 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { applyTokenLayers } from './applyTokenLayers';
13
+ import { getMemoCache } from '@fluentui-react-native/memo-cache';
14
+ var stateOrder = ['hover', 'press', 'disabled'];
15
+ var tokens1 = {
16
+ a: 'a',
17
+ b: 'b',
18
+ c: 'c',
19
+ hover: {
20
+ a: 'a-hover',
21
+ b: 'b-hover',
22
+ press: {
23
+ a: 'a-hover-press',
24
+ },
25
+ },
26
+ press: {
27
+ a: 'a-press',
28
+ b: 'b-press',
29
+ },
30
+ disabled: {
31
+ a: 'disabled',
32
+ b: 'disabled',
33
+ c: 'disabled',
34
+ },
35
+ };
36
+ function stripLayers(tokens) {
37
+ var t = __assign({}, tokens);
38
+ delete t.hover;
39
+ delete t.press;
40
+ delete t.disabled;
41
+ return t;
42
+ }
43
+ describe('applyLayers tests', function () {
44
+ test('no layers returns tokens', function () {
45
+ var cache = getMemoCache();
46
+ var tokens = applyTokenLayers(tokens1, stateOrder, cache, function () { return false; })[0];
47
+ expect(tokens).toBe(tokens1);
48
+ });
49
+ test('apply hover works', function () {
50
+ var cache = getMemoCache();
51
+ var lookup = function (layer) { return layer === 'hover'; };
52
+ var result1 = applyTokenLayers(tokens1, stateOrder, cache, lookup)[0];
53
+ expect(applyTokenLayers(tokens1, stateOrder, cache, lookup)[0]).toBe(result1);
54
+ expect(stripLayers(result1)).toEqual({ a: 'a-hover', b: 'b-hover', c: 'c' });
55
+ });
56
+ test('apply hover and press layer correctly', function () {
57
+ var cache = getMemoCache();
58
+ var lookup = function (layer) { return layer === 'hover' || layer === 'press'; };
59
+ var result1 = applyTokenLayers(tokens1, stateOrder, cache, lookup)[0];
60
+ expect(applyTokenLayers(tokens1, stateOrder, cache, lookup)[0]).toBe(result1);
61
+ expect(stripLayers(result1)).toEqual({ a: 'a-hover-press', b: 'b-press', c: 'c' });
62
+ });
63
+ });
64
+ //# sourceMappingURL=applyTokenLayers.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyTokenLayers.test.js","sourceRoot":"","sources":["../src/applyTokenLayers.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAWjE,IAAM,UAAU,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;AAElD,IAAM,OAAO,GAAW;IACtB,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,KAAK,EAAE;QACL,CAAC,EAAE,SAAS;QACZ,CAAC,EAAE,SAAS;QACZ,KAAK,EAAE;YACL,CAAC,EAAE,eAAe;SACnB;KACF;IACD,KAAK,EAAE;QACL,CAAC,EAAE,SAAS;QACZ,CAAC,EAAE,SAAS;KACb;IACD,QAAQ,EAAE;QACR,CAAC,EAAE,UAAU;QACb,CAAC,EAAE,UAAU;QACb,CAAC,EAAE,UAAU;KACd;CACF,CAAC;AAEF,SAAS,WAAW,CAAC,MAAc;IACjC,IAAM,CAAC,gBAAQ,MAAM,CAAE,CAAC;IACxB,OAAO,CAAC,CAAC,KAAK,CAAC;IACf,OAAO,CAAC,CAAC,KAAK,CAAC;IACf,OAAO,CAAC,CAAC,QAAQ,CAAC;IAClB,OAAO,CAAC,CAAC;AACX,CAAC;AAED,QAAQ,CAAC,mBAAmB,EAAE;IAC5B,IAAI,CAAC,0BAA0B,EAAE;QAC/B,IAAM,KAAK,GAAG,YAAY,EAAE,CAAC;QAC7B,IAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,E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CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { GetMemoValue } from '@fluentui-react-native/memo-cache';
2
+ /** A function to generate tokens based on a theme */
3
+ export declare type TokensFromTheme<TTokens, TTheme> = (theme: TTheme) => TTokens;
4
+ /**
5
+ * Types of tokens, can be:
6
+ * - string - will lookup the name in the theme
7
+ * - Tokens - will merge the tokens in directly
8
+ * - Function - will run against the theme once for each unique theme encountered
9
+ */
10
+ export declare type TokenSettings<TTokens, TTheme> = string | TTokens | TokensFromTheme<TTokens, TTheme>;
11
+ /**
12
+ * The main signature of a useTokens hook is to take the theme and produce a set of resolved tokens,
13
+ * as well as a sub-cache, specific to this particular theme, that can be used for caching various styles
14
+ * or values that are theme specific
15
+ */
16
+ export declare type UseTokensCore<TTokens, TTheme> = (theme: TTheme) => [TTokens, GetMemoValue<TTokens>];
17
+ /**
18
+ * The full signature also includes a customize function that returns an updated version of useTokens
19
+ * that captures both the previous values, and layers in the new values specified
20
+ */
21
+ export declare type UseTokens<TTokens, TTheme> = UseTokensCore<TTokens, TTheme> & {
22
+ customize: (...tokens: TokenSettings<TTokens, TTheme>[]) => UseTokens<TTokens, TTheme>;
23
+ };
24
+ /**
25
+ * Helper function that knows how to try to look up token information from the theme
26
+ */
27
+ export declare type GetComponentInfo<TTokens, TTheme> = (theme: TTheme, name: string) => TTokens | TokensFromTheme<TTokens, TTheme>;
28
+ /**
29
+ * Construct a useStyling hook which returns styled slot props based on props and tokens defined in options and in the theme
30
+ *
31
+ * @param options - options which drive behavior for the generated styling hook
32
+ * @param themeHelper - injected theme functionality
33
+ */
34
+ export declare function buildUseTokens<TTokens, TTheme>(getComponentInfo: GetComponentInfo<TTokens, TTheme> | undefined, ...tokens: TokenSettings<TTokens, TTheme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