@ukic/canary-react 2.0.0-canary.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/components.d.ts +62 -0
- package/dist/components.js +66 -0
- package/dist/core/core.css +101 -0
- package/dist/core/normalize.css +440 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/react-component-lib/createComponent.d.ts +10 -0
- package/dist/react-component-lib/createComponent.js +74 -0
- package/dist/react-component-lib/createOverlayComponent.d.ts +21 -0
- package/dist/react-component-lib/createOverlayComponent.js +108 -0
- package/dist/react-component-lib/index.d.ts +2 -0
- package/dist/react-component-lib/index.js +2 -0
- package/dist/react-component-lib/interfaces.d.ts +29 -0
- package/dist/react-component-lib/interfaces.js +1 -0
- package/dist/react-component-lib/slottedSVG.d.ts +2 -0
- package/dist/react-component-lib/slottedSVG.js +24 -0
- package/dist/react-component-lib/utils/attachProps.d.ts +12 -0
- package/dist/react-component-lib/utils/attachProps.js +97 -0
- package/dist/react-component-lib/utils/case.d.ts +2 -0
- package/dist/react-component-lib/utils/case.js +6 -0
- package/dist/react-component-lib/utils/dev.d.ts +2 -0
- package/dist/react-component-lib/utils/dev.js +12 -0
- package/dist/react-component-lib/utils/index.d.ts +10 -0
- package/dist/react-component-lib/utils/index.js +31 -0
- package/package.json +76 -0
@@ -0,0 +1,440 @@
|
|
1
|
+
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
|
2
|
+
|
3
|
+
/* Document
|
4
|
+
========================================================================== */
|
5
|
+
|
6
|
+
/**
|
7
|
+
* 1. Correct the line height in all browsers.
|
8
|
+
* 2. Prevent adjustments of font size after orientation changes in iOS.
|
9
|
+
*/
|
10
|
+
|
11
|
+
html {
|
12
|
+
line-height: 1.15; /* 1 */
|
13
|
+
-webkit-text-size-adjust: 100%; /* 2 */
|
14
|
+
}
|
15
|
+
|
16
|
+
/* Sections
|
17
|
+
========================================================================== */
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Remove the margin in all browsers.
|
21
|
+
*/
|
22
|
+
|
23
|
+
body {
|
24
|
+
margin: 0;
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Render the `main` element consistently in IE.
|
29
|
+
*/
|
30
|
+
|
31
|
+
main {
|
32
|
+
display: block;
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Correct the font size and margin on `h1` elements within `section` and
|
37
|
+
* `article` contexts in Chrome, Firefox, and Safari.
|
38
|
+
*/
|
39
|
+
|
40
|
+
h1 {
|
41
|
+
font-size: 2em;
|
42
|
+
margin: 0.67em 0;
|
43
|
+
}
|
44
|
+
|
45
|
+
/* Grouping content
|
46
|
+
========================================================================== */
|
47
|
+
|
48
|
+
/**
|
49
|
+
* 1. Add the correct box sizing in Firefox.
|
50
|
+
* 2. Show the overflow in Edge and IE.
|
51
|
+
*/
|
52
|
+
|
53
|
+
hr {
|
54
|
+
box-sizing: content-box; /* 1 */
|
55
|
+
height: 0; /* 1 */
|
56
|
+
overflow: visible; /* 2 */
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* 1. Correct the inheritance and scaling of font size in all browsers.
|
61
|
+
* 2. Correct the odd `em` font sizing in all browsers.
|
62
|
+
*/
|
63
|
+
|
64
|
+
pre {
|
65
|
+
font-family: monospace, monospace; /* 1 */
|
66
|
+
font-size: 1em; /* 2 */
|
67
|
+
}
|
68
|
+
|
69
|
+
/* Text-level semantics
|
70
|
+
========================================================================== */
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Remove the gray background on active links in IE 10.
|
74
|
+
*/
|
75
|
+
|
76
|
+
a {
|
77
|
+
background-color: transparent;
|
78
|
+
}
|
79
|
+
|
80
|
+
/**
|
81
|
+
* 1. Remove the bottom border in Chrome 57-
|
82
|
+
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
|
83
|
+
*/
|
84
|
+
|
85
|
+
abbr[title] {
|
86
|
+
border-bottom: none; /* 1 */
|
87
|
+
text-decoration: underline; /* 2 */
|
88
|
+
text-decoration: underline dotted; /* 2 */
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Add the correct font weight in Chrome, Edge, and Safari.
|
93
|
+
*/
|
94
|
+
|
95
|
+
b,
|
96
|
+
strong {
|
97
|
+
font-weight: bolder;
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* 1. Correct the inheritance and scaling of font size in all browsers.
|
102
|
+
* 2. Correct the odd `em` font sizing in all browsers.
|
103
|
+
*/
|
104
|
+
|
105
|
+
code,
|
106
|
+
kbd,
|
107
|
+
samp {
|
108
|
+
font-family: monospace, monospace; /* 1 */
|
109
|
+
font-size: 1em; /* 2 */
|
110
|
+
}
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Add the correct font size in all browsers.
|
114
|
+
*/
|
115
|
+
|
116
|
+
small {
|
117
|
+
font-size: 80%;
|
118
|
+
}
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Prevent `sub` and `sup` elements from affecting the line height in
|
122
|
+
* all browsers.
|
123
|
+
*/
|
124
|
+
|
125
|
+
sub,
|
126
|
+
sup {
|
127
|
+
font-size: 75%;
|
128
|
+
line-height: 0;
|
129
|
+
position: relative;
|
130
|
+
vertical-align: baseline;
|
131
|
+
}
|
132
|
+
|
133
|
+
sub {
|
134
|
+
bottom: -0.25em;
|
135
|
+
}
|
136
|
+
|
137
|
+
sup {
|
138
|
+
top: -0.5em;
|
139
|
+
}
|
140
|
+
|
141
|
+
/* Embedded content
|
142
|
+
========================================================================== */
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Remove the border on images inside links in IE 10.
|
146
|
+
*/
|
147
|
+
|
148
|
+
img {
|
149
|
+
border-style: none;
|
150
|
+
}
|
151
|
+
|
152
|
+
/* Forms
|
153
|
+
========================================================================== */
|
154
|
+
|
155
|
+
/**
|
156
|
+
* 1. Change the font styles in all browsers.
|
157
|
+
* 2. Remove the margin in Firefox and Safari.
|
158
|
+
*/
|
159
|
+
|
160
|
+
button,
|
161
|
+
input,
|
162
|
+
optgroup,
|
163
|
+
select,
|
164
|
+
textarea {
|
165
|
+
font-family: inherit; /* 1 */
|
166
|
+
font-size: 100%; /* 1 */
|
167
|
+
line-height: 1.15; /* 1 */
|
168
|
+
margin: 0; /* 2 */
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Show the overflow in IE.
|
173
|
+
* 1. Show the overflow in Edge.
|
174
|
+
*/
|
175
|
+
|
176
|
+
button,
|
177
|
+
input {
|
178
|
+
/* 1 */
|
179
|
+
overflow: visible;
|
180
|
+
}
|
181
|
+
|
182
|
+
/**
|
183
|
+
* Remove the inheritance of text transform in Edge, Firefox, and IE.
|
184
|
+
* 1. Remove the inheritance of text transform in Firefox.
|
185
|
+
*/
|
186
|
+
|
187
|
+
button,
|
188
|
+
select {
|
189
|
+
/* 1 */
|
190
|
+
text-transform: none;
|
191
|
+
}
|
192
|
+
|
193
|
+
/**
|
194
|
+
* Correct the inability to style clickable types in iOS and Safari.
|
195
|
+
*/
|
196
|
+
|
197
|
+
button,
|
198
|
+
[type="button"],
|
199
|
+
[type="reset"],
|
200
|
+
[type="submit"] {
|
201
|
+
-webkit-appearance: button;
|
202
|
+
}
|
203
|
+
|
204
|
+
/**
|
205
|
+
* Remove the inner border and padding in Firefox.
|
206
|
+
*/
|
207
|
+
|
208
|
+
button::-moz-focus-inner,
|
209
|
+
[type="button"]::-moz-focus-inner,
|
210
|
+
[type="reset"]::-moz-focus-inner,
|
211
|
+
[type="submit"]::-moz-focus-inner {
|
212
|
+
border-style: none;
|
213
|
+
padding: 0;
|
214
|
+
}
|
215
|
+
|
216
|
+
/**
|
217
|
+
* Restore the focus styles unset by the previous rule.
|
218
|
+
*/
|
219
|
+
|
220
|
+
button:-moz-focusring,
|
221
|
+
[type="button"]:-moz-focusring,
|
222
|
+
[type="reset"]:-moz-focusring,
|
223
|
+
[type="submit"]:-moz-focusring {
|
224
|
+
outline: 1px dotted ButtonText;
|
225
|
+
}
|
226
|
+
|
227
|
+
/**
|
228
|
+
* Correct the padding in Firefox.
|
229
|
+
*/
|
230
|
+
|
231
|
+
fieldset {
|
232
|
+
padding: 0.35em 0.75em 0.625em;
|
233
|
+
}
|
234
|
+
|
235
|
+
/**
|
236
|
+
* 1. Correct the text wrapping in Edge and IE.
|
237
|
+
* 2. Correct the color inheritance from `fieldset` elements in IE.
|
238
|
+
* 3. Remove the padding so developers are not caught out when they zero out
|
239
|
+
* `fieldset` elements in all browsers.
|
240
|
+
*/
|
241
|
+
|
242
|
+
legend {
|
243
|
+
box-sizing: border-box; /* 1 */
|
244
|
+
color: inherit; /* 2 */
|
245
|
+
display: table; /* 1 */
|
246
|
+
max-width: 100%; /* 1 */
|
247
|
+
padding: 0; /* 3 */
|
248
|
+
white-space: normal; /* 1 */
|
249
|
+
}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
|
253
|
+
*/
|
254
|
+
|
255
|
+
progress {
|
256
|
+
vertical-align: baseline;
|
257
|
+
}
|
258
|
+
|
259
|
+
/**
|
260
|
+
* Remove the default vertical scrollbar in IE 10+.
|
261
|
+
*/
|
262
|
+
|
263
|
+
textarea {
|
264
|
+
overflow: auto;
|
265
|
+
}
|
266
|
+
|
267
|
+
/**
|
268
|
+
* 1. Add the correct box sizing in IE 10.
|
269
|
+
* 2. Remove the padding in IE 10.
|
270
|
+
*/
|
271
|
+
|
272
|
+
[type="checkbox"],
|
273
|
+
[type="radio"] {
|
274
|
+
box-sizing: border-box; /* 1 */
|
275
|
+
padding: 0; /* 2 */
|
276
|
+
}
|
277
|
+
|
278
|
+
/**
|
279
|
+
* Correct the cursor style of increment and decrement buttons in Chrome.
|
280
|
+
*/
|
281
|
+
|
282
|
+
[type="number"]::-webkit-inner-spin-button,
|
283
|
+
[type="number"]::-webkit-outer-spin-button {
|
284
|
+
height: auto;
|
285
|
+
}
|
286
|
+
|
287
|
+
/**
|
288
|
+
* 1. Correct the odd appearance in Chrome and Safari.
|
289
|
+
* 2. Correct the outline style in Safari.
|
290
|
+
*/
|
291
|
+
|
292
|
+
[type="search"] {
|
293
|
+
-webkit-appearance: textfield; /* 1 */
|
294
|
+
outline-offset: -2px; /* 2 */
|
295
|
+
}
|
296
|
+
|
297
|
+
/**
|
298
|
+
* Remove the inner padding in Chrome and Safari on macOS.
|
299
|
+
*/
|
300
|
+
|
301
|
+
[type="search"]::-webkit-search-decoration {
|
302
|
+
-webkit-appearance: none;
|
303
|
+
}
|
304
|
+
|
305
|
+
/**
|
306
|
+
* 1. Correct the inability to style clickable types in iOS and Safari.
|
307
|
+
* 2. Change font properties to `inherit` in Safari.
|
308
|
+
*/
|
309
|
+
|
310
|
+
::-webkit-file-upload-button {
|
311
|
+
-webkit-appearance: button; /* 1 */
|
312
|
+
font: inherit; /* 2 */
|
313
|
+
}
|
314
|
+
|
315
|
+
/* Interactive
|
316
|
+
========================================================================== */
|
317
|
+
|
318
|
+
/*
|
319
|
+
* Add the correct display in Edge, IE 10+, and Firefox.
|
320
|
+
*/
|
321
|
+
|
322
|
+
details {
|
323
|
+
display: block;
|
324
|
+
}
|
325
|
+
|
326
|
+
/*
|
327
|
+
* Add the correct display in all browsers.
|
328
|
+
*/
|
329
|
+
|
330
|
+
summary {
|
331
|
+
display: list-item;
|
332
|
+
}
|
333
|
+
|
334
|
+
/* Misc
|
335
|
+
========================================================================== */
|
336
|
+
|
337
|
+
/**
|
338
|
+
* Add the correct display in IE 10+.
|
339
|
+
*/
|
340
|
+
|
341
|
+
template {
|
342
|
+
display: none;
|
343
|
+
}
|
344
|
+
|
345
|
+
/**
|
346
|
+
* Add the correct display in IE 10.
|
347
|
+
*/
|
348
|
+
|
349
|
+
[hidden] {
|
350
|
+
display: none;
|
351
|
+
}
|
352
|
+
|
353
|
+
html,
|
354
|
+
body,
|
355
|
+
div,
|
356
|
+
span,
|
357
|
+
applet,
|
358
|
+
object,
|
359
|
+
iframe,
|
360
|
+
h1,
|
361
|
+
h2,
|
362
|
+
h3,
|
363
|
+
h4,
|
364
|
+
h5,
|
365
|
+
h6,
|
366
|
+
p,
|
367
|
+
blockquote,
|
368
|
+
pre,
|
369
|
+
a,
|
370
|
+
abbr,
|
371
|
+
acronym,
|
372
|
+
address,
|
373
|
+
big,
|
374
|
+
cite,
|
375
|
+
code,
|
376
|
+
del,
|
377
|
+
dfn,
|
378
|
+
em,
|
379
|
+
img,
|
380
|
+
ins,
|
381
|
+
kbd,
|
382
|
+
q,
|
383
|
+
s,
|
384
|
+
samp,
|
385
|
+
small,
|
386
|
+
strike,
|
387
|
+
strong,
|
388
|
+
sub,
|
389
|
+
sup,
|
390
|
+
tt,
|
391
|
+
var,
|
392
|
+
b,
|
393
|
+
u,
|
394
|
+
i,
|
395
|
+
center,
|
396
|
+
dl,
|
397
|
+
dt,
|
398
|
+
dd,
|
399
|
+
ol,
|
400
|
+
ul,
|
401
|
+
li,
|
402
|
+
fieldset,
|
403
|
+
form,
|
404
|
+
label,
|
405
|
+
legend,
|
406
|
+
table,
|
407
|
+
caption,
|
408
|
+
tbody,
|
409
|
+
tfoot,
|
410
|
+
thead,
|
411
|
+
tr,
|
412
|
+
th,
|
413
|
+
td,
|
414
|
+
article,
|
415
|
+
aside,
|
416
|
+
canvas,
|
417
|
+
details,
|
418
|
+
embed,
|
419
|
+
figure,
|
420
|
+
figcaption,
|
421
|
+
footer,
|
422
|
+
header,
|
423
|
+
hgroup,
|
424
|
+
menu,
|
425
|
+
nav,
|
426
|
+
output,
|
427
|
+
ruby,
|
428
|
+
section,
|
429
|
+
summary,
|
430
|
+
time,
|
431
|
+
mark,
|
432
|
+
audio,
|
433
|
+
video {
|
434
|
+
margin: 0;
|
435
|
+
padding: 0;
|
436
|
+
border: 0;
|
437
|
+
font-size: 100%;
|
438
|
+
font-style: inherit;
|
439
|
+
vertical-align: baseline;
|
440
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
export interface HTMLStencilElement extends HTMLElement {
|
3
|
+
componentOnReady(): Promise<this>;
|
4
|
+
}
|
5
|
+
interface StencilReactInternalProps<ElementType> extends React.HTMLAttributes<ElementType> {
|
6
|
+
forwardedRef: React.RefObject<ElementType>;
|
7
|
+
ref?: React.Ref<any>;
|
8
|
+
}
|
9
|
+
export declare const createReactComponent: <PropType, ElementType extends HTMLStencilElement, ContextStateType = {}, ExpandedPropsTypes = {}>(tagName: string, ReactComponentContext?: React.Context<ContextStateType>, manipulatePropsFunction?: (originalProps: StencilReactInternalProps<ElementType>, propsToPass: any) => ExpandedPropsTypes, defineCustomElement?: () => void) => React.ForwardRefExoticComponent<React.PropsWithoutRef<PropType & Omit<React.HTMLAttributes<ElementType>, "style"> & import("./interfaces").StyleReactProps> & React.RefAttributes<ElementType>>;
|
10
|
+
export {};
|
@@ -0,0 +1,74 @@
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
2
|
+
var t = {};
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
4
|
+
t[p] = s[p];
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
8
|
+
t[p[i]] = s[p[i]];
|
9
|
+
}
|
10
|
+
return t;
|
11
|
+
};
|
12
|
+
import React, { createElement } from 'react';
|
13
|
+
import { attachProps, camelToDashCase, createForwardRef, dashToPascalCase, isCoveredByReact, mergeRefs } from './utils';
|
14
|
+
export const createReactComponent = (tagName, ReactComponentContext, manipulatePropsFunction, defineCustomElement) => {
|
15
|
+
if (defineCustomElement !== undefined) {
|
16
|
+
defineCustomElement();
|
17
|
+
}
|
18
|
+
const displayName = dashToPascalCase(tagName);
|
19
|
+
const ReactComponent = class extends React.Component {
|
20
|
+
constructor(props) {
|
21
|
+
super(props);
|
22
|
+
this.setComponentElRef = (element) => {
|
23
|
+
this.componentEl = element;
|
24
|
+
};
|
25
|
+
}
|
26
|
+
componentDidMount() {
|
27
|
+
this.componentDidUpdate(this.props);
|
28
|
+
}
|
29
|
+
componentDidUpdate(prevProps) {
|
30
|
+
attachProps(this.componentEl, this.props, prevProps);
|
31
|
+
}
|
32
|
+
render() {
|
33
|
+
const _a = this.props, { children, forwardedRef, style, className, ref } = _a, cProps = __rest(_a, ["children", "forwardedRef", "style", "className", "ref"]);
|
34
|
+
let propsToPass = Object.keys(cProps).reduce((acc, name) => {
|
35
|
+
const value = cProps[name];
|
36
|
+
if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
|
37
|
+
const eventName = name.substring(2).toLowerCase();
|
38
|
+
if (typeof document !== 'undefined' && isCoveredByReact(eventName)) {
|
39
|
+
acc[name] = value;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
else {
|
43
|
+
// we should only render strings, booleans, and numbers as attrs in html.
|
44
|
+
// objects, functions, arrays etc get synced via properties on mount.
|
45
|
+
const type = typeof value;
|
46
|
+
if (type === 'string' || type === 'boolean' || type === 'number') {
|
47
|
+
acc[camelToDashCase(name)] = value;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
return acc;
|
51
|
+
}, {});
|
52
|
+
if (manipulatePropsFunction) {
|
53
|
+
propsToPass = manipulatePropsFunction(this.props, propsToPass);
|
54
|
+
}
|
55
|
+
const newProps = Object.assign(Object.assign({}, propsToPass), { ref: mergeRefs(forwardedRef, this.setComponentElRef), style });
|
56
|
+
/**
|
57
|
+
* We use createElement here instead of
|
58
|
+
* React.createElement to work around a
|
59
|
+
* bug in Vite (https://github.com/vitejs/vite/issues/6104).
|
60
|
+
* React.createElement causes all elements to be rendered
|
61
|
+
* as <tagname> instead of the actual Web Component.
|
62
|
+
*/
|
63
|
+
return createElement(tagName, newProps, children);
|
64
|
+
}
|
65
|
+
static get displayName() {
|
66
|
+
return displayName;
|
67
|
+
}
|
68
|
+
};
|
69
|
+
// If context was passed to createReactComponent then conditionally add it to the Component Class
|
70
|
+
if (ReactComponentContext) {
|
71
|
+
ReactComponent.contextType = ReactComponentContext;
|
72
|
+
}
|
73
|
+
return createForwardRef(ReactComponent, displayName);
|
74
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { OverlayEventDetail } from './interfaces';
|
3
|
+
import { StencilReactForwardedRef } from './utils';
|
4
|
+
interface OverlayElement extends HTMLElement {
|
5
|
+
present: () => Promise<void>;
|
6
|
+
dismiss: (data?: any, role?: string | undefined) => Promise<boolean>;
|
7
|
+
}
|
8
|
+
export interface ReactOverlayProps {
|
9
|
+
children?: React.ReactNode;
|
10
|
+
isOpen: boolean;
|
11
|
+
onDidDismiss?: (event: CustomEvent<OverlayEventDetail>) => void;
|
12
|
+
onDidPresent?: (event: CustomEvent<OverlayEventDetail>) => void;
|
13
|
+
onWillDismiss?: (event: CustomEvent<OverlayEventDetail>) => void;
|
14
|
+
onWillPresent?: (event: CustomEvent<OverlayEventDetail>) => void;
|
15
|
+
}
|
16
|
+
export declare const createOverlayComponent: <OverlayComponent extends object, OverlayType extends OverlayElement>(tagName: string, controller: {
|
17
|
+
create: (options: any) => Promise<OverlayType>;
|
18
|
+
}, customElement?: any) => React.ForwardRefExoticComponent<React.PropsWithoutRef<OverlayComponent & ReactOverlayProps & {
|
19
|
+
forwardedRef?: StencilReactForwardedRef<OverlayType>;
|
20
|
+
}> & React.RefAttributes<OverlayType>>;
|
21
|
+
export {};
|
@@ -0,0 +1,108 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
11
|
+
var t = {};
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
13
|
+
t[p] = s[p];
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
17
|
+
t[p[i]] = s[p[i]];
|
18
|
+
}
|
19
|
+
return t;
|
20
|
+
};
|
21
|
+
import React from 'react';
|
22
|
+
import ReactDOM from 'react-dom';
|
23
|
+
import { attachProps, dashToPascalCase, defineCustomElement, setRef } from './utils';
|
24
|
+
export const createOverlayComponent = (tagName, controller, customElement) => {
|
25
|
+
defineCustomElement(tagName, customElement);
|
26
|
+
const displayName = dashToPascalCase(tagName);
|
27
|
+
const didDismissEventName = `on${displayName}DidDismiss`;
|
28
|
+
const didPresentEventName = `on${displayName}DidPresent`;
|
29
|
+
const willDismissEventName = `on${displayName}WillDismiss`;
|
30
|
+
const willPresentEventName = `on${displayName}WillPresent`;
|
31
|
+
let isDismissing = false;
|
32
|
+
class Overlay extends React.Component {
|
33
|
+
constructor(props) {
|
34
|
+
super(props);
|
35
|
+
if (typeof document !== 'undefined') {
|
36
|
+
this.el = document.createElement('div');
|
37
|
+
}
|
38
|
+
this.handleDismiss = this.handleDismiss.bind(this);
|
39
|
+
}
|
40
|
+
static get displayName() {
|
41
|
+
return displayName;
|
42
|
+
}
|
43
|
+
componentDidMount() {
|
44
|
+
if (this.props.isOpen) {
|
45
|
+
this.present();
|
46
|
+
}
|
47
|
+
}
|
48
|
+
componentWillUnmount() {
|
49
|
+
if (this.overlay) {
|
50
|
+
this.overlay.dismiss();
|
51
|
+
}
|
52
|
+
}
|
53
|
+
handleDismiss(event) {
|
54
|
+
if (this.props.onDidDismiss) {
|
55
|
+
this.props.onDidDismiss(event);
|
56
|
+
}
|
57
|
+
setRef(this.props.forwardedRef, null);
|
58
|
+
}
|
59
|
+
shouldComponentUpdate(nextProps) {
|
60
|
+
// Check if the overlay component is about to dismiss
|
61
|
+
if (this.overlay && nextProps.isOpen !== this.props.isOpen && nextProps.isOpen === false) {
|
62
|
+
isDismissing = true;
|
63
|
+
}
|
64
|
+
return true;
|
65
|
+
}
|
66
|
+
componentDidUpdate(prevProps) {
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
68
|
+
if (this.overlay) {
|
69
|
+
attachProps(this.overlay, this.props, prevProps);
|
70
|
+
}
|
71
|
+
if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
|
72
|
+
this.present(prevProps);
|
73
|
+
}
|
74
|
+
if (this.overlay && prevProps.isOpen !== this.props.isOpen && this.props.isOpen === false) {
|
75
|
+
yield this.overlay.dismiss();
|
76
|
+
isDismissing = false;
|
77
|
+
/**
|
78
|
+
* Now that the overlay is dismissed
|
79
|
+
* we need to render again so that any
|
80
|
+
* inner components will be unmounted
|
81
|
+
*/
|
82
|
+
this.forceUpdate();
|
83
|
+
}
|
84
|
+
});
|
85
|
+
}
|
86
|
+
present(prevProps) {
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
88
|
+
const _a = this.props, { children, isOpen, onDidDismiss, onDidPresent, onWillDismiss, onWillPresent } = _a, cProps = __rest(_a, ["children", "isOpen", "onDidDismiss", "onDidPresent", "onWillDismiss", "onWillPresent"]);
|
89
|
+
const elementProps = Object.assign(Object.assign({}, cProps), { ref: this.props.forwardedRef, [didDismissEventName]: this.handleDismiss, [didPresentEventName]: (e) => this.props.onDidPresent && this.props.onDidPresent(e), [willDismissEventName]: (e) => this.props.onWillDismiss && this.props.onWillDismiss(e), [willPresentEventName]: (e) => this.props.onWillPresent && this.props.onWillPresent(e) });
|
90
|
+
this.overlay = yield controller.create(Object.assign(Object.assign({}, elementProps), { component: this.el, componentProps: {} }));
|
91
|
+
setRef(this.props.forwardedRef, this.overlay);
|
92
|
+
attachProps(this.overlay, elementProps, prevProps);
|
93
|
+
yield this.overlay.present();
|
94
|
+
});
|
95
|
+
}
|
96
|
+
render() {
|
97
|
+
/**
|
98
|
+
* Continue to render the component even when
|
99
|
+
* overlay is dismissing otherwise component
|
100
|
+
* will be hidden before animation is done.
|
101
|
+
*/
|
102
|
+
return ReactDOM.createPortal(this.props.isOpen || isDismissing ? this.props.children : null, this.el);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
return React.forwardRef((props, ref) => {
|
106
|
+
return React.createElement(Overlay, Object.assign({}, props, { forwardedRef: ref }));
|
107
|
+
});
|
108
|
+
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
export interface EventEmitter<T = any> {
|
2
|
+
emit: (data?: T) => CustomEvent<T>;
|
3
|
+
}
|
4
|
+
export interface StyleReactProps {
|
5
|
+
class?: string;
|
6
|
+
className?: string;
|
7
|
+
style?: {
|
8
|
+
[key: string]: any;
|
9
|
+
};
|
10
|
+
}
|
11
|
+
export interface OverlayEventDetail<T = any> {
|
12
|
+
data?: T;
|
13
|
+
role?: string;
|
14
|
+
}
|
15
|
+
export interface OverlayInterface {
|
16
|
+
el: HTMLElement;
|
17
|
+
animated: boolean;
|
18
|
+
keyboardClose: boolean;
|
19
|
+
overlayIndex: number;
|
20
|
+
presented: boolean;
|
21
|
+
enterAnimation?: any;
|
22
|
+
leaveAnimation?: any;
|
23
|
+
didPresent: EventEmitter<void>;
|
24
|
+
willPresent: EventEmitter<void>;
|
25
|
+
willDismiss: EventEmitter<OverlayEventDetail>;
|
26
|
+
didDismiss: EventEmitter<OverlayEventDetail>;
|
27
|
+
present(): Promise<void>;
|
28
|
+
dismiss(data?: any, role?: string): Promise<boolean>;
|
29
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|