You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+86-1
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,9 @@ See the [Documentation](https://erangrin.github.io/vue-web-component-wrapper) fo
46
46
-**Disable Removal of Styles on Unmount**: Control the removal of styles upon component unmount to solve issues with CSS transitions.
47
47
-**Disable Shadow DOM**: Option to disable Shadow DOM for web components.
48
48
-**Replace `:root` with `:host`**: Optionally replace `:root` selectors with `:host` in your CSS to ensure styles are correctly scoped within the Shadow DOM.
49
-
49
+
-**Async Initialization**: Option to delay the initialization until its Promise resolves.
50
+
-**Loader Support**: Support for loader spinner elements until the application is fully initialized.
51
+
-**Hide slot content until the component is fully mounted**: Option to hide the content of named slots until the web-component is fully mounted.
replaceRootWithHostInCssFramework:false, // default is false
149
+
loaderAttribute:'data-web-component-loader', // default is 'data-web-component-loader'
150
+
hideSlotContentUntilMounted:true, // default is false
147
151
});
148
152
```
149
153
@@ -160,11 +164,92 @@ createWebComponent({
160
164
-**disableStyleRemoval**: Disable removal of styles on unmount (useful for CSS transitions).
161
165
-**disableShadowDOM**: Disable Shadow DOM for web components.
162
166
-**replaceRootWithHostInCssFramework**: Replace `:root` selectors with `:host` in your CSS styles.
167
+
-**asyncInitialization**: Accepts a function that returns a Promise.
168
+
-**loaderAttribute**: Defines the attribute used to mark loader spinner (default is `data-web-component-loader`).
169
+
-**hideSlotContentUntilMounted**: Hide the content of named slots until the component is fully mounted.
170
+
171
+
### asyncInitialization
172
+
173
+
The `asyncInitialization` option accepts a function that returns a Promise. The custom element waits for this Promise to resolve before completing its initialization. This is useful for performing asynchronous tasks (e.g., API calls, dynamic imports) before the app mounts.
174
+
175
+
#### Example Usage
176
+
177
+
```javascript
178
+
constasyncPromise= () => {
179
+
returnnewPromise((resolve) => {
180
+
setTimeout(() => {
181
+
resolve()
182
+
}, 1000)
183
+
})
184
+
}
185
+
186
+
createWebComponent({
187
+
rootComponent: App,
188
+
elementName:'my-web-component',
189
+
plugins: pluginsWrapper,
190
+
cssFrameworkStyles: tailwindStyles,
191
+
VueDefineCustomElement,
192
+
h,
193
+
createApp,
194
+
getCurrentInstance,
195
+
asyncInitialization: asyncPromise, // default is Promise.resolve()
196
+
loaderAttribute:'data-web-component-loader',
197
+
hideSlotContentUntilMounted:true, // default is false
198
+
});
199
+
```
200
+
201
+
### loaderAttribute
202
+
203
+
The `loaderAttribute` option defines the attribute used to mark loader spinner elements in your custom element's DOM. Elements with this attribute will be removed automatically once the component is fully mounted.
border-left-color: #4a90e2; /* Customize spinner color if needed */
219
+
border-radius: 50%;
220
+
width: 30px;
221
+
height: 30px;
222
+
animation: spin 1slinearinfinite;
223
+
margin: auto;
224
+
}
225
+
226
+
@keyframesspin {
227
+
to {
228
+
transform: rotate(360deg);
229
+
}
230
+
}
231
+
</style>
232
+
```
233
+
234
+
### hideSlotContentUntilMounted
235
+
236
+
The `hideSlotContentUntilMounted` option hides the content of named slots until the component is fully mounted.
237
+
- By using the `hidden` attribute on the slot element, the content will be hidden until the component is fully mounted, and the web component wrapper will remove the `hidden` attribute once the component is fully mounted.
238
+
- This could be break the layout of your application, if you use the `hidden` attribute internally in your application.
239
+
- If you want to use the `hidden` attribute internally in your application, you can set the `hideSlotContentUntilMounted` option to `false`.
240
+
241
+
```html
242
+
<my-web-component>
243
+
<!-- named slot -->
244
+
<divclass="customName"hiddenslot="customName">I am a custom named slot </div>
245
+
</my-web-component>
246
+
```
163
247
164
248
### replaceRootWithHostInCssFramework
165
249
166
250
The `replaceRootWithHostInCssFramework` option replaces all occurrences of `:root` with `:host` in your `cssFrameworkStyles`. This is useful when working with CSS variables defined on `:root`, ensuring they are properly scoped within the Shadow DOM.
0 commit comments