@fluentui-react-native/use-slots 0.10.11 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +15 -0
- package/CHANGELOG.md +46 -1
- package/babel.config.js +1 -1
- package/lib/buildUseSlots.d.ts +11 -10
- package/lib/buildUseSlots.d.ts.map +1 -1
- package/lib/buildUseSlots.js +16 -14
- package/lib/buildUseSlots.js.map +1 -1
- package/lib/buildUseSlots.test.d.ts +1 -1
- package/lib/buildUseSlots.test.js +27 -17
- package/lib/buildUseSlots.test.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/useSlots.samples.test.d.ts +1 -1
- package/lib/useSlots.samples.test.js +228 -187
- package/lib/useSlots.samples.test.js.map +1 -1
- package/lib-commonjs/buildUseSlots.d.ts +11 -10
- package/lib-commonjs/buildUseSlots.d.ts.map +1 -1
- package/lib-commonjs/buildUseSlots.js +20 -19
- package/lib-commonjs/buildUseSlots.js.map +1 -1
- package/lib-commonjs/buildUseSlots.test.d.ts +1 -1
- package/lib-commonjs/buildUseSlots.test.js +82 -45
- package/lib-commonjs/buildUseSlots.test.js.map +1 -1
- package/lib-commonjs/index.d.ts +1 -1
- package/lib-commonjs/index.js +10 -5
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/useSlots.samples.test.d.ts +1 -1
- package/lib-commonjs/useSlots.samples.test.js +297 -215
- package/lib-commonjs/useSlots.samples.test.js.map +1 -1
- package/package.json +48 -41
- package/src/__snapshots__/useSlots.samples.test.tsx.snap +42 -42
- package/src/buildUseSlots.test.tsx +8 -5
- package/src/buildUseSlots.ts +8 -5
- package/src/useSlots.samples.test.tsx +42 -42
|
@@ -1,243 +1,325 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
});
|
|
22
|
+
var __setModuleDefault =
|
|
23
|
+
(this && this.__setModuleDefault) ||
|
|
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;
|
|
41
|
+
};
|
|
42
|
+
return ownKeys(o);
|
|
43
|
+
};
|
|
44
|
+
return function (mod) {
|
|
45
|
+
if (mod && mod.__esModule) return mod;
|
|
46
|
+
var result = {};
|
|
47
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== 'default') __createBinding(result, mod, k[i]);
|
|
48
|
+
__setModuleDefault(result, mod);
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
})();
|
|
52
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
53
|
+
const jsx_runtime_1 = require('@fluentui-react-native/framework-base/jsx-runtime');
|
|
54
|
+
/** @jsxImportSource @fluentui-react-native/framework-base */
|
|
55
|
+
const react_1 = require('react');
|
|
56
|
+
const framework_base_1 = require('@fluentui-react-native/framework-base');
|
|
57
|
+
const framework_base_2 = require('@fluentui-react-native/framework-base');
|
|
58
|
+
const renderer = __importStar(require('react-test-renderer'));
|
|
59
|
+
const react_native_1 = require('react-native');
|
|
60
|
+
const buildUseSlots_1 = require('./buildUseSlots');
|
|
30
61
|
/**
|
|
31
62
|
* This file contains samples and description to help explain what the useSlots hook does and why it is useful
|
|
32
63
|
* for building components.
|
|
33
64
|
*/
|
|
34
65
|
describe('useSlots sample code test suite', () => {
|
|
66
|
+
/**
|
|
67
|
+
* The first mechanism to understand is the stagedComponent mechanic. This allows a component to be written, separating
|
|
68
|
+
* hook calls and component rendering. This allows it to be safely called as a function by a higher order component, even conditionally.
|
|
69
|
+
*/
|
|
70
|
+
/**
|
|
71
|
+
* Example #1: Single level simple component ----------------------------------------
|
|
72
|
+
*
|
|
73
|
+
* First we are going to create a wrapped text component that bolds all text. One component will be authored as a staged
|
|
74
|
+
* component and one as a regular component.
|
|
75
|
+
*/
|
|
76
|
+
const boldBaseProps = { style: { fontWeight: 900 } };
|
|
77
|
+
/**
|
|
78
|
+
* First create the bold text in the standard way. This is just a function component.
|
|
79
|
+
*/
|
|
80
|
+
const BoldTextStandard = (props) => {
|
|
35
81
|
/**
|
|
36
|
-
*
|
|
37
|
-
* hook calls and component rendering. This allows it to be safely called as a function by a higher order component, even conditionally.
|
|
82
|
+
* Pick out the children to pass them on to the child Text element
|
|
38
83
|
*/
|
|
84
|
+
const { children, ...rest } = props;
|
|
39
85
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* First we are going to create a wrapped text component that bolds all text. One component will be authored as a staged
|
|
43
|
-
* component and one as a regular component.
|
|
86
|
+
* Now render the text, merging the baseProps with the style updates with the rest param. Note that this leverages the fact
|
|
87
|
+
* that mergeProps will reliably produce style objects with the same reference, given the same inputs.
|
|
44
88
|
*/
|
|
45
|
-
|
|
89
|
+
return jsx_runtime_1.jsx(react_native_1.Text, { ...(0, framework_base_1.mergeProps)(boldBaseProps, rest), children: children });
|
|
90
|
+
};
|
|
91
|
+
BoldTextStandard.displayName = 'BoldTextStandard';
|
|
92
|
+
/**
|
|
93
|
+
* To write the same component using the staged pattern is only slightly more complex. The pattern involves splitting the component rendering into
|
|
94
|
+
* two parts and executing any hooks in the first part.
|
|
95
|
+
*
|
|
96
|
+
* The phasedComponent function takes an input function of this form and wraps it in a function component that react knows how to render
|
|
97
|
+
*/
|
|
98
|
+
const BoldTextStaged = (0, framework_base_2.phasedComponent)((props) => {
|
|
46
99
|
/**
|
|
47
|
-
*
|
|
100
|
+
* This section would be where hook/styling code would go, props here would include everything coming in from the base react tree with the
|
|
101
|
+
* exception of children, which will be passed in stage 2.
|
|
48
102
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
103
|
+
return (extra) => {
|
|
104
|
+
/**
|
|
105
|
+
* extra are additional props that may be filled in by a higher order component. They should not include styling and are only props the
|
|
106
|
+
* enclosing component are passing to the JSX elements
|
|
107
|
+
*/
|
|
108
|
+
const { children, ...rest } = extra;
|
|
109
|
+
return jsx_runtime_1.jsx(react_native_1.Text, {
|
|
110
|
+
...(0, framework_base_1.mergeProps)(boldBaseProps, props, rest),
|
|
111
|
+
children: children,
|
|
112
|
+
});
|
|
59
113
|
};
|
|
60
|
-
|
|
114
|
+
});
|
|
115
|
+
BoldTextStaged.displayName = 'BoldTextStaged';
|
|
116
|
+
it('renders sample 1 - the two types of basic bold text components', () => {
|
|
117
|
+
const styleToMerge = { color: 'black' };
|
|
61
118
|
/**
|
|
62
|
-
*
|
|
63
|
-
* two parts and executing any hooks in the first part.
|
|
64
|
-
*
|
|
65
|
-
* The stagedComponent function takes an input function of this form and wraps it in a function component that react knows how to render
|
|
119
|
+
* First render the staged component. This invokes the wrapper that was built by the stagedComponent function
|
|
66
120
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return (0, framework_base_2.withSlots)("span", { ...(0, framework_base_1.mergeProps)(boldBaseProps, props, extra) }, children);
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
BoldTextStaged.displayName = 'BoldTextStaged';
|
|
81
|
-
it('renders sample 1 - the two types of basic bold text components', () => {
|
|
82
|
-
const styleToMerge = { color: 'black' };
|
|
83
|
-
/**
|
|
84
|
-
* First render the staged component. This invokes the wrapper that was built by the stagedComponent function
|
|
85
|
-
*/
|
|
86
|
-
const wrapper = renderer
|
|
87
|
-
.create((0, framework_base_2.withSlots)("div", null,
|
|
88
|
-
(0, framework_base_2.withSlots)(BoldTextStaged, { style: styleToMerge }, "Staged component at one level"),
|
|
89
|
-
(0, framework_base_2.withSlots)(BoldTextStandard, { style: styleToMerge }, "Standard component of a single level")))
|
|
90
|
-
.toJSON();
|
|
91
|
-
expect(wrapper).toMatchSnapshot();
|
|
121
|
+
let component;
|
|
122
|
+
(0, react_1.act)(() => {
|
|
123
|
+
component = renderer.create(
|
|
124
|
+
jsx_runtime_1.jsxs(react_native_1.View, {
|
|
125
|
+
children: [
|
|
126
|
+
jsx_runtime_1.jsx(BoldTextStaged, { style: styleToMerge, children: 'Staged component at one level' }),
|
|
127
|
+
jsx_runtime_1.jsx(BoldTextStandard, { style: styleToMerge, children: 'Standard component of a single level' }),
|
|
128
|
+
],
|
|
129
|
+
}),
|
|
130
|
+
);
|
|
92
131
|
});
|
|
132
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
133
|
+
});
|
|
134
|
+
/**
|
|
135
|
+
* Example #2 - Simple component containing another simple component -------------------------------------
|
|
136
|
+
*
|
|
137
|
+
* Next we will build a layer on top of the previously authored components to turn the bold text components into header components. This is
|
|
138
|
+
* to illustrate the way in which components can be commonly built on top of other simpler components.
|
|
139
|
+
*/
|
|
140
|
+
const headerBaseProps = { style: { fontSize: 20 } };
|
|
141
|
+
/**
|
|
142
|
+
* The standard way of doing things is a repeat of what happens above. Grab the children, pass them on, merge the rest of the props with
|
|
143
|
+
* base props.
|
|
144
|
+
*
|
|
145
|
+
* This again leverages style merging via mergeProps to avoid changing the references of the style objects on every render
|
|
146
|
+
*/
|
|
147
|
+
const HeaderStandard = (props) => {
|
|
148
|
+
const { children, ...rest } = props;
|
|
149
|
+
return jsx_runtime_1.jsx(BoldTextStandard, { ...(0, framework_base_1.mergeProps)(headerBaseProps, rest), children: children });
|
|
150
|
+
};
|
|
151
|
+
HeaderStandard.displayName = 'HeaderStandard';
|
|
152
|
+
/**
|
|
153
|
+
* To consume the staged component we'll use the use slots hook builder. This allows easy consumption of staged components (or standard components)
|
|
154
|
+
* This will be described in more detail further on but in this case the component has a single child component, so it only has one slot that we
|
|
155
|
+
* will call 'text'
|
|
156
|
+
*
|
|
157
|
+
* This should be built once, and consumed by the component, not built on the fly inside
|
|
158
|
+
*/
|
|
159
|
+
const useHeaderSlots = (0, buildUseSlots_1.buildUseSlots)({ slots: { text: BoldTextStaged } });
|
|
160
|
+
/**
|
|
161
|
+
* Now author the staged component using the slot hook
|
|
162
|
+
*/
|
|
163
|
+
const HeaderStaged = (0, framework_base_2.phasedComponent)((props) => {
|
|
93
164
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* to illustrate the way in which components can be commonly built on top of other simpler components.
|
|
98
|
-
*/
|
|
99
|
-
const headerBaseProps = { style: { fontSize: 20 } };
|
|
100
|
-
/**
|
|
101
|
-
* The standard way of doing things is a repeat of what happens above. Grab the children, pass them on, merge the rest of the props with
|
|
102
|
-
* base props.
|
|
165
|
+
* Call the slots hook (or any hook) outside of the inner closure. The useSlots hook will return an object with each slot as a renderable
|
|
166
|
+
* function. The hooks for sub-components will be called as part of this call. Props passed in at this point will be the props that appear
|
|
167
|
+
* in outer part of the staged component. (For this example `props`)
|
|
103
168
|
*
|
|
104
|
-
*
|
|
105
|
-
*/
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
169
|
+
* Note that while we are passing in props, in the simple usage case it isn't used and could be omitted if desired
|
|
170
|
+
* */
|
|
171
|
+
const BoldText = useHeaderSlots(props).text;
|
|
172
|
+
/** Now the inner closure, pretty much the same as before */
|
|
173
|
+
return (extra) => {
|
|
174
|
+
const { children, ...rest } = extra;
|
|
175
|
+
/**
|
|
176
|
+
* Instead of rendering the <BoldTextStageed> component directly we render using the slot. If this is a staged component it will call the
|
|
177
|
+
* inner closure directly, without going through createElement. Entries passed into the JSX, including children, are what appear in the
|
|
178
|
+
* props of the inner closure. (In this example `extra`)
|
|
179
|
+
*
|
|
180
|
+
* NOTE: this requires using the withSlots helper via the jsx directive. This knows how to pick apart the entries and just call the second
|
|
181
|
+
* part of the function
|
|
182
|
+
*/
|
|
183
|
+
return jsx_runtime_1.jsx(BoldText, { ...(0, framework_base_1.mergeProps)(headerBaseProps, props, rest), children: children });
|
|
109
184
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const useHeaderSlots = (0, buildUseSlots_1.buildUseSlots)({ slots: { text: BoldTextStaged } });
|
|
185
|
+
});
|
|
186
|
+
HeaderStaged.displayName = 'HeaderStaged';
|
|
187
|
+
/**
|
|
188
|
+
* Look at the snapshots to compare the rendered output. The staged component will skip the intermediate levels of the react hieararchy while
|
|
189
|
+
* still rendering to the correct primitives.
|
|
190
|
+
*/
|
|
191
|
+
it('renders sample 2 = the two types of two level header components', () => {
|
|
192
|
+
const styleToMerge = { color: 'black' };
|
|
119
193
|
/**
|
|
120
|
-
*
|
|
194
|
+
* First render the staged component. This invokes the wrapper that was built by the stagedComponent function
|
|
121
195
|
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return (extra, children) => {
|
|
133
|
-
/**
|
|
134
|
-
* Instead of rendering the <BoldTextStageed> component directly we render using the slot. If this is a staged component it will call the
|
|
135
|
-
* inner closure directly, without going through createElement. Entries passed into the JSX, including children, are what appear in the
|
|
136
|
-
* props of the inner closure. (In this example `extra`)
|
|
137
|
-
*
|
|
138
|
-
* NOTE: this requires using the withSlots helper via the jsx directive. This knows how to pick apart the entries and just call the second
|
|
139
|
-
* part of the function
|
|
140
|
-
*/
|
|
141
|
-
return (0, framework_base_2.withSlots)(BoldText, { ...(0, framework_base_1.mergeProps)(headerBaseProps, props, extra) }, children);
|
|
142
|
-
};
|
|
196
|
+
let component;
|
|
197
|
+
(0, react_1.act)(() => {
|
|
198
|
+
component = renderer.create(
|
|
199
|
+
jsx_runtime_1.jsxs('div', {
|
|
200
|
+
children: [
|
|
201
|
+
jsx_runtime_1.jsx(HeaderStaged, { style: styleToMerge, children: 'Staged component with two levels' }),
|
|
202
|
+
jsx_runtime_1.jsx(HeaderStandard, { style: styleToMerge, children: 'Standard component with two levels' }),
|
|
203
|
+
],
|
|
204
|
+
}),
|
|
205
|
+
);
|
|
143
206
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
207
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
208
|
+
});
|
|
209
|
+
/** standard props for the container */
|
|
210
|
+
const containerProps = { style: { display: 'flex', flexDirection: 'column' } };
|
|
211
|
+
/**
|
|
212
|
+
* add a quick cache to ensure that we don't thrash the styles. This is a danger any time a value from a style is added as
|
|
213
|
+
* a prop on a component
|
|
214
|
+
*/
|
|
215
|
+
const colorProps = {};
|
|
216
|
+
const getColorProps = (value) => {
|
|
217
|
+
if (value !== undefined) {
|
|
218
|
+
colorProps[value] = colorProps[value] || { style: { color: value } };
|
|
219
|
+
return colorProps[value];
|
|
220
|
+
}
|
|
221
|
+
return {};
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* now just create the component like a standard react functional component
|
|
225
|
+
*/
|
|
226
|
+
const CaptionedHeaderStandard = (props) => {
|
|
227
|
+
const { headerColor, captionColor, captionText, children, ...rest } = props;
|
|
228
|
+
const headerColorProps = getColorProps(headerColor);
|
|
229
|
+
const captionColorProps = getColorProps(captionColor);
|
|
230
|
+
return jsx_runtime_1.jsxs(react_native_1.View, {
|
|
231
|
+
...(0, framework_base_1.mergeProps)(containerProps, rest),
|
|
232
|
+
children: [
|
|
233
|
+
jsx_runtime_1.jsx(HeaderStandard, { ...headerColorProps, children: children }),
|
|
234
|
+
captionText && jsx_runtime_1.jsx(BoldTextStandard, { ...captionColorProps, children: captionText }),
|
|
235
|
+
],
|
|
160
236
|
});
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
237
|
+
};
|
|
238
|
+
CaptionedHeaderStandard.displayName = `CaptionedHeaderStandard';`;
|
|
239
|
+
/**
|
|
240
|
+
* now build the same component using slots hook. This will also add use of the style injection pattern
|
|
241
|
+
*/
|
|
242
|
+
const useCaptionedHeaderSlots = (0, buildUseSlots_1.buildUseSlots)({
|
|
243
|
+
/** Slots are just like above, this component will have three sub-components */
|
|
244
|
+
slots: {
|
|
245
|
+
container: react_native_1.View,
|
|
246
|
+
header: HeaderStaged,
|
|
247
|
+
caption: BoldTextStaged,
|
|
248
|
+
},
|
|
249
|
+
/** useStyling is an optional function that turns props into props for the sub-components */
|
|
250
|
+
useStyling: (props) => ({
|
|
251
|
+
container: containerProps,
|
|
252
|
+
header: getColorProps(props.headerColor),
|
|
253
|
+
caption: getColorProps(props.captionColor),
|
|
254
|
+
}),
|
|
255
|
+
});
|
|
256
|
+
/** a mask to clear props that we don't want to pass to the inner view */
|
|
257
|
+
const clearCustomProps = { headerColor: undefined, captionColor: undefined };
|
|
258
|
+
/**
|
|
259
|
+
* now use the hook to implement it as a staged component
|
|
260
|
+
*/
|
|
261
|
+
const CaptionedHeaderStaged = (0, framework_base_2.phasedComponent)((props) => {
|
|
262
|
+
// At the point where this is called the slots are initialized with the initial prop values from useStyling above
|
|
263
|
+
const Slots = useCaptionedHeaderSlots(props);
|
|
264
|
+
return (extra) => {
|
|
265
|
+
// merge the props together, picking out the caption text and clearing any custom values we don't want forwarded to the view
|
|
266
|
+
const { children, captionText, ...rest } = (0, framework_base_1.mergeProps)(props, extra, clearCustomProps);
|
|
267
|
+
// now render using the slots. Any values passed in via JSX will be merged with values from the slot hook above
|
|
268
|
+
return jsx_runtime_1.jsxs(Slots.container, {
|
|
269
|
+
...rest,
|
|
270
|
+
children: [
|
|
271
|
+
jsx_runtime_1.jsx(Slots.header, { children: children }),
|
|
272
|
+
captionText && jsx_runtime_1.jsx(Slots.caption, { children: captionText }),
|
|
273
|
+
],
|
|
274
|
+
});
|
|
174
275
|
};
|
|
276
|
+
});
|
|
277
|
+
CaptionedHeaderStaged.displayName = 'CaptionedHeaderStaged';
|
|
278
|
+
it('renders sample 3 - the two types of higher order header components', () => {
|
|
279
|
+
const styleToMerge = { backgroundColor: 'gray', borderColor: 'purple', borderWidth: 1 };
|
|
175
280
|
/**
|
|
176
|
-
*
|
|
281
|
+
* Render the two sets of components. Note in the snapshots how the render tree layers for the standard approach are starting
|
|
282
|
+
* to add up.
|
|
177
283
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
284
|
+
let component;
|
|
285
|
+
(0, react_1.act)(() => {
|
|
286
|
+
component = renderer.create(
|
|
287
|
+
jsx_runtime_1.jsxs('div', {
|
|
288
|
+
children: [
|
|
289
|
+
jsx_runtime_1.jsx('span', { children: '--- SIMPLE USAGE COMPARISON ---' }),
|
|
290
|
+
jsx_runtime_1.jsx(CaptionedHeaderStandard, { style: styleToMerge, children: 'Standard HOC' }),
|
|
291
|
+
jsx_runtime_1.jsx(CaptionedHeaderStaged, { style: styleToMerge, children: 'Staged HOC' }),
|
|
292
|
+
jsx_runtime_1.jsx('span', { children: '--- COMPARISON WITH CAPTIONS ---' }),
|
|
293
|
+
jsx_runtime_1.jsx(CaptionedHeaderStandard, {
|
|
294
|
+
style: styleToMerge,
|
|
295
|
+
captionText: 'Caption text',
|
|
296
|
+
children: 'Standard HOC with Caption',
|
|
297
|
+
}),
|
|
298
|
+
jsx_runtime_1.jsx(CaptionedHeaderStaged, {
|
|
299
|
+
style: styleToMerge,
|
|
300
|
+
captionText: 'Caption text',
|
|
301
|
+
children: 'Staged HOC with Caption',
|
|
302
|
+
}),
|
|
303
|
+
jsx_runtime_1.jsx('span', { children: '--- COMPARISON WITH CAPTIONS AND CUSTOMIZATIONS ---' }),
|
|
304
|
+
jsx_runtime_1.jsx(CaptionedHeaderStandard, {
|
|
305
|
+
style: styleToMerge,
|
|
306
|
+
captionText: 'Caption text',
|
|
307
|
+
captionColor: 'yellow',
|
|
308
|
+
headerColor: 'red',
|
|
309
|
+
children: 'Standard HOC with caption and customizations',
|
|
310
|
+
}),
|
|
311
|
+
jsx_runtime_1.jsx(CaptionedHeaderStaged, {
|
|
312
|
+
style: styleToMerge,
|
|
313
|
+
captionText: 'Caption text',
|
|
314
|
+
captionColor: 'yellow',
|
|
315
|
+
headerColor: 'red',
|
|
316
|
+
children: 'Staged HOC with caption and customizations',
|
|
317
|
+
}),
|
|
318
|
+
],
|
|
202
319
|
}),
|
|
320
|
+
);
|
|
203
321
|
});
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* now use the hook to implement it as a staged component
|
|
208
|
-
*/
|
|
209
|
-
const CaptionedHeaderStaged = (0, framework_base_2.stagedComponent)((props) => {
|
|
210
|
-
// At the point where this is called the slots are initialized with the initial prop values from useStyling above
|
|
211
|
-
const Slots = useCaptionedHeaderSlots(props);
|
|
212
|
-
return (extra, children) => {
|
|
213
|
-
// merge the props together, picking out the caption text and clearing any custom values we don't want forwarded to the view
|
|
214
|
-
const { captionText, ...rest } = (0, framework_base_1.mergeProps)(props, extra, clearCustomProps);
|
|
215
|
-
// now render using the slots. Any values passed in via JSX will be merged with values from the slot hook above
|
|
216
|
-
return ((0, framework_base_2.withSlots)(Slots.container, { ...rest },
|
|
217
|
-
(0, framework_base_2.withSlots)(Slots.header, null, children),
|
|
218
|
-
captionText && (0, framework_base_2.withSlots)(Slots.caption, null, captionText)));
|
|
219
|
-
};
|
|
220
|
-
});
|
|
221
|
-
CaptionedHeaderStaged.displayName = 'CaptionedHeaderStaged';
|
|
222
|
-
it('renders sample 3 - the two types of higher order header components', () => {
|
|
223
|
-
const styleToMerge = { backgroundColor: 'gray', borderColor: 'purple', borderWidth: 1 };
|
|
224
|
-
/**
|
|
225
|
-
* Render the two sets of components. Note in the snapshots how the render tree layers for the standard approach are starting
|
|
226
|
-
* to add up.
|
|
227
|
-
*/
|
|
228
|
-
const wrapper = renderer
|
|
229
|
-
.create((0, framework_base_2.withSlots)("div", null,
|
|
230
|
-
(0, framework_base_2.withSlots)("span", null, "--- SIMPLE USAGE COMPARISON ---"),
|
|
231
|
-
(0, framework_base_2.withSlots)(CaptionedHeaderStandard, { style: styleToMerge }, "Standard HOC"),
|
|
232
|
-
(0, framework_base_2.withSlots)(CaptionedHeaderStaged, { style: styleToMerge }, "Staged HOC"),
|
|
233
|
-
(0, framework_base_2.withSlots)("span", null, "--- COMPARISON WITH CAPTIONS ---"),
|
|
234
|
-
(0, framework_base_2.withSlots)(CaptionedHeaderStandard, { style: styleToMerge, captionText: "Caption text" }, "Standard HOC with Caption"),
|
|
235
|
-
(0, framework_base_2.withSlots)(CaptionedHeaderStaged, { style: styleToMerge, captionText: "Caption text" }, "Staged HOC with Caption"),
|
|
236
|
-
(0, framework_base_2.withSlots)("span", null, "--- COMPARISON WITH CAPTIONS AND CUSTOMIZATIONS ---"),
|
|
237
|
-
(0, framework_base_2.withSlots)(CaptionedHeaderStandard, { style: styleToMerge, captionText: "Caption text", captionColor: "yellow", headerColor: "red" }, "Standard HOC with caption and customizations"),
|
|
238
|
-
(0, framework_base_2.withSlots)(CaptionedHeaderStaged, { style: styleToMerge, captionText: "Caption text", captionColor: "yellow", headerColor: "red" }, "Staged HOC with caption and customizations")))
|
|
239
|
-
.toJSON();
|
|
240
|
-
expect(wrapper).toMatchSnapshot();
|
|
241
|
-
});
|
|
322
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
323
|
+
});
|
|
242
324
|
});
|
|
243
|
-
//# sourceMappingURL=useSlots.samples.test.js.map
|
|
325
|
+
//# sourceMappingURL=useSlots.samples.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlots.samples.test.js","sourceRoot":"","sources":["../src/useSlots.samples.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSlots.samples.test.js","sourceRoot":"","sources":["../src/useSlots.samples.test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAA6D;AAC7D,iCAA4B;AAC5B,0EAAmE;AACnE,0EAAwE;AACxE,MAAY,QAAQ,gDAA4B;AAChD,+CAA0C;AAG1C,mDAAgD;AAEhD;;;GAGG;AAEH,QAAQ,CAAC,iCAAiC,EAAE,GAAG,EAAE,CAAC;IAChD;;;OAGG;IAEH;;;;;OAKG;IAEH,MAAM,aAAa,GAAc,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE,CAAC;IAEhE;;OAEG;IACH,MAAM,gBAAgB,GAAgE,CAAC,KAAyC,EAAE,EAAE,CAAC;QACnI;;WAEG;QACH,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;QAEpC;;;WAGG;QACH,OAAO,kBAAC,mBAAI,OAAK,IAAA,2BAAU,EAAC,aAAa,EAAE,IAAI,CAAC,YAAG,QAAQ,GAAQ,CAAC;IAAA,CACrE,CAAC;IACF,gBAAgB,CAAC,WAAW,GAAG,kBAAkB,CAAC;IAElD;;;;;OAKG;IACH,MAAM,cAAc,GAAG,IAAA,gCAAe,EAAC,CAAC,KAAyC,EAAE,EAAE,CAAC;QACpF;;;WAGG;QACH,OAAO,CAAC,KAAyC,EAAE,EAAE,CAAC;YACpD;;;eAGG;YAEH,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;YACpC,OAAO,kBAAC,mBAAI,OAAK,IAAA,2BAAU,EAAC,aAAa,EAAE,KAAK,EAA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