@travelopia/web-components 0.0.2 → 0.0.4
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/dist/modal/index.js.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/tp-modal-close.d.ts +13 -0
- package/dist/types/tp-modal.d.ts +27 -0
- package/package.json +5 -1
- package/src/modal/README.md +35 -0
- package/src/modal/index.html +35 -0
- package/src/modal/index.ts +16 -0
- package/src/modal/style.scss +34 -0
- package/src/modal/tp-modal-close.ts +25 -0
- package/src/modal/tp-modal.ts +46 -0
package/dist/modal/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dist/modal/index.js","mappings":"mBAGO,MAAMA,UAAuBC,YAInC,WAAAC,G,MACCC,QACgC,QAAhC,EAAAC,SAASC,cAAe,eAAQ,SAAEC,YAAaC,KAChD,CAKA,iBAAAC,GACCD,KAAKE,iBAAkB,QAASF,KAAKG,YAAYC,KAAMJ,MACxD,CAKA,IAAAK,GACCL,KAAKM,aAAc,OAAQ,MAC5B,CAKA,KAAAC,GACCP,KAAKQ,gBAAiB,OACvB,CAOA,WAAAL,CAAaM,GACPA,EAAEC,SAAWV,MAAQ,QAAUA,KAAKW,aAAc,yBACtDF,EAAEG,iBACFH,EAAEI,kBACFb,KAAKO,QAEP,ECpCM,MAAMO,UAA4BpB,YAIxC,iBAAAO,GACC,MAAMc,EAAmCf,KAAKF,cAAe,UAC7DiB,SAAAA,EAAQb,iBAAkB,QAASF,KAAKgB,WAAWZ,KAAMJ,MAC1D,CAKA,UAAAgB,GACC,MAAMC,EAA+BjB,KAAKkB,QAAS,YACnDD,SAAAA,EAAOV,OACR,ECTDY,eAAeC,OAAQ,WAAY3B,GACnC0B,eAAeC,OAAQ,iBAAkBN,E","sources":["webpack
|
|
1
|
+
{"version":3,"file":"dist/modal/index.js","mappings":"mBAGO,MAAMA,UAAuBC,YAInC,WAAAC,G,MACCC,QACgC,QAAhC,EAAAC,SAASC,cAAe,eAAQ,SAAEC,YAAaC,KAChD,CAKA,iBAAAC,GACCD,KAAKE,iBAAkB,QAASF,KAAKG,YAAYC,KAAMJ,MACxD,CAKA,IAAAK,GACCL,KAAKM,aAAc,OAAQ,MAC5B,CAKA,KAAAC,GACCP,KAAKQ,gBAAiB,OACvB,CAOA,WAAAL,CAAaM,GACPA,EAAEC,SAAWV,MAAQ,QAAUA,KAAKW,aAAc,yBACtDF,EAAEG,iBACFH,EAAEI,kBACFb,KAAKO,QAEP,ECpCM,MAAMO,UAA4BpB,YAIxC,iBAAAO,GACC,MAAMc,EAAmCf,KAAKF,cAAe,UAC7DiB,SAAAA,EAAQb,iBAAkB,QAASF,KAAKgB,WAAWZ,KAAMJ,MAC1D,CAKA,UAAAgB,GACC,MAAMC,EAA+BjB,KAAKkB,QAAS,YACnDD,SAAAA,EAAOV,OACR,ECTDY,eAAeC,OAAQ,WAAY3B,GACnC0B,eAAeC,OAAQ,iBAAkBN,E","sources":["webpack://@travelopia/web-components/./src/modal/tp-modal.ts","webpack://@travelopia/web-components/./src/modal/tp-modal-close.ts","webpack://@travelopia/web-components/./src/modal/index.ts"],"sourcesContent":["/**\n * TP Modal.\n */\nexport class TPModalElement extends HTMLElement {\n\t/**\n\t * Constructor.\n\t */\n\tconstructor() {\n\t\tsuper();\n\t\tdocument.querySelector( 'body' )?.appendChild( this );\n\t}\n\n\t/**\n\t * Connected callback.\n\t */\n\tconnectedCallback(): void {\n\t\tthis.addEventListener( 'click', this.handleClick.bind( this ) );\n\t}\n\n\t/**\n\t * Open the modal.\n\t */\n\topen(): void {\n\t\tthis.setAttribute( 'open', 'yes' );\n\t}\n\n\t/**\n\t * Close the modal.\n\t */\n\tclose(): void {\n\t\tthis.removeAttribute( 'open' );\n\t}\n\n\t/**\n\t * Handle when the component is clicked.\n\t *\n\t * @param {Event} e Event.\n\t */\n\thandleClick( e: Event ): void {\n\t\tif ( e.target === this && 'yes' === this.getAttribute( 'overlay-click-close' ) ) {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\t\t\tthis.close();\n\t\t}\n\t}\n}\n","/**\n * Internal dependencies.\n */\nimport { TPModalElement } from './tp-modal';\n\n/**\n * TP Modal Close.\n */\nexport class TPModalCloseElement extends HTMLElement {\n\t/**\n\t * Connected callback.\n\t */\n\tconnectedCallback(): void {\n\t\tconst button: HTMLButtonElement | null = this.querySelector( 'button' );\n\t\tbutton?.addEventListener( 'click', this.closeModal.bind( this ) );\n\t}\n\n\t/**\n\t * Close the modal.\n\t */\n\tcloseModal(): void {\n\t\tconst modal: TPModalElement | null = this.closest( 'tp-modal' );\n\t\tmodal?.close();\n\t}\n}\n","/**\n * Styles.\n */\nimport './style.scss';\n\n/**\n * Components.\n */\nimport { TPModalElement } from './tp-modal';\nimport { TPModalCloseElement } from './tp-modal-close';\n\n/**\n * Register Components.\n */\ncustomElements.define( 'tp-modal', TPModalElement );\ncustomElements.define( 'tp-modal-close', TPModalCloseElement );\n"],"names":["TPModalElement","HTMLElement","constructor","super","document","querySelector","appendChild","this","connectedCallback","addEventListener","handleClick","bind","open","setAttribute","close","removeAttribute","e","target","getAttribute","preventDefault","stopPropagation","TPModalCloseElement","button","closeModal","modal","closest","customElements","define"],"sourceRoot":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TP Modal.
|
|
3
|
+
*/
|
|
4
|
+
export declare class TPModalElement extends HTMLElement {
|
|
5
|
+
/**
|
|
6
|
+
* Constructor.
|
|
7
|
+
*/
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Connected callback.
|
|
11
|
+
*/
|
|
12
|
+
connectedCallback(): void;
|
|
13
|
+
/**
|
|
14
|
+
* Open the modal.
|
|
15
|
+
*/
|
|
16
|
+
open(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Close the modal.
|
|
19
|
+
*/
|
|
20
|
+
close(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Handle when the component is clicked.
|
|
23
|
+
*
|
|
24
|
+
* @param {Event} e Event.
|
|
25
|
+
*/
|
|
26
|
+
handleClick(e: Event): void;
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travelopia/web-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Accessible web components for the modern web",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "webpack --config ./webpack.config.js --mode production --env=production",
|
|
@@ -30,5 +30,9 @@
|
|
|
30
30
|
"webpack": "^5.89.0",
|
|
31
31
|
"webpack-cli": "^5.1.4",
|
|
32
32
|
"webpack-notifier": "^1.15.0"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
"./*": "./dist/*",
|
|
36
|
+
"./package.json": "./package.json"
|
|
33
37
|
}
|
|
34
38
|
}
|
|
@@ -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
|
+
}
|