@travelopia/web-components 0.0.1

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.
@@ -0,0 +1 @@
1
+ since 2019
package/.editorconfig ADDED
@@ -0,0 +1,18 @@
1
+ # WordPress Coding Standards
2
+ # https://make.wordpress.org/core/handbook/coding-standards/
3
+
4
+ root = true
5
+
6
+ [*]
7
+ charset = utf-8
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+ trim_trailing_whitespace = true
11
+ indent_style = tab
12
+
13
+ [{.jshintrc,*.json,*.yml,*.neon}]
14
+ indent_style = space
15
+ indent_size = 2
16
+
17
+ [*.txt]
18
+ end_of_line = crlf
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ dist
3
+ vendor
package/.eslintrc.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": [ "plugin:@wordpress/eslint-plugin/recommended-with-formatting" ],
3
+ "overrides": [
4
+ {
5
+ "files": ["*.ts"],
6
+ "rules": {
7
+ "no-undef": "off",
8
+ "no-unused-vars": "off",
9
+ "import/no-unresolved": "off",
10
+ "import/no-extraneous-dependencies": "off"
11
+ }
12
+ }
13
+ ]
14
+ }
package/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ # --- Windows and Mac files
2
+ [Tt]humbs.db
3
+ .DS_Store
4
+
5
+ # --- Packages
6
+ node_modules
7
+ vendor
8
+
9
+ # --- Root
10
+ /*
11
+ !.browserslistrc
12
+ !.editorconfig
13
+ !.eslintignore
14
+ !.eslintrc.json
15
+ !.gitignore
16
+ !LICENSE
17
+ !package.json
18
+ !package-lock.json
19
+ !README.md
20
+ !tsconfig.json
21
+ !webpack.config.js
22
+
23
+ # --- Components
24
+ !src
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Travelopia
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,16 @@
1
+ # Web Components
2
+
3
+ ![maintenance-status](https://img.shields.io/badge/maintenance-actively--developed-brightgreen.svg)
4
+
5
+ Accessible web components for the modern web.
6
+
7
+ <table width="100%">
8
+ <tr>
9
+ <td align="left" width="70%">
10
+ <p>Built by the super talented team at <strong><a href="https://www.travelopia.com/work-with-us/">Travelopia</a></strong>.</p>
11
+ </td>
12
+ <td align="center" width="30%">
13
+ <img src="https://www.travelopia.com/wp-content/themes/travelopia/assets/svg/logo-travelopia-circle.svg" width="50" />
14
+ </td>
15
+ </tr>
16
+ </table>
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@travelopia/web-components",
3
+ "version": "0.0.1",
4
+ "description": "Accessible web components for the modern web",
5
+ "scripts": {
6
+ "build": "webpack --config ./webpack.config.js --mode production --env=production",
7
+ "dev": "webpack --config ./webpack.config.js --mode production --env=development --watch",
8
+ "lint": "eslint src"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Travelopia/web-components.git"
13
+ },
14
+ "author": "Travelopia Team",
15
+ "license": "MIT",
16
+ "bugs": {
17
+ "url": "https://github.com/Travelopia/web-components/issues"
18
+ },
19
+ "homepage": "https://github.com/Travelopia/web-components#readme",
20
+ "devDependencies": {
21
+ "@wordpress/eslint-plugin": "^17.1.0",
22
+ "css-loader": "^6.8.1",
23
+ "mini-css-extract-plugin": "^2.7.6",
24
+ "postcss-loader": "^7.3.3",
25
+ "sass": "^1.69.5",
26
+ "sass-loader": "^13.3.2",
27
+ "terser-webpack-plugin": "^5.3.9",
28
+ "ts-loader": "^9.5.0",
29
+ "typescript": "^5.2.2",
30
+ "webpack": "^5.89.0",
31
+ "webpack-cli": "^5.1.4",
32
+ "webpack-notifier": "^1.15.0"
33
+ }
34
+ }
@@ -0,0 +1,35 @@
1
+ # Modal
2
+
3
+ <table width="100%">
4
+ <tr>
5
+ <td align="left" width="70%">
6
+ <p>Built by the super talented team at <strong><a href="https://www.travelopia.com/work-with-us/">Travelopia</a></strong>.</p>
7
+ </td>
8
+ <td align="center" width="30%">
9
+ <img src="https://www.travelopia.com/wp-content/themes/travelopia/assets/svg/logo-travelopia-circle.svg" width="50" />
10
+ </td>
11
+ </tr>
12
+ </table>
13
+
14
+ ## Sample Usage
15
+
16
+ This is a super minimal modal that is designed to be highly extendable.
17
+
18
+ Example:
19
+
20
+ ```html
21
+ <tp-modal overlay-click-close="yes">
22
+ <tp-modal-close>
23
+ <button>Close</button> <-- There must be a button inside inside this component.
24
+ </tp-modal-close>
25
+ <tp-modal-content>
26
+ <p>Any modal content here.</p>
27
+ </tp-modal-content>
28
+ </tp-modal>
29
+ ```
30
+
31
+ ## Attributes
32
+
33
+ | Attribute | Required | Values | Notes |
34
+ |----------------------|----------|--------|----------------------------------------------|
35
+ | overlay-click-close | No | `yes` | Closes the modal when the overlay is clicked |
@@ -0,0 +1,35 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
6
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
+ <title>Web Component: Modal</title>
8
+
9
+ <link rel="stylesheet" href="../../dist/modal/style.css" media="all">
10
+ <script type="module" src="../../dist/modal/index.js"></script>
11
+ </head>
12
+ <body>
13
+ <main>
14
+ <button id="open-modal">Open Modal</button>
15
+ <tp-modal id="my-modal" overlay-click-close="yes">
16
+ <tp-modal-close>
17
+ <button>Close</button>
18
+ </tp-modal-close>
19
+ <tp-modal-content>
20
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
21
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
22
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
23
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
24
+ </tp-modal-content>
25
+ </tp-modal>
26
+ </main>
27
+
28
+ <script>
29
+ const button = document.getElementById( 'open-modal' );
30
+ const modal = document.getElementById( 'my-modal' );
31
+
32
+ button.addEventListener( 'click', () => modal.open() );
33
+ </script>
34
+ </body>
35
+ </html>
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Styles.
3
+ */
4
+ import './style.scss';
5
+
6
+ /**
7
+ * Components.
8
+ */
9
+ import { TPModalElement } from './tp-modal';
10
+ import { TPModalCloseElement } from './tp-modal-close';
11
+
12
+ /**
13
+ * Register Components.
14
+ */
15
+ customElements.define( 'tp-modal', TPModalElement );
16
+ customElements.define( 'tp-modal-close', TPModalCloseElement );
@@ -0,0 +1,34 @@
1
+ tp-modal {
2
+ display: none;
3
+ background-color: rgba(#000, 0.5);
4
+ backdrop-filter: blur(2px);
5
+ position: fixed;
6
+ height: 100%;
7
+ width: 100%;
8
+ left: 0;
9
+ top: 0;
10
+ z-index: 99;
11
+ max-width: 100%;
12
+ overflow-y: auto;
13
+ padding: 20px;
14
+ box-sizing: border-box;
15
+
16
+ &[open] {
17
+ display: flex;
18
+ }
19
+
20
+ &-close {
21
+ position: absolute;
22
+ top: 20px;
23
+ right: 20px;
24
+ }
25
+
26
+ &-content {
27
+ display: block;
28
+ min-width: 0;
29
+ margin: auto;
30
+ padding: 20px;
31
+ background-color: #fff;
32
+ max-width: 80ch;
33
+ }
34
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Internal dependencies.
3
+ */
4
+ import { TPModalElement } from './tp-modal';
5
+
6
+ /**
7
+ * TP Modal Close.
8
+ */
9
+ export class TPModalCloseElement extends HTMLElement {
10
+ /**
11
+ * Connected callback.
12
+ */
13
+ connectedCallback(): void {
14
+ const button: HTMLButtonElement | null = this.querySelector( 'button' );
15
+ button?.addEventListener( 'click', this.closeModal.bind( this ) );
16
+ }
17
+
18
+ /**
19
+ * Close the modal.
20
+ */
21
+ closeModal(): void {
22
+ const modal: TPModalElement | null = this.closest( 'tp-modal' );
23
+ modal?.close();
24
+ }
25
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * TP Modal.
3
+ */
4
+ export class TPModalElement extends HTMLElement {
5
+ /**
6
+ * Constructor.
7
+ */
8
+ constructor() {
9
+ super();
10
+ document.querySelector( 'body' )?.appendChild( this );
11
+ }
12
+
13
+ /**
14
+ * Connected callback.
15
+ */
16
+ connectedCallback(): void {
17
+ this.addEventListener( 'click', this.handleClick.bind( this ) );
18
+ }
19
+
20
+ /**
21
+ * Open the modal.
22
+ */
23
+ open(): void {
24
+ this.setAttribute( 'open', 'yes' );
25
+ }
26
+
27
+ /**
28
+ * Close the modal.
29
+ */
30
+ close(): void {
31
+ this.removeAttribute( 'open' );
32
+ }
33
+
34
+ /**
35
+ * Handle when the component is clicked.
36
+ *
37
+ * @param {Event} e Event.
38
+ */
39
+ handleClick( e: Event ): void {
40
+ if ( e.target === this && 'yes' === this.getAttribute( 'overlay-click-close' ) ) {
41
+ e.preventDefault();
42
+ e.stopPropagation();
43
+ this.close();
44
+ }
45
+ }
46
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "noImplicitAny": true,
5
+ "noUnusedLocals": true,
6
+ "noUnusedParameters": true,
7
+ "strictNullChecks": true,
8
+ "strictFunctionTypes": true,
9
+ "strictBindCallApply": true,
10
+ "strictPropertyInitialization": true,
11
+ "noImplicitThis": true,
12
+ "alwaysStrict": true,
13
+ "noImplicitReturns": true,
14
+ "module": "es6",
15
+ "target": "es6",
16
+ "jsx": "react-jsx",
17
+ "allowJs": true,
18
+ "moduleResolution": "node",
19
+ "sourceMap": true,
20
+ "allowSyntheticDefaultImports": true
21
+ }
22
+ }
@@ -0,0 +1,88 @@
1
+ // External dependencies.
2
+ const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
3
+ const WebpackNotifierPlugin = require( 'webpack-notifier' );
4
+ const TerserPlugin = require( 'terser-webpack-plugin' );
5
+
6
+ // Config.
7
+ module.exports = ( env ) => {
8
+ // Build configuration.
9
+ const buildConfig = {
10
+ entry: {
11
+ modal: './src/modal/index.ts',
12
+ },
13
+ module: {
14
+ rules: [
15
+ {
16
+ test: /\.tsx?$/,
17
+ use: 'ts-loader',
18
+ exclude: /node_modules/,
19
+ },
20
+ {
21
+ test: /\.(sa|sc|c)ss$/,
22
+ use: [
23
+ MiniCssExtractPlugin.loader,
24
+ {
25
+ loader: 'css-loader',
26
+ options: {
27
+ url: false,
28
+ sourceMap: false,
29
+ },
30
+ },
31
+ {
32
+ loader: 'postcss-loader',
33
+ },
34
+ {
35
+ loader: 'sass-loader',
36
+ options: {
37
+ sassOptions: {
38
+ outputStyle: 'compressed',
39
+ },
40
+ },
41
+ },
42
+ ],
43
+ },
44
+ ],
45
+ },
46
+ resolve: {
47
+ extensions: [ '*', '.js', '.ts', '.tsx' ],
48
+ },
49
+ output: {
50
+ path: __dirname,
51
+ filename: `dist/[name]/index.js`,
52
+ publicPath: '/',
53
+ },
54
+ optimization: {
55
+ removeEmptyChunks: true,
56
+ minimize: true,
57
+ minimizer: [ new TerserPlugin( {
58
+ parallel: true,
59
+ terserOptions: {
60
+ format: {
61
+ comments: false,
62
+ },
63
+ },
64
+ extractComments: false,
65
+ } ) ],
66
+ },
67
+ plugins: [
68
+ new MiniCssExtractPlugin( {
69
+ filename: `dist/[name]/style.css`,
70
+ } ),
71
+ ],
72
+ performance: {
73
+ hints: false,
74
+ },
75
+ devtool: 'source-map',
76
+ };
77
+
78
+ // Development environment.
79
+ if ( 'development' in env ) {
80
+ buildConfig.plugins.push( new WebpackNotifierPlugin( {
81
+ title: 'Build',
82
+ alwaysNotify: true,
83
+ } ) );
84
+ }
85
+
86
+ // Return config.
87
+ return [ buildConfig ];
88
+ };