Skip to content

Commit 4563214

Browse files
committed
FEATURE | Add docs for support for SFC custom elements and shadow DOM option
1 parent 6474975 commit 4563214

File tree

10 files changed

+126
-66
lines changed

10 files changed

+126
-66
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format
44

55
## [Unreleased]
66

7+
## [1.6.0] - 13.06.2024
8+
### Added
9+
- Added support for SFC custom elements
10+
711
## [1.5.1] - 12.06.2024
812
### Fixed
913
- Fixed issue with HMR in Vite.js

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,24 @@ import style from './style.css?raw'
276276
If you want to create a web component without shadow DOM, you can set the `disableShadowDOM` option to `true` in the `createWebComponent` function. This will create a web component without shadow DOM encapsulation.
277277
This feature uses a patch to the Vue source code, which could lead to some issues with future versions of Vue. If you encounter any issues, please report them in the issues section of this repository.
278278
### Demo without Shadow DOM
279-
[Demo](https://stackblitz.com/~/github.com/EranGrin/web-component-no-shadow-dom-demo)
279+
[Demo Link](https://stackblitz.com/~/github.com/EranGrin/web-component-no-shadow-dom-demo)
280+
281+
282+
## SFC as Custom Element
283+
enhance the core functionality of SFC as Custom Element [defineCustomElement](https://vuejs.org/guide/extras/web-components#sfc-as-custom-element) with 2 new features:
284+
1. **Nested Components**: You can use nested components with styles and for example share base components between multiple custom elements.
285+
2. **Shadow DOM option**: You can disable shadow DOM for the SFC custom element.
286+
287+
### Usage
288+
```javascript
289+
// main.js
290+
import { defineCustomElementSFC } from 'vue-web-component-wrapper';
291+
const MyComponentElement = defineCustomElementSFC(MyComponent, {shadowRoot: false})
292+
customElements.define('my-component', MyComponentElement)
293+
```
294+
295+
### Demo
296+
[Demo Link](https://stackblitz.com/edit/vue-web-component-wrapper?file=README.md&startScript=sfc-demo)
280297

281298

282299
## Tips

demo-SFC-vite/src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { defineCustomElementSFC } from '../../package/index.js'
2-
// import { defineCustomElement } from 'vue'
32
import MyComponent from './MyComponent.ce.vue'
43

54
const MyComponentElement = defineCustomElementSFC(MyComponent, {shadowRoot: false})

docs/.vitepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default {
2121
{ text: 'event-emitting', link: '/event-emitting' },
2222
{ text: 'disable-shadow-dom', link: '/disable-shadow-dom' },
2323
{ text: 'host-implementation', link: '/host-implementation' },
24+
{ text: 'SFC as Custom Element', link: '/sfc-as-custom-element' },
2425
],
2526
},
2627
{

docs/sfc-as-custom-element.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
3+
## SFC as Custom Element
4+
5+
This section explains how to enhance the core functionality of SFC (Single File Component) as a Custom Element using the `defineCustomElementSFC` method. It introduces two new features: **Nested Components** and **Shadow DOM option**.
6+
7+
### Nested Components
8+
9+
With the SFC as Custom Element approach, you can use nested components with styles and share base components between multiple custom elements. This allows for better code organization and reusability.
10+
11+
### Shadow DOM option
12+
13+
The SFC custom element supports the option to enable or disable the Shadow DOM. The Shadow DOM provides encapsulation for the component's styles and DOM structure, preventing them from affecting the rest of the page. By default, the Shadow DOM is enabled, but you can disable it if needed.
14+
15+
### Usage
16+
17+
To use SFC as a Custom Element, follow these steps:
18+
19+
1. Import the `defineCustomElementSFC` function from the `vue-web-component-wrapper` package.
20+
2. Call the `defineCustomElementSFC` function, passing in your SFC component and an options object.
21+
- The options object can include the `shadowRoot` property, which determines whether the Shadow DOM should be enabled or disabled for the custom element.
22+
3. Use the `customElements.define` method to define your custom element, providing a name for the element and the result of the `defineCustomElementSFC` function.
23+
24+
### Example
25+
26+
```javascript
27+
// main.js
28+
import { defineCustomElementSFC } from 'vue-web-component-wrapper';
29+
const MyComponentElement = defineCustomElementSFC(MyComponent, {shadowRoot: false})
30+
customElements.define('my-component', MyComponentElement)
31+
```
32+
33+
### Demo
34+
[Demo Link](https://stackblitz.com/edit/vue-web-component-wrapper?file=README.md&startScript=sfc-demo)

docs/usage.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ createWebComponent({
5757
createApp,
5858
getCurrentInstance,
5959
disableStyleRemoval: false,
60+
disableShadowDOM: false,
6061
});
6162
```
6263
Each option in the `createWebComponent` function has a specific purpose:
@@ -68,4 +69,5 @@ Each option in the `createWebComponent` function has a specific purpose:
6869
- `h`: The `h` function from Vue.
6970
- `createApp`: The `createApp` function from Vue.
7071
- `getCurrentInstance`: The `getCurrentInstance` function from Vue.
71-
- `disableStyleRemoval`: A boolean value that determines whether or not to remove styles on unmount. This is useful for CSS transitions.
72+
- `disableStyleRemoval`: A boolean value that determines whether or not to remove styles on unmount. This is useful for CSS transitions.
73+
- `disableShadowDOM`: A boolean value that determines whether or not to use Shadow DOM for the web component.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "vue-web-component-wrapper",
3-
"version": "1.5.1",
3+
"version": "1.6.0",
44
"description": "A Vue 3 plugin that provides a web component wrapper with styles, seamlessly integrating with Vuex, Vue Router, Vue I18n, and supporting Tailwind CSS and Sass styles.",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/EranGrin/vue3-web-component-wrapper/tree/main/plugin"
88
},
9+
"homepage": "https://erangrin.github.io/vue-web-component-wrapper/",
910
"main": "package/dist/vue-web-component-wrapper.umd.js",
1011
"module": "package/dist/vue-web-component-wrapper.es.js",
1112
"types": "package/types.d.ts",

0 commit comments

Comments
 (0)