@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.
- package/CHANGELOG.md +10 -0
- package/lib/applyPropsToTokens.d.ts +2 -7
- package/lib/applyPropsToTokens.js +7 -7
- package/lib/applyPropsToTokens.test.d.ts +1 -1
- package/lib/applyPropsToTokens.test.js +19 -19
- package/lib/applyTokenLayers.d.ts +2 -7
- package/lib/applyTokenLayers.js +13 -16
- package/lib/applyTokenLayers.test.d.ts +1 -1
- package/lib/applyTokenLayers.test.js +42 -42
- package/lib/buildUseTokens.d.ts +3 -6
- package/lib/buildUseTokens.js +22 -22
- package/lib/buildUseTokens.test.d.ts +1 -1
- package/lib/buildUseTokens.test.js +68 -68
- package/lib/customizable.d.ts +3 -6
- package/lib/customizable.js +7 -7
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/patchTokens.d.ts +2 -6
- package/lib/patchTokens.js +12 -12
- package/lib/patchTokens.test.d.ts +1 -1
- package/lib/patchTokens.test.js +32 -32
- package/lib/useTokens.samples.test.d.ts +1 -1
- package/lib/useTokens.samples.test.js +119 -133
- package/lib-commonjs/applyPropsToTokens.d.ts +2 -7
- package/lib-commonjs/applyPropsToTokens.js +9 -9
- package/lib-commonjs/applyPropsToTokens.test.d.ts +1 -1
- package/lib-commonjs/applyPropsToTokens.test.js +23 -23
- package/lib-commonjs/applyTokenLayers.d.ts +2 -7
- package/lib-commonjs/applyTokenLayers.js +16 -19
- package/lib-commonjs/applyTokenLayers.test.d.ts +1 -1
- package/lib-commonjs/applyTokenLayers.test.js +46 -46
- package/lib-commonjs/buildUseTokens.d.ts +3 -6
- package/lib-commonjs/buildUseTokens.js +26 -29
- package/lib-commonjs/buildUseTokens.test.d.ts +1 -1
- package/lib-commonjs/buildUseTokens.test.js +71 -71
- package/lib-commonjs/customizable.d.ts +3 -6
- package/lib-commonjs/customizable.js +9 -9
- package/lib-commonjs/index.d.ts +1 -1
- package/lib-commonjs/index.js +13 -38
- package/lib-commonjs/patchTokens.d.ts +2 -6
- package/lib-commonjs/patchTokens.js +14 -14
- package/lib-commonjs/patchTokens.test.d.ts +1 -1
- package/lib-commonjs/patchTokens.test.js +36 -36
- package/lib-commonjs/useTokens.samples.test.d.ts +1 -1
- package/lib-commonjs/useTokens.samples.test.js +156 -191
- package/package.json +14 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Change Log - @fluentui-react-native/use-tokens
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0d6e9c1: chore: migrate to `oxfmt`
|
|
8
|
+
- ac6e7af: Ensure packages have a default export that references the typescript entrypoint and clean up build dependency ordering
|
|
9
|
+
- Updated dependencies [0d6e9c1]
|
|
10
|
+
- Updated dependencies [ac6e7af]
|
|
11
|
+
- @fluentui-react-native/framework-base@0.3.1
|
|
12
|
+
|
|
3
13
|
## 0.7.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import type { GetTypedMemoValue } from '@fluentui-react-native/framework-base';
|
|
2
|
-
export declare function applyPropsToTokens<TProps, TTokens>(
|
|
3
|
-
|
|
4
|
-
tokens: TTokens,
|
|
5
|
-
cache: GetTypedMemoValue<TTokens>,
|
|
6
|
-
keys: (keyof TTokens)[],
|
|
7
|
-
): [TTokens, GetTypedMemoValue<TTokens>];
|
|
8
|
-
//# sourceMappingURL=applyPropsToTokens.d.ts.map
|
|
2
|
+
export declare function applyPropsToTokens<TProps, TTokens>(props: TProps, tokens: TTokens, cache: GetTypedMemoValue<TTokens>, keys: (keyof TTokens)[]): [TTokens, GetTypedMemoValue<TTokens>];
|
|
3
|
+
//# sourceMappingURL=applyPropsToTokens.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export function applyPropsToTokens(props, tokens, cache, keys) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
for (const key of keys) {
|
|
3
|
+
const sourceValue = props[key];
|
|
4
|
+
const setValue = sourceValue === tokens[key] ? undefined : sourceValue;
|
|
5
|
+
[tokens, cache] = cache(() => (setValue === undefined ? tokens : { ...tokens, [key]: setValue }), [setValue]);
|
|
6
|
+
}
|
|
7
|
+
return [tokens, cache];
|
|
8
8
|
}
|
|
9
|
-
//# sourceMappingURL=applyPropsToTokens.js.map
|
|
9
|
+
//# sourceMappingURL=applyPropsToTokens.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=applyPropsToTokens.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=applyPropsToTokens.test.d.ts.map
|
|
@@ -2,28 +2,28 @@ import { getTypedMemoCache } from '@fluentui-react-native/framework-base';
|
|
|
2
2
|
import { applyPropsToTokens } from './applyPropsToTokens';
|
|
3
3
|
const tokenProps = ['dos', 'quatro', 'cinco'];
|
|
4
4
|
const themeTokens = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
uno: 'uno',
|
|
6
|
+
dos: 'dos',
|
|
7
|
+
tres: 3,
|
|
8
|
+
quatro: 4,
|
|
9
|
+
cinco: true,
|
|
10
10
|
};
|
|
11
11
|
const props1 = { dos: 'two', quatro: 'four', cinco: false, foo: 'foo', bar: 'bar' };
|
|
12
12
|
// const props2: Props = { dos: 'two' };
|
|
13
13
|
// const props3: Props = { foo: 'foo', bar: 'bar' };
|
|
14
14
|
describe('applyPropsToTokens tests', () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
test('props get copied', () => {
|
|
16
|
+
const cache = getTypedMemoCache();
|
|
17
|
+
const [tokens] = applyPropsToTokens(props1, themeTokens, cache, tokenProps);
|
|
18
|
+
expect(tokens).not.toBe(themeTokens);
|
|
19
|
+
for (const key of tokenProps) {
|
|
20
|
+
expect(tokens[key]).toEqual(props1[key]);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
test('no copied props does not change tokens', () => {
|
|
24
|
+
const cache = getTypedMemoCache();
|
|
25
|
+
const [tokens] = applyPropsToTokens({}, themeTokens, cache, tokenProps);
|
|
26
|
+
expect(tokens).toBe(themeTokens);
|
|
27
|
+
});
|
|
28
28
|
});
|
|
29
|
-
//# sourceMappingURL=applyPropsToTokens.test.js.map
|
|
29
|
+
//# sourceMappingURL=applyPropsToTokens.test.js.map
|
|
@@ -12,10 +12,5 @@ export type HasLayer = (name: string) => boolean;
|
|
|
12
12
|
* @param subCache - cache scoped to the root object with no layers applied
|
|
13
13
|
* @param hasLayer - a function which returns whether a given layer should be applied
|
|
14
14
|
*/
|
|
15
|
-
export declare function applyTokenLayers<TTokens>(
|
|
16
|
-
|
|
17
|
-
states: string[],
|
|
18
|
-
subCache: GetTypedMemoValue<TTokens>,
|
|
19
|
-
hasLayer: HasLayer,
|
|
20
|
-
): [TTokens, GetTypedMemoValue<TTokens>];
|
|
21
|
-
//# sourceMappingURL=applyTokenLayers.d.ts.map
|
|
15
|
+
export declare function applyTokenLayers<TTokens>(tokens: TTokens, states: string[], subCache: GetTypedMemoValue<TTokens>, hasLayer: HasLayer): [TTokens, GetTypedMemoValue<TTokens>];
|
|
16
|
+
//# sourceMappingURL=applyTokenLayers.d.ts.map
|
package/lib/applyTokenLayers.js
CHANGED
|
@@ -9,20 +9,17 @@ import { immutableMerge } from '@fluentui-react-native/framework-base';
|
|
|
9
9
|
* @param hasLayer - a function which returns whether a given layer should be applied
|
|
10
10
|
*/
|
|
11
11
|
export function applyTokenLayers(tokens, states, subCache, hasLayer) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}, final);
|
|
25
|
-
}
|
|
26
|
-
return [final.tokens, final.subCache];
|
|
12
|
+
let final = { tokens, subCache };
|
|
13
|
+
if (states && states.length > 0) {
|
|
14
|
+
// now walk the overrides that are set, merging in props, caching results, and getting a new sub cache
|
|
15
|
+
final = states
|
|
16
|
+
.filter((val) => hasLayer(val))
|
|
17
|
+
.reduce((previous, layerName) => {
|
|
18
|
+
const layer = previous.tokens[layerName];
|
|
19
|
+
const [tokens, subCache] = previous.subCache(() => (layer && typeof layer === 'object' ? immutableMerge(previous.tokens, layer) : previous.tokens), [layer]);
|
|
20
|
+
return { tokens, subCache };
|
|
21
|
+
}, final);
|
|
22
|
+
}
|
|
23
|
+
return [final.tokens, final.subCache];
|
|
27
24
|
}
|
|
28
|
-
//# sourceMappingURL=applyTokenLayers.js.map
|
|
25
|
+
//# sourceMappingURL=applyTokenLayers.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=applyTokenLayers.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=applyTokenLayers.test.d.ts.map
|
|
@@ -2,52 +2,52 @@ import { getMemoCache } from '@fluentui-react-native/framework-base';
|
|
|
2
2
|
import { applyTokenLayers } from './applyTokenLayers';
|
|
3
3
|
const stateOrder = ['hover', 'press', 'disabled'];
|
|
4
4
|
const tokens1 = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
a: 'a',
|
|
6
|
+
b: 'b',
|
|
7
|
+
c: 'c',
|
|
8
|
+
hover: {
|
|
9
|
+
a: 'a-hover',
|
|
10
|
+
b: 'b-hover',
|
|
11
|
+
press: {
|
|
12
|
+
a: 'a-hover-press',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
11
15
|
press: {
|
|
12
|
-
|
|
16
|
+
a: 'a-press',
|
|
17
|
+
b: 'b-press',
|
|
18
|
+
},
|
|
19
|
+
disabled: {
|
|
20
|
+
a: 'disabled',
|
|
21
|
+
b: 'disabled',
|
|
22
|
+
c: 'disabled',
|
|
13
23
|
},
|
|
14
|
-
},
|
|
15
|
-
press: {
|
|
16
|
-
a: 'a-press',
|
|
17
|
-
b: 'b-press',
|
|
18
|
-
},
|
|
19
|
-
disabled: {
|
|
20
|
-
a: 'disabled',
|
|
21
|
-
b: 'disabled',
|
|
22
|
-
c: 'disabled',
|
|
23
|
-
},
|
|
24
24
|
};
|
|
25
25
|
function stripLayers(tokens) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
const t = { ...tokens };
|
|
27
|
+
delete t.hover;
|
|
28
|
+
delete t.press;
|
|
29
|
+
delete t.disabled;
|
|
30
|
+
return t;
|
|
31
31
|
}
|
|
32
32
|
describe('applyLayers tests', () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
test('no layers returns tokens', () => {
|
|
34
|
+
const cache = getMemoCache();
|
|
35
|
+
const tokens = applyTokenLayers(tokens1, stateOrder, cache, () => false)[0];
|
|
36
|
+
expect(tokens).toBe(tokens1);
|
|
37
|
+
});
|
|
38
|
+
test('apply hover works', () => {
|
|
39
|
+
const cache = getMemoCache();
|
|
40
|
+
const lookup = (layer) => layer === 'hover';
|
|
41
|
+
const result1 = applyTokenLayers(tokens1, stateOrder, cache, lookup)[0];
|
|
42
|
+
expect(applyTokenLayers(tokens1, stateOrder, cache, lookup)[0]).toBe(result1);
|
|
43
|
+
expect(stripLayers(result1)).toEqual({ a: 'a-hover', b: 'b-hover', c: 'c' });
|
|
44
|
+
});
|
|
45
|
+
test('apply hover and press layer correctly', () => {
|
|
46
|
+
const cache = getMemoCache();
|
|
47
|
+
const lookup = (layer) => layer === 'hover' || layer === 'press';
|
|
48
|
+
const result1 = applyTokenLayers(tokens1, stateOrder, cache, lookup)[0];
|
|
49
|
+
expect(applyTokenLayers(tokens1, stateOrder, cache, lookup)[0]).toBe(result1);
|
|
50
|
+
expect(stripLayers(result1)).toEqual({ a: 'a-hover-press', b: 'b-press', c: 'c' });
|
|
51
|
+
});
|
|
52
52
|
});
|
|
53
|
-
//# sourceMappingURL=applyTokenLayers.test.js.map
|
|
53
|
+
//# sourceMappingURL=applyTokenLayers.test.js.map
|
package/lib/buildUseTokens.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type UseTokensCore<TTokens, TTheme> = (theme: TTheme) => [TTokens, GetTyp
|
|
|
19
19
|
* that captures both the previous values, and layers in the new values specified
|
|
20
20
|
*/
|
|
21
21
|
export type UseTokens<TTokens, TTheme> = UseTokensCore<TTokens, TTheme> & {
|
|
22
|
-
|
|
22
|
+
customize: (...tokens: TokenSettings<TTokens, TTheme>[]) => UseTokens<TTokens, TTheme>;
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Helper function that knows how to try to look up token information from the theme
|
|
@@ -31,8 +31,5 @@ export type GetComponentInfo<TTokens, TTheme> = (theme: TTheme, name: string) =>
|
|
|
31
31
|
* @param options - options which drive behavior for the generated styling hook
|
|
32
32
|
* @param themeHelper - injected theme functionality
|
|
33
33
|
*/
|
|
34
|
-
export declare function buildUseTokens<TTokens, TTheme>(
|
|
35
|
-
|
|
36
|
-
...tokens: TokenSettings<TTokens, TTheme>[]
|
|
37
|
-
): UseTokens<TTokens, TTheme>;
|
|
38
|
-
//# sourceMappingURL=buildUseTokens.d.ts.map
|
|
34
|
+
export declare function buildUseTokens<TTokens, TTheme>(getComponentInfo: GetComponentInfo<TTokens, TTheme> | undefined, ...tokens: TokenSettings<TTokens, TTheme>[]): UseTokens<TTokens, TTheme>;
|
|
35
|
+
//# sourceMappingURL=buildUseTokens.d.ts.map
|
package/lib/buildUseTokens.js
CHANGED
|
@@ -14,13 +14,13 @@ import { getMemoCache } from '@fluentui-react-native/framework-base';
|
|
|
14
14
|
* @param getComponentInfo - helper to use to lookup the component in the theme
|
|
15
15
|
*/
|
|
16
16
|
function mapToTokens(tokenEntry, theme, getComponentInfo) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
if (typeof tokenEntry === 'string') {
|
|
18
|
+
tokenEntry = (getComponentInfo && getComponentInfo(theme, tokenEntry)) || {};
|
|
19
|
+
}
|
|
20
|
+
if (typeof tokenEntry === 'function') {
|
|
21
|
+
tokenEntry = tokenEntry(theme);
|
|
22
|
+
}
|
|
23
|
+
return tokenEntry;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Construct a useStyling hook which returns styled slot props based on props and tokens defined in options and in the theme
|
|
@@ -29,19 +29,19 @@ function mapToTokens(tokenEntry, theme, getComponentInfo) {
|
|
|
29
29
|
* @param themeHelper - injected theme functionality
|
|
30
30
|
*/
|
|
31
31
|
export function buildUseTokens(getComponentInfo, ...tokens) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
// create a cache instance for use in this particular call to buildUseTokens
|
|
33
|
+
const cache = getMemoCache();
|
|
34
|
+
// the core function simply merges layers together, looking up component definitions in the theme as well as executing any
|
|
35
|
+
// theme functions. This turns the tokens into an array of token objects that then get merged together
|
|
36
|
+
const useTokensCore = (theme) => {
|
|
37
|
+
// get the base styles all merged together, these will only depend on internal tokens and theme
|
|
38
|
+
return cache(() => immutableMerge(...tokens.map((value) => mapToTokens(value, theme, getComponentInfo))), [theme]);
|
|
39
|
+
};
|
|
40
|
+
// attach a customize function to generate a new use
|
|
41
|
+
useTokensCore.customize = (...newTokens) => {
|
|
42
|
+
const mergedTokens = [...tokens, ...newTokens];
|
|
43
|
+
return buildUseTokens(getComponentInfo, ...mergedTokens);
|
|
44
|
+
};
|
|
45
|
+
return useTokensCore;
|
|
46
46
|
}
|
|
47
|
-
//# sourceMappingURL=buildUseTokens.js.map
|
|
47
|
+
//# sourceMappingURL=buildUseTokens.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=buildUseTokens.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=buildUseTokens.test.d.ts.map
|
|
@@ -1,85 +1,85 @@
|
|
|
1
1
|
import { buildUseTokens } from './buildUseTokens';
|
|
2
2
|
const baseTokens = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
a: 'a-base',
|
|
4
|
+
b: 'b-base',
|
|
5
|
+
c: 'c-base',
|
|
6
|
+
hover: {
|
|
7
|
+
c: 'c-base-hover',
|
|
8
|
+
},
|
|
9
|
+
press: {
|
|
10
|
+
c: 'c-base-press',
|
|
11
|
+
},
|
|
12
12
|
};
|
|
13
13
|
const defaultTheme = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
components: {
|
|
19
|
-
uno: {
|
|
20
|
-
a: 'uno-a',
|
|
21
|
-
c: 'uno-c',
|
|
14
|
+
vals: {
|
|
15
|
+
foo: 'foo',
|
|
16
|
+
bar: 'bar',
|
|
22
17
|
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
components: {
|
|
19
|
+
uno: {
|
|
20
|
+
a: 'uno-a',
|
|
21
|
+
c: 'uno-c',
|
|
22
|
+
},
|
|
23
|
+
dos: {
|
|
24
|
+
b: 'dos-b',
|
|
25
|
+
c: 'dos-c',
|
|
26
|
+
},
|
|
26
27
|
},
|
|
27
|
-
},
|
|
28
28
|
};
|
|
29
29
|
const variantTheme = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
vals: {
|
|
31
|
+
foo: 'variant',
|
|
32
|
+
},
|
|
33
|
+
components: {},
|
|
34
34
|
};
|
|
35
35
|
const getComponentInfo = (theme, name) => theme.components[name];
|
|
36
36
|
const componentTokens = [baseTokens, 'uno', (theme) => ({ b: theme.vals.foo })];
|
|
37
37
|
const resolvedTokens = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
a: 'uno-a',
|
|
39
|
+
b: 'foo',
|
|
40
|
+
c: 'uno-c',
|
|
41
|
+
hover: {
|
|
42
|
+
c: 'c-base-hover',
|
|
43
|
+
},
|
|
44
|
+
press: {
|
|
45
|
+
c: 'c-base-press',
|
|
46
|
+
},
|
|
47
47
|
};
|
|
48
48
|
const variantTokens = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
a: 'a-base',
|
|
50
|
+
b: 'variant',
|
|
51
|
+
c: 'c-base',
|
|
52
|
+
hover: {
|
|
53
|
+
c: 'c-base-hover',
|
|
54
|
+
},
|
|
55
|
+
press: {
|
|
56
|
+
c: 'c-base-press',
|
|
57
|
+
},
|
|
58
58
|
};
|
|
59
59
|
describe('buildUseTokens test suite', () => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
test('basic built hook', () => {
|
|
61
|
+
const useTokens = buildUseTokens(getComponentInfo, ...componentTokens);
|
|
62
|
+
const [tokens] = useTokens(defaultTheme);
|
|
63
|
+
expect(tokens).toEqual(resolvedTokens);
|
|
64
|
+
});
|
|
65
|
+
test('multiple calls return same object', () => {
|
|
66
|
+
const useTokens = buildUseTokens(getComponentInfo, ...componentTokens);
|
|
67
|
+
const [tokens1] = useTokens(defaultTheme);
|
|
68
|
+
const [tokens2] = useTokens(defaultTheme);
|
|
69
|
+
expect(tokens1).toBe(tokens2);
|
|
70
|
+
});
|
|
71
|
+
test('variant theme is separate', () => {
|
|
72
|
+
const useTokens = buildUseTokens(getComponentInfo, ...componentTokens);
|
|
73
|
+
const [tokensDefault] = useTokens(defaultTheme);
|
|
74
|
+
const [tokensVariant] = useTokens(variantTheme);
|
|
75
|
+
expect(tokensVariant).not.toBe(tokensDefault);
|
|
76
|
+
expect(tokensVariant).toEqual(variantTokens);
|
|
77
|
+
});
|
|
78
|
+
test('simple customization layers on top', () => {
|
|
79
|
+
const useTokens = buildUseTokens(getComponentInfo, ...componentTokens);
|
|
80
|
+
const useTokensCustom = useTokens.customize({ a: 'custom' });
|
|
81
|
+
const [tokens] = useTokensCustom(defaultTheme);
|
|
82
|
+
expect(tokens).toEqual({ ...resolvedTokens, a: 'custom' });
|
|
83
|
+
});
|
|
84
84
|
});
|
|
85
|
-
//# sourceMappingURL=buildUseTokens.test.js.map
|
|
85
|
+
//# sourceMappingURL=buildUseTokens.test.js.map
|
package/lib/customizable.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type InjectableComponent<TProps, TTokens, TTheme> = (props: TProps, useTo
|
|
|
10
10
|
* A component with an attached customize function, used to create alternatively styled versions of the component
|
|
11
11
|
*/
|
|
12
12
|
export type CustomizableComponent<TProps, TTokens, TTheme> = React.FunctionComponent<TProps> & {
|
|
13
|
-
|
|
13
|
+
customize: (...tokens: TokenSettings<TTokens, TTheme>[]) => CustomizableComponent<TProps, TTokens, TTheme>;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Function helper for easily creating a customizable component based on the useTokens hook
|
|
@@ -21,8 +21,5 @@ export type CustomizableComponent<TProps, TTokens, TTheme> = React.FunctionCompo
|
|
|
21
21
|
* @returns - a function component that has a static function called customize attached. Customize will return a
|
|
22
22
|
* new component (which can also be customized)
|
|
23
23
|
*/
|
|
24
|
-
export declare function customizable<TProps, TTokens, TTheme>(
|
|
25
|
-
|
|
26
|
-
useTokens: UseTokens<TTokens, TTheme>,
|
|
27
|
-
): CustomizableComponent<TProps, TTokens, TTheme>;
|
|
28
|
-
//# sourceMappingURL=customizable.d.ts.map
|
|
24
|
+
export declare function customizable<TProps, TTokens, TTheme>(injectable: InjectableComponent<TProps, TTokens, TTheme>, useTokens: UseTokens<TTokens, TTheme>): CustomizableComponent<TProps, TTokens, TTheme>;
|
|
25
|
+
//# sourceMappingURL=customizable.d.ts.map
|
package/lib/customizable.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
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/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,9 +8,5 @@ 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
|
-
|
|
13
|
-
cache: GetTypedMemoValue<TTokens>,
|
|
14
|
-
patchValues: TTokens,
|
|
15
|
-
): [TTokens, GetTypedMemoValue<TTokens>];
|
|
16
|
-
//# sourceMappingURL=patchTokens.d.ts.map
|
|
11
|
+
export declare function patchTokens<TTokens>(tokens: TTokens, cache: GetTypedMemoValue<TTokens>, patchValues: TTokens): [TTokens, GetTypedMemoValue<TTokens>];
|
|
12
|
+
//# 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
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=patchTokens.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=patchTokens.test.d.ts.map
|