@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,79 +1,62 @@
1
- 'use strict';
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k];
13
- },
14
- };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- });
22
- var __setModuleDefault =
23
- (this && this.__setModuleDefault) ||
24
- (Object.create
25
- ? function (o, v) {
26
- Object.defineProperty(o, 'default', { enumerable: true, value: v });
27
- }
28
- : function (o, v) {
29
- o['default'] = v;
30
- });
31
- var __importStar =
32
- (this && this.__importStar) ||
33
- (function () {
34
- var ownKeys = function (o) {
35
- ownKeys =
36
- Object.getOwnPropertyNames ||
37
- function (o) {
38
- var ar = [];
39
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
40
- return ar;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
41
24
  };
42
- return ownKeys(o);
25
+ return ownKeys(o);
43
26
  };
44
27
  return function (mod) {
45
- if (mod && mod.__esModule) return mod;
46
- var result = {};
47
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== 'default') __createBinding(result, mod, k[i]);
48
- __setModuleDefault(result, mod);
49
- return result;
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
50
33
  };
51
- })();
52
- Object.defineProperty(exports, '__esModule', { value: true });
53
- const jsx_runtime_1 = require('react/jsx-runtime');
54
- const react_1 = require('react');
55
- const react_native_1 = require('react-native');
56
- const framework_base_1 = require('@fluentui-react-native/framework-base');
57
- const framework_base_2 = require('@fluentui-react-native/framework-base');
58
- const renderer = __importStar(require('react-test-renderer'));
59
- const buildUseTokens_1 = require('./buildUseTokens');
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const jsx_runtime_1 = require("react/jsx-runtime");
37
+ const react_1 = require("react");
38
+ const react_native_1 = require("react-native");
39
+ const framework_base_1 = require("@fluentui-react-native/framework-base");
40
+ const framework_base_2 = require("@fluentui-react-native/framework-base");
41
+ const renderer = __importStar(require("react-test-renderer"));
42
+ const buildUseTokens_1 = require("./buildUseTokens");
60
43
  /**
61
44
  * The default/base theme just contains base values
62
45
  */
63
46
  const baseTheme = {
64
- globals: {
65
- backgroundColor: 'white',
66
- color: 'black',
67
- borderColor: 'blue',
68
- fontFamily: 'Arial',
69
- fontSize: 12,
70
- },
71
- components: {},
47
+ globals: {
48
+ backgroundColor: 'white',
49
+ color: 'black',
50
+ borderColor: 'blue',
51
+ fontFamily: 'Arial',
52
+ fontSize: 12,
53
+ },
54
+ components: {},
72
55
  };
73
56
  const current = { theme: baseTheme };
74
57
  const useTheme = () => current.theme;
75
58
  const setActiveTheme = (theme) => {
76
- current.theme = (theme && (0, framework_base_1.immutableMerge)(baseTheme, theme)) || baseTheme;
59
+ current.theme = (theme && (0, framework_base_1.immutableMerge)(baseTheme, theme)) || baseTheme;
77
60
  };
78
61
  /**
79
62
  * 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
@@ -81,139 +64,121 @@ const setActiveTheme = (theme) => {
81
64
  */
82
65
  const getComponentInfo = (theme, name) => theme.components[name];
83
66
  describe('useTokens samples', () => {
84
- /**
85
- * Sample #1 - Themeable text element
86
- *
87
- * This adds some default opinions for how a text element should be styled but only allows for customization
88
- * via theming
89
- */
90
- const useTokensSample1 = (0, buildUseTokens_1.buildUseTokens)(
91
- getComponentInfo,
67
+ /**
68
+ * Sample #1 - Themeable text element
69
+ *
70
+ * This adds some default opinions for how a text element should be styled but only allows for customization
71
+ * via theming
72
+ */
73
+ const useTokensSample1 = (0, buildUseTokens_1.buildUseTokens)(getComponentInfo,
92
74
  /** first the default values should come from the global theme section */
93
75
  (t) => ({
94
- color: t.globals.color,
95
- fontFamily: t.globals.fontFamily,
96
- fontSize: t.globals.fontSize,
97
- }),
76
+ color: t.globals.color,
77
+ fontFamily: t.globals.fontFamily,
78
+ fontSize: t.globals.fontSize,
79
+ }),
98
80
  /** next we should look for a component reference to overlay */
99
- 'SampleText',
100
- );
101
- const SampleText1 = (props) => {
102
- // standard props splitting
103
- const { style, children, ...rest } = props;
104
- // typically this would start with a call to retrieve the theme from the context via whatever method is appropriate
105
- const theme = useTheme();
106
- // next the tokens are resolved from the theme, a cache specific to this theme is returned as well to allow for
107
- // style objects to not be rebuilt unnecessarily
108
- const [tokens, cache] = useTokensSample1(theme);
109
- // build up the text style, or the full props as appropriate
110
- const [styleFromTokens] = cache(
111
- /**
112
- * first build the style object
113
- * - this executes once for every unique set of keys.
114
- * - The cache is already unique for this theme
115
- */
116
- () => ({ ...tokens }),
117
- /**
118
- * now specify the keys
119
- * - because the only changing variable is the theme
120
- * - ...and all the style properties are either constant or come from the tokens
121
- * - ...no keys need to be specified
122
- * - this means that only one style object will be created per component + theme pair
123
- */
124
- [],
125
- );
126
- // merge the props from the tokens with anything passed in via style. This is internally cached via object identity
127
- // so the merged style object won't change identity unless one of the two inputs changes identity.
128
- const mergedStyle = (0, framework_base_2.mergeStyles)(styleFromTokens, style);
129
- // now just render the element, forwarding the props, setting the merged style, then passing the children as appropriate
130
- return jsx_runtime_1.jsx(react_native_1.Text, { ...rest, style: mergedStyle, children: children });
131
- };
132
- beforeEach(() => {
133
- setActiveTheme();
134
- });
135
- /** first render the component with no updates */
136
- it('Sample1Text rendering with no overrides', () => {
137
- let component;
138
- (0, react_1.act)(() => {
139
- component = renderer.create(jsx_runtime_1.jsx(SampleText1, { children: 'Sample1a' }));
140
- });
141
- expect(component.toJSON()).toMatchSnapshot();
142
- });
143
- /** now re-theme the component via the components in the theme */
144
- it('Sample1Text rendering with some custom settings in the theme', () => {
145
- setActiveTheme({
146
- components: {
147
- SampleText: {
148
- color: 'pink',
149
- fontSize: 24,
150
- },
151
- },
152
- });
153
- let component;
154
- (0, react_1.act)(() => {
155
- component = renderer.create(jsx_runtime_1.jsx(SampleText1, { children: 'Sample1b' }));
81
+ 'SampleText');
82
+ const SampleText1 = (props) => {
83
+ // standard props splitting
84
+ const { style, children, ...rest } = props;
85
+ // typically this would start with a call to retrieve the theme from the context via whatever method is appropriate
86
+ const theme = useTheme();
87
+ // next the tokens are resolved from the theme, a cache specific to this theme is returned as well to allow for
88
+ // style objects to not be rebuilt unnecessarily
89
+ const [tokens, cache] = useTokensSample1(theme);
90
+ // build up the text style, or the full props as appropriate
91
+ const [styleFromTokens] = cache(
92
+ /**
93
+ * first build the style object
94
+ * - this executes once for every unique set of keys.
95
+ * - The cache is already unique for this theme
96
+ */
97
+ () => ({ ...tokens }),
98
+ /**
99
+ * now specify the keys
100
+ * - because the only changing variable is the theme
101
+ * - ...and all the style properties are either constant or come from the tokens
102
+ * - ...no keys need to be specified
103
+ * - this means that only one style object will be created per component + theme pair
104
+ */
105
+ []);
106
+ // merge the props from the tokens with anything passed in via style. This is internally cached via object identity
107
+ // so the merged style object won't change identity unless one of the two inputs changes identity.
108
+ const mergedStyle = (0, framework_base_2.mergeStyles)(styleFromTokens, style);
109
+ // now just render the element, forwarding the props, setting the merged style, then passing the children as appropriate
110
+ return (jsx_runtime_1.jsx(react_native_1.Text, { ...rest, style: mergedStyle, children: children }));
111
+ };
112
+ beforeEach(() => {
113
+ setActiveTheme();
156
114
  });
157
- expect(component.toJSON()).toMatchSnapshot();
158
- });
159
- // the Sample2Text component is built the same way as sample1, just using the new hook that has been created
160
- const SampleText2 = (props) => {
161
- const { color, style, children, ...rest } = props;
162
- const theme = useTheme();
163
- // this starts the same as sample1, extract tokens from the theme and get a theme specific cache object
164
- const [tokens, cache] = useTokensSample1(theme);
165
- // now when building up the style this time, the resulting style object is based upon both the theme and the passed
166
- // in value of colors. Because the theme is already part of the cache definition, only color needs to be a key
167
- const styleFromTokens = cache(
168
- /** build the style, only patch the color if it has a value, otherwise the theme value would get stomped if color was undefined */
169
- () => ({ ...tokens, ...(color && { color }) }),
170
- /** use color as an additional key for the style */
171
- [color],
172
- );
173
- // now just render, this time merging styles inline to make it a bit shorter
174
- return jsx_runtime_1.jsx(react_native_1.Text, {
175
- ...rest,
176
- style: (0, framework_base_2.mergeStyles)(styleFromTokens, style),
177
- children: children,
115
+ /** first render the component with no updates */
116
+ it('Sample1Text rendering with no overrides', () => {
117
+ let component;
118
+ (0, react_1.act)(() => {
119
+ component = renderer.create(jsx_runtime_1.jsx(SampleText1, { children: "Sample1a" }));
120
+ });
121
+ expect(component.toJSON()).toMatchSnapshot();
178
122
  });
179
- };
180
- /** rendering the Sample2 component with the base theme */
181
- it('Sample2Text rendering with defaults and a color override', () => {
182
- let component;
183
- (0, react_1.act)(() => {
184
- component = renderer.create(
185
- jsx_runtime_1.jsxs(react_native_1.View, {
186
- children: [
187
- jsx_runtime_1.jsx(SampleText2, { children: 'Sample2 with defaults' }),
188
- jsx_runtime_1.jsx(SampleText2, { color: 'green', children: 'Sample2 with color override via prop' }),
189
- ],
190
- }),
191
- );
123
+ /** now re-theme the component via the components in the theme */
124
+ it('Sample1Text rendering with some custom settings in the theme', () => {
125
+ setActiveTheme({
126
+ components: {
127
+ SampleText: {
128
+ color: 'pink',
129
+ fontSize: 24,
130
+ },
131
+ },
132
+ });
133
+ let component;
134
+ (0, react_1.act)(() => {
135
+ component = renderer.create(jsx_runtime_1.jsx(SampleText1, { children: "Sample1b" }));
136
+ });
137
+ expect(component.toJSON()).toMatchSnapshot();
192
138
  });
193
- expect(component.toJSON()).toMatchSnapshot();
194
- });
195
- /** now re-theme the component via the components in the theme */
196
- it('Sample2Text rendering with some custom settings in the theme', () => {
197
- setActiveTheme({
198
- components: {
199
- SampleText: {
200
- fontSize: 18,
201
- fontFamily: 'Helvetica',
202
- },
203
- },
139
+ // the Sample2Text component is built the same way as sample1, just using the new hook that has been created
140
+ const SampleText2 = (props) => {
141
+ const { color, style, children, ...rest } = props;
142
+ const theme = useTheme();
143
+ // this starts the same as sample1, extract tokens from the theme and get a theme specific cache object
144
+ const [tokens, cache] = useTokensSample1(theme);
145
+ // now when building up the style this time, the resulting style object is based upon both the theme and the passed
146
+ // in value of colors. Because the theme is already part of the cache definition, only color needs to be a key
147
+ const styleFromTokens = cache(
148
+ /** build the style, only patch the color if it has a value, otherwise the theme value would get stomped if color was undefined */
149
+ () => ({ ...tokens, ...(color && { color }) }),
150
+ /** use color as an additional key for the style */
151
+ [color]);
152
+ // now just render, this time merging styles inline to make it a bit shorter
153
+ return (jsx_runtime_1.jsx(react_native_1.Text, { ...rest, style: (0, framework_base_2.mergeStyles)(styleFromTokens, style), children: children }));
154
+ };
155
+ /** rendering the Sample2 component with the base theme */
156
+ it('Sample2Text rendering with defaults and a color override', () => {
157
+ let component;
158
+ (0, react_1.act)(() => {
159
+ component = renderer.create(jsx_runtime_1.jsxs(react_native_1.View, { children: [
160
+ jsx_runtime_1.jsx(SampleText2, { children: "Sample2 with defaults" }), jsx_runtime_1.jsx(SampleText2, { color: "green", children: "Sample2 with color override via prop" })
161
+ ] }));
162
+ });
163
+ expect(component.toJSON()).toMatchSnapshot();
204
164
  });
205
- let component;
206
- (0, react_1.act)(() => {
207
- component = renderer.create(
208
- jsx_runtime_1.jsxs(react_native_1.View, {
209
- children: [
210
- jsx_runtime_1.jsx(SampleText2, { children: 'Sample2 with theme overrides set' }),
211
- jsx_runtime_1.jsx(SampleText2, { color: 'purple', children: 'Sample2 with theme and color prop override' }),
212
- ],
213
- }),
214
- );
165
+ /** now re-theme the component via the components in the theme */
166
+ it('Sample2Text rendering with some custom settings in the theme', () => {
167
+ setActiveTheme({
168
+ components: {
169
+ SampleText: {
170
+ fontSize: 18,
171
+ fontFamily: 'Helvetica',
172
+ },
173
+ },
174
+ });
175
+ let component;
176
+ (0, react_1.act)(() => {
177
+ component = renderer.create(jsx_runtime_1.jsxs(react_native_1.View, { children: [
178
+ jsx_runtime_1.jsx(SampleText2, { children: "Sample2 with theme overrides set" }), jsx_runtime_1.jsx(SampleText2, { color: "purple", children: "Sample2 with theme and color prop override" })
179
+ ] }));
180
+ });
181
+ expect(component.toJSON()).toMatchSnapshot();
215
182
  });
216
- expect(component.toJSON()).toMatchSnapshot();
217
- });
218
183
  });
219
- //# sourceMappingURL=useTokens.samples.test.js.map
184
+ //# sourceMappingURL=useTokens.samples.test.js.map
package/package.json CHANGED
@@ -1,49 +1,50 @@
1
1
  {
2
2
  "name": "@fluentui-react-native/use-tokens",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Utilities and hook function for getting themed tokens for a component",
5
5
  "keywords": [],
6
+ "license": "MIT",
7
+ "author": "",
6
8
  "repository": {
7
9
  "type": "git",
8
10
  "url": "https://github.com/microsoft/fluentui-react-native",
9
11
  "directory": "packages/framework/use-tokens"
10
12
  },
11
- "license": "MIT",
12
- "author": "",
13
+ "main": "lib-commonjs/index.js",
14
+ "module": "lib/index.js",
15
+ "types": "lib/index.d.ts",
13
16
  "exports": {
14
17
  ".": {
15
18
  "types": "./lib/index.d.ts",
16
19
  "import": "./lib/index.js",
17
- "require": "./lib-commonjs/index.js"
20
+ "require": "./lib-commonjs/index.js",
21
+ "default": "./src/index.ts"
18
22
  }
19
23
  },
20
- "main": "lib-commonjs/index.js",
21
- "module": "lib/index.js",
22
- "types": "lib/index.d.ts",
23
24
  "scripts": {
24
25
  "build": "fluentui-scripts build",
25
26
  "build-cjs": "tsgo --outDir lib-commonjs",
26
- "build-esm": "tsgo --outDir lib --module esnext --moduleResolution bundler",
27
+ "build-core": "tsgo --outDir lib --module esnext --moduleResolution bundler",
27
28
  "clean": "fluentui-scripts clean",
28
29
  "depcheck": "fluentui-scripts depcheck",
29
30
  "lint": "fluentui-scripts eslint",
30
31
  "lint-package": "fluentui-scripts lint-package",
31
- "prettier": "fluentui-scripts prettier",
32
+ "format": "fluentui-scripts format",
32
33
  "start": "fluentui-scripts dev",
33
34
  "start-test": "fluentui-scripts jest-watch",
34
35
  "test": "fluentui-scripts jest",
35
36
  "update-snapshots": "fluentui-scripts jest -u"
36
37
  },
37
38
  "dependencies": {
38
- "@fluentui-react-native/framework-base": "0.3.0"
39
+ "@fluentui-react-native/framework-base": "0.3.1"
39
40
  },
40
41
  "devDependencies": {
41
42
  "@babel/core": "^7.20.0",
42
43
  "@fluentui-react-native/babel-config": "0.1.1",
43
- "@fluentui-react-native/eslint-config-rules": "0.1.1",
44
- "@fluentui-react-native/jest-config": "0.1.1",
44
+ "@fluentui-react-native/eslint-config-rules": "0.1.2",
45
+ "@fluentui-react-native/jest-config": "0.1.0",
45
46
  "@fluentui-react-native/kit-config": "0.1.2",
46
- "@fluentui-react-native/scripts": "0.1.2",
47
+ "@fluentui-react-native/scripts": "0.1.0",
47
48
  "@react-native-community/cli": "^20.0.0",
48
49
  "@react-native-community/cli-platform-android": "^20.0.0",
49
50
  "@react-native-community/cli-platform-ios": "^20.0.0",