@sesamy/sesamy-components 0.0.6 → 0.0.8
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/README.md +13 -41
- package/dist/lib/sesamy-components.d.ts +1 -0
- package/dist/lib/sesamy-components.es.js +885 -671
- package/dist/lib/sesamy-components.umd.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# 🌐
|
|
1
|
+
# 🌐 sesamy-components
|
|
2
2
|
|
|
3
|
-
> A
|
|
3
|
+
> A project for building a shareable web components library using [Vite](https://vitejs.dev), [Svelte](https://svelte.dev), [storybook](https://storybook.js.org) and [TypeScript](https://www.typescriptlang.org).
|
|
4
4
|
|
|
5
|
-
This templates generates
|
|
5
|
+
This templates generates typed [web components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) than can be used with [plain HTML](https://www.webcomponents.org/introduction#how-do-i-use-a-web-component-) or within any major frameworks, such as React, Angular, Vue or Svelte (see [compatibility](https://custom-elements-everywhere.com/)).
|
|
6
6
|
|
|
7
7
|
## How to use this template
|
|
8
8
|
|
|
@@ -11,9 +11,9 @@ You can directly create a new GitHub repo from this template by selecting the **
|
|
|
11
11
|
You can also clone it locally with the following commands:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npx degit
|
|
15
|
-
cd
|
|
16
|
-
|
|
14
|
+
npx degit sesamy/sesamy-components
|
|
15
|
+
cd sesamy-components
|
|
16
|
+
yarn
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Your components source code lives in `lib/` folder. Only components with the `.wc.svelte` extension will be exported as web components and available in your library. This means that you can also use regular Svelte components with the `.svelte` extension as child components for your implementation details.
|
|
@@ -76,7 +76,7 @@ Here's an example:
|
|
|
76
76
|
<script>
|
|
77
77
|
import { get_current_component } from "svelte/internal";
|
|
78
78
|
const component = get_current_component();
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
// example function for dispatching events
|
|
81
81
|
const dispatchEvent = (name, detail) =>
|
|
82
82
|
component.dispatchEvent(new CustomEvent(name, { detail }));
|
|
@@ -86,39 +86,11 @@ Here's an example:
|
|
|
86
86
|
</button>
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
##
|
|
90
|
-
|
|
91
|
-
By default this template will build all components into a single module.
|
|
92
|
-
|
|
93
|
-
If you prefer to build each component into its own module, you can do so by setting the environment variable `BUNDLE_COMPONENTS` to `false`, or editing `vite.config.js` and setting the `bundleComponents` option to `false`.
|
|
94
|
-
|
|
95
|
-
Then you also need to replace the content of `packages/lib/index.ts` with:
|
|
96
|
-
|
|
97
|
-
```js
|
|
98
|
-
export default () => {
|
|
99
|
-
import('./MyComponent.wc.svelte');
|
|
100
|
-
// Import each of your component this way
|
|
101
|
-
};
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
This will enable code-splitting and will generate an ES module for each component in the `dist/lib/` folder.
|
|
89
|
+
## Create a new component
|
|
105
90
|
|
|
106
|
-
|
|
91
|
+
These are the files needed to create a new component:
|
|
107
92
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
## Why is HMR not preserving my local component state?
|
|
114
|
-
|
|
115
|
-
HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/sveltejs/svelte-hmr/tree/master/packages/svelte-hmr#svelte-hmr).
|
|
116
|
-
|
|
117
|
-
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
// store.ts
|
|
121
|
-
// An extremely simple external store
|
|
122
|
-
import { writable } from 'svelte/store'
|
|
123
|
-
export default writable(0)
|
|
124
|
-
```
|
|
93
|
+
- Add the `my-component.wc.svelte` file in the `lib/src` folder.
|
|
94
|
+
- Add the class in the `lib/src/sesamy-component.d.ts` file to get the types exported.
|
|
95
|
+
- Add the component to the `lib/src/index.ts` file to export it.
|
|
96
|
+
- Add a story in the `stories` folder.
|