-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathmodal.ts
More file actions
73 lines (60 loc) · 1.61 KB
/
modal.ts
File metadata and controls
73 lines (60 loc) · 1.61 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import type {CSSResultGroup, PropertyValues} from 'lit';
import {html, LitElement} from 'lit';
import {property} from 'lit/decorators.js';
import {OverlayMixin, withModalDialogConfig} from '@lion/ui/overlays.js';
import styles from './modal.styles';
/**
* @summary Modal that extends the LionDialog web component
*/
export default class CraftModal extends OverlayMixin(LitElement) {
@property({type: String})
name: string | null = null;
// @ts-ignore
_defineOverlayConfig() {
return {
...withModalDialogConfig(),
};
}
static override get styles(): CSSResultGroup {
return [super.styles ?? [], styles];
}
/**
* Applies an aria-label to the content node with the name property.
*/
__setAccessibleName() {
if (!this.name) return;
const contentNode = this._overlayContentNode;
if (contentNode) {
if (!this.name) return;
contentNode.setAttribute('aria-label', this.name);
}
}
override firstUpdated(changed: PropertyValues<this>) {
super.firstUpdated(changed);
if (changed.has('name')) {
this.__setAccessibleName();
}
}
override updated(changed: PropertyValues<this>) {
super.updated(changed);
if (changed.has('name')) {
this.__setAccessibleName();
}
}
override render() {
return html`
<slot name="invoker"></slot>
<div id="overlay-content-node-wrapper">
<slot name="content"></slot>
</div>
`;
}
}
if (!customElements.get('craft-modal')) {
customElements.define('craft-modal', CraftModal);
}
declare global {
interface HTMLElementTagNameMap {
'craft-modal': CraftModal;
}
}