@nanoporetech-digital/components-react 7.3.2 → 7.4.3
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/LICENSE +0 -0
- package/README.md +0 -0
- package/dist/components.js +0 -1
- package/dist/components.js.map +1 -1
- package/dist/types/components.d.ts +0 -1
- package/package.json +17 -18
- package/CHANGELOG.md +0 -1924
- package/src/components.ts +0 -62
- package/src/index.ts +0 -1
- package/src/react-component-lib/createComponent.tsx +0 -113
- package/src/react-component-lib/createOverlayComponent.tsx +0 -162
- package/src/react-component-lib/index.ts +0 -2
- package/src/react-component-lib/interfaces.ts +0 -34
- package/src/react-component-lib/utils/attachProps.ts +0 -114
- package/src/react-component-lib/utils/case.ts +0 -8
- package/src/react-component-lib/utils/dev.ts +0 -14
- package/src/react-component-lib/utils/index.tsx +0 -57
package/src/components.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
/* tslint:disable */
|
|
3
|
-
/* auto-generated react proxies */
|
|
4
|
-
import { createReactComponent } from './react-component-lib';
|
|
5
|
-
|
|
6
|
-
import type { JSX } from '@nanoporetech-digital/components';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export const NanoAccordion = /*@__PURE__*/createReactComponent<JSX.NanoAccordion, HTMLNanoAccordionElement>('nano-accordion');
|
|
11
|
-
export const NanoAlert = /*@__PURE__*/createReactComponent<JSX.NanoAlert, HTMLNanoAlertElement>('nano-alert');
|
|
12
|
-
export const NanoAlgolia = /*@__PURE__*/createReactComponent<JSX.NanoAlgolia, HTMLNanoAlgoliaElement>('nano-algolia');
|
|
13
|
-
export const NanoAlgoliaFilter = /*@__PURE__*/createReactComponent<JSX.NanoAlgoliaFilter, HTMLNanoAlgoliaFilterElement>('nano-algolia-filter');
|
|
14
|
-
export const NanoAlgoliaPagination = /*@__PURE__*/createReactComponent<JSX.NanoAlgoliaPagination, HTMLNanoAlgoliaPaginationElement>('nano-algolia-pagination');
|
|
15
|
-
export const NanoAlgoliaResults = /*@__PURE__*/createReactComponent<JSX.NanoAlgoliaResults, HTMLNanoAlgoliaResultsElement>('nano-algolia-results');
|
|
16
|
-
export const NanoAnimation = /*@__PURE__*/createReactComponent<JSX.NanoAnimation, HTMLNanoAnimationElement>('nano-animation');
|
|
17
|
-
export const NanoCheckbox = /*@__PURE__*/createReactComponent<JSX.NanoCheckbox, HTMLNanoCheckboxElement>('nano-checkbox');
|
|
18
|
-
export const NanoCheckboxGroup = /*@__PURE__*/createReactComponent<JSX.NanoCheckboxGroup, HTMLNanoCheckboxGroupElement>('nano-checkbox-group');
|
|
19
|
-
export const NanoDatalist = /*@__PURE__*/createReactComponent<JSX.NanoDatalist, HTMLNanoDatalistElement>('nano-datalist');
|
|
20
|
-
export const NanoDateInput = /*@__PURE__*/createReactComponent<JSX.NanoDateInput, HTMLNanoDateInputElement>('nano-date-input');
|
|
21
|
-
export const NanoDatePicker = /*@__PURE__*/createReactComponent<JSX.NanoDatePicker, HTMLNanoDatePickerElement>('nano-date-picker');
|
|
22
|
-
export const NanoDemo = /*@__PURE__*/createReactComponent<JSX.NanoDemo, HTMLNanoDemoElement>('nano-demo');
|
|
23
|
-
export const NanoDetails = /*@__PURE__*/createReactComponent<JSX.NanoDetails, HTMLNanoDetailsElement>('nano-details');
|
|
24
|
-
export const NanoDialog = /*@__PURE__*/createReactComponent<JSX.NanoDialog, HTMLNanoDialogElement>('nano-dialog');
|
|
25
|
-
export const NanoDrawer = /*@__PURE__*/createReactComponent<JSX.NanoDrawer, HTMLNanoDrawerElement>('nano-drawer');
|
|
26
|
-
export const NanoDropdown = /*@__PURE__*/createReactComponent<JSX.NanoDropdown, HTMLNanoDropdownElement>('nano-dropdown');
|
|
27
|
-
export const NanoFieldValidator = /*@__PURE__*/createReactComponent<JSX.NanoFieldValidator, HTMLNanoFieldValidatorElement>('nano-field-validator');
|
|
28
|
-
export const NanoFileUpload = /*@__PURE__*/createReactComponent<JSX.NanoFileUpload, HTMLNanoFileUploadElement>('nano-file-upload');
|
|
29
|
-
export const NanoGlobalNav = /*@__PURE__*/createReactComponent<JSX.NanoGlobalNav, HTMLNanoGlobalNavElement>('nano-global-nav');
|
|
30
|
-
export const NanoGlobalNavUserProfile = /*@__PURE__*/createReactComponent<JSX.NanoGlobalNavUserProfile, HTMLNanoGlobalNavUserProfileElement>('nano-global-nav-user-profile');
|
|
31
|
-
export const NanoGlobalSearchResults = /*@__PURE__*/createReactComponent<JSX.NanoGlobalSearchResults, HTMLNanoGlobalSearchResultsElement>('nano-global-search-results');
|
|
32
|
-
export const NanoGrid = /*@__PURE__*/createReactComponent<JSX.NanoGrid, HTMLNanoGridElement>('nano-grid');
|
|
33
|
-
export const NanoGridItem = /*@__PURE__*/createReactComponent<JSX.NanoGridItem, HTMLNanoGridItemElement>('nano-grid-item');
|
|
34
|
-
export const NanoHero = /*@__PURE__*/createReactComponent<JSX.NanoHero, HTMLNanoHeroElement>('nano-hero');
|
|
35
|
-
export const NanoIcon = /*@__PURE__*/createReactComponent<JSX.NanoIcon, HTMLNanoIconElement>('nano-icon');
|
|
36
|
-
export const NanoIconButton = /*@__PURE__*/createReactComponent<JSX.NanoIconButton, HTMLNanoIconButtonElement>('nano-icon-button');
|
|
37
|
-
export const NanoImg = /*@__PURE__*/createReactComponent<JSX.NanoImg, HTMLNanoImgElement>('nano-img');
|
|
38
|
-
export const NanoInput = /*@__PURE__*/createReactComponent<JSX.NanoInput, HTMLNanoInputElement>('nano-input');
|
|
39
|
-
export const NanoIntersectionObserve = /*@__PURE__*/createReactComponent<JSX.NanoIntersectionObserve, HTMLNanoIntersectionObserveElement>('nano-intersection-observe');
|
|
40
|
-
export const NanoMenu = /*@__PURE__*/createReactComponent<JSX.NanoMenu, HTMLNanoMenuElement>('nano-menu');
|
|
41
|
-
export const NanoMenuDrawer = /*@__PURE__*/createReactComponent<JSX.NanoMenuDrawer, HTMLNanoMenuDrawerElement>('nano-menu-drawer');
|
|
42
|
-
export const NanoMoreLess = /*@__PURE__*/createReactComponent<JSX.NanoMoreLess, HTMLNanoMoreLessElement>('nano-more-less');
|
|
43
|
-
export const NanoNavItem = /*@__PURE__*/createReactComponent<JSX.NanoNavItem, HTMLNanoNavItemElement>('nano-nav-item');
|
|
44
|
-
export const NanoOption = /*@__PURE__*/createReactComponent<JSX.NanoOption, HTMLNanoOptionElement>('nano-option');
|
|
45
|
-
export const NanoOverflowNav = /*@__PURE__*/createReactComponent<JSX.NanoOverflowNav, HTMLNanoOverflowNavElement>('nano-overflow-nav');
|
|
46
|
-
export const NanoProgressBar = /*@__PURE__*/createReactComponent<JSX.NanoProgressBar, HTMLNanoProgressBarElement>('nano-progress-bar');
|
|
47
|
-
export const NanoRange = /*@__PURE__*/createReactComponent<JSX.NanoRange, HTMLNanoRangeElement>('nano-range');
|
|
48
|
-
export const NanoRating = /*@__PURE__*/createReactComponent<JSX.NanoRating, HTMLNanoRatingElement>('nano-rating');
|
|
49
|
-
export const NanoResizeObserve = /*@__PURE__*/createReactComponent<JSX.NanoResizeObserve, HTMLNanoResizeObserveElement>('nano-resize-observe');
|
|
50
|
-
export const NanoSelect = /*@__PURE__*/createReactComponent<JSX.NanoSelect, HTMLNanoSelectElement>('nano-select');
|
|
51
|
-
export const NanoSkeleton = /*@__PURE__*/createReactComponent<JSX.NanoSkeleton, HTMLNanoSkeletonElement>('nano-skeleton');
|
|
52
|
-
export const NanoSlide = /*@__PURE__*/createReactComponent<JSX.NanoSlide, HTMLNanoSlideElement>('nano-slide');
|
|
53
|
-
export const NanoSlides = /*@__PURE__*/createReactComponent<JSX.NanoSlides, HTMLNanoSlidesElement>('nano-slides');
|
|
54
|
-
export const NanoSortable = /*@__PURE__*/createReactComponent<JSX.NanoSortable, HTMLNanoSortableElement>('nano-sortable');
|
|
55
|
-
export const NanoSpinner = /*@__PURE__*/createReactComponent<JSX.NanoSpinner, HTMLNanoSpinnerElement>('nano-spinner');
|
|
56
|
-
export const NanoSplitPane = /*@__PURE__*/createReactComponent<JSX.NanoSplitPane, HTMLNanoSplitPaneElement>('nano-split-pane');
|
|
57
|
-
export const NanoSticker = /*@__PURE__*/createReactComponent<JSX.NanoSticker, HTMLNanoStickerElement>('nano-sticker');
|
|
58
|
-
export const NanoTab = /*@__PURE__*/createReactComponent<JSX.NanoTab, HTMLNanoTabElement>('nano-tab');
|
|
59
|
-
export const NanoTabContent = /*@__PURE__*/createReactComponent<JSX.NanoTabContent, HTMLNanoTabContentElement>('nano-tab-content');
|
|
60
|
-
export const NanoTabGroup = /*@__PURE__*/createReactComponent<JSX.NanoTabGroup, HTMLNanoTabGroupElement>('nano-tab-group');
|
|
61
|
-
export const NanoTable = /*@__PURE__*/createReactComponent<JSX.NanoTable, HTMLNanoTableElement>('nano-table');
|
|
62
|
-
export const NanoTooltip = /*@__PURE__*/createReactComponent<JSX.NanoTooltip, HTMLNanoTooltipElement>('nano-tooltip');
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './components';
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import React, { createElement } from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
attachProps,
|
|
5
|
-
camelToDashCase,
|
|
6
|
-
createForwardRef,
|
|
7
|
-
dashToPascalCase,
|
|
8
|
-
isCoveredByReact,
|
|
9
|
-
mergeRefs,
|
|
10
|
-
} from './utils';
|
|
11
|
-
|
|
12
|
-
export interface HTMLStencilElement extends HTMLElement {
|
|
13
|
-
componentOnReady(): Promise<this>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface StencilReactInternalProps<ElementType> extends React.HTMLAttributes<ElementType> {
|
|
17
|
-
forwardedRef: React.RefObject<ElementType>;
|
|
18
|
-
ref?: React.Ref<any>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const createReactComponent = <
|
|
22
|
-
PropType,
|
|
23
|
-
ElementType extends HTMLStencilElement,
|
|
24
|
-
ContextStateType = {},
|
|
25
|
-
ExpandedPropsTypes = {}
|
|
26
|
-
>(
|
|
27
|
-
tagName: string,
|
|
28
|
-
ReactComponentContext?: React.Context<ContextStateType>,
|
|
29
|
-
manipulatePropsFunction?: (
|
|
30
|
-
originalProps: StencilReactInternalProps<ElementType>,
|
|
31
|
-
propsToPass: any,
|
|
32
|
-
) => ExpandedPropsTypes,
|
|
33
|
-
defineCustomElement?: () => void,
|
|
34
|
-
) => {
|
|
35
|
-
if (defineCustomElement !== undefined) {
|
|
36
|
-
defineCustomElement();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const displayName = dashToPascalCase(tagName);
|
|
40
|
-
const ReactComponent = class extends React.Component<StencilReactInternalProps<ElementType>> {
|
|
41
|
-
componentEl!: ElementType;
|
|
42
|
-
|
|
43
|
-
setComponentElRef = (element: ElementType) => {
|
|
44
|
-
this.componentEl = element;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
constructor(props: StencilReactInternalProps<ElementType>) {
|
|
48
|
-
super(props);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
componentDidMount() {
|
|
52
|
-
this.componentDidUpdate(this.props);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
componentDidUpdate(prevProps: StencilReactInternalProps<ElementType>) {
|
|
56
|
-
attachProps(this.componentEl, this.props, prevProps);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
render() {
|
|
60
|
-
const { children, forwardedRef, style, className, ref, ...cProps } = this.props;
|
|
61
|
-
|
|
62
|
-
let propsToPass = Object.keys(cProps).reduce((acc: any, name) => {
|
|
63
|
-
const value = (cProps as any)[name];
|
|
64
|
-
|
|
65
|
-
if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
|
|
66
|
-
const eventName = name.substring(2).toLowerCase();
|
|
67
|
-
if (typeof document !== 'undefined' && isCoveredByReact(eventName)) {
|
|
68
|
-
acc[name] = value;
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
// we should only render strings, booleans, and numbers as attrs in html.
|
|
72
|
-
// objects, functions, arrays etc get synced via properties on mount.
|
|
73
|
-
const type = typeof value;
|
|
74
|
-
|
|
75
|
-
if (type === 'string' || type === 'boolean' || type === 'number') {
|
|
76
|
-
acc[camelToDashCase(name)] = value;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return acc;
|
|
80
|
-
}, {});
|
|
81
|
-
|
|
82
|
-
if (manipulatePropsFunction) {
|
|
83
|
-
propsToPass = manipulatePropsFunction(this.props, propsToPass);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const newProps: Omit<StencilReactInternalProps<ElementType>, 'forwardedRef'> = {
|
|
87
|
-
...propsToPass,
|
|
88
|
-
ref: mergeRefs(forwardedRef, this.setComponentElRef),
|
|
89
|
-
style,
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* We use createElement here instead of
|
|
94
|
-
* React.createElement to work around a
|
|
95
|
-
* bug in Vite (https://github.com/vitejs/vite/issues/6104).
|
|
96
|
-
* React.createElement causes all elements to be rendered
|
|
97
|
-
* as <tagname> instead of the actual Web Component.
|
|
98
|
-
*/
|
|
99
|
-
return createElement(tagName, newProps, children);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
static get displayName() {
|
|
103
|
-
return displayName;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// If context was passed to createReactComponent then conditionally add it to the Component Class
|
|
108
|
-
if (ReactComponentContext) {
|
|
109
|
-
ReactComponent.contextType = ReactComponentContext;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return createForwardRef<PropType, ElementType>(ReactComponent, displayName);
|
|
113
|
-
};
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom';
|
|
3
|
-
|
|
4
|
-
import { OverlayEventDetail } from './interfaces';
|
|
5
|
-
import {
|
|
6
|
-
StencilReactForwardedRef,
|
|
7
|
-
attachProps,
|
|
8
|
-
dashToPascalCase,
|
|
9
|
-
defineCustomElement,
|
|
10
|
-
setRef,
|
|
11
|
-
} from './utils';
|
|
12
|
-
|
|
13
|
-
interface OverlayElement extends HTMLElement {
|
|
14
|
-
present: () => Promise<void>;
|
|
15
|
-
dismiss: (data?: any, role?: string | undefined) => Promise<boolean>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface ReactOverlayProps {
|
|
19
|
-
children?: React.ReactNode;
|
|
20
|
-
isOpen: boolean;
|
|
21
|
-
onDidDismiss?: (event: CustomEvent<OverlayEventDetail>) => void;
|
|
22
|
-
onDidPresent?: (event: CustomEvent<OverlayEventDetail>) => void;
|
|
23
|
-
onWillDismiss?: (event: CustomEvent<OverlayEventDetail>) => void;
|
|
24
|
-
onWillPresent?: (event: CustomEvent<OverlayEventDetail>) => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const createOverlayComponent = <
|
|
28
|
-
OverlayComponent extends object,
|
|
29
|
-
OverlayType extends OverlayElement
|
|
30
|
-
>(
|
|
31
|
-
tagName: string,
|
|
32
|
-
controller: { create: (options: any) => Promise<OverlayType> },
|
|
33
|
-
customElement?: any
|
|
34
|
-
) => {
|
|
35
|
-
defineCustomElement(tagName, customElement);
|
|
36
|
-
|
|
37
|
-
const displayName = dashToPascalCase(tagName);
|
|
38
|
-
const didDismissEventName = `on${displayName}DidDismiss`;
|
|
39
|
-
const didPresentEventName = `on${displayName}DidPresent`;
|
|
40
|
-
const willDismissEventName = `on${displayName}WillDismiss`;
|
|
41
|
-
const willPresentEventName = `on${displayName}WillPresent`;
|
|
42
|
-
|
|
43
|
-
type Props = OverlayComponent &
|
|
44
|
-
ReactOverlayProps & {
|
|
45
|
-
forwardedRef?: StencilReactForwardedRef<OverlayType>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
let isDismissing = false;
|
|
49
|
-
|
|
50
|
-
class Overlay extends React.Component<Props> {
|
|
51
|
-
overlay?: OverlayType;
|
|
52
|
-
el!: HTMLDivElement;
|
|
53
|
-
|
|
54
|
-
constructor(props: Props) {
|
|
55
|
-
super(props);
|
|
56
|
-
if (typeof document !== 'undefined') {
|
|
57
|
-
this.el = document.createElement('div');
|
|
58
|
-
}
|
|
59
|
-
this.handleDismiss = this.handleDismiss.bind(this);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static get displayName() {
|
|
63
|
-
return displayName;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
componentDidMount() {
|
|
67
|
-
if (this.props.isOpen) {
|
|
68
|
-
this.present();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
componentWillUnmount() {
|
|
73
|
-
if (this.overlay) {
|
|
74
|
-
this.overlay.dismiss();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
handleDismiss(event: CustomEvent<OverlayEventDetail<any>>) {
|
|
79
|
-
if (this.props.onDidDismiss) {
|
|
80
|
-
this.props.onDidDismiss(event);
|
|
81
|
-
}
|
|
82
|
-
setRef(this.props.forwardedRef, null)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
shouldComponentUpdate(nextProps: Props) {
|
|
86
|
-
// Check if the overlay component is about to dismiss
|
|
87
|
-
if (this.overlay && nextProps.isOpen !== this.props.isOpen && nextProps.isOpen === false) {
|
|
88
|
-
isDismissing = true;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async componentDidUpdate(prevProps: Props) {
|
|
95
|
-
if (this.overlay) {
|
|
96
|
-
attachProps(this.overlay, this.props, prevProps);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
|
|
100
|
-
this.present(prevProps);
|
|
101
|
-
}
|
|
102
|
-
if (this.overlay && prevProps.isOpen !== this.props.isOpen && this.props.isOpen === false) {
|
|
103
|
-
await this.overlay.dismiss();
|
|
104
|
-
isDismissing = false;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Now that the overlay is dismissed
|
|
108
|
-
* we need to render again so that any
|
|
109
|
-
* inner components will be unmounted
|
|
110
|
-
*/
|
|
111
|
-
this.forceUpdate();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async present(prevProps?: Props) {
|
|
116
|
-
const {
|
|
117
|
-
children,
|
|
118
|
-
isOpen,
|
|
119
|
-
onDidDismiss,
|
|
120
|
-
onDidPresent,
|
|
121
|
-
onWillDismiss,
|
|
122
|
-
onWillPresent,
|
|
123
|
-
...cProps
|
|
124
|
-
} = this.props;
|
|
125
|
-
const elementProps = {
|
|
126
|
-
...cProps,
|
|
127
|
-
ref: this.props.forwardedRef,
|
|
128
|
-
[didDismissEventName]: this.handleDismiss,
|
|
129
|
-
[didPresentEventName]: (e: CustomEvent) =>
|
|
130
|
-
this.props.onDidPresent && this.props.onDidPresent(e),
|
|
131
|
-
[willDismissEventName]: (e: CustomEvent) =>
|
|
132
|
-
this.props.onWillDismiss && this.props.onWillDismiss(e),
|
|
133
|
-
[willPresentEventName]: (e: CustomEvent) =>
|
|
134
|
-
this.props.onWillPresent && this.props.onWillPresent(e),
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
this.overlay = await controller.create({
|
|
138
|
-
...elementProps,
|
|
139
|
-
component: this.el,
|
|
140
|
-
componentProps: {},
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
setRef(this.props.forwardedRef, this.overlay);
|
|
144
|
-
attachProps(this.overlay, elementProps, prevProps);
|
|
145
|
-
|
|
146
|
-
await this.overlay.present();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
render() {
|
|
150
|
-
/**
|
|
151
|
-
* Continue to render the component even when
|
|
152
|
-
* overlay is dismissing otherwise component
|
|
153
|
-
* will be hidden before animation is done.
|
|
154
|
-
*/
|
|
155
|
-
return ReactDOM.createPortal(this.props.isOpen || isDismissing ? this.props.children : null, this.el);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return React.forwardRef<OverlayType, Props>((props, ref) => {
|
|
160
|
-
return <Overlay {...props} forwardedRef={ref} />;
|
|
161
|
-
});
|
|
162
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// General types important to applications using stencil built components
|
|
2
|
-
export interface EventEmitter<T = any> {
|
|
3
|
-
emit: (data?: T) => CustomEvent<T>;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface StyleReactProps {
|
|
7
|
-
class?: string;
|
|
8
|
-
className?: string;
|
|
9
|
-
style?: { [key: string]: any };
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface OverlayEventDetail<T = any> {
|
|
13
|
-
data?: T;
|
|
14
|
-
role?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface OverlayInterface {
|
|
18
|
-
el: HTMLElement;
|
|
19
|
-
animated: boolean;
|
|
20
|
-
keyboardClose: boolean;
|
|
21
|
-
overlayIndex: number;
|
|
22
|
-
presented: boolean;
|
|
23
|
-
|
|
24
|
-
enterAnimation?: any;
|
|
25
|
-
leaveAnimation?: any;
|
|
26
|
-
|
|
27
|
-
didPresent: EventEmitter<void>;
|
|
28
|
-
willPresent: EventEmitter<void>;
|
|
29
|
-
willDismiss: EventEmitter<OverlayEventDetail>;
|
|
30
|
-
didDismiss: EventEmitter<OverlayEventDetail>;
|
|
31
|
-
|
|
32
|
-
present(): Promise<void>;
|
|
33
|
-
dismiss(data?: any, role?: string): Promise<boolean>;
|
|
34
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { camelToDashCase } from './case';
|
|
2
|
-
|
|
3
|
-
export const attachProps = (node: HTMLElement, newProps: any, oldProps: any = {}) => {
|
|
4
|
-
// some test frameworks don't render DOM elements, so we test here to make sure we are dealing with DOM first
|
|
5
|
-
if (node instanceof Element) {
|
|
6
|
-
// add any classes in className to the class list
|
|
7
|
-
const className = getClassName(node.classList, newProps, oldProps);
|
|
8
|
-
if (className !== '') {
|
|
9
|
-
node.className = className;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
Object.keys(newProps).forEach((name) => {
|
|
13
|
-
if (
|
|
14
|
-
name === 'children' ||
|
|
15
|
-
name === 'style' ||
|
|
16
|
-
name === 'ref' ||
|
|
17
|
-
name === 'class' ||
|
|
18
|
-
name === 'className' ||
|
|
19
|
-
name === 'forwardedRef'
|
|
20
|
-
) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
|
|
24
|
-
const eventName = name.substring(2);
|
|
25
|
-
const eventNameLc = eventName[0].toLowerCase() + eventName.substring(1);
|
|
26
|
-
|
|
27
|
-
if (!isCoveredByReact(eventNameLc)) {
|
|
28
|
-
syncEvent(node, eventNameLc, newProps[name]);
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
(node as any)[name] = newProps[name];
|
|
32
|
-
const propType = typeof newProps[name];
|
|
33
|
-
if (propType === 'string') {
|
|
34
|
-
node.setAttribute(camelToDashCase(name), newProps[name]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const getClassName = (classList: DOMTokenList, newProps: any, oldProps: any) => {
|
|
42
|
-
const newClassProp: string = newProps.className || newProps.class;
|
|
43
|
-
const oldClassProp: string = oldProps.className || oldProps.class;
|
|
44
|
-
// map the classes to Maps for performance
|
|
45
|
-
const currentClasses = arrayToMap(classList);
|
|
46
|
-
const incomingPropClasses = arrayToMap(newClassProp ? newClassProp.split(' ') : []);
|
|
47
|
-
const oldPropClasses = arrayToMap(oldClassProp ? oldClassProp.split(' ') : []);
|
|
48
|
-
const finalClassNames: string[] = [];
|
|
49
|
-
// loop through each of the current classes on the component
|
|
50
|
-
// to see if it should be a part of the classNames added
|
|
51
|
-
currentClasses.forEach((currentClass) => {
|
|
52
|
-
if (incomingPropClasses.has(currentClass)) {
|
|
53
|
-
// add it as its already included in classnames coming in from newProps
|
|
54
|
-
finalClassNames.push(currentClass);
|
|
55
|
-
incomingPropClasses.delete(currentClass);
|
|
56
|
-
} else if (!oldPropClasses.has(currentClass)) {
|
|
57
|
-
// add it as it has NOT been removed by user
|
|
58
|
-
finalClassNames.push(currentClass);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
incomingPropClasses.forEach((s) => finalClassNames.push(s));
|
|
62
|
-
return finalClassNames.join(' ');
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Checks if an event is supported in the current execution environment.
|
|
67
|
-
* @license Modernizr 3.0.0pre (Custom Build) | MIT
|
|
68
|
-
*/
|
|
69
|
-
export const isCoveredByReact = (eventNameSuffix: string) => {
|
|
70
|
-
if (typeof document === 'undefined') {
|
|
71
|
-
return true;
|
|
72
|
-
} else {
|
|
73
|
-
const eventName = 'on' + eventNameSuffix;
|
|
74
|
-
let isSupported = eventName in document;
|
|
75
|
-
|
|
76
|
-
if (!isSupported) {
|
|
77
|
-
const element = document.createElement('div');
|
|
78
|
-
element.setAttribute(eventName, 'return;');
|
|
79
|
-
isSupported = typeof (element as any)[eventName] === 'function';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return isSupported;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export const syncEvent = (
|
|
87
|
-
node: Element & { __events?: { [key: string]: ((e: Event) => any) | undefined } },
|
|
88
|
-
eventName: string,
|
|
89
|
-
newEventHandler?: (e: Event) => any
|
|
90
|
-
) => {
|
|
91
|
-
const eventStore = node.__events || (node.__events = {});
|
|
92
|
-
const oldEventHandler = eventStore[eventName];
|
|
93
|
-
|
|
94
|
-
// Remove old listener so they don't double up.
|
|
95
|
-
if (oldEventHandler) {
|
|
96
|
-
node.removeEventListener(eventName, oldEventHandler);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Bind new listener.
|
|
100
|
-
node.addEventListener(
|
|
101
|
-
eventName,
|
|
102
|
-
(eventStore[eventName] = function handler(e: Event) {
|
|
103
|
-
if (newEventHandler) {
|
|
104
|
-
newEventHandler.call(this, e);
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const arrayToMap = (arr: string[] | DOMTokenList) => {
|
|
111
|
-
const map = new Map<string, string>();
|
|
112
|
-
(arr as string[]).forEach((s: string) => map.set(s, s));
|
|
113
|
-
return map;
|
|
114
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const dashToPascalCase = (str: string) =>
|
|
2
|
-
str
|
|
3
|
-
.toLowerCase()
|
|
4
|
-
.split('-')
|
|
5
|
-
.map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
|
|
6
|
-
.join('');
|
|
7
|
-
export const camelToDashCase = (str: string) =>
|
|
8
|
-
str.replace(/([A-Z])/g, (m: string) => `-${m[0].toLowerCase()}`);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const isDevMode = () => {
|
|
2
|
-
return process && process.env && process.env.NODE_ENV === 'development';
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
const warnings: { [key: string]: boolean } = {};
|
|
6
|
-
|
|
7
|
-
export const deprecationWarning = (key: string, message: string) => {
|
|
8
|
-
if (isDevMode()) {
|
|
9
|
-
if (!warnings[key]) {
|
|
10
|
-
console.warn(message);
|
|
11
|
-
warnings[key] = true;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import type { StyleReactProps } from '../interfaces';
|
|
4
|
-
|
|
5
|
-
export type StencilReactExternalProps<PropType, ElementType> = PropType &
|
|
6
|
-
Omit<React.HTMLAttributes<ElementType>, 'style'> &
|
|
7
|
-
StyleReactProps;
|
|
8
|
-
|
|
9
|
-
// This will be replaced with React.ForwardedRef when react-output-target is upgraded to React v17
|
|
10
|
-
export type StencilReactForwardedRef<T> = ((instance: T | null) => void) | React.MutableRefObject<T | null> | null;
|
|
11
|
-
|
|
12
|
-
export const setRef = (ref: StencilReactForwardedRef<any> | React.Ref<any> | undefined, value: any) => {
|
|
13
|
-
if (typeof ref === 'function') {
|
|
14
|
-
ref(value)
|
|
15
|
-
} else if (ref != null) {
|
|
16
|
-
// Cast as a MutableRef so we can assign current
|
|
17
|
-
(ref as React.MutableRefObject<any>).current = value
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const mergeRefs = (
|
|
22
|
-
...refs: (StencilReactForwardedRef<any> | React.Ref<any> | undefined)[]
|
|
23
|
-
): React.RefCallback<any> => {
|
|
24
|
-
return (value: any) => {
|
|
25
|
-
refs.forEach(ref => {
|
|
26
|
-
setRef(ref, value)
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const createForwardRef = <PropType, ElementType>(
|
|
32
|
-
ReactComponent: any,
|
|
33
|
-
displayName: string,
|
|
34
|
-
) => {
|
|
35
|
-
const forwardRef = (
|
|
36
|
-
props: StencilReactExternalProps<PropType, ElementType>,
|
|
37
|
-
ref: StencilReactForwardedRef<ElementType>,
|
|
38
|
-
) => {
|
|
39
|
-
return <ReactComponent {...props} forwardedRef={ref} />;
|
|
40
|
-
};
|
|
41
|
-
forwardRef.displayName = displayName;
|
|
42
|
-
|
|
43
|
-
return React.forwardRef(forwardRef);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const defineCustomElement = (tagName: string, customElement: any) => {
|
|
47
|
-
if (
|
|
48
|
-
customElement !== undefined &&
|
|
49
|
-
typeof customElements !== 'undefined' &&
|
|
50
|
-
!customElements.get(tagName)
|
|
51
|
-
) {
|
|
52
|
-
customElements.define(tagName, customElement);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export * from './attachProps';
|
|
57
|
-
export * from './case';
|