@reliability-design/web 1.1.1 → 1.2.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.
Files changed (64) hide show
  1. package/dist/components/rel-accordion/rel-accordion.ts +17 -32
  2. package/dist/components/rel-alert/rel-alert.ts +34 -34
  3. package/dist/components/rel-avatar/rel-avatar.ts +5 -3
  4. package/dist/components/rel-badge/rel-badge.ts +2 -1
  5. package/dist/components/rel-breadcrumb/rel-breadcrumb.ts +6 -6
  6. package/dist/components/rel-button/rel-button.ts +67 -21
  7. package/dist/components/rel-calendar/rel-calendar.ts +15 -8
  8. package/dist/components/rel-card/rel-card.ts +9 -17
  9. package/dist/components/rel-cardmedia/rel-cardmedia.ts +20 -23
  10. package/dist/components/rel-carousel/rel-carousel.ts +596 -468
  11. package/dist/components/rel-checkbox/rel-checkbox.ts +68 -16
  12. package/dist/components/rel-chip/rel-chip.ts +291 -244
  13. package/dist/components/rel-container/rel-container.ts +2 -2
  14. package/dist/components/rel-date-picker/rel-date-picker.ts +23 -19
  15. package/dist/components/rel-divider/rel-divider.ts +3 -3
  16. package/dist/components/rel-drawer/rel-drawer-footer.ts +0 -2
  17. package/dist/components/rel-drawer/rel-drawer.ts +41 -88
  18. package/dist/components/rel-kbd/rel-kbd.ts +94 -118
  19. package/dist/components/rel-layout/rel-layout.ts +49 -58
  20. package/dist/components/rel-menu/rel-menu.ts +359 -359
  21. package/dist/components/rel-menubar/rel-menubar-menu.css +3 -0
  22. package/dist/components/rel-menubar/rel-menubar-menu.ts +2 -1
  23. package/dist/components/rel-menubar/rel-menubar.ts +602 -605
  24. package/dist/components/rel-otp/rel-otp.ts +22 -25
  25. package/dist/components/rel-pagination/rel-pagination.ts +101 -57
  26. package/dist/components/rel-popover/rel-popover-content.ts +6 -5
  27. package/dist/components/rel-popover/rel-popover.ts +26 -7
  28. package/dist/components/rel-progress/rel-progress.ts +10 -9
  29. package/dist/components/rel-radio/rel-radio.ts +228 -172
  30. package/dist/components/rel-range-picker/rel-range-picker.css +349 -0
  31. package/dist/components/rel-range-picker/rel-range-picker.ts +1079 -0
  32. package/dist/components/rel-resizable/rel-resizable-handle.ts +8 -7
  33. package/dist/components/rel-segmented-button/rel-segmented-button.ts +41 -20
  34. package/dist/components/rel-select/rel-select.ts +103 -32
  35. package/dist/components/rel-sheet/rel-sheet.ts +362 -684
  36. package/dist/components/rel-slider/rel-slider.ts +49 -27
  37. package/dist/components/rel-snackbar/rel-snackbar.ts +28 -28
  38. package/dist/components/rel-stepper/rel-stepper.ts +11 -10
  39. package/dist/components/rel-switch/rel-switch.ts +7 -6
  40. package/dist/components/rel-tab/rel-tab.ts +15 -29
  41. package/dist/components/rel-textfield/rel-textfield.ts +144 -35
  42. package/dist/components/rel-toast/rel-toast.ts +25 -12
  43. package/dist/components/rel-tooltip/rel-tooltip.ts +123 -123
  44. package/dist/components/rel-topbar/rel-topbar-actions.ts +1 -0
  45. package/dist/components/rel-topbar/rel-topbar-brand.ts +1 -0
  46. package/dist/components/rel-topbar/rel-topbar-dropdown-item.ts +32 -2
  47. package/dist/components/rel-topbar/rel-topbar-dropdown.ts +1 -1
  48. package/dist/components/rel-topbar/rel-topbar-item.ts +15 -10
  49. package/dist/components/rel-topbar/rel-topbar-mobile-panel.ts +1 -0
  50. package/dist/components/rel-topbar/rel-topbar-profile.ts +30 -56
  51. package/dist/components/rel-topbar/rel-topbar-utilities.ts +1 -0
  52. package/dist/components/rel-topbar/rel-topbar.ts +137 -28
  53. package/dist/index.d.mts +153 -178
  54. package/dist/index.d.ts +153 -178
  55. package/dist/index.js +4711 -3875
  56. package/dist/index.js.map +1 -1
  57. package/dist/index.mjs +4047 -3202
  58. package/dist/index.mjs.map +1 -1
  59. package/dist/rel-menubar-menu-BEEQDAXW.css +3 -0
  60. package/dist/styles/vars-v2.css +525 -0
  61. package/dist/styles/vars.css +346 -346
  62. package/dist/{vars-TBB4BMSD.css → vars-I2PC74XD.css} +346 -346
  63. package/dist/vars-v2-VMGWTFJZ.css +525 -0
  64. package/package.json +2 -1
@@ -1,684 +1,362 @@
1
- import { LitElement, html, css } from "lit";
2
- import { customElement, property, state, query } from "lit/decorators.js";
3
-
4
- export type SheetSide = "top" | "right" | "bottom" | "left";
5
- export type SheetSize = "sm" | "md" | "lg" | "xl";
6
- export type SheetCloseReason = "trigger" | "close" | "overlay" | "escape" | "api";
7
-
8
- // ============================================================================
9
- // rel-sheet (Controller/Root Component)
10
- // ============================================================================
11
- @customElement("rel-sheet")
12
- export class RelSheet extends LitElement {
13
- @property({ type: Boolean, reflect: true }) open?: boolean;
14
- @property({ type: Boolean, attribute: "defaultopen" }) defaultOpen = false;
15
- @property({ type: Boolean }) disabled = false;
16
- @property({ type: Boolean }) modal = true;
17
-
18
- @state() private internalOpen = false;
19
-
20
- static styles = css`
21
- :host {
22
- display: contents;
23
- }
24
- `;
25
-
26
- connectedCallback() {
27
- super.connectedCallback();
28
- this.internalOpen = this.isControlled() ? !!this.open : this.defaultOpen;
29
- }
30
-
31
- updated(changed: Map<string, unknown>) {
32
- if (changed.has("open") && this.isControlled()) {
33
- this.internalOpen = !!this.open;
34
- }
35
- }
36
-
37
- private isControlled() {
38
- return this.open !== undefined;
39
- }
40
-
41
- get activeOpen() {
42
- return this.isControlled() ? !!this.open : this.internalOpen;
43
- }
44
-
45
- setOpen(next: boolean, reason: SheetCloseReason = "api") {
46
- if (!this.isControlled()) {
47
- this.internalOpen = next;
48
- }
49
-
50
- this.dispatchEvent(
51
- new CustomEvent("rel-open-change", {
52
- detail: { open: next, reason },
53
- bubbles: true,
54
- composed: true,
55
- })
56
- );
57
- }
58
-
59
- render() {
60
- return html`<slot></slot>`;
61
- }
62
- }
63
-
64
- // ============================================================================
65
- // rel-sheet-trigger (Opens Sheet)
66
- // ============================================================================
67
- @customElement("rel-sheet-trigger")
68
- export class RelSheetTrigger extends LitElement {
69
- static styles = css`
70
- :host {
71
- display: inline-block;
72
- }
73
-
74
- button {
75
- background: none;
76
- border: none;
77
- padding: 0;
78
- margin: 0;
79
- font: inherit;
80
- cursor: pointer;
81
- display: contents;
82
- }
83
- `;
84
-
85
- private getSheet(): RelSheet | null {
86
- let parent = this.parentElement;
87
- while (parent) {
88
- if (parent instanceof RelSheet) {
89
- return parent;
90
- }
91
- parent = parent.parentElement;
92
- }
93
- return null;
94
- }
95
-
96
- private handleClick = () => {
97
- const sheet = this.getSheet();
98
- if (sheet && !sheet.disabled) {
99
- sheet.setOpen(!sheet.activeOpen, "trigger");
100
- }
101
- };
102
-
103
- render() {
104
- return html`
105
- <button @click="${this.handleClick}" type="button">
106
- <slot></slot>
107
- </button>
108
- `;
109
- }
110
- }
111
-
112
- // ============================================================================
113
- // rel-sheet-content (Panel)
114
- // ============================================================================
115
- @customElement("rel-sheet-content")
116
- export class RelSheetContent extends LitElement {
117
- @property({ type: String }) side: SheetSide = "right";
118
- @property({ type: String }) size: SheetSize = "md";
119
- @property({ type: Boolean, attribute: "hide-overlay" }) hideOverlay = false;
120
- @property({ type: Boolean, attribute: "close-on-overlay" }) closeOnOverlay = true;
121
- @property({ type: Boolean, attribute: "show-close" }) showClose = true;
122
-
123
- @query(".panel") private panelElement!: HTMLElement;
124
- @query(".overlay") private overlayElement!: HTMLElement;
125
-
126
- private sheet: RelSheet | null = null;
127
- private previousFocus: HTMLElement | null = null;
128
- private originalBodyOverflow = "";
129
- private originalBodyPaddingRight = "";
130
- private isOpen = false;
131
-
132
- static styles = css`
133
- :host {
134
- --sheet-transition-duration: 0.3s;
135
- --sheet-transition-timing: cubic-bezier(0.32, 0.72, 0, 1);
136
- --sheet-size-sm: 320px;
137
- --sheet-size-md: 420px;
138
- --sheet-size-lg: 540px;
139
- --sheet-size-xl: 640px;
140
- }
141
-
142
- .sheet-container {
143
- position: fixed;
144
- top: 0;
145
- left: 0;
146
- right: 0;
147
- bottom: 0;
148
- z-index: 1000;
149
- pointer-events: none;
150
- }
151
-
152
- .sheet-container.open {
153
- pointer-events: auto;
154
- }
155
-
156
- /* Overlay */
157
- .overlay {
158
- position: absolute;
159
- top: 0;
160
- left: 0;
161
- right: 0;
162
- bottom: 0;
163
- background: var(--rel-overlay-scrim);
164
- opacity: 0;
165
- transition: opacity var(--sheet-transition-duration) var(--sheet-transition-timing);
166
- }
167
-
168
- .sheet-container.open .overlay {
169
- opacity: var(--rel-sheet-scrim-opacity, 1);
170
- }
171
-
172
- .overlay.hidden {
173
- display: none;
174
- }
175
-
176
- /* Panel base */
177
- .panel {
178
- position: absolute;
179
- background: var(--rel-colors-white);
180
- box-shadow: var(--rel-shadows-shadow-500);
181
- display: flex;
182
- flex-direction: column;
183
- outline: none;
184
- font-family: var(--rel-fontFamilies-primary);
185
- transition: transform var(--sheet-transition-duration) var(--sheet-transition-timing);
186
- overflow: hidden;
187
- }
188
-
189
- /* Right side (default) */
190
- .panel[data-side="right"] {
191
- top: 0;
192
- right: 0;
193
- bottom: 0;
194
- width: var(--sheet-width);
195
- max-width: 90vw;
196
- border-top-left-radius: var(--rel-borders-radius-border-radius-300);
197
- border-bottom-left-radius: var(--rel-borders-radius-border-radius-300);
198
- transform: translateX(100%);
199
- }
200
-
201
- .sheet-container.open .panel[data-side="right"] {
202
- transform: translateX(0);
203
- }
204
-
205
- /* Left side */
206
- .panel[data-side="left"] {
207
- top: 0;
208
- left: 0;
209
- bottom: 0;
210
- width: var(--sheet-width);
211
- max-width: 90vw;
212
- border-top-right-radius: var(--rel-borders-radius-border-radius-300);
213
- border-bottom-right-radius: var(--rel-borders-radius-border-radius-300);
214
- transform: translateX(-100%);
215
- }
216
-
217
- .sheet-container.open .panel[data-side="left"] {
218
- transform: translateX(0);
219
- }
220
-
221
- /* Top side */
222
- .panel[data-side="top"] {
223
- top: 0;
224
- left: 0;
225
- right: 0;
226
- height: var(--sheet-width);
227
- max-height: 80vh;
228
- border-bottom-left-radius: var(--rel-borders-radius-border-radius-300);
229
- border-bottom-right-radius: var(--rel-borders-radius-border-radius-300);
230
- transform: translateY(-100%);
231
- }
232
-
233
- .sheet-container.open .panel[data-side="top"] {
234
- transform: translateY(0);
235
- }
236
-
237
- /* Bottom side */
238
- .panel[data-side="bottom"] {
239
- bottom: 0;
240
- left: 0;
241
- right: 0;
242
- height: var(--sheet-width);
243
- max-height: 80vh;
244
- border-top-left-radius: var(--rel-borders-radius-border-radius-300);
245
- border-top-right-radius: var(--rel-borders-radius-border-radius-300);
246
- transform: translateY(100%);
247
- }
248
-
249
- .sheet-container.open .panel[data-side="bottom"] {
250
- transform: translateY(0);
251
- }
252
-
253
- /* Panel content wrapper */
254
- .panel-content {
255
- flex: 1;
256
- overflow-y: auto;
257
- padding: var(--rel-spacing-space-lg);
258
- }
259
-
260
- /* Close button */
261
- .close-button {
262
- position: absolute;
263
- top: var(--rel-spacing-space-md);
264
- right: var(--rel-spacing-space-md);
265
- background: none;
266
- border: none;
267
- cursor: pointer;
268
- padding: var(--rel-spacing-space-xs);
269
- display: flex;
270
- align-items: center;
271
- justify-content: center;
272
- border-radius: var(--rel-borders-radius-border-radius-200);
273
- color: var(--rel-colors-gray-heading);
274
- font-size: 20px;
275
- line-height: 1;
276
- z-index: 1;
277
- transition: background 0.2s;
278
- }
279
-
280
- .close-button:hover {
281
- background: var(--rel-colors-gray-surface);
282
- }
283
-
284
- .close-button:focus-visible {
285
- outline: 2px solid var(--rel-colors-primary-500);
286
- outline-offset: 2px;
287
- }
288
-
289
- /* Left side close button positioning */
290
- .panel[data-side="left"] .close-button {
291
- right: auto;
292
- left: var(--rel-spacing-space-md);
293
- }
294
-
295
- /* Reduced motion support */
296
- @media (prefers-reduced-motion: reduce) {
297
- .overlay,
298
- .panel {
299
- transition: none;
300
- }
301
-
302
- .sheet-container .panel {
303
- transform: none;
304
- }
305
-
306
- .sheet-container:not(.open) .panel {
307
- display: none;
308
- }
309
- }
310
- `;
311
-
312
- connectedCallback() {
313
- super.connectedCallback();
314
- this.findSheet();
315
- }
316
-
317
- disconnectedCallback() {
318
- super.disconnectedCallback();
319
- this.cleanup();
320
- }
321
-
322
- private findSheet() {
323
- let parent = this.parentElement;
324
- while (parent) {
325
- if (parent instanceof RelSheet) {
326
- this.sheet = parent;
327
- break;
328
- }
329
- parent = parent.parentElement;
330
- }
331
-
332
- if (this.sheet) {
333
- this.sheet.addEventListener("rel-open-change", this.handleSheetOpenChange);
334
- }
335
- }
336
-
337
- private handleSheetOpenChange = (e: Event) => {
338
- const customEvent = e as CustomEvent<{ open: boolean }>;
339
- const nextOpen = customEvent.detail.open;
340
-
341
- if (nextOpen !== this.isOpen) {
342
- this.isOpen = nextOpen;
343
- if (nextOpen) {
344
- this.handleOpen();
345
- } else {
346
- this.handleClose();
347
- }
348
- this.requestUpdate();
349
- }
350
- };
351
-
352
- private handleOpen() {
353
- this.previousFocus = document.activeElement as HTMLElement;
354
- this.lockScroll();
355
-
356
- if (this.sheet?.modal) {
357
- this.updateComplete.then(() => {
358
- const focusTarget = this.shadowRoot?.querySelector<HTMLElement>("[autofocus], .close-button, .panel");
359
- focusTarget?.focus();
360
- });
361
- }
362
-
363
- document.addEventListener("keydown", this.handleKeydown);
364
- }
365
-
366
- private handleClose() {
367
- this.unlockScroll();
368
- document.removeEventListener("keydown", this.handleKeydown);
369
-
370
- if (this.previousFocus && this.previousFocus.focus) {
371
- this.updateComplete.then(() => {
372
- this.previousFocus?.focus();
373
- this.previousFocus = null;
374
- });
375
- }
376
- }
377
-
378
- private cleanup() {
379
- this.unlockScroll();
380
- document.removeEventListener("keydown", this.handleKeydown);
381
- if (this.sheet) {
382
- this.sheet.removeEventListener("rel-open-change", this.handleSheetOpenChange);
383
- }
384
- }
385
-
386
- private lockScroll() {
387
- if (typeof document === "undefined") return;
388
-
389
- const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
390
-
391
- this.originalBodyOverflow = document.body.style.overflow;
392
- this.originalBodyPaddingRight = document.body.style.paddingRight;
393
-
394
- document.body.style.overflow = "hidden";
395
- if (scrollbarWidth > 0) {
396
- document.body.style.paddingRight = `${scrollbarWidth}px`;
397
- }
398
- }
399
-
400
- private unlockScroll() {
401
- if (typeof document === "undefined") return;
402
-
403
- document.body.style.overflow = this.originalBodyOverflow;
404
- document.body.style.paddingRight = this.originalBodyPaddingRight;
405
- }
406
-
407
- private focusPanel() {
408
- if (!this.panelElement) return;
409
-
410
- const focusable = this.getFocusableElements();
411
- if (focusable.length > 0) {
412
- focusable[0].focus();
413
- } else {
414
- this.panelElement.setAttribute("tabindex", "-1");
415
- this.panelElement.focus();
416
- }
417
- }
418
-
419
- private getFocusableElements(): HTMLElement[] {
420
- if (!this.panelElement) return [];
421
-
422
- const selectors = [
423
- 'a[href]',
424
- 'button:not([disabled])',
425
- 'textarea:not([disabled])',
426
- 'input:not([disabled])',
427
- 'select:not([disabled])',
428
- '[tabindex]:not([tabindex="-1"])',
429
- ].join(",");
430
-
431
- const elements = Array.from(
432
- this.panelElement.querySelectorAll(selectors)
433
- ) as HTMLElement[];
434
-
435
- // Also check slotted content
436
- const slots = this.panelElement.querySelectorAll("slot");
437
- slots.forEach((slot) => {
438
- const assigned = slot.assignedElements({ flatten: true });
439
- assigned.forEach((el) => {
440
- const focusableInSlot = el.querySelectorAll(selectors);
441
- elements.push(...(Array.from(focusableInSlot) as HTMLElement[]));
442
- });
443
- });
444
-
445
- return elements.filter((el) => el.offsetWidth || el.offsetHeight);
446
- }
447
-
448
- private handleKeydown = (e: KeyboardEvent) => {
449
- if (!this.isOpen) return;
450
-
451
- if (e.key === "Escape") {
452
- e.preventDefault();
453
- this.sheet?.setOpen(false, "escape");
454
- return;
455
- }
456
-
457
- // Focus trap
458
- if (e.key === "Tab" && this.sheet?.modal) {
459
- const focusable = this.getFocusableElements();
460
- if (focusable.length === 0) {
461
- e.preventDefault();
462
- return;
463
- }
464
-
465
- const firstFocusable = focusable[0];
466
- const lastFocusable = focusable[focusable.length - 1];
467
- const activeElement = this.shadowRoot?.activeElement || document.activeElement;
468
-
469
- if (e.shiftKey) {
470
- if (activeElement === firstFocusable) {
471
- e.preventDefault();
472
- lastFocusable.focus();
473
- }
474
- } else {
475
- if (activeElement === lastFocusable) {
476
- e.preventDefault();
477
- firstFocusable.focus();
478
- }
479
- }
480
- }
481
- };
482
-
483
- private handleOverlayClick = (e: MouseEvent) => {
484
- if (!this.closeOnOverlay) return;
485
-
486
- if (e.target === this.overlayElement) {
487
- this.sheet?.setOpen(false, "overlay");
488
- }
489
- };
490
-
491
- private handleCloseClick = () => {
492
- this.sheet?.setOpen(false, "close");
493
- };
494
-
495
- private getSizeValue(): string {
496
- const sizeMap: Record<SheetSize, string> = {
497
- sm: "var(--sheet-size-sm)",
498
- md: "var(--sheet-size-md)",
499
- lg: "var(--sheet-size-lg)",
500
- xl: "var(--sheet-size-xl)",
501
- };
502
- return sizeMap[this.size] || sizeMap.md;
503
- }
504
-
505
- private getTitle(): string | null {
506
- const titleEl = this.querySelector("rel-sheet-title");
507
- return titleEl?.textContent?.trim() || null;
508
- }
509
-
510
- private getDescription(): string | null {
511
- const descEl = this.querySelector("rel-sheet-description");
512
- return descEl?.textContent?.trim() || null;
513
- }
514
-
515
- render() {
516
- const title = this.getTitle();
517
- const description = this.getDescription();
518
- const titleId = title ? "sheet-title" : undefined;
519
- const descId = description ? "sheet-description" : undefined;
520
-
521
- return html`
522
- <div class="sheet-container ${this.isOpen ? "open" : ""}">
523
- <div
524
- part="overlay"
525
- class="overlay ${this.hideOverlay ? "hidden" : ""}"
526
- @click="${this.handleOverlayClick}"></div>
527
-
528
- <div
529
- part="panel"
530
- class="panel"
531
- data-side="${this.side}"
532
- style="--sheet-width: ${this.getSizeValue()}"
533
- role="dialog"
534
- aria-modal="${this.sheet?.modal ?? true}"
535
- aria-labelledby="${titleId || ""}"
536
- aria-describedby="${descId || ""}"
537
- tabindex="-1">
538
- ${this.showClose
539
- ? html`
540
- <button
541
- class="close-button"
542
- @click="${this.handleCloseClick}"
543
- aria-label="Close"
544
- type="button">
545
- ✕
546
- </button>
547
- `
548
- : ""}
549
-
550
- <div class="panel-content">
551
- <slot></slot>
552
- </div>
553
- </div>
554
- </div>
555
- `;
556
- }
557
- }
558
-
559
- // ============================================================================
560
- // rel-sheet-header (Layout Helper)
561
- // ============================================================================
562
- @customElement("rel-sheet-header")
563
- export class RelSheetHeader extends LitElement {
564
- static styles = css`
565
- :host {
566
- display: block;
567
- padding-bottom: var(--rel-spacing-space-md);
568
- border-bottom: 1px solid var(--rel-colors-gray-border);
569
- margin-bottom: var(--rel-spacing-space-lg);
570
- }
571
- `;
572
-
573
- render() {
574
- return html`<slot></slot>`;
575
- }
576
- }
577
-
578
- // ============================================================================
579
- // rel-sheet-footer (Layout Helper)
580
- // ============================================================================
581
- @customElement("rel-sheet-footer")
582
- export class RelSheetFooter extends LitElement {
583
- static styles = css`
584
- :host {
585
- display: block;
586
- padding-top: var(--rel-spacing-space-md);
587
- border-top: 1px solid var(--rel-colors-gray-border);
588
- margin-top: var(--rel-spacing-space-lg);
589
- }
590
- `;
591
-
592
- render() {
593
- return html`<slot></slot>`;
594
- }
595
- }
596
-
597
- // ============================================================================
598
- // rel-sheet-title (Layout Helper)
599
- // ============================================================================
600
- @customElement("rel-sheet-title")
601
- export class RelSheetTitle extends LitElement {
602
- static styles = css`
603
- :host {
604
- display: block;
605
- font-size: 20px;
606
- font-weight: 600;
607
- color: var(--rel-colors-gray-heading);
608
- margin: 0 0 var(--rel-spacing-space-xs) 0;
609
- padding-right: var(--rel-spacing-space-lg);
610
- }
611
- `;
612
-
613
- render() {
614
- return html`<slot></slot>`;
615
- }
616
- }
617
-
618
- // ============================================================================
619
- // rel-sheet-description (Layout Helper)
620
- // ============================================================================
621
- @customElement("rel-sheet-description")
622
- export class RelSheetDescription extends LitElement {
623
- static styles = css`
624
- :host {
625
- display: block;
626
- font-size: 14px;
627
- color: var(--rel-colors-gray-body);
628
- margin: 0;
629
- line-height: 1.5;
630
- }
631
- `;
632
-
633
- render() {
634
- return html`<slot></slot>`;
635
- }
636
- }
637
-
638
- // ============================================================================
639
- // rel-sheet-close (Close Button Wrapper)
640
- // ============================================================================
641
- @customElement("rel-sheet-close")
642
- export class RelSheetClose extends LitElement {
643
- static styles = css`
644
- :host {
645
- display: inline-block;
646
- }
647
-
648
- button {
649
- background: none;
650
- border: none;
651
- padding: 0;
652
- margin: 0;
653
- font: inherit;
654
- cursor: pointer;
655
- display: contents;
656
- }
657
- `;
658
-
659
- private getSheet(): RelSheet | null {
660
- let parent = this.parentElement;
661
- while (parent) {
662
- if (parent instanceof RelSheet) {
663
- return parent;
664
- }
665
- parent = parent.parentElement;
666
- }
667
- return null;
668
- }
669
-
670
- private handleClick = () => {
671
- const sheet = this.getSheet();
672
- if (sheet) {
673
- sheet.setOpen(false, "close");
674
- }
675
- };
676
-
677
- render() {
678
- return html`
679
- <button @click="${this.handleClick}" type="button">
680
- <slot></slot>
681
- </button>
682
- `;
683
- }
684
- }
1
+ import { LitElement, html, css } from "lit";
2
+ import { customElement, property, query } from "lit/decorators.js";
3
+ import "../../styles/vars-v2.css";
4
+ import "@reliability-design/icons/rel-icon";
5
+
6
+ export type ModalSide = "top" | "bottom" | "center";
7
+
8
+ @customElement("rel-modal")
9
+ export class RelModal extends LitElement {
10
+ @property({ type: Boolean, reflect: true }) open = false;
11
+ @property({ type: String }) side: ModalSide = "bottom";
12
+ @property({ type: String }) title = "";
13
+ @property({ type: String }) description = "";
14
+ @property({ type: Boolean }) dismissible = true;
15
+ @property({ type: Boolean }) modal = true;
16
+
17
+ @query(".overlay") private overlayElement!: HTMLElement;
18
+
19
+ private previousFocus: HTMLElement | null = null;
20
+ private originalBodyOverflow = "";
21
+ private originalBodyPaddingRight = "";
22
+
23
+ static styles = css`
24
+ :host {
25
+ --modal-transition-duration: 0.3s;
26
+ --modal-transition-timing: cubic-bezier(0.32, 0.72, 0, 1);
27
+ }
28
+
29
+ .modal-container {
30
+ position: fixed;
31
+ top: 0;
32
+ left: 0;
33
+ right: 0;
34
+ bottom: 0;
35
+ z-index: 1000;
36
+ pointer-events: none;
37
+ }
38
+
39
+ .modal-container.open {
40
+ pointer-events: auto;
41
+ }
42
+
43
+ .overlay {
44
+ position: absolute;
45
+ top: 0;
46
+ left: 0;
47
+ right: 0;
48
+ bottom: 0;
49
+ background: var(--rel-overlay-scrim);
50
+ opacity: 0;
51
+ transition: opacity var(--modal-transition-duration) var(--modal-transition-timing);
52
+ }
53
+
54
+ .modal-container.open .overlay {
55
+ opacity: 1;
56
+ }
57
+
58
+ .overlay.no-modal {
59
+ display: none !important;
60
+ }
61
+
62
+ .panel {
63
+ position: absolute;
64
+ background: var(--rel-color-bg-primary);
65
+ box-shadow: var(--rel-shadows-shadow-500);
66
+ display: flex;
67
+ flex-direction: column;
68
+ overflow: hidden;
69
+ outline: none;
70
+ font-family: var(--rel-fontFamilies-primary);
71
+ width: clamp(360px, 49vw, 708px);
72
+ left: 50%;
73
+ transition: transform var(--modal-transition-duration) var(--modal-transition-timing);
74
+ }
75
+
76
+ .panel[data-side="bottom"] {
77
+ bottom: 48px;
78
+ left: 50%;
79
+ width: clamp(360px, 49vw, 708px);
80
+ max-height: calc(100vh - 96px);
81
+ border-radius: var(--rel-borders-radius-border-radius-200);
82
+ transform: translateX(-50%) translateY(calc(100% + 48px));
83
+ }
84
+
85
+ .modal-container.open .panel[data-side="bottom"] {
86
+ transform: translateX(-50%) translateY(0);
87
+ }
88
+
89
+ .panel[data-side="top"] {
90
+ top: 48px;
91
+ left: 50%;
92
+ width: clamp(360px, 49vw, 708px);
93
+ max-height: calc(100vh - 96px);
94
+ border-radius: var(--rel-borders-radius-border-radius-200);
95
+ transform: translateX(-50%) translateY(calc(-100% - 48px));
96
+ }
97
+
98
+ .modal-container.open .panel[data-side="top"] {
99
+ transform: translateX(-50%) translateY(0);
100
+ }
101
+
102
+ .panel[data-side="center"] {
103
+ top: 50%;
104
+ left: 50%;
105
+ width: clamp(360px, 49vw, 708px);
106
+ max-height: calc(100vh - 96px);
107
+ border-radius: var(--rel-borders-radius-border-radius-200);
108
+ transform: translate(-50%, -50%);
109
+ }
110
+
111
+ .modal-container.open .panel[data-side="center"] {
112
+ transform: translate(-50%, -50%);
113
+ }
114
+
115
+ .header {
116
+ display: flex;
117
+ align-items: flex-start;
118
+ justify-content: space-between;
119
+ padding: var(--rel-spacing-space-md) var(--rel-spacing-space-lg);
120
+ border-bottom: var(--rel-borders-width-stroke-100) solid var(--rel-color-border-default);
121
+ flex-shrink: 0;
122
+ }
123
+
124
+ .header.empty {
125
+ display: none;
126
+ }
127
+
128
+ .header-text {
129
+ display: flex;
130
+ flex-direction: column;
131
+ gap: var(--rel-spacing-space-2xs);
132
+ }
133
+
134
+ .title {
135
+ font-size: var(--rel-fontSizes-lg);
136
+ font-weight: var(--rel-fontWeights-semibold);
137
+ color: var(--rel-color-text-heading);
138
+ margin: 0;
139
+ }
140
+
141
+ .description {
142
+ font-size: var(--rel-fontSizes-sm);
143
+ color: var(--rel-color-text-primary);
144
+ margin: 0;
145
+ }
146
+
147
+ .close-button {
148
+ background: transparent;
149
+ border: none;
150
+ cursor: pointer;
151
+ padding: var(--rel-spacing-space-2xs);
152
+ display: flex;
153
+ align-items: center;
154
+ justify-content: center;
155
+ align-self: flex-start;
156
+ flex-shrink: 0;
157
+ border-radius: var(--rel-borders-radius-border-radius-100);
158
+ color: var(--rel-color-text-primary);
159
+ transition: background 0.15s ease;
160
+ }
161
+
162
+ .close-button:hover {
163
+ background: var(--rel-color-bg-tertiary);
164
+ }
165
+
166
+ .close-button:focus-visible {
167
+ outline: 2px solid var(--rel-color-border-focus);
168
+ outline-offset: 2px;
169
+ }
170
+
171
+ .content {
172
+ flex: 1;
173
+ overflow-y: auto;
174
+ padding: var(--rel-spacing-space-lg);
175
+ }
176
+
177
+ .footer {
178
+ display: none;
179
+ }
180
+
181
+ :host([has-footer]) .footer {
182
+ display: flex;
183
+ flex-shrink: 0;
184
+ padding: var(--rel-spacing-space-md) var(--rel-spacing-space-lg);
185
+ border-top: var(--rel-borders-width-stroke-100) solid var(--rel-color-border-default);
186
+ justify-content: flex-end;
187
+ gap: var(--rel-spacing-space-xs);
188
+ }
189
+
190
+ @media (prefers-reduced-motion: reduce) {
191
+ .overlay,
192
+ .panel {
193
+ transition: none;
194
+ }
195
+
196
+ .modal-container .panel {
197
+ transform: none;
198
+ }
199
+
200
+ .modal-container:not(.open) .panel {
201
+ display: none;
202
+ }
203
+ }
204
+ `;
205
+
206
+ connectedCallback() {
207
+ super.connectedCallback();
208
+ if (this.open) {
209
+ this.lockScroll();
210
+ }
211
+ this.updateComplete.then(() => {
212
+ const footerSlot = this.shadowRoot?.querySelector(
213
+ 'slot[name="footer"]'
214
+ ) as HTMLSlotElement | null;
215
+ if (footerSlot) {
216
+ const sync = () => {
217
+ const hasContent = footerSlot.assignedElements({ flatten: true }).length > 0;
218
+ this.toggleAttribute('has-footer', hasContent);
219
+ };
220
+ footerSlot.addEventListener('slotchange', sync);
221
+ sync();
222
+ }
223
+ });
224
+ }
225
+
226
+ disconnectedCallback() {
227
+ super.disconnectedCallback();
228
+ this.unlockScroll();
229
+ document.removeEventListener("keydown", this.handleKeydown);
230
+ }
231
+
232
+ updated(changed: Map<string, unknown>) {
233
+ if (changed.has("open")) {
234
+ if (this.open) {
235
+ this.handleOpen();
236
+ } else {
237
+ this.handleClose();
238
+ }
239
+ }
240
+ }
241
+
242
+ private handleOpen() {
243
+ this.previousFocus = document.activeElement as HTMLElement;
244
+ this.lockScroll();
245
+ document.addEventListener("keydown", this.handleKeydown);
246
+ this.dispatchEvent(
247
+ new CustomEvent("rel-open-change", {
248
+ detail: true,
249
+ bubbles: true,
250
+ composed: true,
251
+ })
252
+ );
253
+ }
254
+
255
+ private handleClose() {
256
+ this.unlockScroll();
257
+ document.removeEventListener("keydown", this.handleKeydown);
258
+ if (this.previousFocus?.focus) {
259
+ this.updateComplete.then(() => {
260
+ this.previousFocus?.focus();
261
+ this.previousFocus = null;
262
+ });
263
+ }
264
+ this.dispatchEvent(
265
+ new CustomEvent("rel-open-change", {
266
+ detail: false,
267
+ bubbles: true,
268
+ composed: true,
269
+ })
270
+ );
271
+ }
272
+
273
+ private lockScroll() {
274
+ if (typeof document === "undefined") return;
275
+ const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
276
+ this.originalBodyOverflow = document.body.style.overflow;
277
+ this.originalBodyPaddingRight = document.body.style.paddingRight;
278
+ document.body.style.overflow = "hidden";
279
+ if (scrollbarWidth > 0) {
280
+ document.body.style.paddingRight = `${scrollbarWidth}px`;
281
+ }
282
+ }
283
+
284
+ private unlockScroll() {
285
+ if (typeof document === "undefined") return;
286
+ document.body.style.overflow = this.originalBodyOverflow;
287
+ document.body.style.paddingRight = this.originalBodyPaddingRight;
288
+ }
289
+
290
+ private handleKeydown = (e: KeyboardEvent) => {
291
+ if (!this.open) return;
292
+ if (e.key === "Escape" && this.dismissible) {
293
+ e.preventDefault();
294
+ this.open = false;
295
+ }
296
+ };
297
+
298
+ private handleOverlayClick = (e: MouseEvent) => {
299
+ if (!this.dismissible) return;
300
+ if (e.target === this.overlayElement) {
301
+ this.open = false;
302
+ }
303
+ };
304
+
305
+ private handleCloseButtonClick() {
306
+ this.open = false;
307
+ }
308
+
309
+ render() {
310
+ const hasTitle = !!this.title;
311
+ const hasDescription = !!this.description;
312
+ const showHeader = hasTitle || hasDescription || this.dismissible;
313
+
314
+ return html`
315
+ <div class="modal-container ${this.open ? "open" : ""}">
316
+ <div
317
+ part="overlay"
318
+ class="overlay ${!this.modal ? 'no-modal' : ''}"
319
+ @click="${this.handleOverlayClick}"></div>
320
+
321
+ <div
322
+ part="panel"
323
+ class="panel"
324
+ data-side="${this.side}"
325
+ role="${this.modal ? "dialog" : "region"}"
326
+ aria-modal="${this.modal}"
327
+ tabindex="-1">
328
+
329
+ <div part="header" class="header ${!showHeader ? "empty" : ""}">
330
+ <div class="header-text">
331
+ ${hasTitle ? html`<h2 class="title">${this.title}</h2>` : ""}
332
+ ${hasDescription ? html`<p class="description">${this.description}</p>` : ""}
333
+ </div>
334
+ ${this.dismissible
335
+ ? html`<button
336
+ part="close-button"
337
+ class="close-button"
338
+ @click="${this.handleCloseButtonClick}"
339
+ aria-label="Close">
340
+ <rel-icon name="close" size="sm"></rel-icon>
341
+ </button>`
342
+ : ""}
343
+ </div>
344
+
345
+ <div part="content" class="content">
346
+ <slot></slot>
347
+ </div>
348
+
349
+ <div part="footer" class="footer">
350
+ <slot name="footer"></slot>
351
+ </div>
352
+ </div>
353
+ </div>
354
+ `;
355
+ }
356
+ }
357
+
358
+ declare global {
359
+ interface HTMLElementTagNameMap {
360
+ "rel-modal": RelModal;
361
+ }
362
+ }