@fluentui-react-native/framework-base 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.json +16 -1
  2. package/CHANGELOG.md +10 -2
  3. package/lib/component-patterns/renderSlot.d.ts +21 -0
  4. package/lib/component-patterns/renderSlot.d.ts.map +1 -0
  5. package/lib/component-patterns/renderSlot.js +14 -0
  6. package/lib/component-patterns/renderSlot.js.map +1 -0
  7. package/lib/component-patterns/stagedComponent.d.ts +39 -0
  8. package/lib/component-patterns/stagedComponent.d.ts.map +1 -0
  9. package/lib/component-patterns/stagedComponent.js +20 -0
  10. package/lib/component-patterns/stagedComponent.js.map +1 -0
  11. package/lib/component-patterns/withSlots.d.ts +15 -0
  12. package/lib/component-patterns/withSlots.d.ts.map +1 -0
  13. package/lib/component-patterns/withSlots.js +19 -0
  14. package/lib/component-patterns/withSlots.js.map +1 -0
  15. package/lib/index.d.ts +5 -0
  16. package/lib/index.d.ts.map +1 -1
  17. package/lib/index.js +4 -0
  18. package/lib/index.js.map +1 -1
  19. package/lib-commonjs/component-patterns/renderSlot.d.ts +21 -0
  20. package/lib-commonjs/component-patterns/renderSlot.d.ts.map +1 -0
  21. package/lib-commonjs/component-patterns/renderSlot.js +19 -0
  22. package/lib-commonjs/component-patterns/renderSlot.js.map +1 -0
  23. package/lib-commonjs/component-patterns/stagedComponent.d.ts +39 -0
  24. package/lib-commonjs/component-patterns/stagedComponent.d.ts.map +1 -0
  25. package/lib-commonjs/component-patterns/stagedComponent.js +25 -0
  26. package/lib-commonjs/component-patterns/stagedComponent.js.map +1 -0
  27. package/lib-commonjs/component-patterns/withSlots.d.ts +15 -0
  28. package/lib-commonjs/component-patterns/withSlots.d.ts.map +1 -0
  29. package/lib-commonjs/component-patterns/withSlots.js +23 -0
  30. package/lib-commonjs/component-patterns/withSlots.js.map +1 -0
  31. package/lib-commonjs/index.d.ts +5 -0
  32. package/lib-commonjs/index.d.ts.map +1 -1
  33. package/lib-commonjs/index.js +8 -1
  34. package/lib-commonjs/index.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/component-patterns/renderSlot.ts +27 -0
  37. package/src/component-patterns/stagedComponent.ts +53 -0
  38. package/src/component-patterns/withSlots.tsx +25 -0
  39. package/src/index.ts +7 -0
package/CHANGELOG.json CHANGED
@@ -2,7 +2,22 @@
2
2
  "name": "@fluentui-react-native/framework-base",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 16 Jul 2025 20:02:37 GMT",
5
+ "date": "Tue, 22 Jul 2025 19:02:21 GMT",
6
+ "version": "0.1.2",
7
+ "tag": "@fluentui-react-native/framework-base_v0.1.2",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "jasonmo@microsoft.com",
12
+ "package": "@fluentui-react-native/framework-base",
13
+ "commit": "21e536f6875cb6fb9c33b439f0eafe1d4debc7a4",
14
+ "comment": "centralize jsx rendering functionality in framework-base"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Wed, 16 Jul 2025 20:06:45 GMT",
6
21
  "version": "0.1.1",
7
22
  "tag": "@fluentui-react-native/framework-base_v0.1.1",
8
23
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,20 @@
1
1
  # Change Log - @fluentui-react-native/framework-base
2
2
 
3
- <!-- This log was last generated on Wed, 16 Jul 2025 20:02:37 GMT and should not be manually modified. -->
3
+ <!-- This log was last generated on Tue, 22 Jul 2025 19:02:21 GMT and should not be manually modified. -->
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.1.2
8
+
9
+ Tue, 22 Jul 2025 19:02:21 GMT
10
+
11
+ ### Patches
12
+
13
+ - centralize jsx rendering functionality in framework-base (jasonmo@microsoft.com)
14
+
7
15
  ## 0.1.1
8
16
 
9
- Wed, 16 Jul 2025 20:02:37 GMT
17
+ Wed, 16 Jul 2025 20:06:45 GMT
10
18
 
11
19
  ### Patches
12
20
 
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Component slots have a marker which allows the slot render handler to know which ones are safe to call as a function.
4
+ */
5
+ export type SlotFn<TProps> = React.FunctionComponent<TProps> & {
6
+ _canCompose?: boolean;
7
+ };
8
+ /**
9
+ * The standard element type inputs for react and react-native. This might be View or Button, or it might be 'div' in web. Effectively
10
+ * it is what react accepts for React.createElement
11
+ */
12
+ export type NativeReactType = React.ElementType<any> | string;
13
+ /**
14
+ * Renders a slot
15
+ *
16
+ * @param slot - native react type or slot function to render
17
+ * @param extraProps - additional props to mixin
18
+ * @param children - the children to pass down to the slot
19
+ */
20
+ export declare function renderSlot<TProps>(slot: NativeReactType | SlotFn<TProps>, extraProps: TProps, ...children: React.ReactNode[]): React.ReactElement<any, any>;
21
+ //# sourceMappingURL=renderSlot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderSlot.d.ts","sourceRoot":"","sources":["../../src/component-patterns/renderSlot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,gCAI5H"}
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Renders a slot
4
+ *
5
+ * @param slot - native react type or slot function to render
6
+ * @param extraProps - additional props to mixin
7
+ * @param children - the children to pass down to the slot
8
+ */
9
+ export function renderSlot(slot, extraProps, ...children) {
10
+ return typeof slot === 'function' && slot._canCompose
11
+ ? slot(extraProps, ...children)
12
+ : React.createElement(slot, extraProps, ...children);
13
+ }
14
+ //# sourceMappingURL=renderSlot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderSlot.js","sourceRoot":"","sources":["../../src/component-patterns/renderSlot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAe/B;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAS,IAAsC,EAAE,UAAkB,EAAE,GAAG,QAA2B;IAC3H,OAAO,OAAO,IAAI,KAAK,UAAU,IAAK,IAAuB,CAAC,WAAW;QACvE,CAAC,CAAE,IAAuB,CAAC,UAAU,EAAE,GAAG,QAAQ,CAAC;QACnD,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,39 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * The final rendering of the props in a staged render. This is the function component signature that matches that of
4
+ * React.createElement, children (if present) will be part of the variable args at the end.
5
+ */
6
+ export type FinalRender<TProps> = (props: TProps, ...children: React.ReactNode[]) => JSX.Element | null;
7
+ /**
8
+ * This is a pattern of rendering where a functional component can be executed in two stages rather than in a single pass.
9
+ *
10
+ * The pattern looks like:
11
+ * (props) => {
12
+ * // handle props
13
+ * // call hooks, remember these can't be conditional
14
+ * // build styles and props to pass to child components
15
+ *
16
+ * return (additionalProps, ...children) => {
17
+ * // return the actual element tree, this includes conditional branching or rendering
18
+ * // mixin additional props, props which require logic should be required in phase 1.
19
+ *
20
+ * // NOTE: This is where children will show up
21
+ * };
22
+ * }
23
+ */
24
+ export type StagedRender<TProps> = (props: TProps, ...args: any[]) => FinalRender<TProps>;
25
+ /**
26
+ * A composable function may have a two stage render function as an attached property. This allows the function to work
27
+ * in all the standard react flows, but allows for pulling out the staged render when components understand it.
28
+ */
29
+ export type ComposableFunction<TProps> = React.FunctionComponent<TProps> & {
30
+ _staged?: StagedRender<TProps>;
31
+ };
32
+ /**
33
+ * Take a staged render function and make a real component out of it
34
+ *
35
+ * @param staged - staged render function to wrap into a staged component
36
+ * @param memo - optional flag to enable wrapping the created component in a React.memo HOC
37
+ */
38
+ export declare function stagedComponent<TProps>(staged: StagedRender<TProps>, memo?: boolean): ComposableFunction<TProps>;
39
+ //# sourceMappingURL=stagedComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stagedComponent.d.ts","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;AAExG;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,YAAY,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC;AAE1F;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAM9G;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAQhH"}
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ function asArray(val) {
3
+ return Array.isArray(val) ? val : [val];
4
+ }
5
+ /**
6
+ * Take a staged render function and make a real component out of it
7
+ *
8
+ * @param staged - staged render function to wrap into a staged component
9
+ * @param memo - optional flag to enable wrapping the created component in a React.memo HOC
10
+ */
11
+ export function stagedComponent(staged, memo) {
12
+ const component = (props) => {
13
+ const { children, ...rest } = props;
14
+ return staged(rest)({}, asArray(children));
15
+ };
16
+ const stagedComponent = memo ? React.memo(component) : component;
17
+ Object.assign(stagedComponent, { _staged: staged });
18
+ return stagedComponent;
19
+ }
20
+ //# sourceMappingURL=stagedComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stagedComponent.js","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkC/B,SAAS,OAAO,CAAI,GAAY;IAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAS,MAA4B,EAAE,IAAc;IAClF,MAAM,SAAS,GAAG,CAAC,KAAsC,EAAE,EAAE;QAC3D,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;QACpC,OAAO,MAAM,CAAC,IAAc,CAAC,CAAC,EAAqC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC;IACF,MAAM,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACjE,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACpD,OAAO,eAA6C,CAAC;AACvD,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { NativeReactType } from './renderSlot';
2
+ /**
3
+ * This function is required for any module that uses slots.
4
+ *
5
+ * This function is a slot resolver that automatically evaluates slot functions to generate React elements.
6
+ * A byproduct of this resolver is that it removes slots from the React hierarchy by bypassing React.createElement.
7
+ *
8
+ * To use this function on a per-file basis, use the jsx directive targeting withSlots.
9
+ * This directive must be the FIRST LINE in the file to work correctly.
10
+ * Usage of this pragma also requires withSlots import statement.
11
+ *
12
+ * See React.createElement
13
+ */
14
+ export declare function withSlots<P>(reactType: NativeReactType, props?: (React.Attributes & P) | null, ...children: React.ReactNode[]): ReturnType<React.FunctionComponent<P>>;
15
+ //# sourceMappingURL=withSlots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withSlots.d.ts","sourceRoot":"","sources":["../../src/component-patterns/withSlots.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD;;;;;;;;;;;GAWG;AAGH,wBAAgB,SAAS,CAAC,CAAC,EACzB,SAAS,EAAE,eAAe,EAC1B,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,GAAG,IAAI,EACrC,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,GAC7B,UAAU,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAGxC"}
@@ -0,0 +1,19 @@
1
+ import { renderSlot } from './renderSlot';
2
+ /**
3
+ * This function is required for any module that uses slots.
4
+ *
5
+ * This function is a slot resolver that automatically evaluates slot functions to generate React elements.
6
+ * A byproduct of this resolver is that it removes slots from the React hierarchy by bypassing React.createElement.
7
+ *
8
+ * To use this function on a per-file basis, use the jsx directive targeting withSlots.
9
+ * This directive must be the FIRST LINE in the file to work correctly.
10
+ * Usage of this pragma also requires withSlots import statement.
11
+ *
12
+ * See React.createElement
13
+ */
14
+ // Can't use typeof on React.createElement since it's overloaded. Approximate createElement's signature for now and widen as needed.
15
+ export function withSlots(reactType, props, ...children) {
16
+ // if it is a non-string type with _canCompose set just call the function directly, otherwise call createElement as normal
17
+ return renderSlot(reactType, props, ...children);
18
+ }
19
+ //# sourceMappingURL=withSlots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withSlots.js","sourceRoot":"","sources":["../../src/component-patterns/withSlots.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;GAWG;AAEH,oIAAoI;AACpI,MAAM,UAAU,SAAS,CACvB,SAA0B,EAC1B,KAAqC,EACrC,GAAG,QAA2B;IAE9B,0HAA0H;IAC1H,OAAO,UAAU,CAAI,SAAS,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC;AACtD,CAAC"}
package/lib/index.d.ts CHANGED
@@ -6,4 +6,9 @@ export { memoize } from './memo-cache/memoize';
6
6
  export type { StyleProp } from './merge-props/mergeStyles.types';
7
7
  export { mergeStyles } from './merge-props/mergeStyles';
8
8
  export { mergeProps } from './merge-props/mergeProps';
9
+ export { renderSlot } from './component-patterns/renderSlot';
10
+ export type { SlotFn, NativeReactType } from './component-patterns/renderSlot';
11
+ export { withSlots } from './component-patterns/withSlots';
12
+ export { stagedComponent } from './component-patterns/stagedComponent';
13
+ export type { FinalRender, StagedRender, ComposableFunction } from './component-patterns/stagedComponent';
9
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAChH,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,YAAY,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAChH,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,YAAY,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC"}
package/lib/index.js CHANGED
@@ -4,4 +4,8 @@ export { getMemoCache } from './memo-cache/getMemoCache';
4
4
  export { memoize } from './memo-cache/memoize';
5
5
  export { mergeStyles } from './merge-props/mergeStyles';
6
6
  export { mergeProps } from './merge-props/mergeProps';
7
+ // component pattern exports
8
+ export { renderSlot } from './component-patterns/renderSlot';
9
+ export { withSlots } from './component-patterns/withSlots';
10
+ export { stagedComponent } from './component-patterns/stagedComponent';
7
11
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAYhH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAI/C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAYhH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAI/C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,4BAA4B;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Component slots have a marker which allows the slot render handler to know which ones are safe to call as a function.
4
+ */
5
+ export type SlotFn<TProps> = React.FunctionComponent<TProps> & {
6
+ _canCompose?: boolean;
7
+ };
8
+ /**
9
+ * The standard element type inputs for react and react-native. This might be View or Button, or it might be 'div' in web. Effectively
10
+ * it is what react accepts for React.createElement
11
+ */
12
+ export type NativeReactType = React.ElementType<any> | string;
13
+ /**
14
+ * Renders a slot
15
+ *
16
+ * @param slot - native react type or slot function to render
17
+ * @param extraProps - additional props to mixin
18
+ * @param children - the children to pass down to the slot
19
+ */
20
+ export declare function renderSlot<TProps>(slot: NativeReactType | SlotFn<TProps>, extraProps: TProps, ...children: React.ReactNode[]): React.ReactElement<any, any>;
21
+ //# sourceMappingURL=renderSlot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderSlot.d.ts","sourceRoot":"","sources":["../../src/component-patterns/renderSlot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,gCAI5H"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderSlot = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ /**
7
+ * Renders a slot
8
+ *
9
+ * @param slot - native react type or slot function to render
10
+ * @param extraProps - additional props to mixin
11
+ * @param children - the children to pass down to the slot
12
+ */
13
+ function renderSlot(slot, extraProps, ...children) {
14
+ return typeof slot === 'function' && slot._canCompose
15
+ ? slot(extraProps, ...children)
16
+ : React.createElement(slot, extraProps, ...children);
17
+ }
18
+ exports.renderSlot = renderSlot;
19
+ //# sourceMappingURL=renderSlot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderSlot.js","sourceRoot":"","sources":["../../src/component-patterns/renderSlot.ts"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAe/B;;;;;;GAMG;AACH,SAAgB,UAAU,CAAS,IAAsC,EAAE,UAAkB,EAAE,GAAG,QAA2B;IAC3H,OAAO,OAAO,IAAI,KAAK,UAAU,IAAK,IAAuB,CAAC,WAAW;QACvE,CAAC,CAAE,IAAuB,CAAC,UAAU,EAAE,GAAG,QAAQ,CAAC;QACnD,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,CAAC;AACzD,CAAC;AAJD,gCAIC"}
@@ -0,0 +1,39 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * The final rendering of the props in a staged render. This is the function component signature that matches that of
4
+ * React.createElement, children (if present) will be part of the variable args at the end.
5
+ */
6
+ export type FinalRender<TProps> = (props: TProps, ...children: React.ReactNode[]) => JSX.Element | null;
7
+ /**
8
+ * This is a pattern of rendering where a functional component can be executed in two stages rather than in a single pass.
9
+ *
10
+ * The pattern looks like:
11
+ * (props) => {
12
+ * // handle props
13
+ * // call hooks, remember these can't be conditional
14
+ * // build styles and props to pass to child components
15
+ *
16
+ * return (additionalProps, ...children) => {
17
+ * // return the actual element tree, this includes conditional branching or rendering
18
+ * // mixin additional props, props which require logic should be required in phase 1.
19
+ *
20
+ * // NOTE: This is where children will show up
21
+ * };
22
+ * }
23
+ */
24
+ export type StagedRender<TProps> = (props: TProps, ...args: any[]) => FinalRender<TProps>;
25
+ /**
26
+ * A composable function may have a two stage render function as an attached property. This allows the function to work
27
+ * in all the standard react flows, but allows for pulling out the staged render when components understand it.
28
+ */
29
+ export type ComposableFunction<TProps> = React.FunctionComponent<TProps> & {
30
+ _staged?: StagedRender<TProps>;
31
+ };
32
+ /**
33
+ * Take a staged render function and make a real component out of it
34
+ *
35
+ * @param staged - staged render function to wrap into a staged component
36
+ * @param memo - optional flag to enable wrapping the created component in a React.memo HOC
37
+ */
38
+ export declare function stagedComponent<TProps>(staged: StagedRender<TProps>, memo?: boolean): ComposableFunction<TProps>;
39
+ //# sourceMappingURL=stagedComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stagedComponent.d.ts","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;AAExG;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,YAAY,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC;AAE1F;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAM9G;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAQhH"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stagedComponent = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ function asArray(val) {
7
+ return Array.isArray(val) ? val : [val];
8
+ }
9
+ /**
10
+ * Take a staged render function and make a real component out of it
11
+ *
12
+ * @param staged - staged render function to wrap into a staged component
13
+ * @param memo - optional flag to enable wrapping the created component in a React.memo HOC
14
+ */
15
+ function stagedComponent(staged, memo) {
16
+ const component = (props) => {
17
+ const { children, ...rest } = props;
18
+ return staged(rest)({}, asArray(children));
19
+ };
20
+ const stagedComponent = memo ? React.memo(component) : component;
21
+ Object.assign(stagedComponent, { _staged: staged });
22
+ return stagedComponent;
23
+ }
24
+ exports.stagedComponent = stagedComponent;
25
+ //# sourceMappingURL=stagedComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stagedComponent.js","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.ts"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAkC/B,SAAS,OAAO,CAAI,GAAY;IAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAS,MAA4B,EAAE,IAAc;IAClF,MAAM,SAAS,GAAG,CAAC,KAAsC,EAAE,EAAE;QAC3D,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;QACpC,OAAO,MAAM,CAAC,IAAc,CAAC,CAAC,EAAqC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC;IACF,MAAM,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACjE,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACpD,OAAO,eAA6C,CAAC;AACvD,CAAC;AARD,0CAQC"}
@@ -0,0 +1,15 @@
1
+ import type { NativeReactType } from './renderSlot';
2
+ /**
3
+ * This function is required for any module that uses slots.
4
+ *
5
+ * This function is a slot resolver that automatically evaluates slot functions to generate React elements.
6
+ * A byproduct of this resolver is that it removes slots from the React hierarchy by bypassing React.createElement.
7
+ *
8
+ * To use this function on a per-file basis, use the jsx directive targeting withSlots.
9
+ * This directive must be the FIRST LINE in the file to work correctly.
10
+ * Usage of this pragma also requires withSlots import statement.
11
+ *
12
+ * See React.createElement
13
+ */
14
+ export declare function withSlots<P>(reactType: NativeReactType, props?: (React.Attributes & P) | null, ...children: React.ReactNode[]): ReturnType<React.FunctionComponent<P>>;
15
+ //# sourceMappingURL=withSlots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withSlots.d.ts","sourceRoot":"","sources":["../../src/component-patterns/withSlots.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD;;;;;;;;;;;GAWG;AAGH,wBAAgB,SAAS,CAAC,CAAC,EACzB,SAAS,EAAE,eAAe,EAC1B,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,GAAG,IAAI,EACrC,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,GAC7B,UAAU,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAGxC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withSlots = void 0;
4
+ const renderSlot_1 = require("./renderSlot");
5
+ /**
6
+ * This function is required for any module that uses slots.
7
+ *
8
+ * This function is a slot resolver that automatically evaluates slot functions to generate React elements.
9
+ * A byproduct of this resolver is that it removes slots from the React hierarchy by bypassing React.createElement.
10
+ *
11
+ * To use this function on a per-file basis, use the jsx directive targeting withSlots.
12
+ * This directive must be the FIRST LINE in the file to work correctly.
13
+ * Usage of this pragma also requires withSlots import statement.
14
+ *
15
+ * See React.createElement
16
+ */
17
+ // Can't use typeof on React.createElement since it's overloaded. Approximate createElement's signature for now and widen as needed.
18
+ function withSlots(reactType, props, ...children) {
19
+ // if it is a non-string type with _canCompose set just call the function directly, otherwise call createElement as normal
20
+ return (0, renderSlot_1.renderSlot)(reactType, props, ...children);
21
+ }
22
+ exports.withSlots = withSlots;
23
+ //# sourceMappingURL=withSlots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withSlots.js","sourceRoot":"","sources":["../../src/component-patterns/withSlots.tsx"],"names":[],"mappings":";;;AACA,6CAA0C;AAE1C;;;;;;;;;;;GAWG;AAEH,oIAAoI;AACpI,SAAgB,SAAS,CACvB,SAA0B,EAC1B,KAAqC,EACrC,GAAG,QAA2B;IAE9B,0HAA0H;IAC1H,OAAO,IAAA,uBAAU,EAAI,SAAS,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC;AACtD,CAAC;AAPD,8BAOC"}
@@ -6,4 +6,9 @@ export { memoize } from './memo-cache/memoize';
6
6
  export type { StyleProp } from './merge-props/mergeStyles.types';
7
7
  export { mergeStyles } from './merge-props/mergeStyles';
8
8
  export { mergeProps } from './merge-props/mergeProps';
9
+ export { renderSlot } from './component-patterns/renderSlot';
10
+ export type { SlotFn, NativeReactType } from './component-patterns/renderSlot';
11
+ export { withSlots } from './component-patterns/withSlots';
12
+ export { stagedComponent } from './component-patterns/stagedComponent';
13
+ export type { FinalRender, StagedRender, ComposableFunction } from './component-patterns/stagedComponent';
9
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAChH,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,YAAY,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAChH,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,YAAY,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeProps = exports.mergeStyles = exports.memoize = exports.getMemoCache = exports.filterToObjects = exports.processImmutable = exports.immutableMergeCore = exports.immutableMerge = void 0;
3
+ exports.stagedComponent = exports.withSlots = exports.renderSlot = exports.mergeProps = exports.mergeStyles = exports.memoize = exports.getMemoCache = exports.filterToObjects = exports.processImmutable = exports.immutableMergeCore = exports.immutableMerge = void 0;
4
4
  // immutable-merge exports
5
5
  var Merge_1 = require("./immutable-merge/Merge");
6
6
  Object.defineProperty(exports, "immutableMerge", { enumerable: true, get: function () { return Merge_1.immutableMerge; } });
@@ -15,4 +15,11 @@ var mergeStyles_1 = require("./merge-props/mergeStyles");
15
15
  Object.defineProperty(exports, "mergeStyles", { enumerable: true, get: function () { return mergeStyles_1.mergeStyles; } });
16
16
  var mergeProps_1 = require("./merge-props/mergeProps");
17
17
  Object.defineProperty(exports, "mergeProps", { enumerable: true, get: function () { return mergeProps_1.mergeProps; } });
18
+ // component pattern exports
19
+ var renderSlot_1 = require("./component-patterns/renderSlot");
20
+ Object.defineProperty(exports, "renderSlot", { enumerable: true, get: function () { return renderSlot_1.renderSlot; } });
21
+ var withSlots_1 = require("./component-patterns/withSlots");
22
+ Object.defineProperty(exports, "withSlots", { enumerable: true, get: function () { return withSlots_1.withSlots; } });
23
+ var stagedComponent_1 = require("./component-patterns/stagedComponent");
24
+ Object.defineProperty(exports, "stagedComponent", { enumerable: true, get: function () { return stagedComponent_1.stagedComponent; } });
18
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AAC1B,iDAAgH;AAAvG,uGAAA,cAAc,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAY9E,0DAAyD;AAAhD,4GAAA,YAAY,OAAA;AACrB,gDAA+C;AAAtC,kGAAA,OAAO,OAAA;AAIhB,yDAAwD;AAA/C,0GAAA,WAAW,OAAA;AACpB,uDAAsD;AAA7C,wGAAA,UAAU,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AAC1B,iDAAgH;AAAvG,uGAAA,cAAc,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAY9E,0DAAyD;AAAhD,4GAAA,YAAY,OAAA;AACrB,gDAA+C;AAAtC,kGAAA,OAAO,OAAA;AAIhB,yDAAwD;AAA/C,0GAAA,WAAW,OAAA;AACpB,uDAAsD;AAA7C,wGAAA,UAAU,OAAA;AAEnB,4BAA4B;AAC5B,8DAA6D;AAApD,wGAAA,UAAU,OAAA;AAEnB,4DAA2D;AAAlD,sGAAA,SAAS,OAAA;AAClB,wEAAuE;AAA9D,kHAAA,eAAe,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui-react-native/framework-base",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Base types and utilities fluentui-react-native frameworks",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * Component slots have a marker which allows the slot render handler to know which ones are safe to call as a function.
5
+ */
6
+ export type SlotFn<TProps> = React.FunctionComponent<TProps> & {
7
+ _canCompose?: boolean;
8
+ };
9
+
10
+ /**
11
+ * The standard element type inputs for react and react-native. This might be View or Button, or it might be 'div' in web. Effectively
12
+ * it is what react accepts for React.createElement
13
+ */
14
+ export type NativeReactType = React.ElementType<any> | string;
15
+
16
+ /**
17
+ * Renders a slot
18
+ *
19
+ * @param slot - native react type or slot function to render
20
+ * @param extraProps - additional props to mixin
21
+ * @param children - the children to pass down to the slot
22
+ */
23
+ export function renderSlot<TProps>(slot: NativeReactType | SlotFn<TProps>, extraProps: TProps, ...children: React.ReactNode[]) {
24
+ return typeof slot === 'function' && (slot as SlotFn<TProps>)._canCompose
25
+ ? (slot as SlotFn<TProps>)(extraProps, ...children)
26
+ : React.createElement(slot, extraProps, ...children);
27
+ }
@@ -0,0 +1,53 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * The final rendering of the props in a staged render. This is the function component signature that matches that of
5
+ * React.createElement, children (if present) will be part of the variable args at the end.
6
+ */
7
+ export type FinalRender<TProps> = (props: TProps, ...children: React.ReactNode[]) => JSX.Element | null;
8
+
9
+ /**
10
+ * This is a pattern of rendering where a functional component can be executed in two stages rather than in a single pass.
11
+ *
12
+ * The pattern looks like:
13
+ * (props) => {
14
+ * // handle props
15
+ * // call hooks, remember these can't be conditional
16
+ * // build styles and props to pass to child components
17
+ *
18
+ * return (additionalProps, ...children) => {
19
+ * // return the actual element tree, this includes conditional branching or rendering
20
+ * // mixin additional props, props which require logic should be required in phase 1.
21
+ *
22
+ * // NOTE: This is where children will show up
23
+ * };
24
+ * }
25
+ */
26
+
27
+ export type StagedRender<TProps> = (props: TProps, ...args: any[]) => FinalRender<TProps>;
28
+
29
+ /**
30
+ * A composable function may have a two stage render function as an attached property. This allows the function to work
31
+ * in all the standard react flows, but allows for pulling out the staged render when components understand it.
32
+ */
33
+ export type ComposableFunction<TProps> = React.FunctionComponent<TProps> & { _staged?: StagedRender<TProps> };
34
+
35
+ function asArray<T>(val: T | T[]): T[] {
36
+ return Array.isArray(val) ? val : [val];
37
+ }
38
+
39
+ /**
40
+ * Take a staged render function and make a real component out of it
41
+ *
42
+ * @param staged - staged render function to wrap into a staged component
43
+ * @param memo - optional flag to enable wrapping the created component in a React.memo HOC
44
+ */
45
+ export function stagedComponent<TProps>(staged: StagedRender<TProps>, memo?: boolean): ComposableFunction<TProps> {
46
+ const component = (props: React.PropsWithChildren<TProps>) => {
47
+ const { children, ...rest } = props;
48
+ return staged(rest as TProps)({} as React.PropsWithChildren<TProps>, asArray(children));
49
+ };
50
+ const stagedComponent = memo ? React.memo(component) : component;
51
+ Object.assign(stagedComponent, { _staged: staged });
52
+ return stagedComponent as ComposableFunction<TProps>;
53
+ }
@@ -0,0 +1,25 @@
1
+ import type { NativeReactType } from './renderSlot';
2
+ import { renderSlot } from './renderSlot';
3
+
4
+ /**
5
+ * This function is required for any module that uses slots.
6
+ *
7
+ * This function is a slot resolver that automatically evaluates slot functions to generate React elements.
8
+ * A byproduct of this resolver is that it removes slots from the React hierarchy by bypassing React.createElement.
9
+ *
10
+ * To use this function on a per-file basis, use the jsx directive targeting withSlots.
11
+ * This directive must be the FIRST LINE in the file to work correctly.
12
+ * Usage of this pragma also requires withSlots import statement.
13
+ *
14
+ * See React.createElement
15
+ */
16
+
17
+ // Can't use typeof on React.createElement since it's overloaded. Approximate createElement's signature for now and widen as needed.
18
+ export function withSlots<P>(
19
+ reactType: NativeReactType,
20
+ props?: (React.Attributes & P) | null,
21
+ ...children: React.ReactNode[]
22
+ ): ReturnType<React.FunctionComponent<P>> {
23
+ // if it is a non-string type with _canCompose set just call the function directly, otherwise call createElement as normal
24
+ return renderSlot<P>(reactType, props, ...children);
25
+ }
package/src/index.ts CHANGED
@@ -18,3 +18,10 @@ export { memoize } from './memo-cache/memoize';
18
18
  export type { StyleProp } from './merge-props/mergeStyles.types';
19
19
  export { mergeStyles } from './merge-props/mergeStyles';
20
20
  export { mergeProps } from './merge-props/mergeProps';
21
+
22
+ // component pattern exports
23
+ export { renderSlot } from './component-patterns/renderSlot';
24
+ export type { SlotFn, NativeReactType } from './component-patterns/renderSlot';
25
+ export { withSlots } from './component-patterns/withSlots';
26
+ export { stagedComponent } from './component-patterns/stagedComponent';
27
+ export type { FinalRender, StagedRender, ComposableFunction } from './component-patterns/stagedComponent';