@fluentui-react-native/use-styling 0.14.3 → 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.
- package/.cache/tsconfig.tsbuildinfo +1 -0
- package/CHANGELOG.md +20 -0
- package/jest.config.cjs +1 -0
- package/lib/buildProps.js.map +1 -1
- package/lib/buildProps.test.js +1 -1
- package/lib/buildProps.test.js.map +1 -1
- package/lib/buildUseStyling.d.ts +1 -1
- package/lib/buildUseStyling.d.ts.map +1 -1
- package/lib/buildUseStyling.js +1 -1
- package/lib/buildUseStyling.js.map +1 -1
- package/lib/buildUseStyling.test.js +2 -2
- package/lib/buildUseStyling.test.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/useStyling.samples.test.js +4 -8
- package/lib/useStyling.samples.test.js.map +1 -1
- package/package.json +13 -18
- package/src/buildProps.test.ts +1 -1
- package/src/buildUseStyling.test.ts +3 -3
- package/src/buildUseStyling.ts +2 -2
- package/src/index.ts +4 -4
- package/src/useStyling.samples.test.tsx +3 -3
- package/babel.config.js +0 -1
- package/lib-commonjs/buildProps.d.ts +0 -51
- package/lib-commonjs/buildProps.d.ts.map +0 -1
- package/lib-commonjs/buildProps.js +0 -48
- package/lib-commonjs/buildProps.js.map +0 -1
- package/lib-commonjs/buildProps.test.d.ts +0 -2
- package/lib-commonjs/buildProps.test.d.ts.map +0 -1
- package/lib-commonjs/buildProps.test.js +0 -38
- package/lib-commonjs/buildProps.test.js.map +0 -1
- package/lib-commonjs/buildUseStyling.d.ts +0 -49
- package/lib-commonjs/buildUseStyling.d.ts.map +0 -1
- package/lib-commonjs/buildUseStyling.js +0 -54
- package/lib-commonjs/buildUseStyling.js.map +0 -1
- package/lib-commonjs/buildUseStyling.test.d.ts +0 -2
- package/lib-commonjs/buildUseStyling.test.d.ts.map +0 -1
- package/lib-commonjs/buildUseStyling.test.js +0 -89
- package/lib-commonjs/buildUseStyling.test.js.map +0 -1
- package/lib-commonjs/index.d.ts +0 -7
- package/lib-commonjs/index.d.ts.map +0 -1
- package/lib-commonjs/index.js +0 -11
- package/lib-commonjs/index.js.map +0 -1
- package/lib-commonjs/useStyling.samples.test.d.ts +0 -2
- package/lib-commonjs/useStyling.samples.test.d.ts.map +0 -1
- package/lib-commonjs/useStyling.samples.test.js +0 -222
- package/lib-commonjs/useStyling.samples.test.js.map +0 -1
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { GetMemoValue } from '@fluentui-react-native/framework-base';
|
|
2
|
-
/**
|
|
3
|
-
* Informs the framework of any tokens that also appear as props for the component.
|
|
4
|
-
* - 'none' | undefined : this means no properties should be treated as tokens, the tokens that will be passed in to buildProps
|
|
5
|
-
* will not be patched from props. This also means that for a given theme + state the tokens will not
|
|
6
|
-
* change. As a result this is the most efficient mode.
|
|
7
|
-
* - 'all' : treat all props as tokens. Props will be spread into the tokens before the slot functions are called
|
|
8
|
-
* - array of keys : this is the discrete list of tokens which also appear in props
|
|
9
|
-
*/
|
|
10
|
-
export type TokensThatAreAlsoProps<TTokens> = (keyof TTokens)[] | 'all' | 'none';
|
|
11
|
-
/**
|
|
12
|
-
* Raw format for producing styles in a functional manner. These can only depend on tokens or theme as inputs.
|
|
13
|
-
* - tokens: these will be produced from the theme and component constants, then they will be potentially
|
|
14
|
-
* be modified by the props. See the TokensThatAreAlsoProps type for more details.
|
|
15
|
-
* - theme: the theme is provided for reference
|
|
16
|
-
* The provided
|
|
17
|
-
* cache will be scoped to the theme, slot, and tokens that are coming out of the theme.
|
|
18
|
-
*/
|
|
19
|
-
export type BuildPropsBase<TProps, TTokens, TTheme> = (tokens: TTokens, theme: TTheme, cache: GetMemoValue) => Partial<TProps>;
|
|
20
|
-
/**
|
|
21
|
-
* A refine function allows style functions to be updated based on tokens that are also props. Only those tokens that are also
|
|
22
|
-
* props need to be considered as a key for caching
|
|
23
|
-
*/
|
|
24
|
-
export type RefineFunctionBase<TProps, TTokens, TTheme> = (mask?: TokensThatAreAlsoProps<TTokens>) => BuildPropsBase<TProps, TTokens, TTheme>;
|
|
25
|
-
/**
|
|
26
|
-
* Signature for a style function which can be optionally refined by the styling hook if prop masks are provided
|
|
27
|
-
*/
|
|
28
|
-
export type RefinableBuildPropsBase<TProps, TTokens, TTheme> = BuildPropsBase<TProps, TTokens, TTheme> & {
|
|
29
|
-
refine?: RefineFunctionBase<TProps, TTokens, TTheme>;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Style functions can be plain functions, refinable functions, or just raw props
|
|
33
|
-
*/
|
|
34
|
-
export type BuildSlotProps<TSlotProps, TTokens, TTheme> = {
|
|
35
|
-
[K in keyof TSlotProps]?: RefinableBuildPropsBase<TSlotProps[K], TTokens, TTheme> | TSlotProps[K];
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Standard wrapper for a function that provides props for a component based on tokens and theme.
|
|
39
|
-
*
|
|
40
|
-
* @param fn - function which does the work of producing props for the tokens and theme provided
|
|
41
|
-
* @param keys - which token properties are used by this style, this determines the keys to use for caching
|
|
42
|
-
*/
|
|
43
|
-
export declare function buildProps<TProps, TTokens, TTheme>(fn: (tokens: TTokens, theme: TTheme) => TProps, keys?: (keyof TTokens)[]): RefinableBuildPropsBase<TProps, TTokens, TTheme>;
|
|
44
|
-
/**
|
|
45
|
-
* Utility function to check the type and refinement capabilities of a styleFunction and refine it if appropriate
|
|
46
|
-
*
|
|
47
|
-
* @param fn - function or props to potentially refine
|
|
48
|
-
* @param mask - prop mask to use for refinement
|
|
49
|
-
*/
|
|
50
|
-
export declare function refinePropsFunctions<TSlotProps, TTokens, TTheme>(styles: BuildSlotProps<TSlotProps, TTokens, TTheme>, mask: TokensThatAreAlsoProps<TTokens>): BuildSlotProps<TSlotProps, TTokens, TTheme>;
|
|
51
|
-
//# sourceMappingURL=buildProps.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version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AAM,KAAK,MAAM,EAC9C,IAAI,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,EAAE,GACvB,uBAAuB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAclD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAC9D,MAAM,EAAE,cAAc,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,EACnD,IAAI,EAAE,sBAAsB,CAAC,OAAO,CAAC,GACpC,cAAc,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAQ7C"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildProps = buildProps;
|
|
4
|
-
exports.refinePropsFunctions = refinePropsFunctions;
|
|
5
|
-
function cacheStyleClosure(fn, keys) {
|
|
6
|
-
return (tokens, theme, cache) => cache(() => fn(tokens, theme), (keys || []).map((key) => tokens[key]))[0];
|
|
7
|
-
}
|
|
8
|
-
function refineKeys(keys, mask) {
|
|
9
|
-
return typeof mask === 'object' && Array.isArray(mask)
|
|
10
|
-
? keys.filter((key) => mask.findIndex((val) => val === key) !== -1)
|
|
11
|
-
: mask
|
|
12
|
-
? keys
|
|
13
|
-
: [];
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Standard wrapper for a function that provides props for a component based on tokens and theme.
|
|
17
|
-
*
|
|
18
|
-
* @param fn - function which does the work of producing props for the tokens and theme provided
|
|
19
|
-
* @param keys - which token properties are used by this style, this determines the keys to use for caching
|
|
20
|
-
*/
|
|
21
|
-
function buildProps(fn, keys) {
|
|
22
|
-
// wrap the provided function in the standard caching layer, basing it upon the provided keys
|
|
23
|
-
const result = cacheStyleClosure(fn, keys);
|
|
24
|
-
// if results are being cached on keys, provide the ability to refine the function if a prop mask is specified
|
|
25
|
-
result.refine =
|
|
26
|
-
keys && keys.length > 0
|
|
27
|
-
? (mask) => {
|
|
28
|
-
return cacheStyleClosure(fn, refineKeys(keys, mask));
|
|
29
|
-
}
|
|
30
|
-
: undefined;
|
|
31
|
-
// return the style function decorated with the refine function
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Utility function to check the type and refinement capabilities of a styleFunction and refine it if appropriate
|
|
36
|
-
*
|
|
37
|
-
* @param fn - function or props to potentially refine
|
|
38
|
-
* @param mask - prop mask to use for refinement
|
|
39
|
-
*/
|
|
40
|
-
function refinePropsFunctions(styles, mask) {
|
|
41
|
-
const result = {};
|
|
42
|
-
for (const key of Object.keys(styles)) {
|
|
43
|
-
const refine = typeof styles[key] === 'function' && styles[key].refine;
|
|
44
|
-
result[key] = refine ? refine(mask) : styles[key];
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=buildProps.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildProps.js","sourceRoot":"","sources":["../src/buildProps.ts"],"names":[],"mappings":";;;;AA4CA,SAAS,iBAAiB,CACxB,EAA8C,EAC9C,IAAwB,EAC0B;IAClD,OAAO,CAAC,MAAe,EAAE,KAAa,EAAE,KAAmB,EAAE,EAAE,CAC7D,KAAK,CACH,GAAG,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EACvB,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CACvC,CAAC,CAAC,CAAC,CAAC;AAAA,CACR;AAED,SAAS,UAAU,CAAU,IAAuB,EAAE,IAAsC,EAAqB;IAC/G,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QACpD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,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0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const framework_base_1 = require("@fluentui-react-native/framework-base");
|
|
4
|
-
const buildProps_1 = require("./buildProps");
|
|
5
|
-
const theme = { foo: 'foo', bar: 'bar' };
|
|
6
|
-
let instanceCount = 0;
|
|
7
|
-
function munge(tokens, theme) {
|
|
8
|
-
return {
|
|
9
|
-
...theme,
|
|
10
|
-
...tokens,
|
|
11
|
-
instance: instanceCount++,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
describe('props function tests', () => {
|
|
15
|
-
test('basic build props function caches as expected', () => {
|
|
16
|
-
const cache = (0, framework_base_1.getMemoCache)();
|
|
17
|
-
const styleFn = (0, buildProps_1.buildProps)(munge, ['a', 'b']);
|
|
18
|
-
const p1 = styleFn({ a: 'a', b: 'b', c: 'c' }, theme, cache);
|
|
19
|
-
expect(styleFn({ a: 'a', b: 'b', c: 'foo' }, theme, cache)).toBe(p1);
|
|
20
|
-
const p2 = styleFn({ a: 'b', b: 'b' }, theme, cache);
|
|
21
|
-
expect(p2).not.toBe(p1);
|
|
22
|
-
expect(styleFn({ a: 'b', b: 'b', c: 'bar' }, theme, cache)).toBe(p2);
|
|
23
|
-
});
|
|
24
|
-
test('build props function refinement works with explicit keys', () => {
|
|
25
|
-
const cache = (0, framework_base_1.getMemoCache)();
|
|
26
|
-
const styleFn = (0, buildProps_1.buildProps)(munge, ['a', 'b', 'c', 'd']);
|
|
27
|
-
const refinedFn = styleFn.refine(['a', 'b']);
|
|
28
|
-
const t1 = { a: 'a', b: 'b', c: 'c', d: 'd' };
|
|
29
|
-
const t2 = { a: 'a', b: 'b', c: 'foo', d: 'bar' };
|
|
30
|
-
const p1 = styleFn(t1, theme, cache);
|
|
31
|
-
const p2 = styleFn(t2, theme, cache);
|
|
32
|
-
expect(p2).not.toBe(p1);
|
|
33
|
-
const rp1 = refinedFn(t1, theme, cache);
|
|
34
|
-
const rp2 = refinedFn(t2, theme, cache);
|
|
35
|
-
expect(rp2).toBe(rp1);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
//# sourceMappingURL=buildProps.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildProps.test.js","sourceRoot":"","sources":["../src/buildProps.test.ts"],"names":[],"mappings":";;AAAA,0EAAqE;AAErE,6CAA0C;AAM1C,MAAM,KAAK,GAAW,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AAEjD,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB,SAAS,KAAK,CAAC,MAAe,EAAE,KAAa,EAAU;IACrD,OAAO;QACL,GAAG,KAAK;QACR,GAAG,MAAM;QACT,QAAQ,EAAE,aAAa,EAAE;KAC1B,CAAC;AAAA,CACH;AAED,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE,CAAC;IACrC,IAAI,CAAC,+CAA+C,EAAE,GAAG,EAAE,CAAC;QAC1D,MAAM,KAAK,GAAG,IAAA,6BAAY,GAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,IAAA,uBAAU,EAAC,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAC9C,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC7D,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrE,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CA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,EAAE,KAAK,CAAC,CAAC;QACxC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAAA,CACvB,CAAC,CAAC;AAAA,CACJ,CAAC,CAAC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { HasLayer, TokenSettings } from '@fluentui-react-native/use-tokens';
|
|
2
|
-
import type { TokensThatAreAlsoProps, BuildSlotProps } from './buildProps';
|
|
3
|
-
/**
|
|
4
|
-
* Options used to build up a useStyling hook
|
|
5
|
-
*/
|
|
6
|
-
export type UseStylingOptions<TProps, TSlotProps, TTokens, TTheme> = {
|
|
7
|
-
/**
|
|
8
|
-
* Baseline tokens for this component
|
|
9
|
-
*/
|
|
10
|
-
tokens?: TokenSettings<TTokens, TTheme>[];
|
|
11
|
-
/**
|
|
12
|
-
* States that might be applied for the component like disabled or hovered, these should be listed
|
|
13
|
-
* in the order that they should be applied
|
|
14
|
-
*/
|
|
15
|
-
states?: (keyof TTokens)[];
|
|
16
|
-
/**
|
|
17
|
-
* Functions which build up the props for each slot
|
|
18
|
-
*/
|
|
19
|
-
slotProps?: BuildSlotProps<TSlotProps, TTokens, TTheme>;
|
|
20
|
-
/**
|
|
21
|
-
* Which props should be considered to be tokens.
|
|
22
|
-
* - If an array of keys this will ensure these props are promoted to tokens
|
|
23
|
-
* - If true all props will be added to tokens, if false or not specified no props will be treated as tokens
|
|
24
|
-
*/
|
|
25
|
-
tokensThatAreAlsoProps?: TokensThatAreAlsoProps<TTokens>;
|
|
26
|
-
/** purely used to make type inferencing work correctly so the hook builder can pick up TProps from this type */
|
|
27
|
-
_propsType?: TProps;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Signature for the use styling hook
|
|
31
|
-
*/
|
|
32
|
-
export type UseStyling<TProps, TSlotProps> = (props: TProps, lookup?: HasLayer) => TSlotProps;
|
|
33
|
-
/**
|
|
34
|
-
* Helper object which injects theme specific functionality
|
|
35
|
-
*/
|
|
36
|
-
export type ThemeHelper<TTheme> = {
|
|
37
|
-
/** query the theme from the context, or from a global if your system doesn't use theming */
|
|
38
|
-
useTheme: () => TTheme;
|
|
39
|
-
/** lookup info for the component in the theme */
|
|
40
|
-
getComponentInfo: (theme: TTheme, name: string) => any;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Construct a useStyling hook which returns styled slot props based on props and tokens defined in options and in the theme
|
|
44
|
-
*
|
|
45
|
-
* @param options - options which drive behavior for the generated styling hook
|
|
46
|
-
* @param themeHelper - injected theme functionality
|
|
47
|
-
*/
|
|
48
|
-
export declare function buildUseStyling<TProps, TSlotProps, TTokens, TTheme>(options: UseStylingOptions<TProps, TSlotProps, TTokens, TTheme>, themeHelper: ThemeHelper<TTheme>): UseStyling<TProps, TSlotProps>;
|
|
49
|
-
//# sourceMappingURL=buildUseStyling.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildUseStyling.d.ts","sourceRoot":"","sources":["../src/buildUseStyling.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAGjF,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG3E;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI;IACnE;;OAEG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC;IAE1C;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,EAAE,CAAC;IAE3B;;OAEG;IACH,SAAS,CAAC,EAAE,cAAc,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAExD;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAEzD,gHAAgH;IAChH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,EAAE,UAAU,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,KAAK,UAAU,CAAC;AAE9F;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI;IAChC,4FAA4F;IAC5F,QAAQ,EAAE,MAAM,MAAM,CAAC;IAEvB,iDAAiD;IACjD,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;CACxD,CAAC;AAwBF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EACjE,OAAO,EAAE,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,EAC/D,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,GAC/B,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,CA6BhC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildUseStyling = buildUseStyling;
|
|
4
|
-
const use_tokens_1 = require("@fluentui-react-native/use-tokens");
|
|
5
|
-
const buildProps_1 = require("./buildProps");
|
|
6
|
-
/**
|
|
7
|
-
* Produce the final slot props for the styled hook
|
|
8
|
-
*
|
|
9
|
-
* @param styles - refined style functions or props to use for processing
|
|
10
|
-
* @param tokens - token inputs for the style functions
|
|
11
|
-
* @param theme - theme to resolve against
|
|
12
|
-
* @param cache - cache to use for the base of slot caching
|
|
13
|
-
*/
|
|
14
|
-
function resolveToSlotProps(styles, tokens, theme, cache) {
|
|
15
|
-
const slotProps = {};
|
|
16
|
-
for (const key of Object.keys(styles)) {
|
|
17
|
-
const style = styles[key];
|
|
18
|
-
slotProps[key] = typeof style === 'function' ? style(tokens, theme, cache(null, [key])[1]) : style;
|
|
19
|
-
}
|
|
20
|
-
return slotProps;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Construct a useStyling hook which returns styled slot props based on props and tokens defined in options and in the theme
|
|
24
|
-
*
|
|
25
|
-
* @param options - options which drive behavior for the generated styling hook
|
|
26
|
-
* @param themeHelper - injected theme functionality
|
|
27
|
-
*/
|
|
28
|
-
function buildUseStyling(options, themeHelper) {
|
|
29
|
-
// create a cache instance for this use styling implementation
|
|
30
|
-
const { useTheme, getComponentInfo } = themeHelper;
|
|
31
|
-
const { tokens, tokensThatAreAlsoProps: tokenProps } = options;
|
|
32
|
-
const styles = (0, buildProps_1.refinePropsFunctions)(options.slotProps || {}, tokenProps);
|
|
33
|
-
const useTokens = (0, use_tokens_1.buildUseTokens)(getComponentInfo, ...tokens);
|
|
34
|
-
return (props, lookup) => {
|
|
35
|
-
// query the theme
|
|
36
|
-
const theme = useTheme();
|
|
37
|
-
// get the merged tokens from the theme
|
|
38
|
-
let [mergedTokens, cache] = useTokens(theme);
|
|
39
|
-
// resolve overrides as appropriate
|
|
40
|
-
if (options.states) {
|
|
41
|
-
[mergedTokens, cache] = (0, use_tokens_1.applyTokenLayers)(mergedTokens, options.states, cache, lookup || ((val) => props[val]));
|
|
42
|
-
}
|
|
43
|
-
// now resolve tokens
|
|
44
|
-
if (typeof tokenProps === 'object' && Array.isArray(tokenProps)) {
|
|
45
|
-
[mergedTokens, cache] = (0, use_tokens_1.applyPropsToTokens)(props, mergedTokens, cache, tokenProps);
|
|
46
|
-
}
|
|
47
|
-
else if (tokenProps === 'all') {
|
|
48
|
-
mergedTokens = { ...mergedTokens, ...props };
|
|
49
|
-
}
|
|
50
|
-
// finally produce slotProps from calling the style functions on each entry
|
|
51
|
-
return resolveToSlotProps(styles, mergedTokens, theme, cache);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=buildUseStyling.js.map
|
|
@@ -1 +0,0 @@
|
|
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AC,CAAC;QAE7C,mCAAmC;QACnC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,CAAC,YAAY,EAAE,KAAK,CAAC,GAAG,IAAA,6BAAgB,EAAC,YAAY,EAAE,OAAO,CAAC,MAAkB,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC7H,CAAC;QAED,qBAAqB;QACrB,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAChE,CAAC,YAAY,EAAE,KAAK,CAAC,GAAG,IAAA,+BAAkB,EAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;QACrF,CAAC;aAAM,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;YAChC,YAAY,GAAG,EAAE,GAAG,YAAY,EAAE,GAAG,KAAK,EAAE,CAAC;QAC/C,CAAC;QAED,2EAA2E;QAC3E,OAAO,kBAAkB,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAAA,CAC/D,CAAC;AAAA,CACH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildUseStyling.test.d.ts","sourceRoot":"","sources":["../src/buildUseStyling.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const framework_base_1 = require("@fluentui-react-native/framework-base");
|
|
4
|
-
const buildProps_1 = require("./buildProps");
|
|
5
|
-
const buildUseStyling_1 = require("./buildUseStyling");
|
|
6
|
-
let lastInstance = 0;
|
|
7
|
-
const baseTokens = {
|
|
8
|
-
a: 'a-base',
|
|
9
|
-
b: 'b-base',
|
|
10
|
-
c: 'c-base',
|
|
11
|
-
hover: {
|
|
12
|
-
c: 'c-base-hover',
|
|
13
|
-
},
|
|
14
|
-
press: {
|
|
15
|
-
c: 'c-base-press',
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
const defaultTheme = {
|
|
19
|
-
vals: {
|
|
20
|
-
foo: 'foo',
|
|
21
|
-
bar: 'bar',
|
|
22
|
-
},
|
|
23
|
-
components: {
|
|
24
|
-
uno: {
|
|
25
|
-
a: 'uno-a',
|
|
26
|
-
c: 'uno-c',
|
|
27
|
-
},
|
|
28
|
-
dos: {
|
|
29
|
-
b: 'dos-b',
|
|
30
|
-
c: 'dos-c',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
const themeHelper = {
|
|
35
|
-
useTheme: () => defaultTheme,
|
|
36
|
-
getComponentInfo: (theme, name) => theme.components[name],
|
|
37
|
-
};
|
|
38
|
-
const slotFn1 = (tokens, theme) => {
|
|
39
|
-
return {
|
|
40
|
-
style: {
|
|
41
|
-
a: tokens.a,
|
|
42
|
-
b: tokens.b,
|
|
43
|
-
c: tokens.c,
|
|
44
|
-
...theme.vals,
|
|
45
|
-
instance: lastInstance++,
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
const extraCache = (0, framework_base_1.getMemoCache)();
|
|
50
|
-
const slotFn2 = (tokens) => {
|
|
51
|
-
return extraCache(() => ({
|
|
52
|
-
style: {
|
|
53
|
-
a: tokens.a,
|
|
54
|
-
b: tokens.b,
|
|
55
|
-
instance: lastInstance++,
|
|
56
|
-
},
|
|
57
|
-
}), [tokens.a, tokens.b])[0];
|
|
58
|
-
};
|
|
59
|
-
const baseOptions = {
|
|
60
|
-
tokens: [
|
|
61
|
-
baseTokens,
|
|
62
|
-
'uno',
|
|
63
|
-
(theme) => ({
|
|
64
|
-
b: theme.vals.foo,
|
|
65
|
-
}),
|
|
66
|
-
],
|
|
67
|
-
states: ['hover', 'press'],
|
|
68
|
-
slotProps: {
|
|
69
|
-
slot1: {
|
|
70
|
-
style: {
|
|
71
|
-
instance: lastInstance++,
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
slot2: (0, buildProps_1.buildProps)(slotFn1, ['a', 'b', 'c']),
|
|
75
|
-
slot3: slotFn2,
|
|
76
|
-
},
|
|
77
|
-
tokensThatAreAlsoProps: ['b'],
|
|
78
|
-
};
|
|
79
|
-
describe('useStyling test suite', () => {
|
|
80
|
-
test('basic built hook', () => {
|
|
81
|
-
const useStyling = (0, buildUseStyling_1.buildUseStyling)(baseOptions, themeHelper);
|
|
82
|
-
const slotProps = useStyling({});
|
|
83
|
-
const slotProps2 = useStyling({ p1: 2, p2: 'bar' });
|
|
84
|
-
for (const key of Object.keys(slotProps)) {
|
|
85
|
-
expect(slotProps[key]).toBe(slotProps2[key]);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
//# sourceMappingURL=buildUseStyling.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildUseStyling.test.js","sourceRoot":"","sources":["../src/buildUseStyling.test.ts"],"names":[],"mappings":";;AAAA,0EAAqE;AAErE,6CAA0C;AAE1C,uDAAoD;AAEpD,IAAI,YAAY,GAAG,CAAC,CAAC;AAUrB,MAAM,UAAU,GAAW;IACzB,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,QAAQ;IACX,KAAK,EAAE;QACL,CAAC,EAAE,cAAc;KAClB;IACD,KAAK,EAAE;QACL,CAAC,EAAE,cAAc;KAClB;CACF,CAAC;AAYF,MAAM,YAAY,GAAU;IAC1B,IAAI,EAAE;QACJ,GAAG,EAAE,KAAK;QACV,GAAG,EAAE,KAAK;KACX;IACD,UAAU,EAAE;QACV,GAAG,EAAE;YACH,CAAC,EAAE,OAAO;YACV,CAAC,EAAE,OAAO;SACX;QACD,GAAG,EAAE;YACH,CAAC,EAAE,OAAO;YACV,CAAC,EAAE,OAAO;SACX;KACF;CACF,CAAC;AAEF,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EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QAC3C,KAAK,EAAE,OAAO;KACf;IACD,sBAAsB,EAAE,CAAC,GAAG,CAAC;CAC9B,CAAC;AAEF,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE,CAAC;IACtC,IAAI,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC;QAC7B,MAAM,UAAU,GAAG,IAAA,iCAAe,EAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QAC7D,MAAM,SAAS,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;QACjC,MAAM,UAAU,GAAG,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACpD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACzC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/C,CAAC;IAAA,CACF,CAAC,CAAC;AAAA,CACJ,CAAC,CAAC"}
|
package/lib-commonjs/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { buildUseStyling } from './buildUseStyling';
|
|
2
|
-
export type { ThemeHelper, UseStyling, UseStylingOptions } from './buildUseStyling';
|
|
3
|
-
export { buildProps, refinePropsFunctions } from './buildProps';
|
|
4
|
-
export type { BuildPropsBase, BuildSlotProps, RefinableBuildPropsBase, RefineFunctionBase, TokensThatAreAlsoProps } from './buildProps';
|
|
5
|
-
export type { HasLayer, TokenSettings, TokensFromTheme } from '@fluentui-react-native/use-tokens';
|
|
6
|
-
export { applyTokenLayers } from '@fluentui-react-native/use-tokens';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAChE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACxI,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC"}
|
package/lib-commonjs/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applyTokenLayers = exports.refinePropsFunctions = exports.buildProps = exports.buildUseStyling = void 0;
|
|
4
|
-
const buildUseStyling_1 = require("./buildUseStyling");
|
|
5
|
-
Object.defineProperty(exports, "buildUseStyling", { enumerable: true, get: function () { return buildUseStyling_1.buildUseStyling; } });
|
|
6
|
-
const buildProps_1 = require("./buildProps");
|
|
7
|
-
Object.defineProperty(exports, "buildProps", { enumerable: true, get: function () { return buildProps_1.buildProps; } });
|
|
8
|
-
Object.defineProperty(exports, "refinePropsFunctions", { enumerable: true, get: function () { return buildProps_1.refinePropsFunctions; } });
|
|
9
|
-
const use_tokens_1 = require("@fluentui-react-native/use-tokens");
|
|
10
|
-
Object.defineProperty(exports, "applyTokenLayers", { enumerable: true, get: function () { return use_tokens_1.applyTokenLayers; } });
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAA3C,kHAAA,eAAe,OAAA;AAExB,6CAAgE;AAAvD,wGAAA,UAAU,OAAA;AAAE,kHAAA,oBAAoB,OAAA;AAGzC,kEAAqE;AAA5D,8GAAA,gBAAgB,OAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useStyling.samples.test.d.ts","sourceRoot":"","sources":["../src/useStyling.samples.test.tsx"],"names":[],"mappings":""}
|
|
@@ -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
|