(
parentElement: HTMLElement,
userComponent: any,
userComponentProps: any = {},
cssClasses: string[] = []
)
| 50 | let BaseComponent: any; |
| 51 | let Reference: any; |
| 52 | const attachViewToDom = async ( |
| 53 | parentElement: HTMLElement, |
| 54 | userComponent: any, |
| 55 | userComponentProps: any = {}, |
| 56 | cssClasses: string[] = [] |
| 57 | ) => { |
| 58 | BaseComponent = parentElement; |
| 59 | let ChildComponent; |
| 60 | /** |
| 61 | * If passing in a component via the `component` props |
| 62 | * we need to append it inside of our overlay component. |
| 63 | */ |
| 64 | if (userComponent) { |
| 65 | /** |
| 66 | * If passing in the tag name, create |
| 67 | * the element otherwise just get a reference |
| 68 | * to the component. |
| 69 | */ |
| 70 | const el: any = |
| 71 | typeof userComponent === 'string' ? BaseComponent.ownerDocument?.createElement(userComponent) : userComponent; |
| 72 | |
| 73 | /** |
| 74 | * Add any css classes passed in |
| 75 | * via the cssClasses prop on the overlay. |
| 76 | */ |
| 77 | cssClasses.forEach((c) => el.classList.add(c)); |
| 78 | |
| 79 | /** |
| 80 | * Add any props passed in |
| 81 | * via the componentProps prop on the overlay. |
| 82 | */ |
| 83 | Object.assign(el, userComponentProps); |
| 84 | |
| 85 | /** |
| 86 | * Finally, append the component |
| 87 | * inside of the overlay component. |
| 88 | */ |
| 89 | BaseComponent.appendChild(el); |
| 90 | |
| 91 | ChildComponent = el; |
| 92 | |
| 93 | await new Promise((resolve) => componentOnReady(el, resolve)); |
| 94 | } else if ( |
| 95 | BaseComponent.children.length > 0 && |
| 96 | (BaseComponent.tagName === 'ION-MODAL' || BaseComponent.tagName === 'ION-POPOVER') |
| 97 | ) { |
| 98 | /** |
| 99 | * The delegate host wrapper el is only needed for modals and popovers |
| 100 | * because they allow the dev to provide custom content to the overlay. |
| 101 | */ |
| 102 | const root = (ChildComponent = BaseComponent.children[0] as HTMLElement); |
| 103 | if (!root.classList.contains('ion-delegate-host')) { |
| 104 | /** |
| 105 | * If the root element is not a delegate host, it means |
| 106 | * that the overlay has not been presented yet and we need |
| 107 | * to create the containing element with the specified classes. |
| 108 | */ |
| 109 | const el = BaseComponent.ownerDocument?.createElement('div'); |
nothing calls this directly
no test coverage detected