snice 1.14.3 → 2.1.0
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/bin/templates/base/tsconfig.json +5 -4
- package/components/accordion/demo.html +403 -0
- package/components/accordion/snice-accordion-item.css +85 -0
- package/components/accordion/snice-accordion-item.ts +226 -0
- package/components/accordion/snice-accordion.css +31 -0
- package/components/accordion/snice-accordion.ts +182 -0
- package/components/accordion/snice-accordion.types.ts +32 -0
- package/components/alert/demo.html +445 -0
- package/components/alert/snice-alert.css +195 -0
- package/components/alert/snice-alert.ts +141 -0
- package/components/alert/snice-alert.types.ts +12 -0
- package/components/avatar/demo.html +598 -0
- package/components/avatar/snice-avatar.css +131 -0
- package/components/avatar/snice-avatar.ts +136 -0
- package/components/avatar/snice-avatar.types.ts +13 -0
- package/components/badge/demo.html +523 -0
- package/components/badge/snice-badge.css +161 -0
- package/components/badge/snice-badge.ts +117 -0
- package/components/badge/snice-badge.types.ts +16 -0
- package/components/breadcrumbs/demo.html +404 -0
- package/components/breadcrumbs/snice-breadcrumbs.css +133 -0
- package/components/breadcrumbs/snice-breadcrumbs.ts +191 -0
- package/components/breadcrumbs/snice-breadcrumbs.types.ts +26 -0
- package/components/breadcrumbs/snice-crumb.ts +26 -0
- package/components/button/demo.html +42 -0
- package/components/button/snice-button.css +230 -0
- package/components/button/snice-button.ts +169 -0
- package/components/button/snice-button.types.ts +25 -0
- package/components/card/demo.html +525 -0
- package/components/card/snice-card.css +140 -0
- package/components/card/snice-card.ts +102 -0
- package/components/card/snice-card.types.ts +10 -0
- package/components/checkbox/demo.html +253 -0
- package/components/checkbox/snice-checkbox.css +164 -0
- package/components/checkbox/snice-checkbox.ts +223 -0
- package/components/checkbox/snice-checkbox.types.ts +22 -0
- package/components/chip/demo.html +383 -0
- package/components/chip/snice-chip.css +195 -0
- package/components/chip/snice-chip.ts +139 -0
- package/components/chip/snice-chip.types.ts +15 -0
- package/components/date-picker/README.md +233 -0
- package/components/date-picker/demo.html +191 -0
- package/components/date-picker/snice-date-picker.css +330 -0
- package/components/date-picker/snice-date-picker.ts +777 -0
- package/components/date-picker/snice-date-picker.types.ts +83 -0
- package/components/divider/demo.html +233 -0
- package/components/divider/snice-divider.css +155 -0
- package/components/divider/snice-divider.ts +69 -0
- package/components/divider/snice-divider.types.ts +15 -0
- package/components/drawer/demo.html +328 -0
- package/components/drawer/snice-drawer.css +476 -0
- package/components/drawer/snice-drawer.ts +287 -0
- package/components/drawer/snice-drawer.types.ts +17 -0
- package/components/global.d.ts +14 -0
- package/components/input/demo.html +303 -0
- package/components/input/snice-input.css +257 -0
- package/components/input/snice-input.ts +442 -0
- package/components/input/snice-input.types.ts +59 -0
- package/components/input/test.html +77 -0
- package/components/layout/README.md +260 -0
- package/components/layout/demo.html +538 -0
- package/components/layout/snice-layout-blog.css +129 -0
- package/components/layout/snice-layout-blog.ts +48 -0
- package/components/layout/snice-layout-card.css +104 -0
- package/components/layout/snice-layout-card.ts +35 -0
- package/components/layout/snice-layout-centered.css +51 -0
- package/components/layout/snice-layout-centered.ts +22 -0
- package/components/layout/snice-layout-dashboard.css +98 -0
- package/components/layout/snice-layout-dashboard.ts +45 -0
- package/components/layout/snice-layout-fullscreen.css +72 -0
- package/components/layout/snice-layout-fullscreen.ts +34 -0
- package/components/layout/snice-layout-landing.css +92 -0
- package/components/layout/snice-layout-landing.ts +47 -0
- package/components/layout/snice-layout-minimal.css +16 -0
- package/components/layout/snice-layout-minimal.ts +19 -0
- package/components/layout/snice-layout-sidebar.css +117 -0
- package/components/layout/snice-layout-sidebar.ts +48 -0
- package/components/layout/snice-layout-split.css +103 -0
- package/components/layout/snice-layout-split.ts +29 -0
- package/components/layout/snice-layout.css +72 -0
- package/components/layout/snice-layout.ts +35 -0
- package/components/layout/snice-layout.types.ts +5 -0
- package/components/login/demo-auth-controller.ts +185 -0
- package/components/login/demo.html +470 -0
- package/components/login/snice-login.css +204 -0
- package/components/login/snice-login.ts +337 -0
- package/components/login/snice-login.types.ts +34 -0
- package/components/modal/demo.html +291 -0
- package/components/modal/snice-modal.css +203 -0
- package/components/modal/snice-modal.ts +233 -0
- package/components/modal/snice-modal.types.ts +21 -0
- package/components/pagination/demo.html +395 -0
- package/components/pagination/snice-pagination.ts +333 -0
- package/components/pagination/snice-pagination.types.ts +21 -0
- package/components/progress/demo.html +510 -0
- package/components/progress/snice-progress.css +267 -0
- package/components/progress/snice-progress.ts +247 -0
- package/components/progress/snice-progress.types.ts +19 -0
- package/components/radio/demo.html +287 -0
- package/components/radio/snice-radio.css +171 -0
- package/components/radio/snice-radio.ts +218 -0
- package/components/radio/snice-radio.types.ts +21 -0
- package/components/select/demo.html +511 -0
- package/components/select/snice-option.ts +52 -0
- package/components/select/snice-option.types.ts +14 -0
- package/components/select/snice-select.css +392 -0
- package/components/select/snice-select.ts +796 -0
- package/components/select/snice-select.types.ts +55 -0
- package/components/skeleton/demo.html +514 -0
- package/components/skeleton/snice-skeleton.css +109 -0
- package/components/skeleton/snice-skeleton.ts +126 -0
- package/components/skeleton/snice-skeleton.types.ts +11 -0
- package/components/switch/demo.html +284 -0
- package/components/switch/snice-switch.css +221 -0
- package/components/switch/snice-switch.ts +229 -0
- package/components/switch/snice-switch.types.ts +23 -0
- package/components/symbols.ts +23 -0
- package/components/table/demo-table-controller.ts +100 -0
- package/components/table/demo.html +480 -0
- package/components/table/snice-cell-boolean.ts +112 -0
- package/components/table/snice-cell-date.ts +210 -0
- package/components/table/snice-cell-duration.ts +91 -0
- package/components/table/snice-cell-filesize.ts +90 -0
- package/components/table/snice-cell-number.ts +165 -0
- package/components/table/snice-cell-progress.ts +83 -0
- package/components/table/snice-cell-rating.ts +82 -0
- package/components/table/snice-cell-sparkline.ts +253 -0
- package/components/table/snice-cell-text.ts +125 -0
- package/components/table/snice-cell.css +296 -0
- package/components/table/snice-cell.ts +473 -0
- package/components/table/snice-column.ts +353 -0
- package/components/table/snice-header.css +243 -0
- package/components/table/snice-header.ts +261 -0
- package/components/table/snice-progress.ts +66 -0
- package/components/table/snice-rating.ts +45 -0
- package/components/table/snice-row.css +255 -0
- package/components/table/snice-row.ts +331 -0
- package/components/table/snice-table.css +241 -0
- package/components/table/snice-table.ts +737 -0
- package/components/table/snice-table.types.ts +158 -0
- package/components/tabs/demo.html +487 -0
- package/components/tabs/snice-tab-panel.css +264 -0
- package/components/tabs/snice-tab-panel.ts +47 -0
- package/components/tabs/snice-tab.css +96 -0
- package/components/tabs/snice-tab.ts +65 -0
- package/components/tabs/snice-tabs.css +189 -0
- package/components/tabs/snice-tabs.ts +332 -0
- package/components/tabs/snice-tabs.types.ts +28 -0
- package/components/theme/theme.css +234 -0
- package/components/toast/demo.html +329 -0
- package/components/toast/snice-toast-container.ts +256 -0
- package/components/toast/snice-toast.css +213 -0
- package/components/toast/snice-toast.ts +276 -0
- package/components/toast/snice-toast.types.ts +35 -0
- package/components/tooltip/demo.html +350 -0
- package/components/tooltip/snice-tooltip-portal.css +79 -0
- package/components/tooltip/snice-tooltip.css +117 -0
- package/components/tooltip/snice-tooltip.ts +612 -0
- package/components/tooltip/snice-tooltip.types.ts +32 -0
- package/components/transitions.ts +94 -0
- package/components/tsconfig.json +18 -0
- package/dist/index.cjs +441 -329
- package/dist/index.cjs.map +1 -1
- package/dist/index.cjs.min.map +1 -1
- package/dist/index.esm.js +441 -329
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +3 -3
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +441 -329
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +3 -3
- package/dist/index.iife.min.js.map +1 -1
- package/dist/symbols.esm.js +1 -1
- package/dist/transitions.esm.js +1 -1
- package/dist/types/controller.d.ts +1 -1
- package/dist/types/element.d.ts +10 -10
- package/dist/types/events.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/observe.d.ts +1 -1
- package/dist/types/request-response.d.ts +2 -3
- package/dist/types/router.d.ts +1 -1
- package/package.json +9 -3
- package/dist/index.cjs.min +0 -15
- package/dist/symbols.cjs +0 -103
- package/dist/transitions.cjs +0 -219
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
--modal-z-index: 1000;
|
|
3
|
+
--modal-backdrop-bg: rgba(0, 0, 0, 0.5);
|
|
4
|
+
--modal-panel-bg: var(--snice-color-background, white);
|
|
5
|
+
--modal-panel-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
|
6
|
+
--modal-border-radius: var(--snice-border-radius-lg, 8px);
|
|
7
|
+
--modal-padding: var(--snice-spacing-lg, 1.5rem);
|
|
8
|
+
--modal-transition-duration: 200ms;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.modal {
|
|
12
|
+
position: fixed;
|
|
13
|
+
top: 0;
|
|
14
|
+
left: 0;
|
|
15
|
+
right: 0;
|
|
16
|
+
bottom: 0;
|
|
17
|
+
z-index: var(--modal-z-index);
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
padding: var(--modal-padding);
|
|
22
|
+
pointer-events: none;
|
|
23
|
+
opacity: 0;
|
|
24
|
+
visibility: hidden;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.modal--open {
|
|
28
|
+
pointer-events: auto;
|
|
29
|
+
opacity: 1;
|
|
30
|
+
visibility: visible;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.modal__backdrop {
|
|
34
|
+
position: absolute;
|
|
35
|
+
top: 0;
|
|
36
|
+
left: 0;
|
|
37
|
+
right: 0;
|
|
38
|
+
bottom: 0;
|
|
39
|
+
background: var(--modal-backdrop-bg);
|
|
40
|
+
opacity: 0;
|
|
41
|
+
transition: opacity var(--modal-transition-duration) ease;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.modal--open .modal__backdrop {
|
|
45
|
+
opacity: 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.modal__panel {
|
|
49
|
+
position: relative;
|
|
50
|
+
background: var(--modal-panel-bg);
|
|
51
|
+
border-radius: var(--modal-border-radius);
|
|
52
|
+
box-shadow: var(--modal-panel-shadow);
|
|
53
|
+
display: flex;
|
|
54
|
+
flex-direction: column;
|
|
55
|
+
max-height: calc(100vh - 2 * var(--modal-padding));
|
|
56
|
+
opacity: 0;
|
|
57
|
+
transform: scale(0.95) translateY(1.25rem); /* 20px */
|
|
58
|
+
transition:
|
|
59
|
+
opacity var(--modal-transition-duration) ease,
|
|
60
|
+
transform var(--modal-transition-duration) ease;
|
|
61
|
+
z-index: 1;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.modal--open .modal__panel {
|
|
65
|
+
opacity: 1;
|
|
66
|
+
transform: scale(1) translateY(0);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Sizes */
|
|
70
|
+
.modal__panel--small {
|
|
71
|
+
width: 100%;
|
|
72
|
+
max-width: 25rem; /* 400px */
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.modal__panel--medium {
|
|
76
|
+
width: 100%;
|
|
77
|
+
max-width: 37.5rem; /* 600px */
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.modal__panel--large {
|
|
81
|
+
width: 100%;
|
|
82
|
+
max-width: 56.25rem; /* 900px */
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.modal__panel--fullscreen {
|
|
86
|
+
width: calc(100vw - 2 * var(--modal-padding));
|
|
87
|
+
height: calc(100vh - 2 * var(--modal-padding));
|
|
88
|
+
max-width: none;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.modal__header {
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
justify-content: space-between;
|
|
95
|
+
padding: var(--modal-padding);
|
|
96
|
+
border-bottom: 1px solid var(--snice-color-border, #e5e7eb);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.modal__header:empty {
|
|
100
|
+
display: none;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
::slotted([slot="header"]) {
|
|
104
|
+
flex: 1;
|
|
105
|
+
margin: 0;
|
|
106
|
+
font-size: var(--snice-font-size-lg, 1.125rem);
|
|
107
|
+
font-weight: 600;
|
|
108
|
+
color: var(--snice-color-text, #111827);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.modal__close {
|
|
112
|
+
display: flex;
|
|
113
|
+
align-items: center;
|
|
114
|
+
justify-content: center;
|
|
115
|
+
width: 2rem; /* 32px */
|
|
116
|
+
height: 2rem; /* 32px */
|
|
117
|
+
padding: 0;
|
|
118
|
+
margin-left: auto;
|
|
119
|
+
background: transparent;
|
|
120
|
+
border: none;
|
|
121
|
+
border-radius: var(--snice-border-radius-md, 6px);
|
|
122
|
+
color: var(--snice-color-text-secondary, #6b7280);
|
|
123
|
+
cursor: pointer;
|
|
124
|
+
transition:
|
|
125
|
+
background-color var(--snice-transition-fast) ease,
|
|
126
|
+
color var(--snice-transition-fast) ease;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.modal__close:hover {
|
|
130
|
+
background: var(--snice-color-background-hover, #f3f4f6);
|
|
131
|
+
color: var(--snice-color-text, #111827);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.modal__close:focus-visible {
|
|
135
|
+
outline: 2px solid var(--snice-color-primary, #3b82f6);
|
|
136
|
+
outline-offset: 2px;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.modal__body {
|
|
140
|
+
flex: 1;
|
|
141
|
+
padding: var(--modal-padding);
|
|
142
|
+
overflow-y: auto;
|
|
143
|
+
color: var(--snice-color-text, #111827);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.modal__footer {
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
justify-content: flex-end;
|
|
150
|
+
gap: var(--snice-spacing-sm, 0.5rem);
|
|
151
|
+
padding: var(--modal-padding);
|
|
152
|
+
border-top: 1px solid var(--snice-color-border, #e5e7eb);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.modal__footer:empty {
|
|
156
|
+
display: none;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* Remove borders when header/footer are empty */
|
|
160
|
+
.modal__header:empty + .modal__body {
|
|
161
|
+
padding-top: var(--modal-padding);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.modal__body:has(+ .modal__footer:empty) {
|
|
165
|
+
padding-bottom: var(--modal-padding);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* Animation for entrance from bottom (alternative) */
|
|
169
|
+
@keyframes slideUp {
|
|
170
|
+
from {
|
|
171
|
+
opacity: 0;
|
|
172
|
+
transform: translateY(6.25rem); /* 100px */
|
|
173
|
+
}
|
|
174
|
+
to {
|
|
175
|
+
opacity: 1;
|
|
176
|
+
transform: translateY(0);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/* Animation for exit */
|
|
181
|
+
@keyframes fadeOut {
|
|
182
|
+
from {
|
|
183
|
+
opacity: 1;
|
|
184
|
+
}
|
|
185
|
+
to {
|
|
186
|
+
opacity: 0;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* Mobile responsiveness */
|
|
191
|
+
@media (max-width: 640px) {
|
|
192
|
+
.modal {
|
|
193
|
+
padding: 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.modal__panel:not(.modal__panel--fullscreen) {
|
|
197
|
+
width: 100%;
|
|
198
|
+
height: 100%;
|
|
199
|
+
max-width: none;
|
|
200
|
+
max-height: none;
|
|
201
|
+
border-radius: 0;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { element, property, query, on, watch, ready, dispatch } from 'snice';
|
|
2
|
+
import css from './snice-modal.css?inline';
|
|
3
|
+
import type { ModalSize, SniceModalElement } from './snice-modal.types';
|
|
4
|
+
|
|
5
|
+
@element('snice-modal')
|
|
6
|
+
export class SniceModal extends HTMLElement implements SniceModalElement {
|
|
7
|
+
@property({ type: Boolean, reflect: true })
|
|
8
|
+
open = false;
|
|
9
|
+
|
|
10
|
+
@property({ reflect: true })
|
|
11
|
+
size: ModalSize = 'medium';
|
|
12
|
+
|
|
13
|
+
private previousSize = 'medium';
|
|
14
|
+
|
|
15
|
+
@property({ type: Boolean, attribute: 'no-backdrop-dismiss', reflect: true })
|
|
16
|
+
noBackdropDismiss = false;
|
|
17
|
+
|
|
18
|
+
@property({ type: Boolean, attribute: 'no-escape-dismiss', reflect: true })
|
|
19
|
+
noEscapeDismiss = false;
|
|
20
|
+
|
|
21
|
+
@property({ type: Boolean, attribute: 'no-focus-trap', reflect: true })
|
|
22
|
+
noFocusTrap = false;
|
|
23
|
+
|
|
24
|
+
@property({ type: Boolean, attribute: 'no-close-button', reflect: true })
|
|
25
|
+
noCloseButton = false;
|
|
26
|
+
|
|
27
|
+
@property({ reflect: true })
|
|
28
|
+
label = '';
|
|
29
|
+
|
|
30
|
+
@query('.modal')
|
|
31
|
+
modal?: HTMLElement;
|
|
32
|
+
|
|
33
|
+
@query('.modal__panel')
|
|
34
|
+
panel?: HTMLElement;
|
|
35
|
+
|
|
36
|
+
@query('.modal__backdrop')
|
|
37
|
+
backdrop?: HTMLElement;
|
|
38
|
+
|
|
39
|
+
private previousFocus: HTMLElement | null = null;
|
|
40
|
+
|
|
41
|
+
html() {
|
|
42
|
+
// Renders once - initial state
|
|
43
|
+
return /*html*/`
|
|
44
|
+
<div class="modal"
|
|
45
|
+
role="dialog"
|
|
46
|
+
aria-modal="true"
|
|
47
|
+
aria-label="${this.label}"
|
|
48
|
+
aria-hidden="true">
|
|
49
|
+
<div class="modal__backdrop" part="backdrop"></div>
|
|
50
|
+
<div class="modal__panel modal__panel--${this.size}" part="panel">
|
|
51
|
+
<div class="modal__header" part="header">
|
|
52
|
+
<slot name="header"></slot>
|
|
53
|
+
<button class="modal__close" part="close" aria-label="Close modal">
|
|
54
|
+
<svg viewBox="0 0 24 24" width="20" height="20">
|
|
55
|
+
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" fill="currentColor"/>
|
|
56
|
+
</svg>
|
|
57
|
+
</button>
|
|
58
|
+
</div>
|
|
59
|
+
<div class="modal__body" part="body">
|
|
60
|
+
<slot></slot>
|
|
61
|
+
</div>
|
|
62
|
+
<div class="modal__footer" part="footer">
|
|
63
|
+
<slot name="footer"></slot>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
css() {
|
|
71
|
+
return css;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@ready()
|
|
75
|
+
init() {
|
|
76
|
+
// Make sure modal state is properly initialized
|
|
77
|
+
if (this.open) {
|
|
78
|
+
this.showModal();
|
|
79
|
+
}
|
|
80
|
+
// Apply initial close button state
|
|
81
|
+
if (this.noCloseButton) {
|
|
82
|
+
const closeButton = this.shadowRoot?.querySelector('.modal__close') as HTMLElement;
|
|
83
|
+
if (closeButton) {
|
|
84
|
+
closeButton.style.display = 'none';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@watch('open')
|
|
90
|
+
handleOpenChange() {
|
|
91
|
+
// Imperatively update the modal DOM
|
|
92
|
+
if (this.modal) {
|
|
93
|
+
if (this.open) {
|
|
94
|
+
this.modal.classList.add('modal--open');
|
|
95
|
+
this.modal.setAttribute('aria-hidden', 'false');
|
|
96
|
+
this.showModal();
|
|
97
|
+
} else {
|
|
98
|
+
this.modal.classList.remove('modal--open');
|
|
99
|
+
this.modal.setAttribute('aria-hidden', 'true');
|
|
100
|
+
this.hideModal();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@watch('size')
|
|
106
|
+
handleSizeChange() {
|
|
107
|
+
// Imperatively update the panel size class
|
|
108
|
+
if (this.panel) {
|
|
109
|
+
this.panel.classList.remove(`modal__panel--${this.previousSize}`);
|
|
110
|
+
this.panel.classList.add(`modal__panel--${this.size}`);
|
|
111
|
+
this.previousSize = this.size;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@watch('noCloseButton')
|
|
116
|
+
handleCloseButtonChange() {
|
|
117
|
+
// Imperatively show/hide the close button
|
|
118
|
+
const closeButton = this.shadowRoot?.querySelector('.modal__close') as HTMLElement;
|
|
119
|
+
if (closeButton) {
|
|
120
|
+
closeButton.style.display = this.noCloseButton ? 'none' : '';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@on('click', '.modal__backdrop')
|
|
125
|
+
handleBackdropClick() {
|
|
126
|
+
if (!this.noBackdropDismiss) {
|
|
127
|
+
this.close();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@on('click', '.modal__close')
|
|
132
|
+
handleCloseClick() {
|
|
133
|
+
this.close();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@on('keydown:Escape', { stopPropagation: true })
|
|
137
|
+
handleEscape() {
|
|
138
|
+
if (!this.open) return;
|
|
139
|
+
if (!this.noEscapeDismiss) {
|
|
140
|
+
this.close();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
@on('keydown:Tab')
|
|
145
|
+
handleTab(e: KeyboardEvent) {
|
|
146
|
+
if (!this.open) return;
|
|
147
|
+
if (!this.noFocusTrap) {
|
|
148
|
+
this.trapFocus(e);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
private showModal() {
|
|
154
|
+
// Store current focus
|
|
155
|
+
this.previousFocus = document.activeElement as HTMLElement;
|
|
156
|
+
|
|
157
|
+
// Lock body scroll
|
|
158
|
+
document.body.style.overflow = 'hidden';
|
|
159
|
+
|
|
160
|
+
// Focus first focusable element or modal itself
|
|
161
|
+
requestAnimationFrame(() => {
|
|
162
|
+
const firstFocusable = this.panel?.querySelector<HTMLElement>(
|
|
163
|
+
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
164
|
+
);
|
|
165
|
+
if (firstFocusable) {
|
|
166
|
+
firstFocusable.focus();
|
|
167
|
+
} else {
|
|
168
|
+
this.panel?.focus();
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
this.dispatchOpenEvent();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private hideModal() {
|
|
176
|
+
// Restore body scroll
|
|
177
|
+
document.body.style.overflow = '';
|
|
178
|
+
|
|
179
|
+
// Restore previous focus
|
|
180
|
+
if (this.previousFocus) {
|
|
181
|
+
this.previousFocus.focus();
|
|
182
|
+
this.previousFocus = null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
this.dispatchCloseEvent();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private trapFocus(e: KeyboardEvent) {
|
|
189
|
+
if (!this.panel) return;
|
|
190
|
+
|
|
191
|
+
const focusableElements = this.panel.querySelectorAll<HTMLElement>(
|
|
192
|
+
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
const focusable = Array.from(focusableElements);
|
|
196
|
+
const firstFocusable = focusable[0];
|
|
197
|
+
const lastFocusable = focusable[focusable.length - 1];
|
|
198
|
+
|
|
199
|
+
if (e.shiftKey) {
|
|
200
|
+
// Shift + Tab
|
|
201
|
+
if (document.activeElement === firstFocusable) {
|
|
202
|
+
lastFocusable?.focus();
|
|
203
|
+
e.preventDefault();
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
// Tab
|
|
207
|
+
if (document.activeElement === lastFocusable) {
|
|
208
|
+
firstFocusable?.focus();
|
|
209
|
+
e.preventDefault();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
@dispatch('@snice/modal-open', { bubbles: true, composed: true })
|
|
215
|
+
private dispatchOpenEvent() {
|
|
216
|
+
return { modal: this };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@dispatch('@snice/modal-close', { bubbles: true, composed: true })
|
|
220
|
+
private dispatchCloseEvent() {
|
|
221
|
+
return { modal: this };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Public API
|
|
225
|
+
show() {
|
|
226
|
+
this.open = true;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
close() {
|
|
230
|
+
this.open = false;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type ModalSize = 'small' | 'medium' | 'large' | 'fullscreen';
|
|
2
|
+
|
|
3
|
+
export interface SniceModalElement extends HTMLElement {
|
|
4
|
+
open: boolean;
|
|
5
|
+
size: ModalSize;
|
|
6
|
+
noBackdropDismiss: boolean;
|
|
7
|
+
noEscapeDismiss: boolean;
|
|
8
|
+
noFocusTrap: boolean;
|
|
9
|
+
noCloseButton: boolean;
|
|
10
|
+
label: string;
|
|
11
|
+
show(): void;
|
|
12
|
+
close(): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ModalOpenDetail {
|
|
16
|
+
modal: SniceModalElement;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ModalCloseDetail {
|
|
20
|
+
modal: SniceModalElement;
|
|
21
|
+
}
|