@fluentui-react-native/use-tokens 0.6.12 → 0.7.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.
- package/CHANGELOG.json +1 -1
- package/CHANGELOG.md +38 -2
- package/README.md +1 -1
- package/lib/applyPropsToTokens.d.ts +7 -2
- package/lib/applyPropsToTokens.js +7 -7
- package/lib/applyPropsToTokens.js.map +1 -1
- package/lib/applyPropsToTokens.test.d.ts +1 -1
- package/lib/applyPropsToTokens.test.js +19 -19
- package/lib/applyPropsToTokens.test.js.map +1 -1
- package/lib/applyTokenLayers.d.ts +7 -2
- package/lib/applyTokenLayers.js +16 -13
- package/lib/applyTokenLayers.js.map +1 -1
- package/lib/applyTokenLayers.test.d.ts +1 -1
- package/lib/applyTokenLayers.test.js +42 -42
- package/lib/applyTokenLayers.test.js.map +1 -1
- package/lib/buildUseTokens.d.ts +6 -3
- package/lib/buildUseTokens.js +22 -22
- package/lib/buildUseTokens.js.map +1 -1
- package/lib/buildUseTokens.test.d.ts +1 -1
- package/lib/buildUseTokens.test.js +68 -68
- package/lib/buildUseTokens.test.js.map +1 -1
- package/lib/customizable.d.ts +9 -5
- package/lib/customizable.d.ts.map +1 -1
- package/lib/customizable.js +8 -8
- package/lib/customizable.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/patchTokens.d.ts +6 -2
- package/lib/patchTokens.js +12 -12
- package/lib/patchTokens.js.map +1 -1
- package/lib/patchTokens.test.d.ts +1 -1
- package/lib/patchTokens.test.js +32 -32
- package/lib/patchTokens.test.js.map +1 -1
- package/lib/useTokens.samples.test.d.ts +1 -1
- package/lib/useTokens.samples.test.js +134 -111
- package/lib/useTokens.samples.test.js.map +1 -1
- package/lib-commonjs/applyPropsToTokens.d.ts +7 -2
- package/lib-commonjs/applyPropsToTokens.js +10 -11
- package/lib-commonjs/applyPropsToTokens.js.map +1 -1
- package/lib-commonjs/applyPropsToTokens.test.d.ts +1 -1
- package/lib-commonjs/applyPropsToTokens.test.js +23 -23
- package/lib-commonjs/applyPropsToTokens.test.js.map +1 -1
- package/lib-commonjs/applyTokenLayers.d.ts +7 -2
- package/lib-commonjs/applyTokenLayers.js +20 -18
- package/lib-commonjs/applyTokenLayers.js.map +1 -1
- package/lib-commonjs/applyTokenLayers.test.d.ts +1 -1
- package/lib-commonjs/applyTokenLayers.test.js +46 -46
- package/lib-commonjs/applyTokenLayers.test.js.map +1 -1
- package/lib-commonjs/buildUseTokens.d.ts +6 -3
- package/lib-commonjs/buildUseTokens.js +30 -28
- package/lib-commonjs/buildUseTokens.js.map +1 -1
- package/lib-commonjs/buildUseTokens.test.d.ts +1 -1
- package/lib-commonjs/buildUseTokens.test.js +71 -71
- package/lib-commonjs/buildUseTokens.test.js.map +1 -1
- package/lib-commonjs/customizable.d.ts +9 -5
- package/lib-commonjs/customizable.d.ts.map +1 -1
- package/lib-commonjs/customizable.js +11 -12
- package/lib-commonjs/customizable.js.map +1 -1
- package/lib-commonjs/index.d.ts +1 -1
- package/lib-commonjs/index.js +38 -13
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/patchTokens.d.ts +6 -2
- package/lib-commonjs/patchTokens.js +15 -16
- package/lib-commonjs/patchTokens.js.map +1 -1
- package/lib-commonjs/patchTokens.test.d.ts +1 -1
- package/lib-commonjs/patchTokens.test.js +36 -36
- package/lib-commonjs/patchTokens.test.js.map +1 -1
- package/lib-commonjs/useTokens.samples.test.d.ts +1 -1
- package/lib-commonjs/useTokens.samples.test.js +195 -141
- package/lib-commonjs/useTokens.samples.test.js.map +1 -1
- package/package.json +45 -45
- package/src/customizable.ts +3 -2
- package/src/useTokens.samples.test.tsx +24 -15
package/lib/customizable.d.ts
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type { TokenSettings, UseTokens } from './buildUseTokens';
|
|
3
|
+
import type { FurnJSX } from '@fluentui-react-native/framework-base';
|
|
3
4
|
/**
|
|
4
5
|
* A component implementation, with a use tokens hook passed in. Implementing it this way allows the useTokens hook to be
|
|
5
6
|
* modified by the customization handler
|
|
6
7
|
*/
|
|
7
|
-
export type InjectableComponent<TProps, TTokens, TTheme> = (props: TProps, useTokens: UseTokens<TTokens, TTheme>) =>
|
|
8
|
+
export type InjectableComponent<TProps, TTokens, TTheme> = (props: TProps, useTokens: UseTokens<TTokens, TTheme>) => FurnJSX.Element | null;
|
|
8
9
|
/**
|
|
9
10
|
* A component with an attached customize function, used to create alternatively styled versions of the component
|
|
10
11
|
*/
|
|
11
12
|
export type CustomizableComponent<TProps, TTokens, TTheme> = React.FunctionComponent<TProps> & {
|
|
12
|
-
|
|
13
|
+
customize: (...tokens: TokenSettings<TTokens, TTheme>[]) => CustomizableComponent<TProps, TTokens, TTheme>;
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
15
16
|
* Function helper for easily creating a customizable component based on the useTokens hook
|
|
16
17
|
*
|
|
17
|
-
* @param injectable - a function component implementation, written in (props, useTokens) =>
|
|
18
|
+
* @param injectable - a function component implementation, written in (props, useTokens) => FurnJSX.Element form
|
|
18
19
|
* @param useTokens - a hook function, generally built via buildUseTokens, used to retrieve design tokens for the component
|
|
19
20
|
*
|
|
20
21
|
* @returns - a function component that has a static function called customize attached. Customize will return a
|
|
21
22
|
* new component (which can also be customized)
|
|
22
23
|
*/
|
|
23
|
-
export declare function customizable<TProps, TTokens, TTheme>(
|
|
24
|
-
|
|
24
|
+
export declare function customizable<TProps, TTokens, TTheme>(
|
|
25
|
+
injectable: InjectableComponent<TProps, TTokens, TTheme>,
|
|
26
|
+
useTokens: UseTokens<TTokens, TTheme>,
|
|
27
|
+
): CustomizableComponent<TProps, TTokens, TTheme>;
|
|
28
|
+
//# sourceMappingURL=customizable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customizable.d.ts","sourceRoot":"","sources":["../src/customizable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"customizable.d.ts","sourceRoot":"","sources":["../src/customizable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAErE;;;GAGG;AACH,MAAM,MAAM,mBAAmB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;AAE5I;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG;IAC7F,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,KAAK,qBAAqB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;CAC5G,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAClD,UAAU,EAAE,mBAAmB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EACxD,SAAS,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,GACpC,qBAAqB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAOhD"}
|
package/lib/customizable.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Function helper for easily creating a customizable component based on the useTokens hook
|
|
3
3
|
*
|
|
4
|
-
* @param injectable - a function component implementation, written in (props, useTokens) =>
|
|
4
|
+
* @param injectable - a function component implementation, written in (props, useTokens) => FurnJSX.Element form
|
|
5
5
|
* @param useTokens - a hook function, generally built via buildUseTokens, used to retrieve design tokens for the component
|
|
6
6
|
*
|
|
7
7
|
* @returns - a function component that has a static function called customize attached. Customize will return a
|
|
8
8
|
* new component (which can also be customized)
|
|
9
9
|
*/
|
|
10
10
|
export function customizable(injectable, useTokens) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const component = (props) => injectable(props, useTokens);
|
|
12
|
+
component.customize = (...tokens) => {
|
|
13
|
+
const useTokensNew = useTokens.customize(...tokens);
|
|
14
|
+
return customizable(injectable, useTokensNew);
|
|
15
|
+
};
|
|
16
|
+
return component;
|
|
17
17
|
}
|
|
18
|
-
//# sourceMappingURL=customizable.js.map
|
|
18
|
+
//# sourceMappingURL=customizable.js.map
|
package/lib/customizable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customizable.js","sourceRoot":"","sources":["../src/customizable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"customizable.js","sourceRoot":"","sources":["../src/customizable.ts"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,UAAwD,EACxD,SAAqC,EACW;IAChD,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAClE,SAAS,CAAC,SAAS,GAAG,CAAC,GAAG,MAAwC,EAAE,EAAE,CAAC;QACrE,MAAM,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC;QACpD,OAAO,YAAY,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IAAA,CAC/C,CAAC;IACF,OAAO,SAAS,CAAC;AAAA,CAClB"}
|
package/lib/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export type { GetComponentInfo, TokenSettings, TokensFromTheme, UseTokens, UseTo
|
|
|
6
6
|
export { customizable } from './customizable';
|
|
7
7
|
export type { CustomizableComponent, InjectableComponent } from './customizable';
|
|
8
8
|
export { patchTokens } from './patchTokens';
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -3,4 +3,4 @@ export { applyTokenLayers } from './applyTokenLayers';
|
|
|
3
3
|
export { buildUseTokens } from './buildUseTokens';
|
|
4
4
|
export { customizable } from './customizable';
|
|
5
5
|
export { patchTokens } from './patchTokens';
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
package/lib/patchTokens.d.ts
CHANGED
|
@@ -8,5 +8,9 @@ import type { GetTypedMemoValue } from '@fluentui-react-native/framework-base';
|
|
|
8
8
|
* @param patchValues - new values to apply, values will be obtained via keys in the object
|
|
9
9
|
* @returns - a tuple consisting of a new tokens object and a new memo-cache
|
|
10
10
|
*/
|
|
11
|
-
export declare function patchTokens<TTokens>(
|
|
12
|
-
|
|
11
|
+
export declare function patchTokens<TTokens>(
|
|
12
|
+
tokens: TTokens,
|
|
13
|
+
cache: GetTypedMemoValue<TTokens>,
|
|
14
|
+
patchValues: TTokens,
|
|
15
|
+
): [TTokens, GetTypedMemoValue<TTokens>];
|
|
16
|
+
//# sourceMappingURL=patchTokens.d.ts.map
|
package/lib/patchTokens.js
CHANGED
|
@@ -8,16 +8,16 @@
|
|
|
8
8
|
* @returns - a tuple consisting of a new tokens object and a new memo-cache
|
|
9
9
|
*/
|
|
10
10
|
export function patchTokens(tokens, cache, patchValues) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
// reduce the patch values to the set of keys that are defined, and sort them to ensure consistent ordering
|
|
12
|
+
const keys = Object.keys(patchValues)
|
|
13
|
+
.filter((v) => patchValues[v] !== undefined)
|
|
14
|
+
.sort();
|
|
15
|
+
// for each key get an updated tokens collection based on key + value. Value alone isn't sufficient as the values
|
|
16
|
+
// are not necessarily unique. i.e. { a: 'blue' } and { b: 'blue' } would cache to the same without the key
|
|
17
|
+
for (const key of keys) {
|
|
18
|
+
[tokens, cache] = cache(() => ({ ...tokens, [key]: patchValues[key] }), [key, patchValues[key]]);
|
|
19
|
+
}
|
|
20
|
+
// return the updated tokens and cache (if there were any keys applied)
|
|
21
|
+
return [tokens, cache];
|
|
22
22
|
}
|
|
23
|
-
//# sourceMappingURL=patchTokens.js.map
|
|
23
|
+
//# sourceMappingURL=patchTokens.js.map
|
package/lib/patchTokens.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patchTokens.js","sourceRoot":"","sources":["../src/patchTokens.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACzB,MAAe,EACf,KAAiC,EACjC,WAAoB;
|
|
1
|
+
{"version":3,"file":"patchTokens.js","sourceRoot":"","sources":["../src/patchTokens.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACzB,MAAe,EACf,KAAiC,EACjC,WAAoB,EACmB;IACvC,2GAA2G;IAC3G,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;SAClC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;SAC3C,IAAI,EAAE,CAAC;IAEV,iHAAiH;IACjH,2GAA2G;IAC3G,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACnG,CAAC;IAED,uEAAuE;IACvE,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAAA,CACxB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=patchTokens.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=patchTokens.test.d.ts.map
|
package/lib/patchTokens.test.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
import { getMemoCache } from '@fluentui-react-native/framework-base';
|
|
2
2
|
import { patchTokens } from './patchTokens';
|
|
3
3
|
const themeTokens = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
uno: 'uno',
|
|
5
|
+
dos: 'dos',
|
|
6
|
+
tres: 3,
|
|
7
|
+
quatro: 4,
|
|
8
|
+
cinco: true,
|
|
9
9
|
};
|
|
10
10
|
describe('patchTokens tests', () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
11
|
+
test('props get copied', () => {
|
|
12
|
+
const cache = getMemoCache();
|
|
13
|
+
const patchValues = { uno: 'one', quatro: 'quatro' };
|
|
14
|
+
const [tokens] = patchTokens(themeTokens, cache, patchValues);
|
|
15
|
+
expect(tokens).not.toBe(themeTokens);
|
|
16
|
+
for (const key in patchValues) {
|
|
17
|
+
expect(tokens[key]).toEqual(patchValues[key]);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
test('no copied props does not change tokens', () => {
|
|
21
|
+
const cache = getMemoCache();
|
|
22
|
+
const patchValues1 = {};
|
|
23
|
+
const [tokens] = patchTokens(themeTokens, cache, patchValues1);
|
|
24
|
+
expect(tokens).toBe(themeTokens);
|
|
25
|
+
const patchValues2 = { tres: undefined };
|
|
26
|
+
const [tokens2] = patchTokens(themeTokens, cache, patchValues2);
|
|
27
|
+
expect(tokens2).toBe(themeTokens);
|
|
28
|
+
});
|
|
29
|
+
test('patching tokens cache independent of order', () => {
|
|
30
|
+
const cache = getMemoCache();
|
|
31
|
+
const patch1 = { uno: 'one', cinco: false };
|
|
32
|
+
const patch2 = { cinco: false, uno: 'one' };
|
|
33
|
+
const [tokens1] = patchTokens(themeTokens, cache, patch1);
|
|
34
|
+
const [tokens2] = patchTokens(themeTokens, cache, patch2);
|
|
35
|
+
expect(tokens1).toBe(tokens2);
|
|
36
|
+
});
|
|
37
37
|
});
|
|
38
|
-
//# sourceMappingURL=patchTokens.test.js.map
|
|
38
|
+
//# sourceMappingURL=patchTokens.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patchTokens.test.js","sourceRoot":"","sources":["../src/patchTokens.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C,MAAM,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,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;
|
|
1
|
+
{"version":3,"file":"patchTokens.test.js","sourceRoot":"","sources":["../src/patchTokens.test.ts"],"names":[],"mappings":"AAAA,OAAO,E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AAE,KAAK,EAAE,YAAY,CAAC,CAAC;QAChE,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAAA,CACnC,CAAC,CAAC;IAEH,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE,CAAC;QACvD,MAAM,KAAK,GAAG,YAAY,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QAC5C,MAAM,MAAM,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;QAC5C,MAAM,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1D,MAAM,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1D,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAAA,CAC/B,CAAC,CAAC;AAAA,CACJ,CAAC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=useTokens.samples.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=useTokens.samples.test.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
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 { immutableMerge } from '@fluentui-react-native/framework-base';
|
|
4
5
|
import { mergeStyles } from '@fluentui-react-native/framework-base';
|
|
@@ -8,19 +9,19 @@ import { buildUseTokens } from './buildUseTokens';
|
|
|
8
9
|
* The default/base theme just contains base values
|
|
9
10
|
*/
|
|
10
11
|
const baseTheme = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
globals: {
|
|
13
|
+
backgroundColor: 'white',
|
|
14
|
+
color: 'black',
|
|
15
|
+
borderColor: 'blue',
|
|
16
|
+
fontFamily: 'Arial',
|
|
17
|
+
fontSize: 12,
|
|
18
|
+
},
|
|
19
|
+
components: {},
|
|
19
20
|
};
|
|
20
21
|
const current = { theme: baseTheme };
|
|
21
22
|
const useTheme = () => current.theme;
|
|
22
23
|
const setActiveTheme = (theme) => {
|
|
23
|
-
|
|
24
|
+
current.theme = (theme && immutableMerge(baseTheme, theme)) || baseTheme;
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
26
27
|
* 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
|
|
@@ -28,113 +29,135 @@ const setActiveTheme = (theme) => {
|
|
|
28
29
|
*/
|
|
29
30
|
const getComponentInfo = (theme, name) => theme.components[name];
|
|
30
31
|
describe('useTokens samples', () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Sample #1 - Themeable text element
|
|
34
|
+
*
|
|
35
|
+
* This adds some default opinions for how a text element should be styled but only allows for customization
|
|
36
|
+
* via theming
|
|
37
|
+
*/
|
|
38
|
+
const useTokensSample1 = buildUseTokens(
|
|
39
|
+
getComponentInfo,
|
|
38
40
|
/** first the default values should come from the global theme section */
|
|
39
41
|
(t) => ({
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}),
|
|
42
|
+
color: t.globals.color,
|
|
43
|
+
fontFamily: t.globals.fontFamily,
|
|
44
|
+
fontSize: t.globals.fontSize,
|
|
45
|
+
}),
|
|
44
46
|
/** next we should look for a component reference to overlay */
|
|
45
|
-
'SampleText'
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
47
|
+
'SampleText',
|
|
48
|
+
);
|
|
49
|
+
const SampleText1 = (props) => {
|
|
50
|
+
// standard props splitting
|
|
51
|
+
const { style, children, ...rest } = props;
|
|
52
|
+
// typically this would start with a call to retrieve the theme from the context via whatever method is appropriate
|
|
53
|
+
const theme = useTheme();
|
|
54
|
+
// next the tokens are resolved from the theme, a cache specific to this theme is returned as well to allow for
|
|
55
|
+
// style objects to not be rebuilt unnecessarily
|
|
56
|
+
const [tokens, cache] = useTokensSample1(theme);
|
|
57
|
+
// build up the text style, or the full props as appropriate
|
|
58
|
+
const [styleFromTokens] = cache(
|
|
59
|
+
/**
|
|
60
|
+
* first build the style object
|
|
61
|
+
* - this executes once for every unique set of keys.
|
|
62
|
+
* - The cache is already unique for this theme
|
|
63
|
+
*/
|
|
64
|
+
() => ({ ...tokens }),
|
|
65
|
+
/**
|
|
66
|
+
* now specify the keys
|
|
67
|
+
* - because the only changing variable is the theme
|
|
68
|
+
* - ...and all the style properties are either constant or come from the tokens
|
|
69
|
+
* - ...no keys need to be specified
|
|
70
|
+
* - this means that only one style object will be created per component + theme pair
|
|
71
|
+
*/
|
|
72
|
+
[],
|
|
73
|
+
);
|
|
74
|
+
// merge the props from the tokens with anything passed in via style. This is internally cached via object identity
|
|
75
|
+
// so the merged style object won't change identity unless one of the two inputs changes identity.
|
|
76
|
+
const mergedStyle = mergeStyles(styleFromTokens, style);
|
|
77
|
+
// now just render the element, forwarding the props, setting the merged style, then passing the children as appropriate
|
|
78
|
+
return _jsx(Text, { ...rest, style: mergedStyle, children: children });
|
|
79
|
+
};
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
setActiveTheme();
|
|
82
|
+
});
|
|
83
|
+
/** first render the component with no updates */
|
|
84
|
+
it('Sample1Text rendering with no overrides', () => {
|
|
85
|
+
let component;
|
|
86
|
+
act(() => {
|
|
87
|
+
component = renderer.create(_jsx(SampleText1, { children: 'Sample1a' }));
|
|
78
88
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
90
|
+
});
|
|
91
|
+
/** now re-theme the component via the components in the theme */
|
|
92
|
+
it('Sample1Text rendering with some custom settings in the theme', () => {
|
|
93
|
+
setActiveTheme({
|
|
94
|
+
components: {
|
|
95
|
+
SampleText: {
|
|
96
|
+
color: 'pink',
|
|
97
|
+
fontSize: 24,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
83
100
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
components: {
|
|
88
|
-
SampleText: {
|
|
89
|
-
color: 'pink',
|
|
90
|
-
fontSize: 24,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
const tree = renderer.create(React.createElement(SampleText1, null, "Sample1b")).toJSON();
|
|
95
|
-
expect(tree).toMatchSnapshot();
|
|
101
|
+
let component;
|
|
102
|
+
act(() => {
|
|
103
|
+
component = renderer.create(_jsx(SampleText1, { children: 'Sample1b' }));
|
|
96
104
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
105
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
106
|
+
});
|
|
107
|
+
// the Sample2Text component is built the same way as sample1, just using the new hook that has been created
|
|
108
|
+
const SampleText2 = (props) => {
|
|
109
|
+
const { color, style, children, ...rest } = props;
|
|
110
|
+
const theme = useTheme();
|
|
111
|
+
// this starts the same as sample1, extract tokens from the theme and get a theme specific cache object
|
|
112
|
+
const [tokens, cache] = useTokensSample1(theme);
|
|
113
|
+
// now when building up the style this time, the resulting style object is based upon both the theme and the passed
|
|
114
|
+
// in value of colors. Because the theme is already part of the cache definition, only color needs to be a key
|
|
115
|
+
const styleFromTokens = cache(
|
|
116
|
+
/** build the style, only patch the color if it has a value, otherwise the theme value would get stomped if color was undefined */
|
|
117
|
+
() => ({ ...tokens, ...(color && { color }) }),
|
|
118
|
+
/** use color as an additional key for the style */
|
|
119
|
+
[color],
|
|
120
|
+
);
|
|
121
|
+
// now just render, this time merging styles inline to make it a bit shorter
|
|
122
|
+
return _jsx(Text, { ...rest, style: mergeStyles(styleFromTokens, style), children: children });
|
|
123
|
+
};
|
|
124
|
+
/** rendering the Sample2 component with the base theme */
|
|
125
|
+
it('Sample2Text rendering with defaults and a color override', () => {
|
|
126
|
+
let component;
|
|
127
|
+
act(() => {
|
|
128
|
+
component = renderer.create(
|
|
129
|
+
_jsxs(View, {
|
|
130
|
+
children: [
|
|
131
|
+
_jsx(SampleText2, { children: 'Sample2 with defaults' }),
|
|
132
|
+
_jsx(SampleText2, { color: 'green', children: 'Sample2 with color override via prop' }),
|
|
133
|
+
],
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
121
136
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
.create(React.createElement(View, null,
|
|
134
|
-
React.createElement(SampleText2, null, "Sample2 with theme overrides set"),
|
|
135
|
-
React.createElement(SampleText2, { color: "purple" }, "Sample2 with theme and color prop override")))
|
|
136
|
-
.toJSON();
|
|
137
|
-
expect(tree).toMatchSnapshot();
|
|
137
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
138
|
+
});
|
|
139
|
+
/** now re-theme the component via the components in the theme */
|
|
140
|
+
it('Sample2Text rendering with some custom settings in the theme', () => {
|
|
141
|
+
setActiveTheme({
|
|
142
|
+
components: {
|
|
143
|
+
SampleText: {
|
|
144
|
+
fontSize: 18,
|
|
145
|
+
fontFamily: 'Helvetica',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
138
148
|
});
|
|
149
|
+
let component;
|
|
150
|
+
act(() => {
|
|
151
|
+
component = renderer.create(
|
|
152
|
+
_jsxs(View, {
|
|
153
|
+
children: [
|
|
154
|
+
_jsx(SampleText2, { children: 'Sample2 with theme overrides set' }),
|
|
155
|
+
_jsx(SampleText2, { color: 'purple', children: 'Sample2 with theme and color prop override' }),
|
|
156
|
+
],
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
161
|
+
});
|
|
139
162
|
});
|
|
140
|
-
//# sourceMappingURL=useTokens.samples.test.js.map
|
|
163
|
+
//# sourceMappingURL=useTokens.samples.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTokens.samples.test.js","sourceRoot":"","sources":["../src/useTokens.samples.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTokens.samples.test.js","sourceRoot":"","sources":["../src/useTokens.samples.test.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE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AM,CAAC,SAAU,CAAC,MAAM,EAAE,CAAC,CAAC,eAAe,EAAE,CAAC;IAAA,CAC/C,CAAC,CAAC;IAEH,iEAAiE;IACjE,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE,CAAC;QACvE,cAAc,CAAC;YACb,UAAU,EAAE;gBACV,UAAU,EAAE;oBACV,QAAQ,EAAE,EAAE;oBACZ,UAAU,EAAE,WAAW;iBACxB;aACF;SACF,CAAC,CAAC;QACH,IAAI,SAAqC,CAAC;QAC1C,GAAG,CAAC,GAAG,EAAE,CAAC;YACR,SAAS,GAAG,QAAQ,CAAC,MAAM,CACzB,MAAC,IAAI;oBACH,KAAC,WAAW,mDAA+C,EAC3D,KAAC,WAAW,IAAC,KAAK,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"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { GetTypedMemoValue } from '@fluentui-react-native/framework-base';
|
|
2
|
-
export declare function applyPropsToTokens<TProps, TTokens>(
|
|
3
|
-
|
|
2
|
+
export declare function applyPropsToTokens<TProps, TTokens>(
|
|
3
|
+
props: TProps,
|
|
4
|
+
tokens: TTokens,
|
|
5
|
+
cache: GetTypedMemoValue<TTokens>,
|
|
6
|
+
keys: (keyof TTokens)[],
|
|
7
|
+
): [TTokens, GetTypedMemoValue<TTokens>];
|
|
8
|
+
//# sourceMappingURL=applyPropsToTokens.d.ts.map
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.applyPropsToTokens =
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.applyPropsToTokens = applyPropsToTokens;
|
|
4
4
|
function applyPropsToTokens(props, tokens, cache, keys) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
for (const key of keys) {
|
|
6
|
+
const sourceValue = props[key];
|
|
7
|
+
const setValue = sourceValue === tokens[key] ? undefined : sourceValue;
|
|
8
|
+
[tokens, cache] = cache(() => (setValue === undefined ? tokens : { ...tokens, [key]: setValue }), [setValue]);
|
|
9
|
+
}
|
|
10
|
+
return [tokens, cache];
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=applyPropsToTokens.js.map
|
|
12
|
+
//# sourceMappingURL=applyPropsToTokens.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyPropsToTokens.js","sourceRoot":"","sources":["../src/applyPropsToTokens.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"applyPropsToTokens.js","sourceRoot":"","sources":["../src/applyPropsToTokens.ts"],"names":[],"mappings":";;;AAEA,4BACE,KAAa,EACb,MAAe,EACf,KAAiC,EACjC,IAAuB,EACgB;IACvC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,WAAW,GAAG,KAAK,CAAC,GAAa,CAAC,CAAC;QACzC,MAAM,QAAQ,GAAG,WAAW,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;QACvE,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChH,CAAC;IACD,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAAA,CACxB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=applyPropsToTokens.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=applyPropsToTokens.test.d.ts.map
|