Skip to content

Commit a7e1e8d

Browse files
committed
Added side modal
1 parent 53044d8 commit a7e1e8d

File tree

7 files changed

+131
-14
lines changed

7 files changed

+131
-14
lines changed

src/component/button/CloseButtonElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class CloseButtonElement extends LitElement {
6060
render() {
6161
return html`
6262
<button role="button" ?disabled="${this.disabled}" @click=${this.onClick}>
63-
<wc-icon name="x-circle"></wc-icon>
63+
<wc-icon name="x-lg"></wc-icon>
6464
</button>
6565
`;
6666
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
import { LitElement, html, css } from 'lit';
3+
4+
/**
5+
* A modal pop-up element which is hidden by default
6+
*/
7+
export class SideModalElement extends LitElement {
8+
constructor() {
9+
super();
10+
// Default properties
11+
this.visible = false;
12+
}
13+
static get properties() {
14+
return {
15+
/**
16+
* Whether the modal is visible
17+
* @type {Boolean}
18+
* @memberof ModalElement
19+
*/
20+
visible: { type: Boolean },
21+
};
22+
}
23+
static get styles() {
24+
return css`
25+
.canvas {
26+
position: fixed;
27+
left: 0;
28+
top: 0;
29+
bottom: 0;
30+
right: 0;
31+
overflow-x: hidden;
32+
overflow-y: hidden;
33+
background-color: var(--modal-canvas-color);
34+
}
35+
.modal {
36+
position: fixed;
37+
top: 0;
38+
bottom: 0;
39+
left: 0;
40+
background-color: var(--modal-background-color);
41+
}
42+
.animation {
43+
transition:
44+
opacity var(--modal-fade-delay) ease,
45+
visibility var(--modal-fade-delay) ease,
46+
display var(--modal-fade-delay) ease,
47+
transform var(--modal-position-delay) ease;
48+
}
49+
.hidden-canvas {
50+
opacity: 0;
51+
visibility: hidden;
52+
}
53+
.hidden-modal {
54+
visibility: hidden;
55+
opacity: 0;
56+
transform: translateX(-12rem);
57+
}
58+
.visible-modal {
59+
visibility: visible;
60+
opacity: 1;
61+
transform: translateX(0);
62+
}
63+
.visible-canvas {
64+
visibility: visible;
65+
opacity: var(--modal-canvas-opacity);
66+
}
67+
.wrapper {
68+
position: relative;
69+
width: auto;
70+
height: auto;
71+
}`;
72+
}
73+
render() {
74+
return html`
75+
<div class="canvas animation ${this.visible ? 'visible-canvas' : 'hidden-canvas'}"></div>
76+
<div class="modal animation ${this.visible ? 'visible-modal' : 'hidden-modal'}">
77+
<div class="wrapper"><slot></slot></div>
78+
</div>
79+
`;
80+
}
81+
toggle() {
82+
this.visible = !this.visible;
83+
}
84+
show() {
85+
this.visible = true;
86+
}
87+
hide() {
88+
this.visible = false;
89+
}
90+
}
91+
92+
customElements.define('wc-sidemodal', SideModalElement);

src/core/event.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Define events used by web components
22
const EVENT_CLICK = 'js-click';
3+
const EVENT_HOVER = 'js-hover';
34
const EVENT_START = 'js-start';
45
const EVENT_DONE = 'js-done';
56
const EVENT_ERROR = 'js-error';
67

78
export default {
8-
EVENT_CLICK, EVENT_START, EVENT_DONE, EVENT_ERROR,
9+
EVENT_CLICK, EVENT_HOVER, EVENT_START, EVENT_DONE, EVENT_ERROR,
910
};

src/css/core.css

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@
112112
--icon-size-large: 2em;
113113
--icon-size-xlarge: 3em;
114114

115+
/* modal */
116+
--modal-margin-x: 20%;
117+
--modal-padding: calc(var(--spacer) * 1.5);
118+
--modal-background-color: var(--body-background-color);
119+
--modal-border: calc(var(--spacer) * 0.3);
120+
--modal-border-radius: var(--border-radius);
121+
--modal-fade-delay: 300ms;
122+
--modal-position-delay: 300ms;
123+
--modal-fadein-delay: var(-modal-fade-delay);
124+
--modal-fadeout-delay: var(-modal-fade-delay);
125+
--modal-canvas-color: var(--black-color);
126+
--modal-canvas-opacity: 0.7;
127+
115128
/* navbar */
116129
--navbar-color: var(--light-color);
117130
--navbar-background-color: var(--primary-color);
@@ -168,14 +181,4 @@
168181
--form-label-line-height: 1;
169182
--form-label-border: none;
170183

171-
/* modal */
172-
--modal-margin-x: 20%;
173-
--modal-padding: calc(var(--spacer) * 1.5);
174-
--modal-canvas-color: var(--black-color);
175-
--modal-background-color: var(--body-background-color);
176-
--modal-border: calc(var(--spacer) * 0.2);
177-
--modal-border-radius: var(--border-radius);
178-
--modal-canvas-opacity: 0.7;
179-
--modal-fadein-delay: 300ms;
180-
--modal-fadeout-delay: 300ms;
181184
}

src/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,14 @@ <h1>Modal</h1>
8989
<wc-button name="modal">Pop-up</wc-button>
9090
<wc-modal>
9191
<wc-close name="modal-close"></wc-close>
92-
<p>Here is some content within a container</p>
92+
<p>Here is some content within a modal</p>
9393
</wc-modal>
94+
<wc-sidemodal>
95+
<wc-close name="modal-close"></wc-close>
96+
<div class=""container">
97+
<p>Here is some content within a sidemodal</p>
98+
</div>
99+
</wc-sidemodal>
94100
</div>
95101
</body>
96102

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import './component/nav/NavItemElement';
1919

2020
// Modals
2121
import './component/modal/ModalElement';
22+
import './component/modal/SideModalElement';
2223

2324
// CSS
2425
import './css/core.css';

src/test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,25 @@ window.addEventListener('load', () => {
4848
document.querySelector('wc-modal').hide();
4949
}
5050
});
51+
document.querySelector('wc-sidemodal').addEventListener(Event.EVENT_CLICK, (evt) => {
52+
if (evt.detail == "modal-close") {
53+
document.querySelector('wc-sidemodal').hide();
54+
}
55+
});
5156

5257
// NavItem
5358
document.querySelectorAll('wc-nav-item').forEach((navitem) => {
5459
navitem.addEventListener(Event.EVENT_CLICK, (evt) => {
55-
console.log("NavItem Click", evt.detail);
60+
switch (evt.detail) {
61+
case "menu":
62+
document.querySelector('wc-sidemodal').toggle();
63+
break;
64+
case 'help':
65+
document.querySelector('wc-sidemodal').toggle();
66+
break;
67+
default:
68+
console.log("NavItem Click", evt.detail);
69+
}
5670
});
5771
});
5872
});

0 commit comments

Comments
 (0)