-
Notifications
You must be signed in to change notification settings - Fork 2
/
error-message.js
39 lines (33 loc) · 1.03 KB
/
error-message.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class ErrorMessage extends HTMLElement {
constructor () {
super()
this.attachShadow({ mode: 'open' })
// Create the main element for the error message
const errorElement = document.createElement('p')
errorElement.classList.add('error')
errorElement.textContent =
this.getAttribute('message') || 'An error occurred'
const style = document.createElement('style')
style.textContent = `
.error {
color: var(--rdp-details-color);
text-align: center;
margin: 20px;
font-size: 1rem;
border: 1px solid var(--rdp-border-color);
border-radius: 4px;
padding: 6px;
}
`
this.shadowRoot.append(style, errorElement)
}
static get observedAttributes () {
return ['message']
}
attributeChangedCallback (name, oldValue, newValue) {
if (name === 'message' && oldValue !== newValue) {
this.shadowRoot.querySelector('.error').textContent = newValue
}
}
}
customElements.define('error-message', ErrorMessage)