@fluentui-react-native/use-styling 0.14.1 → 0.15.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 (50) hide show
  1. package/.cache/tsconfig.tsbuildinfo +1 -0
  2. package/CHANGELOG.md +38 -0
  3. package/jest.config.cjs +1 -0
  4. package/lib/buildProps.js.map +1 -1
  5. package/lib/buildProps.test.js +1 -1
  6. package/lib/buildProps.test.js.map +1 -1
  7. package/lib/buildUseStyling.d.ts +1 -1
  8. package/lib/buildUseStyling.d.ts.map +1 -1
  9. package/lib/buildUseStyling.js +3 -3
  10. package/lib/buildUseStyling.js.map +1 -1
  11. package/lib/buildUseStyling.test.js +4 -4
  12. package/lib/buildUseStyling.test.js.map +1 -1
  13. package/lib/index.d.ts +4 -4
  14. package/lib/index.d.ts.map +1 -1
  15. package/lib/index.js +2 -2
  16. package/lib/index.js.map +1 -1
  17. package/lib/useStyling.samples.test.js +4 -8
  18. package/lib/useStyling.samples.test.js.map +1 -1
  19. package/package.json +20 -25
  20. package/src/buildProps.test.ts +1 -1
  21. package/src/buildUseStyling.test.ts +5 -5
  22. package/src/buildUseStyling.ts +4 -4
  23. package/src/index.ts +4 -4
  24. package/src/useStyling.samples.test.tsx +3 -3
  25. package/babel.config.js +0 -1
  26. package/eslint.config.js +0 -3
  27. package/lib-commonjs/buildProps.d.ts +0 -51
  28. package/lib-commonjs/buildProps.d.ts.map +0 -1
  29. package/lib-commonjs/buildProps.js +0 -48
  30. package/lib-commonjs/buildProps.js.map +0 -1
  31. package/lib-commonjs/buildProps.test.d.ts +0 -2
  32. package/lib-commonjs/buildProps.test.d.ts.map +0 -1
  33. package/lib-commonjs/buildProps.test.js +0 -38
  34. package/lib-commonjs/buildProps.test.js.map +0 -1
  35. package/lib-commonjs/buildUseStyling.d.ts +0 -49
  36. package/lib-commonjs/buildUseStyling.d.ts.map +0 -1
  37. package/lib-commonjs/buildUseStyling.js +0 -54
  38. package/lib-commonjs/buildUseStyling.js.map +0 -1
  39. package/lib-commonjs/buildUseStyling.test.d.ts +0 -2
  40. package/lib-commonjs/buildUseStyling.test.d.ts.map +0 -1
  41. package/lib-commonjs/buildUseStyling.test.js +0 -89
  42. package/lib-commonjs/buildUseStyling.test.js.map +0 -1
  43. package/lib-commonjs/index.d.ts +0 -7
  44. package/lib-commonjs/index.d.ts.map +0 -1
  45. package/lib-commonjs/index.js +0 -11
  46. package/lib-commonjs/index.js.map +0 -1
  47. package/lib-commonjs/useStyling.samples.test.d.ts +0 -2
  48. package/lib-commonjs/useStyling.samples.test.d.ts.map +0 -1
  49. package/lib-commonjs/useStyling.samples.test.js +0 -222
  50. package/lib-commonjs/useStyling.samples.test.js.map +0 -1
@@ -1,222 +0,0 @@
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;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
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;
33
- };
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 renderer = __importStar(require("react-test-renderer"));
40
- const buildProps_1 = require("./buildProps");
41
- const buildUseStyling_1 = require("./buildUseStyling");
42
- /**
43
- * The default/base theme just contains base values
44
- */
45
- const baseTheme = {
46
- globals: {
47
- backgroundColor: 'white',
48
- color: 'black',
49
- borderColor: 'blue',
50
- fontFamily: 'Arial',
51
- fontSize: 12,
52
- },
53
- components: {},
54
- };
55
- const current = { theme: baseTheme };
56
- /**
57
- * Because the buildUseStyling utility is not opinionated about theming, the theming is injected via
58
- * a theme helper implementation. This allows for a framework to build an opinionated version with
59
- * whatever system they desire
60
- */
61
- const themeHelper = {
62
- useTheme: () => current.theme,
63
- getComponentInfo: (theme, name) => theme.components[name],
64
- setActive: (theme) => {
65
- current.theme = theme ? { ...baseTheme, ...theme } : baseTheme;
66
- },
67
- };
68
- describe('useStyling samples', () => {
69
- /**
70
- * Sample #1 - Themeable text element
71
- *
72
- * This adds some default opinions for how a text element should be styled but only allows for customization
73
- * via theming
74
- */
75
- // now create the styling hook, first the options so they can be reused later
76
- const sample1StylingOptions = {
77
- /**
78
- * tell the styling hook how to build up the tokens
79
- */
80
- tokens: [
81
- /** first the default values should come from the global theme section */
82
- (t) => ({
83
- color: t.globals.color,
84
- fontFamily: t.globals.fontFamily,
85
- fontSize: t.globals.fontSize,
86
- }),
87
- /** next we should look for a component reference to overlay */
88
- 'Sample1',
89
- ],
90
- /**
91
- * Now provide the recipe for how to build props for the sub-components given the tokens
92
- */
93
- slotProps: {
94
- /** only one sub-component, a Text element called content, as a result this needs to build up TextProps */
95
- content: (0, buildProps_1.buildProps)(
96
- /**
97
- * first input for buildProps is a function which takes tokens and a theme and returns props
98
- */
99
- (tokens /*, theme: Theme */) => {
100
- return {
101
- style: { ...tokens },
102
- };
103
- },
104
- /**
105
- * The second input are the tokens used as inputs for the above function. This is similar to the way the useEffect hook
106
- * works in react.
107
- */
108
- ['color', 'fontFamily', 'fontSize']),
109
- },
110
- };
111
- // now build the actual hook from the options and theme helper
112
- const useStylingSample1 = (0, buildUseStyling_1.buildUseStyling)(sample1StylingOptions, themeHelper);
113
- // now the sample 1 component becomes simple to build, just merge the styled props with the input props
114
- const Sample1Text = (props) => {
115
- const styledProps = useStylingSample1(props).content;
116
- const merged = { ...props, ...styledProps };
117
- return jsx_runtime_1.jsx(react_native_1.Text, { ...merged, children: props.children });
118
- };
119
- /** first render the component with no updates */
120
- it('Sample1Text rendering with no overrides', () => {
121
- let component;
122
- (0, react_1.act)(() => {
123
- component = renderer.create(jsx_runtime_1.jsx(Sample1Text, { children: "Sample1a" }));
124
- });
125
- expect(component.toJSON()).toMatchSnapshot();
126
- });
127
- /** now re-theme the component via the components in the theme */
128
- it('Sample1Text rendering with some custom settings in the theme', () => {
129
- themeHelper.setActive({
130
- components: {
131
- Sample1: {
132
- color: 'pink',
133
- fontSize: 24,
134
- },
135
- },
136
- });
137
- let component;
138
- (0, react_1.act)(() => {
139
- component = renderer.create(jsx_runtime_1.jsx(Sample1Text, { children: "Sample1b" }));
140
- });
141
- expect(component.toJSON()).toMatchSnapshot();
142
- });
143
- /**
144
- * Build the styling hook for sample2. Because this isn't being recombined this is being specified inline rather
145
- * than using a separate options object. Both are fine.
146
- */
147
- const useStylingSample2 = (0, buildUseStyling_1.buildUseStyling)({
148
- /**
149
- * This just starts with the baseline styling from sample1, in particular we are using the recipes of how to turn
150
- * token values into the props for the internal sub-components. While this example is not super complex, for real-world
151
- * components, re-using these can be extremely valuable.
152
- *
153
- * With that in mind, this copies over the recipes for how to turn tokens into props, the customizations that
154
- * will be made are about how to ensure the tokens are set up correctly.
155
- */
156
- ...sample1StylingOptions,
157
- /**
158
- * In sample1 tokens are set to defaults from the global theme section, then patched with any values looked up with
159
- * the string 'Sample1'
160
- *
161
- * We want to maintain the logic of setting up the globals, but add an additional lookup for 'Sample2'. This might correspond
162
- * to saying that if we were making a variant of a 'Text' component called 'HeaderText', we might want to look up
163
- * customizations from 'Text' first, then override those customizations with those from 'HeaderText'
164
- *
165
- * 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
166
- * that could be filtered out of the array that is being copied
167
- */
168
- tokens: [...sample1StylingOptions.tokens, 'Sample2'],
169
- /**
170
- * This is the final bit of magic. The tokens will already have values set from the global theme, they will then be patched with
171
- * any customizations set into Sample1 and/or Sample2.
172
- *
173
- * If this value was omitted then the tokens would be passed to the slotProps recipies as is. To have those values patched from
174
- * 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
175
- * tokens then this value can be set to 'all'. If none should be passed it can be omitted or set to 'none'
176
- */
177
- tokensThatAreAlsoProps: ['color'],
178
- }, themeHelper);
179
- // the Sample2Text component is built the same way as sample1, just using the new hook that has been created
180
- const Sample2Text = (props) => {
181
- const styledProps = useStylingSample2(props).content;
182
- const merged = { ...props, ...styledProps };
183
- // delete the color key to not pass it through to the text props, could be done via destructuring, filtering, or any number of ways
184
- delete merged.color;
185
- // render the text
186
- return jsx_runtime_1.jsx(react_native_1.Text, { ...merged, children: props.children });
187
- };
188
- /** rendering the Sample2 component with the base theme */
189
- it('Sample2Text rendering with defaults and a color override', () => {
190
- themeHelper.setActive();
191
- let component;
192
- (0, react_1.act)(() => {
193
- component = renderer.create(jsx_runtime_1.jsxs(react_native_1.View, { children: [
194
- jsx_runtime_1.jsx(Sample2Text, { children: "Sample2 with defaults" }), jsx_runtime_1.jsx(Sample2Text, { color: "green", children: "Sample2 with color override via prop" })
195
- ] }));
196
- });
197
- expect(component.toJSON()).toMatchSnapshot();
198
- });
199
- /** now re-theme the component via the components in the theme */
200
- it('Sample2Text rendering with some custom settings in the theme', () => {
201
- themeHelper.setActive({
202
- components: {
203
- Sample1: {
204
- color: 'pink',
205
- fontSize: 24,
206
- },
207
- Sample2: {
208
- fontSize: 18,
209
- fontFamily: 'Helvetica',
210
- },
211
- },
212
- });
213
- let component;
214
- (0, react_1.act)(() => {
215
- component = renderer.create(jsx_runtime_1.jsxs(react_native_1.View, { children: [
216
- jsx_runtime_1.jsx(Sample2Text, { children: "Sample2 with theme overrides set" }), jsx_runtime_1.jsx(Sample2Text, { color: "purple", children: "Sample2 with theme and color prop override" })
217
- ] }));
218
- });
219
- expect(component.toJSON()).toMatchSnapshot();
220
- });
221
- });
222
- //# sourceMappingURL=useStyling.samples.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStyling.samples.test.js","sourceRoot":"","sources":["../src/useStyling.samples.test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAA4B;AAE5B,+CAA0C;AAE1C,MAAY,QAAQ,gDAA4B;AAEhD,6CAA0C;AAE1C,uDAAoD;AAuBpD;;GAEG;AACH,MAAM,SAAS,GAAU;IACvB,OAAO,EAAE;QACP,eAAe,EAAE,OAAO;QACxB,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,MAAM;QACnB,UAAU,EAAE,OAAO;QACnB,QAAQ,EAAE,EAAE;KACb;IACD,UAAU,EAAE,EAAE;CACf,CAAC;AAEF,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAErC;;;;GAIG;AACH,MAAM,WAAW,GAAyE;IACxF,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK;IAC7B,gBAAgB,EAAE,CAAC,KAAY,EAAE,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;IACxE,SAAS,EAAE,CAAC,KAAsB,EAAE,EAAE,CAAC;QACrC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAAA,CAChE;CACF,CAAC;AAEF,QAAQ,CAAC,oBA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