@fluentui-react-native/composition 0.12.0 → 0.12.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 +12 -0
- package/lib/composeFactory.d.ts +7 -19
- package/lib/composeFactory.js +22 -22
- package/lib/composeFactory.js.map +1 -1
- package/lib/composeFactory.test.d.ts +1 -1
- package/lib/composeFactory.test.js +40 -43
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib-commonjs/composeFactory.d.ts +7 -19
- package/lib-commonjs/composeFactory.js +28 -30
- package/lib-commonjs/composeFactory.js.map +1 -1
- package/lib-commonjs/composeFactory.test.d.ts +1 -1
- package/lib-commonjs/composeFactory.test.js +75 -96
- package/lib-commonjs/index.d.ts +1 -1
- package/lib-commonjs/index.js +5 -10
- package/package.json +16 -15
- package/src/composeFactory.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Change Log - @fluentui-react-native/composition
|
|
2
2
|
|
|
3
|
+
## 0.12.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/use-styling@0.14.1
|
|
12
|
+
- @fluentui-react-native/use-slots@0.11.1
|
|
13
|
+
- @fluentui-react-native/framework-base@0.3.1
|
|
14
|
+
|
|
3
15
|
## 0.12.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/lib/composeFactory.d.ts
CHANGED
|
@@ -2,13 +2,7 @@ import type { ComposableFunction, FinalRender } from '@fluentui-react-native/fra
|
|
|
2
2
|
import type { UseSlotOptions, Slots } from '@fluentui-react-native/use-slots';
|
|
3
3
|
import type { UseStylingOptions, TokenSettings, ThemeHelper, HasLayer } from '@fluentui-react-native/use-styling';
|
|
4
4
|
export type UseStyledSlots<TProps, TSlotProps> = (props: TProps, lookup?: HasLayer) => Slots<TSlotProps>;
|
|
5
|
-
export type ComposeFactoryOptions<TProps, TSlotProps, TTokens, TTheme, TStatics extends object = object> = UseStylingOptions<
|
|
6
|
-
TProps,
|
|
7
|
-
TSlotProps,
|
|
8
|
-
TTokens,
|
|
9
|
-
TTheme
|
|
10
|
-
> &
|
|
11
|
-
UseSlotOptions<TSlotProps> & {
|
|
5
|
+
export type ComposeFactoryOptions<TProps, TSlotProps, TTokens, TTheme, TStatics extends object = object> = UseStylingOptions<TProps, TSlotProps, TTokens, TTheme> & UseSlotOptions<TSlotProps> & {
|
|
12
6
|
/**
|
|
13
7
|
* Includes from UseStylingOptions:
|
|
14
8
|
*
|
|
@@ -22,17 +16,11 @@ export type ComposeFactoryOptions<TProps, TSlotProps, TTokens, TTheme, TStatics
|
|
|
22
16
|
* optional statics to attach to the component
|
|
23
17
|
*/
|
|
24
18
|
statics?: TStatics;
|
|
25
|
-
|
|
19
|
+
};
|
|
26
20
|
export type ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics extends object = object> = ComposableFunction<TProps> & {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
options: Partial<ComposeFactoryOptions<TProps, TOverrideSlotProps, TTokens, TTheme, TStatics>>,
|
|
31
|
-
): ComposeFactoryComponent<TProps, TOverrideSlotProps, TTokens, TTheme, TStatics>;
|
|
21
|
+
__options: ComposeFactoryOptions<TProps, TSlotProps, TTokens, TTheme, TStatics>;
|
|
22
|
+
customize: (...tokens: TokenSettings<TTokens, TTheme>[]) => ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics>;
|
|
23
|
+
compose<TOverrideSlotProps = TSlotProps>(options: Partial<ComposeFactoryOptions<TProps, TOverrideSlotProps, TTokens, TTheme, TStatics>>): ComposeFactoryComponent<TProps, TOverrideSlotProps, TTokens, TTheme, TStatics>;
|
|
32
24
|
} & TStatics;
|
|
33
|
-
export declare function composeFactory<TProps, TSlotProps, TTokens, TTheme, TStatics extends object = object>(
|
|
34
|
-
|
|
35
|
-
themeHelper: ThemeHelper<TTheme>,
|
|
36
|
-
base?: ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics>,
|
|
37
|
-
): ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics>;
|
|
38
|
-
//# sourceMappingURL=composeFactory.d.ts.map
|
|
25
|
+
export declare function composeFactory<TProps, TSlotProps, TTokens, TTheme, TStatics extends object = object>(options: ComposeFactoryOptions<TProps, TSlotProps, TTokens, TTheme, TStatics>, themeHelper: ThemeHelper<TTheme>, base?: ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics>): ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics>;
|
|
26
|
+
//# sourceMappingURL=composeFactory.d.ts.map
|
package/lib/composeFactory.js
CHANGED
|
@@ -6,28 +6,28 @@ import { buildUseStyling } from '@fluentui-react-native/use-styling';
|
|
|
6
6
|
* options get deep merged except the tokens array gets appended
|
|
7
7
|
*/
|
|
8
8
|
const mergeOptions = {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
tokens: 'appendArray',
|
|
10
|
+
object: true,
|
|
11
11
|
};
|
|
12
12
|
export function composeFactory(options, themeHelper, base) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
// merge options together if a base is specified
|
|
14
|
+
const baseOptions = base?.__options;
|
|
15
|
+
options = baseOptions ? immutableMergeCore(mergeOptions, baseOptions, options) : { ...options };
|
|
16
|
+
// build styling if styling options are specified
|
|
17
|
+
options.useStyling = options.slotProps || options.tokens ? buildUseStyling(options, themeHelper) : () => ({});
|
|
18
|
+
// build the slots hook, which will use the styling hook if it has been built
|
|
19
|
+
const useSlots = buildUseSlots(options);
|
|
20
|
+
// build the staged component
|
|
21
|
+
const component = stagedComponent((props) => options.useRender(props, useSlots));
|
|
22
|
+
// attach additional props to the returned component
|
|
23
|
+
component.displayName = options.displayName;
|
|
24
|
+
component.__options = options;
|
|
25
|
+
component.customize = (...tokens) => composeFactory(immutableMergeCore(mergeOptions, options, { tokens: tokens }), themeHelper);
|
|
26
|
+
component.compose = (customOptions) => composeFactory(immutableMergeCore(mergeOptions, options, customOptions), themeHelper);
|
|
27
|
+
// attach statics if specified
|
|
28
|
+
if (options.statics) {
|
|
29
|
+
Object.assign(component, options.statics);
|
|
30
|
+
}
|
|
31
|
+
return component;
|
|
32
32
|
}
|
|
33
|
-
//# sourceMappingURL=composeFactory.js.map
|
|
33
|
+
//# sourceMappingURL=composeFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composeFactory.js","sourceRoot":"","sources":["../src/composeFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAqCrE;;GAEG;AACH,MAAM,YAAY,GAAiB;IACjC,MAAM,EAAE,aAAa;IACrB,MAAM,EAAE,IAAI;CACb,CAAC;AAEF,MAAM,UAAU,cAAc,CAC5B,OAA6E,EAC7E,WAAgC,EAChC,IAA6E,EACL;IAIxE,gDAAgD;IAChD,MAAM,WAAW,GAAiB,IAAI,EAAE,SAAyB,CAAC;IAClE,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,kBAAkB,C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SAAS,GAAG,eAAe,CAAS,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAmB,CAAC;IAE3G,oDAAoD;IACpD,SAAS,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAC5C,SAAS,CAAC,SAAS,GAAG,OAAO,CAAC;IAC9B,SAAS,CAAC,SAAS,GAAG,CAAC,GAAG,MAA8B,EAAE,EAAE,CAC1D,cAAc,CACZ,kBAAkB,CAAC,YAAY,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAkB,CAAC,EAC7E,WAAW,CACZ,CAAC;IAEJ,SAAS,CAAC,OAAO,GAAG,CAClB,aAAoG,EACpG,EAAE,CACF,cAAc,CACZ,kBAAkB,CAAC,YAAY,EAAE,OAAO,EAAE,aAAuB,CAMhE,EACD,WAAW,CACZ,CAAC;IAEJ,8BAA8B;IAC9B,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,SAAS,CAAC;AAAA,CAClB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=composeFactory.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=composeFactory.test.d.ts.map
|
|
@@ -1,69 +1,66 @@
|
|
|
1
|
-
import { jsx as _jsx } from
|
|
1
|
+
import { jsx as _jsx } from "@fluentui-react-native/framework-base/jsx-runtime";
|
|
2
2
|
/** @jsxImportSource @fluentui-react-native/framework-base */
|
|
3
3
|
import { act } from 'react';
|
|
4
4
|
import { View, Text } from 'react-native';
|
|
5
5
|
import * as renderer from 'react-test-renderer';
|
|
6
6
|
import { composeFactory } from './composeFactory';
|
|
7
7
|
const theme = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
values: {
|
|
9
|
+
backgroundColor: 'black',
|
|
10
|
+
color: 'white',
|
|
11
|
+
},
|
|
12
|
+
components: {},
|
|
13
13
|
};
|
|
14
14
|
const themeHelper = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
useTheme: () => theme,
|
|
16
|
+
getComponentInfo: (theme, name) => {
|
|
17
|
+
return theme?.components ?? theme.components[name];
|
|
18
|
+
},
|
|
19
19
|
};
|
|
20
20
|
function mergeProps(p1, p2) {
|
|
21
|
-
|
|
21
|
+
return { ...p1, ...p2 };
|
|
22
22
|
}
|
|
23
|
-
const Base = composeFactory(
|
|
24
|
-
{
|
|
23
|
+
const Base = composeFactory({
|
|
25
24
|
tokens: [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
(t) => ({
|
|
26
|
+
backgroundColor: t.values.backgroundColor,
|
|
27
|
+
color: t.values.color,
|
|
28
|
+
}),
|
|
30
29
|
],
|
|
31
30
|
slotProps: {
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
outer: (tokens) => ({ style: { backgroundColor: tokens.backgroundColor } }),
|
|
32
|
+
content: (tokens) => ({ style: { color: tokens.color } }),
|
|
34
33
|
},
|
|
35
34
|
slots: {
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
outer: View,
|
|
36
|
+
content: Text,
|
|
38
37
|
},
|
|
39
38
|
useRender: (props, useSlots) => {
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const Slots = useSlots(props);
|
|
40
|
+
return (extra) => (_jsx(Slots.outer, { ...mergeProps(props, extra), children: _jsx(Slots.content, { children: "Hello" }) }));
|
|
42
41
|
},
|
|
43
|
-
|
|
44
|
-
themeHelper,
|
|
45
|
-
);
|
|
42
|
+
}, themeHelper);
|
|
46
43
|
const Customized = Base.customize({ backgroundColor: 'pink' });
|
|
47
44
|
const mixinStyle = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
width: 30,
|
|
46
|
+
height: 20,
|
|
47
|
+
borderColor: 'green',
|
|
48
|
+
borderWidth: 1,
|
|
52
49
|
};
|
|
53
50
|
describe('composeFactory test suite', () => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
it('Base component render', () => {
|
|
52
|
+
let component;
|
|
53
|
+
act(() => {
|
|
54
|
+
component = renderer.create(_jsx(Base, { style: mixinStyle }));
|
|
55
|
+
});
|
|
56
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
58
57
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
it('Customized component render', () => {
|
|
59
|
+
let component;
|
|
60
|
+
act(() => {
|
|
61
|
+
component = renderer.create(_jsx(Customized, { style: mixinStyle }));
|
|
62
|
+
});
|
|
63
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
65
64
|
});
|
|
66
|
-
expect(component.toJSON()).toMatchSnapshot();
|
|
67
|
-
});
|
|
68
65
|
});
|
|
69
|
-
//# sourceMappingURL=composeFactory.test.js.map
|
|
66
|
+
//# sourceMappingURL=composeFactory.test.js.map
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { composeFactory } from './composeFactory';
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -2,13 +2,7 @@ import type { ComposableFunction, FinalRender } from '@fluentui-react-native/fra
|
|
|
2
2
|
import type { UseSlotOptions, Slots } from '@fluentui-react-native/use-slots';
|
|
3
3
|
import type { UseStylingOptions, TokenSettings, ThemeHelper, HasLayer } from '@fluentui-react-native/use-styling';
|
|
4
4
|
export type UseStyledSlots<TProps, TSlotProps> = (props: TProps, lookup?: HasLayer) => Slots<TSlotProps>;
|
|
5
|
-
export type ComposeFactoryOptions<TProps, TSlotProps, TTokens, TTheme, TStatics extends object = object> = UseStylingOptions<
|
|
6
|
-
TProps,
|
|
7
|
-
TSlotProps,
|
|
8
|
-
TTokens,
|
|
9
|
-
TTheme
|
|
10
|
-
> &
|
|
11
|
-
UseSlotOptions<TSlotProps> & {
|
|
5
|
+
export type ComposeFactoryOptions<TProps, TSlotProps, TTokens, TTheme, TStatics extends object = object> = UseStylingOptions<TProps, TSlotProps, TTokens, TTheme> & UseSlotOptions<TSlotProps> & {
|
|
12
6
|
/**
|
|
13
7
|
* Includes from UseStylingOptions:
|
|
14
8
|
*
|
|
@@ -22,17 +16,11 @@ export type ComposeFactoryOptions<TProps, TSlotProps, TTokens, TTheme, TStatics
|
|
|
22
16
|
* optional statics to attach to the component
|
|
23
17
|
*/
|
|
24
18
|
statics?: TStatics;
|
|
25
|
-
|
|
19
|
+
};
|
|
26
20
|
export type ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics extends object = object> = ComposableFunction<TProps> & {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
options: Partial<ComposeFactoryOptions<TProps, TOverrideSlotProps, TTokens, TTheme, TStatics>>,
|
|
31
|
-
): ComposeFactoryComponent<TProps, TOverrideSlotProps, TTokens, TTheme, TStatics>;
|
|
21
|
+
__options: ComposeFactoryOptions<TProps, TSlotProps, TTokens, TTheme, TStatics>;
|
|
22
|
+
customize: (...tokens: TokenSettings<TTokens, TTheme>[]) => ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics>;
|
|
23
|
+
compose<TOverrideSlotProps = TSlotProps>(options: Partial<ComposeFactoryOptions<TProps, TOverrideSlotProps, TTokens, TTheme, TStatics>>): ComposeFactoryComponent<TProps, TOverrideSlotProps, TTokens, TTheme, TStatics>;
|
|
32
24
|
} & TStatics;
|
|
33
|
-
export declare function composeFactory<TProps, TSlotProps, TTokens, TTheme, TStatics extends object = object>(
|
|
34
|
-
|
|
35
|
-
themeHelper: ThemeHelper<TTheme>,
|
|
36
|
-
base?: ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics>,
|
|
37
|
-
): ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics>;
|
|
38
|
-
//# sourceMappingURL=composeFactory.d.ts.map
|
|
25
|
+
export declare function composeFactory<TProps, TSlotProps, TTokens, TTheme, TStatics extends object = object>(options: ComposeFactoryOptions<TProps, TSlotProps, TTokens, TTheme, TStatics>, themeHelper: ThemeHelper<TTheme>, base?: ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics>): ComposeFactoryComponent<TProps, TSlotProps, TTokens, TTheme, TStatics>;
|
|
26
|
+
//# sourceMappingURL=composeFactory.d.ts.map
|
|
@@ -1,38 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.composeFactory = composeFactory;
|
|
4
|
-
const framework_base_1 = require(
|
|
5
|
-
const framework_base_2 = require(
|
|
6
|
-
const use_slots_1 = require(
|
|
7
|
-
const use_styling_1 = require(
|
|
4
|
+
const framework_base_1 = require("@fluentui-react-native/framework-base");
|
|
5
|
+
const framework_base_2 = require("@fluentui-react-native/framework-base");
|
|
6
|
+
const use_slots_1 = require("@fluentui-react-native/use-slots");
|
|
7
|
+
const use_styling_1 = require("@fluentui-react-native/use-styling");
|
|
8
8
|
/**
|
|
9
9
|
* options get deep merged except the tokens array gets appended
|
|
10
10
|
*/
|
|
11
11
|
const mergeOptions = {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
tokens: 'appendArray',
|
|
13
|
+
object: true,
|
|
14
14
|
};
|
|
15
15
|
function composeFactory(options, themeHelper, base) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
composeFactory((0, framework_base_1.immutableMergeCore)(mergeOptions, options,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
return component;
|
|
16
|
+
// merge options together if a base is specified
|
|
17
|
+
const baseOptions = base?.__options;
|
|
18
|
+
options = baseOptions ? (0, framework_base_1.immutableMergeCore)(mergeOptions, baseOptions, options) : { ...options };
|
|
19
|
+
// build styling if styling options are specified
|
|
20
|
+
options.useStyling = options.slotProps || options.tokens ? (0, use_styling_1.buildUseStyling)(options, themeHelper) : () => ({});
|
|
21
|
+
// build the slots hook, which will use the styling hook if it has been built
|
|
22
|
+
const useSlots = (0, use_slots_1.buildUseSlots)(options);
|
|
23
|
+
// build the staged component
|
|
24
|
+
const component = (0, framework_base_2.stagedComponent)((props) => options.useRender(props, useSlots));
|
|
25
|
+
// attach additional props to the returned component
|
|
26
|
+
component.displayName = options.displayName;
|
|
27
|
+
component.__options = options;
|
|
28
|
+
component.customize = (...tokens) => composeFactory((0, framework_base_1.immutableMergeCore)(mergeOptions, options, { tokens: tokens }), themeHelper);
|
|
29
|
+
component.compose = (customOptions) => composeFactory((0, framework_base_1.immutableMergeCore)(mergeOptions, options, customOptions), themeHelper);
|
|
30
|
+
// attach statics if specified
|
|
31
|
+
if (options.statics) {
|
|
32
|
+
Object.assign(component, options.statics);
|
|
33
|
+
}
|
|
34
|
+
return component;
|
|
37
35
|
}
|
|
38
|
-
//# sourceMappingURL=composeFactory.js.map
|
|
36
|
+
//# sourceMappingURL=composeFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composeFactory.js","sourceRoot":"","sources":["../src/composeFactory.ts"],"names":[],"mappings":";;;AACA,0EAA2E;AAE3E,0EAAwE;AAExE,gEAAiE;AACjE,oEAAqE;AAqCrE;;GAEG;AACH,MAAM,YAAY,GAAiB;IACjC,MAAM,EAAE,aAAa;IACrB,MAAM,EAAE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21
|
-
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
(Object.create
|
|
25
|
-
? function (o, v) {
|
|
26
|
-
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
27
|
-
}
|
|
28
|
-
: function (o, v) {
|
|
29
|
-
o['default'] = v;
|
|
30
|
-
});
|
|
31
|
-
var __importStar =
|
|
32
|
-
(this && this.__importStar) ||
|
|
33
|
-
(function () {
|
|
34
|
-
var ownKeys = function (o) {
|
|
35
|
-
ownKeys =
|
|
36
|
-
Object.getOwnPropertyNames ||
|
|
37
|
-
function (o) {
|
|
38
|
-
var ar = [];
|
|
39
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
40
|
-
return ar;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
41
24
|
};
|
|
42
|
-
|
|
25
|
+
return ownKeys(o);
|
|
43
26
|
};
|
|
44
27
|
return function (mod) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
50
33
|
};
|
|
51
|
-
|
|
52
|
-
Object.defineProperty(exports,
|
|
53
|
-
const jsx_runtime_1 = require(
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const jsx_runtime_1 = require("@fluentui-react-native/framework-base/jsx-runtime");
|
|
54
37
|
/** @jsxImportSource @fluentui-react-native/framework-base */
|
|
55
|
-
const react_1 = require(
|
|
56
|
-
const react_native_1 = require(
|
|
57
|
-
const renderer = __importStar(require(
|
|
58
|
-
const composeFactory_1 = require(
|
|
38
|
+
const react_1 = require("react");
|
|
39
|
+
const react_native_1 = require("react-native");
|
|
40
|
+
const renderer = __importStar(require("react-test-renderer"));
|
|
41
|
+
const composeFactory_1 = require("./composeFactory");
|
|
59
42
|
const theme = {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
43
|
+
values: {
|
|
44
|
+
backgroundColor: 'black',
|
|
45
|
+
color: 'white',
|
|
46
|
+
},
|
|
47
|
+
components: {},
|
|
65
48
|
};
|
|
66
49
|
const themeHelper = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
50
|
+
useTheme: () => theme,
|
|
51
|
+
getComponentInfo: (theme, name) => {
|
|
52
|
+
return theme?.components ?? theme.components[name];
|
|
53
|
+
},
|
|
71
54
|
};
|
|
72
55
|
function mergeProps(p1, p2) {
|
|
73
|
-
|
|
56
|
+
return { ...p1, ...p2 };
|
|
74
57
|
}
|
|
75
|
-
const Base = (0, composeFactory_1.composeFactory)(
|
|
76
|
-
{
|
|
58
|
+
const Base = (0, composeFactory_1.composeFactory)({
|
|
77
59
|
tokens: [
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
60
|
+
(t) => ({
|
|
61
|
+
backgroundColor: t.values.backgroundColor,
|
|
62
|
+
color: t.values.color,
|
|
63
|
+
}),
|
|
82
64
|
],
|
|
83
65
|
slotProps: {
|
|
84
|
-
|
|
85
|
-
|
|
66
|
+
outer: (tokens) => ({ style: { backgroundColor: tokens.backgroundColor } }),
|
|
67
|
+
content: (tokens) => ({ style: { color: tokens.color } }),
|
|
86
68
|
},
|
|
87
69
|
slots: {
|
|
88
|
-
|
|
89
|
-
|
|
70
|
+
outer: react_native_1.View,
|
|
71
|
+
content: react_native_1.Text,
|
|
90
72
|
},
|
|
91
73
|
useRender: (props, useSlots) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
jsx_runtime_1.jsx(Slots.outer, { ...mergeProps(props, extra), children: jsx_runtime_1.jsx(Slots.content, { children: 'Hello' }) });
|
|
74
|
+
const Slots = useSlots(props);
|
|
75
|
+
return (extra) => (jsx_runtime_1.jsx(Slots.outer, { ...mergeProps(props, extra), children: jsx_runtime_1.jsx(Slots.content, { children: "Hello" }) }));
|
|
95
76
|
},
|
|
96
|
-
|
|
97
|
-
themeHelper,
|
|
98
|
-
);
|
|
77
|
+
}, themeHelper);
|
|
99
78
|
const Customized = Base.customize({ backgroundColor: 'pink' });
|
|
100
79
|
const mixinStyle = {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
80
|
+
width: 30,
|
|
81
|
+
height: 20,
|
|
82
|
+
borderColor: 'green',
|
|
83
|
+
borderWidth: 1,
|
|
105
84
|
};
|
|
106
85
|
describe('composeFactory test suite', () => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
86
|
+
it('Base component render', () => {
|
|
87
|
+
let component;
|
|
88
|
+
(0, react_1.act)(() => {
|
|
89
|
+
component = renderer.create(jsx_runtime_1.jsx(Base, { style: mixinStyle }));
|
|
90
|
+
});
|
|
91
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
111
92
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
93
|
+
it('Customized component render', () => {
|
|
94
|
+
let component;
|
|
95
|
+
(0, react_1.act)(() => {
|
|
96
|
+
component = renderer.create(jsx_runtime_1.jsx(Customized, { style: mixinStyle }));
|
|
97
|
+
});
|
|
98
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
118
99
|
});
|
|
119
|
-
expect(component.toJSON()).toMatchSnapshot();
|
|
120
|
-
});
|
|
121
100
|
});
|
|
122
|
-
//# sourceMappingURL=composeFactory.test.js.map
|
|
101
|
+
//# sourceMappingURL=composeFactory.test.js.map
|
package/lib-commonjs/index.d.ts
CHANGED
package/lib-commonjs/index.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.composeFactory = void 0;
|
|
4
|
-
const composeFactory_1 = require(
|
|
5
|
-
Object.defineProperty(exports,
|
|
6
|
-
|
|
7
|
-
get: function () {
|
|
8
|
-
return composeFactory_1.composeFactory;
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
|
4
|
+
const composeFactory_1 = require("./composeFactory");
|
|
5
|
+
Object.defineProperty(exports, "composeFactory", { enumerable: true, get: function () { return composeFactory_1.composeFactory; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,51 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui-react-native/composition",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Composition factories for building HOCs",
|
|
5
5
|
"keywords": [],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "",
|
|
6
8
|
"repository": {
|
|
7
9
|
"type": "git",
|
|
8
10
|
"url": "https://github.com/microsoft/fluentui-react-native",
|
|
9
11
|
"directory": "packages/framework/composition"
|
|
10
12
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
+
"main": "lib-commonjs/index.js",
|
|
14
|
+
"module": "lib/index.js",
|
|
15
|
+
"types": "lib/index.d.ts",
|
|
13
16
|
"exports": {
|
|
14
17
|
".": {
|
|
15
18
|
"types": "./lib/index.d.ts",
|
|
16
19
|
"import": "./lib/index.js",
|
|
17
|
-
"require": "./lib-commonjs/index.js"
|
|
20
|
+
"require": "./lib-commonjs/index.js",
|
|
21
|
+
"default": "./src/index.ts"
|
|
18
22
|
}
|
|
19
23
|
},
|
|
20
|
-
"main": "lib-commonjs/index.js",
|
|
21
|
-
"module": "lib/index.js",
|
|
22
|
-
"types": "lib/index.d.ts",
|
|
23
24
|
"scripts": {
|
|
24
25
|
"build": "fluentui-scripts build",
|
|
25
26
|
"build-cjs": "tsgo --outDir lib-commonjs",
|
|
26
|
-
"build-
|
|
27
|
+
"build-core": "tsgo --outDir lib --module esnext --moduleResolution bundler",
|
|
27
28
|
"clean": "fluentui-scripts clean",
|
|
28
29
|
"depcheck": "fluentui-scripts depcheck",
|
|
29
30
|
"lint": "fluentui-scripts eslint",
|
|
30
31
|
"lint-package": "fluentui-scripts lint-package",
|
|
31
|
-
"
|
|
32
|
+
"format": "fluentui-scripts format",
|
|
32
33
|
"start": "fluentui-scripts dev",
|
|
33
34
|
"start-test": "fluentui-scripts jest-watch",
|
|
34
35
|
"test": "fluentui-scripts jest",
|
|
35
36
|
"update-snapshots": "fluentui-scripts jest -u"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@fluentui-react-native/framework-base": "0.3.
|
|
39
|
-
"@fluentui-react-native/use-slots": "0.11.
|
|
40
|
-
"@fluentui-react-native/use-styling": "0.14.
|
|
39
|
+
"@fluentui-react-native/framework-base": "0.3.1",
|
|
40
|
+
"@fluentui-react-native/use-slots": "0.11.1",
|
|
41
|
+
"@fluentui-react-native/use-styling": "0.14.1"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@babel/core": "^7.20.0",
|
|
44
45
|
"@fluentui-react-native/babel-config": "0.1.1",
|
|
45
|
-
"@fluentui-react-native/eslint-config-rules": "0.1.
|
|
46
|
-
"@fluentui-react-native/jest-config": "0.1.
|
|
46
|
+
"@fluentui-react-native/eslint-config-rules": "0.1.2",
|
|
47
|
+
"@fluentui-react-native/jest-config": "0.1.0",
|
|
47
48
|
"@fluentui-react-native/kit-config": "0.1.2",
|
|
48
|
-
"@fluentui-react-native/scripts": "0.1.
|
|
49
|
+
"@fluentui-react-native/scripts": "0.1.0",
|
|
49
50
|
"@react-native/babel-preset": "^0.81.0",
|
|
50
51
|
"@types/react": "~19.1.0",
|
|
51
52
|
"@types/react-test-renderer": "^19.1.0",
|
package/src/composeFactory.ts
CHANGED
|
@@ -62,7 +62,7 @@ export function composeFactory<TProps, TSlotProps, TTokens, TTheme, TStatics ext
|
|
|
62
62
|
options = baseOptions ? immutableMergeCore<LocalOptions>(mergeOptions, baseOptions, options) : { ...options };
|
|
63
63
|
|
|
64
64
|
// build styling if styling options are specified
|
|
65
|
-
options.useStyling = options.slotProps || options.tokens ? buildUseStyling(options, themeHelper) : () => ({} as TSlotProps
|
|
65
|
+
options.useStyling = options.slotProps || options.tokens ? buildUseStyling(options, themeHelper) : () => ({}) as TSlotProps;
|
|
66
66
|
|
|
67
67
|
// build the slots hook, which will use the styling hook if it has been built
|
|
68
68
|
const useSlots = buildUseSlots(options) as UseStyledSlots<TProps, TSlotProps>;
|