edu-webcomponents 1.7.0

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/.editorconfig ADDED
@@ -0,0 +1,29 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+
8
+ [*]
9
+
10
+ # Change these settings to your own preference
11
+ indent_style = space
12
+ indent_size = 2
13
+
14
+ # We recommend you to keep these unchanged
15
+ end_of_line = lf
16
+ charset = utf-8
17
+ trim_trailing_whitespace = true
18
+ insert_final_newline = true
19
+
20
+ [*.md]
21
+ trim_trailing_whitespace = false
22
+
23
+ [*.json]
24
+ indent_size = 2
25
+
26
+ [*.{html,js,md}]
27
+ block_comment_start = /**
28
+ block_comment = *
29
+ block_comment_end = */
@@ -0,0 +1,28 @@
1
+ name: Build and Publish Storybook to GitHub Pages
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'main'
7
+
8
+ permissions:
9
+ contents: read
10
+ pages: write
11
+ id-token: write
12
+
13
+ jobs:
14
+ deploy:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - uses: actions/setup-node@v4
20
+ with:
21
+ node-version: '18.x'
22
+
23
+ - uses: bitovi/github-actions-storybook-to-github-pages@v1.0.3
24
+ with:
25
+ install_command: npm install
26
+ build_command: npm run build-storybook
27
+ path: storybook-static
28
+ checkout: false
@@ -0,0 +1,17 @@
1
+ name: Publish Package to npmjs
2
+ on:
3
+ release:
4
+ types: [published]
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v4
10
+ - uses: actions/setup-node@v4
11
+ with:
12
+ node-version: '20.x'
13
+ registry-url: 'https://registry.npmjs.org'
14
+ - run: npm ci
15
+ - run: npm publish --access public
16
+ env:
17
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,19 @@
1
+ on:
2
+ push:
3
+ branches:
4
+ - main
5
+
6
+ jobs:
7
+ release-on-merge:
8
+ runs-on: ubuntu-latest
9
+ permissions:
10
+ contents: write
11
+ env:
12
+ GITHUB_TOKEN: ${{ secrets.RELEASE }}
13
+ steps:
14
+ - name: release
15
+ uses: dexwritescode/release-on-merge-action@v1
16
+ with:
17
+ version-increment-strategy: minor
18
+ initial-version: '1.6.0'
19
+ tag-prefix: v
@@ -0,0 +1,15 @@
1
+ /** @type { import('@storybook/web-components-webpack5').StorybookConfig } */
2
+ const config = {
3
+ stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
4
+ addons: [
5
+ '@storybook/addon-webpack5-compiler-swc',
6
+ '@storybook/addon-links',
7
+ '@storybook/addon-essentials',
8
+ '@chromatic-com/storybook',
9
+ ],
10
+ framework: {
11
+ name: '@storybook/web-components-webpack5',
12
+ options: {},
13
+ },
14
+ };
15
+ export default config;
@@ -0,0 +1,13 @@
1
+ /** @type { import('@storybook/web-components').Preview } */
2
+ const preview = {
3
+ parameters: {
4
+ controls: {
5
+ matchers: {
6
+ color: /(background|color)$/i,
7
+ date: /Date$/i,
8
+ },
9
+ },
10
+ },
11
+ };
12
+
13
+ export default preview;
package/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Change Log
2
+
3
+ ## 1.0.0 - 2024-05-25
4
+ - (Initial commit) run npm init @open-wc and select these options: Scaffold a new project, scaffold a Web Component, add Linting (eslint & prettier) and Testing (web-test-runner), do not use typescript, use edu-webcomponents as tag name
5
+
6
+ ## 1.1.0 - 2024-05-26
7
+ - Setup Husky
8
+
9
+ ## 1.2.0 - 2024-05-27
10
+ - Setup the repository to be a library of web components
11
+
12
+ ## 1.3.0 - 2024-05-28
13
+ - Setup Storybook
14
+
15
+ ## 1.4.0 - 2024-05-30
16
+ - Setup GitHub Actions to publish Storybook built artifacts in GitHub Pages
17
+
18
+ ## 1.5.0 - 2024-05-30
19
+ - Add docs to enable the deployment of GitHub Actions artifacts into GitHub Pages
20
+
21
+ ## 1.6.0 - 2024-06-01
22
+ - Setup GitHub Actions to tag and release after merge into main
23
+
24
+ ## 1.7.0 - 2024-06-02
25
+ - Setup GitHub Actions to publish packages in npm registry
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 edu-webcomponents
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Edu web components library
2
+
3
+ This web components library follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i edu-webcomponents
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import 'edu-webcomponents/index.js';
16
+ </script>
17
+
18
+ <webcomponent-tagname></webcomponent-tagname>
19
+ ```
20
+
21
+ ## Linting and formatting
22
+
23
+ To scan the project for linting and formatting errors, run
24
+
25
+ ```bash
26
+ npm run lint
27
+ ```
28
+
29
+ To automatically fix linting and formatting errors, run
30
+
31
+ ```bash
32
+ npm run format
33
+ ```
34
+
35
+ ## Testing with Web Test Runner
36
+
37
+ To execute a single test run:
38
+
39
+ ```bash
40
+ npm run test
41
+ ```
42
+
43
+ To run the tests in interactive watch mode run:
44
+
45
+ ```bash
46
+ npm run test:watch
47
+ ```
48
+
49
+
50
+ ## Tooling configs
51
+
52
+ For most of the tools, the configuration is in the `package.json` to minimize the amount of files in your project.
53
+
54
+ If you customize the configuration a lot, you can consider moving them to individual files.
55
+
56
+ ## Local Demo with `web-dev-server`
57
+
58
+ ```bash
59
+ npm start
60
+ ```
61
+
62
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,29 @@
1
+ <!doctype html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <style>
6
+ body {
7
+ background: #fafafa;
8
+ }
9
+ </style>
10
+ </head>
11
+ <body>
12
+ <div id="demo"></div>
13
+
14
+ <script type="module">
15
+ import { html, render } from 'lit';
16
+ import '../index.js';
17
+
18
+ const textButton = 'This is a button';
19
+ render(
20
+ html`
21
+ <h1>Edu web components library</h1>
22
+ <edu-button .text=${textButton}>
23
+ </edu-button>
24
+ `,
25
+ document.querySelector('#demo')
26
+ );
27
+ </script>
28
+ </body>
29
+ </html>
@@ -0,0 +1,4 @@
1
+ # Deploy Storybook build to GitHub Pages by using GitHub Actions
2
+ - Select "GitHub Actions" option as source below "Build and deployment" in your repository's Settings (see Pages in menu)
3
+ - Use this workflow: https://storybook.js.org/docs/sharing/publish-storybook#github-pages
4
+ - After that, deployment should work when running the ad hoc job
@@ -0,0 +1,12 @@
1
+ # Husky docs
2
+
3
+ ## Setup
4
+
5
+ ### Required
6
+ - Node.js package: https://www.npmjs.com/package/husky
7
+ - Version: 9.0.11
8
+
9
+ ### How to
10
+ - Documentation followed: https://github.com/typicode/husky/blob/main/docs/get-started.md
11
+ - Run this command to setup: npx husky init
12
+ - Delete content in .husky/pre-commit and write: npm run format
@@ -0,0 +1,5 @@
1
+ # Publish packages to npm registry by using GitHub Actions
2
+ - Have an account in npm.com and create a PAT with write permissions
3
+ - Add PAT created to GitHub secrets
4
+ - Use workflow from [here](https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-to-the-npm-registry)
5
+
@@ -0,0 +1,4 @@
1
+ # Release and tag to GitHub by using GitHub Actions
2
+ Use workflow from [here](https://github.com/marketplace/actions/release-on-merge-action) and:
3
+ - Add corresponding inputs
4
+ - Create the needed token and add it to GitHub secrets
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { EduButton } from './src/EduButton.js';
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "edu-webcomponents",
3
+ "description": "Webcomponent edu-webcomponents following open-wc recommendations",
4
+ "license": "MIT",
5
+ "author": "edu-webcomponents",
6
+ "version": "1.7.0",
7
+ "type": "module",
8
+ "main": "index.js",
9
+ "module": "index.js",
10
+ "exports": {
11
+ ".": "./index.js"
12
+ },
13
+ "scripts": {
14
+ "analyze": "cem analyze --litelement",
15
+ "start": "web-dev-server",
16
+ "lint": "eslint --ext .js,.html . --ignore-path .gitignore && prettier \"**/*.js\" --check --ignore-path .gitignore",
17
+ "format": "eslint --ext .js,.html . --fix --ignore-path .gitignore && prettier \"**/*.js\" --write --ignore-path .gitignore",
18
+ "test": "web-test-runner --coverage",
19
+ "test:watch": "web-test-runner --watch",
20
+ "prepare": "husky",
21
+ "storybook": "storybook dev -p 6006",
22
+ "build-storybook": "storybook build"
23
+ },
24
+ "dependencies": {
25
+ "lit": "^2.0.2"
26
+ },
27
+ "devDependencies": {
28
+ "@chromatic-com/storybook": "^1.4.0",
29
+ "@custom-elements-manifest/analyzer": "^0.4.17",
30
+ "@open-wc/eslint-config": "^9.2.1",
31
+ "@open-wc/testing": "^3.1.6",
32
+ "@storybook/addon-essentials": "^8.1.4",
33
+ "@storybook/addon-links": "^8.1.4",
34
+ "@storybook/addon-webpack5-compiler-swc": "^1.0.2",
35
+ "@storybook/blocks": "^8.1.4",
36
+ "@storybook/test": "^8.1.4",
37
+ "@storybook/web-components": "^8.1.4",
38
+ "@storybook/web-components-webpack5": "^8.1.4",
39
+ "@web/dev-server": "^0.1.34",
40
+ "@web/test-runner": "^0.14.0",
41
+ "eslint": "^8.31.0",
42
+ "eslint-config-prettier": "^8.3.0",
43
+ "eslint-plugin-storybook": "^0.8.0",
44
+ "husky": "^9.0.11",
45
+ "lint-staged": "^10.5.4",
46
+ "prettier": "^2.4.1",
47
+ "storybook": "^8.1.4"
48
+ },
49
+ "customElements": "custom-elements.json",
50
+ "eslintConfig": {
51
+ "extends": [
52
+ "@open-wc",
53
+ "prettier",
54
+ "plugin:storybook/recommended"
55
+ ]
56
+ },
57
+ "prettier": {
58
+ "singleQuote": true,
59
+ "arrowParens": "avoid"
60
+ }
61
+ }
@@ -0,0 +1,24 @@
1
+ import { html, css, LitElement } from 'lit';
2
+
3
+ export class EduButton extends LitElement {
4
+ static styles = css`
5
+ :host {
6
+ display: block;
7
+ }
8
+ `;
9
+
10
+ static properties = {
11
+ text: { type: String },
12
+ };
13
+
14
+ constructor() {
15
+ super();
16
+ this.text = 'Default text';
17
+ }
18
+
19
+ render() {
20
+ return html` <button>${this.text}</button> `;
21
+ }
22
+ }
23
+
24
+ window.customElements.define('edu-button', EduButton);
@@ -0,0 +1,28 @@
1
+ import { html } from 'lit';
2
+ import '../EduButton.js';
3
+
4
+ export default {
5
+ title: 'Edu web components/EduButton',
6
+ tags: ['autodocs'],
7
+ render: ({ text }) => html`<edu-button .text=${text}></edu-button>`,
8
+ argTypes: {
9
+ text: {
10
+ control: 'text',
11
+ description: 'Overwritten button text',
12
+ name: 'text',
13
+ },
14
+ },
15
+ args: {
16
+ text: 'Default text',
17
+ },
18
+ };
19
+
20
+ export const DefaultButton = {
21
+ args: {},
22
+ };
23
+
24
+ export const ButtonWithTextChanged = {
25
+ args: {
26
+ text: 'Custom text',
27
+ },
28
+ };
@@ -0,0 +1,28 @@
1
+ import { html } from 'lit';
2
+ import { fixture, expect } from '@open-wc/testing';
3
+
4
+ import '../src/EduButton.js';
5
+
6
+ const textDefault = 'Default text';
7
+
8
+ const textOther = 'bla bla';
9
+
10
+ describe('EduButton', () => {
11
+ it(`has a default text ${textDefault}`, async () => {
12
+ const el = await fixture(html`<edu-button></edu-button>`);
13
+
14
+ expect(el.text).to.equal(textDefault);
15
+ });
16
+
17
+ it('can override the text via attribute', async () => {
18
+ const el = await fixture(html`<edu-button text=${textOther}></edu-button>`);
19
+
20
+ expect(el.text).to.equal(textOther);
21
+ });
22
+
23
+ it('passes the a11y audit', async () => {
24
+ const el = await fixture(html`<edu-button></edu-button>`);
25
+
26
+ await expect(el).shadowDom.to.be.accessible();
27
+ });
28
+ });
@@ -0,0 +1,27 @@
1
+ // import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
2
+
3
+ /** Use Hot Module replacement by adding --hmr to the start command */
4
+ const hmr = process.argv.includes('--hmr');
5
+
6
+ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
7
+ open: '/demo/',
8
+ /** Use regular watch mode if HMR is not enabled. */
9
+ watch: !hmr,
10
+ /** Resolve bare module imports */
11
+ nodeResolve: {
12
+ exportConditions: ['browser', 'development'],
13
+ },
14
+
15
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
16
+ // esbuildTarget: 'auto'
17
+
18
+ /** Set appIndex to enable SPA routing */
19
+ // appIndex: 'demo/index.html',
20
+
21
+ plugins: [
22
+ /** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
23
+ // hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
24
+ ],
25
+
26
+ // See documentation for all available options
27
+ });
@@ -0,0 +1,41 @@
1
+ // import { playwrightLauncher } from '@web/test-runner-playwright';
2
+
3
+ const filteredLogs = ['Running in dev mode', 'lit-html is in dev mode'];
4
+
5
+ export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
6
+ /** Test files to run */
7
+ files: 'test/**/*.test.js',
8
+
9
+ /** Resolve bare module imports */
10
+ nodeResolve: {
11
+ exportConditions: ['browser', 'development'],
12
+ },
13
+
14
+ /** Filter out lit dev mode logs */
15
+ filterBrowserLogs(log) {
16
+ for (const arg of log.args) {
17
+ if (typeof arg === 'string' && filteredLogs.some(l => arg.includes(l))) {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ },
23
+
24
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
25
+ // esbuildTarget: 'auto',
26
+
27
+ /** Amount of browsers to run concurrently */
28
+ // concurrentBrowsers: 2,
29
+
30
+ /** Amount of test files per browser to test concurrently */
31
+ // concurrency: 1,
32
+
33
+ /** Browsers to run tests on */
34
+ // browsers: [
35
+ // playwrightLauncher({ product: 'chromium' }),
36
+ // playwrightLauncher({ product: 'firefox' }),
37
+ // playwrightLauncher({ product: 'webkit' }),
38
+ // ],
39
+
40
+ // See documentation for all available options
41
+ });