forked from ProjectEvergreen/greenwood-demo-adapter-vercel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a model component for handling selected product notification (#13)
1 parent
9551355
commit d34d6b0
Showing
3 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { LitElement, html, css } from 'lit'; | ||
|
||
export class Modal extends LitElement { | ||
static properties = { | ||
content: '', | ||
}; | ||
|
||
static styles = css` | ||
dialog { | ||
border: 1px solid #818181; | ||
text-align: center; | ||
width: 40%; | ||
border-radius: 10px; | ||
padding: 2rem 1rem; | ||
min-height: 200px; | ||
background-color: #fff; | ||
overflow-x: hidden; | ||
} | ||
h3 { | ||
font-size: 1.85rem; | ||
} | ||
button { | ||
background: var(--color-accent); | ||
color: var(--color-white); | ||
padding: 1rem 2rem; | ||
border: 0; | ||
font-size: 1rem; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
} | ||
@media(max-width: 768px) { | ||
dialog { | ||
width: 80%; | ||
} | ||
} | ||
`; | ||
|
||
updateModal(content) { | ||
console.log(`selected item is => ${content}`); | ||
const dialog = this.shadowRoot.querySelector('dialog'); | ||
|
||
this.content = content; | ||
|
||
dialog.showModal(); | ||
this.requestUpdate(); | ||
} | ||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
|
||
window.addEventListener('update-modal', (event) => { | ||
this.updateModal(event.detail.content); | ||
}) | ||
} | ||
|
||
firstUpdated() { | ||
const button = this.shadowRoot.querySelector('button') | ||
const dialog = this.shadowRoot.querySelector('dialog'); | ||
|
||
button.addEventListener("click", () => dialog.close()); | ||
} | ||
|
||
render() { | ||
const { content } = this; | ||
|
||
return html` | ||
<dialog> | ||
<h3 id="content">${content}</h3> | ||
<button autofocus>Close</button> | ||
</dialog> | ||
`; | ||
} | ||
} | ||
|
||
customElements.define('app-modal', Modal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters