@designbasekorea/ui-wc 0.5.6 → 0.6.1
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/dist/chunks/lottie-35a9b0f5.js +1 -0
- package/dist/esm/components/animation-background/canvas-controller.js +1 -121
- package/dist/esm/components/animation-background/controls.js +1 -180
- package/dist/esm/components/animation-background/graphite-controller.js +1 -196
- package/dist/esm/components/animation-background/graphite-presets.js +1 -42
- package/dist/esm/components/animation-background/graphite-shader.js +1 -111
- package/dist/esm/components/animation-background/layers.js +1 -369
- package/dist/esm/components/animation-background/lumina-presets.js +1 -53
- package/dist/esm/components/animation-background/lumina-shaders.js +1 -181
- package/dist/esm/components/animation-background/lumina-utils.js +1 -60
- package/dist/esm/components/animation-background/particle-defaults.js +1 -36
- package/dist/esm/components/animation-background/renderers.js +1 -167
- package/dist/esm/components/animation-background/shader-controller.js +1 -154
- package/dist/esm/components/color-picker-utils.js +1 -134
- package/dist/esm/components/date-picker-utils.js +1 -140
- package/dist/esm/components/db-accordion.js +1 -304
- package/dist/esm/components/db-ad-banner.js +1 -455
- package/dist/esm/components/db-ai-chat-list.d.ts +43 -0
- package/dist/esm/components/db-ai-chat-list.js +1 -0
- package/dist/esm/components/db-ai-chat.d.ts +159 -0
- package/dist/esm/components/db-ai-chat.js +1 -0
- package/dist/esm/components/db-alert.js +1 -149
- package/dist/esm/components/db-animation-background.js +1 -486
- package/dist/esm/components/db-animation-text.js +1 -601
- package/dist/esm/components/db-app-badge.js +1 -88
- package/dist/esm/components/db-audio-player.js +1 -752
- package/dist/esm/components/db-avatar.js +1 -188
- package/dist/esm/components/db-backdrop.js +1 -139
- package/dist/esm/components/db-badge.js +1 -91
- package/dist/esm/components/db-banner.js +1 -188
- package/dist/esm/components/db-bottom-navigation.js +1 -146
- package/dist/esm/components/db-bottom-sheet.js +1 -481
- package/dist/esm/components/db-breadcrumbs.js +1 -329
- package/dist/esm/components/db-button.js +1 -316
- package/dist/esm/components/db-calendar.js +1 -675
- package/dist/esm/components/db-card.js +1 -265
- package/dist/esm/components/db-carousel.js +1 -264
- package/dist/esm/components/db-chat-composer.d.ts +134 -0
- package/dist/esm/components/db-chat-composer.js +1 -0
- package/dist/esm/components/db-chat-list.d.ts +47 -0
- package/dist/esm/components/db-chat-list.js +1 -0
- package/dist/esm/components/db-chat-message.d.ts +39 -0
- package/dist/esm/components/db-chat-message.js +1 -0
- package/dist/esm/components/db-chat-orb.d.ts +99 -0
- package/dist/esm/components/db-chat-orb.js +1 -0
- package/dist/esm/components/db-chat-room.d.ts +71 -0
- package/dist/esm/components/db-chat-room.js +1 -0
- package/dist/esm/components/db-chat-suggestions.d.ts +44 -0
- package/dist/esm/components/db-chat-suggestions.js +1 -0
- package/dist/esm/components/db-chat-typing.d.ts +22 -0
- package/dist/esm/components/db-chat-typing.js +1 -0
- package/dist/esm/components/db-chat-welcome.d.ts +32 -0
- package/dist/esm/components/db-chat-welcome.js +1 -0
- package/dist/esm/components/db-chat-widget.d.ts +146 -0
- package/dist/esm/components/db-chat-widget.js +1 -0
- package/dist/esm/components/db-checkbox.js +1 -202
- package/dist/esm/components/db-chip.js +1 -104
- package/dist/esm/components/db-code-block.js +1 -304
- package/dist/esm/components/db-color-picker.js +1 -746
- package/dist/esm/components/db-confirm.js +1 -191
- package/dist/esm/components/db-container.js +1 -39
- package/dist/esm/components/db-context-menu.js +1 -265
- package/dist/esm/components/db-countdown.js +1 -146
- package/dist/esm/components/db-cursor-follower.js +1 -173
- package/dist/esm/components/db-date-picker.js +1 -837
- package/dist/esm/components/db-divider.js +1 -66
- package/dist/esm/components/db-download-progress.d.ts +89 -0
- package/dist/esm/components/db-download-progress.js +1 -0
- package/dist/esm/components/db-drawer.js +1 -245
- package/dist/esm/components/db-dropdown.js +1 -493
- package/dist/esm/components/db-dropzone.js +1 -266
- package/dist/esm/components/db-email-verify.d.ts +64 -0
- package/dist/esm/components/db-email-verify.js +1 -0
- package/dist/esm/components/db-empty-state.js +1 -97
- package/dist/esm/components/db-file-uploader.js +1 -256
- package/dist/esm/components/db-floating-action-button.js +1 -139
- package/dist/esm/components/db-footer.js +1 -385
- package/dist/esm/components/db-form.js +1 -566
- package/dist/esm/components/db-gantt.js +1 -882
- package/dist/esm/components/db-gradient.js +1 -133
- package/dist/esm/components/db-grid-background.js +1 -909
- package/dist/esm/components/db-grid.js +1 -73
- package/dist/esm/components/db-icons.d.ts +3 -0
- package/dist/esm/components/db-icons.js +1 -82
- package/dist/esm/components/db-image-list.js +1 -214
- package/dist/esm/components/db-image-placeholder.js +1 -96
- package/dist/esm/components/db-image.js +1 -289
- package/dist/esm/components/db-indicator.js +1 -517
- package/dist/esm/components/db-input.js +1 -420
- package/dist/esm/components/db-kanban.js +1 -538
- package/dist/esm/components/db-label.js +1 -66
- package/dist/esm/components/db-lightbox.js +1 -372
- package/dist/esm/components/db-list.js +1 -340
- package/dist/esm/components/db-logo-svg.js +1 -72
- package/dist/esm/components/db-logo.js +1 -106
- package/dist/esm/components/db-lottie.js +1 -109
- package/dist/esm/components/db-markdown-editor.js +1 -458
- package/dist/esm/components/db-marquee.js +1 -402
- package/dist/esm/components/db-masonry.js +1 -94
- package/dist/esm/components/db-menu-item.js +1 -211
- package/dist/esm/components/db-modal.js +1 -522
- package/dist/esm/components/db-navbar.js +1 -680
- package/dist/esm/components/db-onboarding-modal.js +1 -322
- package/dist/esm/components/db-otp-input.d.ts +53 -0
- package/dist/esm/components/db-otp-input.js +1 -0
- package/dist/esm/components/db-page-header.js +1 -312
- package/dist/esm/components/db-pagination.js +1 -271
- package/dist/esm/components/db-phone-verify.d.ts +63 -0
- package/dist/esm/components/db-phone-verify.js +1 -0
- package/dist/esm/components/db-popover.js +1 -580
- package/dist/esm/components/db-progress-step.js +1 -166
- package/dist/esm/components/db-progress.js +1 -171
- package/dist/esm/components/db-progressbar.js +1 -72
- package/dist/esm/components/db-radio.js +1 -172
- package/dist/esm/components/db-random-gradient.js +1 -121
- package/dist/esm/components/db-range-slider.js +1 -811
- package/dist/esm/components/db-rating.js +1 -325
- package/dist/esm/components/db-reorder.js +1 -286
- package/dist/esm/components/db-resizable-panels.js +1 -282
- package/dist/esm/components/db-scroll-area.js +1 -126
- package/dist/esm/components/db-search-bar.js +1 -668
- package/dist/esm/components/db-section-app-download.js +1 -101
- package/dist/esm/components/db-section-contact.js +1 -102
- package/dist/esm/components/db-section-cta.js +1 -150
- package/dist/esm/components/db-section-faq.js +1 -120
- package/dist/esm/components/db-section-feature-grid.js +1 -137
- package/dist/esm/components/db-section-feature.js +1 -179
- package/dist/esm/components/db-section-hero.js +1 -243
- package/dist/esm/components/db-section-logo-cloud.js +1 -138
- package/dist/esm/components/db-section-pricing.js +1 -166
- package/dist/esm/components/db-section-stats.js +1 -129
- package/dist/esm/components/db-section-testimonials.js +1 -252
- package/dist/esm/components/db-section.js +1 -385
- package/dist/esm/components/db-segment-control.js +1 -231
- package/dist/esm/components/db-select.js +1 -571
- package/dist/esm/components/db-share-icons.js +1 -40
- package/dist/esm/components/db-share.js +1 -489
- package/dist/esm/components/db-sidebar.d.ts +20 -0
- package/dist/esm/components/db-sidebar.js +1 -1068
- package/dist/esm/components/db-skeleton.js +1 -94
- package/dist/esm/components/db-spinner.js +1 -102
- package/dist/esm/components/db-split-view.js +1 -297
- package/dist/esm/components/db-stack.js +1 -46
- package/dist/esm/components/db-stat.js +1 -218
- package/dist/esm/components/db-stepper.js +1 -398
- package/dist/esm/components/db-table.js +1 -412
- package/dist/esm/components/db-tabs.js +1 -335
- package/dist/esm/components/db-testimonial.d.ts +2 -0
- package/dist/esm/components/db-testimonial.js +1 -162
- package/dist/esm/components/db-textarea.js +1 -233
- package/dist/esm/components/db-time-picker.js +1 -523
- package/dist/esm/components/db-timeline.js +1 -174
- package/dist/esm/components/db-toast.js +1 -158
- package/dist/esm/components/db-toggle.js +1 -162
- package/dist/esm/components/db-toolbar.js +1 -94
- package/dist/esm/components/db-tooltip.js +1 -440
- package/dist/esm/components/db-top-banner.js +1 -121
- package/dist/esm/components/db-tutorial.js +1 -324
- package/dist/esm/components/db-two-factor.d.ts +71 -0
- package/dist/esm/components/db-two-factor.js +1 -0
- package/dist/esm/components/db-video-player.js +1 -503
- package/dist/esm/components/db-youtube-player.js +1 -194
- package/dist/esm/components/highlight-code.js +1 -65
- package/dist/esm/components/input-validation.js +1 -50
- package/dist/esm/components/marketing-block-host-utils.js +1 -9
- package/dist/esm/components/number-scrub.js +1 -117
- package/dist/esm/components/random-gradient-palettes.js +1 -67
- package/dist/esm/components/section-block-header-utils.js +1 -48
- package/dist/esm/helpers/confirm.js +1 -52
- package/dist/esm/helpers/toast.js +1 -73
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +1 -111
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +1 -235
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +1 -31
- package/dist/esm/node_modules/prismjs/components/prism-css.js +1 -64
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +1 -172
- package/dist/esm/node_modules/prismjs/components/prism-json.js +1 -27
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +1 -143
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +1 -186
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +1 -81
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +1 -15
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +1 -60
- package/dist/index.cjs +1 -55414
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1125 -2
- package/dist/index.esm.js +1 -38284
- package/dist/react/chunks/lottie-14e7addb.js +1 -0
- package/dist/react/index.cjs +1 -56503
- package/dist/react/index.d.ts +1637 -21
- package/dist/react/index.esm.js +1 -39373
- package/package.json +2 -2
- package/dist/chunks/lottie-e273b936.js +0 -17032
- package/dist/react/chunks/lottie-72a4c6d4.js +0 -17032
|
@@ -1,522 +1 @@
|
|
|
1
|
-
import { createDbIcon } from './db-icons.js';
|
|
2
|
-
|
|
3
|
-
const SIZES = ['s', 'm', 'l', 'xl', 'full'];
|
|
4
|
-
const HEADER_VARIANTS = ['default', 'tabs', 'segment'];
|
|
5
|
-
const NAV_SIZES = ['s', 'm', 'l'];
|
|
6
|
-
class DbModal extends HTMLElement {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
this.titleId = `db-modal-title-${Math.random().toString(36).slice(2, 9)}`;
|
|
10
|
-
this.isMounted = false;
|
|
11
|
-
this.internalTabId = '';
|
|
12
|
-
this.internalSegment = '';
|
|
13
|
-
this.exitTimerId = null;
|
|
14
|
-
this.handleDocumentKeyDown = (event) => {
|
|
15
|
-
if (event.key === 'Escape' && this.open && this.getAttribute('close-on-escape') !== 'false') {
|
|
16
|
-
event.preventDefault();
|
|
17
|
-
this.close();
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
static get observedAttributes() {
|
|
22
|
-
return [
|
|
23
|
-
'open',
|
|
24
|
-
'title',
|
|
25
|
-
'size',
|
|
26
|
-
'header-variant',
|
|
27
|
-
'tabs',
|
|
28
|
-
'segments',
|
|
29
|
-
'selected-tab-id',
|
|
30
|
-
'default-selected-tab-id',
|
|
31
|
-
'segment-value',
|
|
32
|
-
'default-segment-value',
|
|
33
|
-
'nav-size',
|
|
34
|
-
'segment-full-width',
|
|
35
|
-
'close-on-outside-click',
|
|
36
|
-
'close-on-escape',
|
|
37
|
-
'show-close-button',
|
|
38
|
-
];
|
|
39
|
-
}
|
|
40
|
-
get open() {
|
|
41
|
-
return this.hasAttribute('open') && this.getAttribute('open') !== 'false';
|
|
42
|
-
}
|
|
43
|
-
set open(value) {
|
|
44
|
-
if (value)
|
|
45
|
-
this.setAttribute('open', 'true');
|
|
46
|
-
else
|
|
47
|
-
this.removeAttribute('open');
|
|
48
|
-
}
|
|
49
|
-
connectedCallback() {
|
|
50
|
-
this.classList.add('designbase-wc-modal-host');
|
|
51
|
-
document.addEventListener('keydown', this.handleDocumentKeyDown);
|
|
52
|
-
this.childObserver = new MutationObserver(() => {
|
|
53
|
-
if (this.open)
|
|
54
|
-
this.render();
|
|
55
|
-
});
|
|
56
|
-
this.childObserver.observe(this, { childList: true });
|
|
57
|
-
this.syncOpenState();
|
|
58
|
-
}
|
|
59
|
-
disconnectedCallback() {
|
|
60
|
-
this.childObserver?.disconnect();
|
|
61
|
-
document.removeEventListener('keydown', this.handleDocumentKeyDown);
|
|
62
|
-
if (this.exitTimerId)
|
|
63
|
-
clearTimeout(this.exitTimerId);
|
|
64
|
-
this.teardown();
|
|
65
|
-
}
|
|
66
|
-
attributeChangedCallback(name) {
|
|
67
|
-
if (!this.isConnected)
|
|
68
|
-
return;
|
|
69
|
-
if (name === 'open') {
|
|
70
|
-
this.syncOpenState();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (name === 'selected-tab-id' || name === 'segment-value') {
|
|
74
|
-
const classified = this.getClassifiedChildren();
|
|
75
|
-
this.renderBodyContent(classified.body);
|
|
76
|
-
this.renderHeader(classified.header);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
this.render();
|
|
80
|
-
if (this.isMounted)
|
|
81
|
-
this.syncVisibility();
|
|
82
|
-
}
|
|
83
|
-
resolvedSize() {
|
|
84
|
-
return SIZES.includes(this.size) ? this.size : 'm';
|
|
85
|
-
}
|
|
86
|
-
get size() {
|
|
87
|
-
return this.getAttribute('size') || 'm';
|
|
88
|
-
}
|
|
89
|
-
set size(value) {
|
|
90
|
-
if (value)
|
|
91
|
-
this.setAttribute('size', value);
|
|
92
|
-
else
|
|
93
|
-
this.removeAttribute('size');
|
|
94
|
-
}
|
|
95
|
-
resolvedHeaderVariant() {
|
|
96
|
-
const value = this.getAttribute('header-variant') || 'default';
|
|
97
|
-
return HEADER_VARIANTS.includes(value) ? value : 'default';
|
|
98
|
-
}
|
|
99
|
-
parsedTabs() {
|
|
100
|
-
const raw = this.getAttribute('tabs');
|
|
101
|
-
if (!raw)
|
|
102
|
-
return [];
|
|
103
|
-
try {
|
|
104
|
-
const parsed = JSON.parse(raw);
|
|
105
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
return [];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
parsedSegments() {
|
|
112
|
-
const raw = this.getAttribute('segments');
|
|
113
|
-
if (!raw)
|
|
114
|
-
return [];
|
|
115
|
-
try {
|
|
116
|
-
const parsed = JSON.parse(raw);
|
|
117
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
118
|
-
}
|
|
119
|
-
catch {
|
|
120
|
-
return [];
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
usesIntegratedNav() {
|
|
124
|
-
const variant = this.resolvedHeaderVariant();
|
|
125
|
-
return ((variant === 'tabs' && this.parsedTabs().length > 0) ||
|
|
126
|
-
(variant === 'segment' && this.parsedSegments().length > 0));
|
|
127
|
-
}
|
|
128
|
-
closeIconSize() {
|
|
129
|
-
const size = this.resolvedSize();
|
|
130
|
-
if (size === 's')
|
|
131
|
-
return 16;
|
|
132
|
-
if (size === 'l')
|
|
133
|
-
return 20;
|
|
134
|
-
if (size === 'xl')
|
|
135
|
-
return 24;
|
|
136
|
-
return 18;
|
|
137
|
-
}
|
|
138
|
-
activeTabId() {
|
|
139
|
-
return (this.getAttribute('selected-tab-id') ||
|
|
140
|
-
this.internalTabId ||
|
|
141
|
-
this.getAttribute('default-selected-tab-id') ||
|
|
142
|
-
this.parsedTabs()[0]?.id ||
|
|
143
|
-
'');
|
|
144
|
-
}
|
|
145
|
-
activeSegmentValue() {
|
|
146
|
-
return (this.getAttribute('segment-value') ||
|
|
147
|
-
this.internalSegment ||
|
|
148
|
-
this.getAttribute('default-segment-value') ||
|
|
149
|
-
this.parsedSegments()[0]?.value ||
|
|
150
|
-
'');
|
|
151
|
-
}
|
|
152
|
-
collectUserChildren() {
|
|
153
|
-
return Array.from(this.children).filter((child) => !child.hasAttribute('data-wc-internal'));
|
|
154
|
-
}
|
|
155
|
-
classifyChildren(children) {
|
|
156
|
-
const isPart = (child, part, className) => child.classList.contains(className) || child.getAttribute('data-modal-part') === part;
|
|
157
|
-
const header = children.filter((child) => isPart(child, 'header', 'designbase-wc-modal__header'));
|
|
158
|
-
const footer = children.filter((child) => isPart(child, 'footer', 'designbase-wc-modal__footer') || child.getAttribute('slot') === 'footer');
|
|
159
|
-
const body = children.filter((child) => isPart(child, 'body', 'designbase-wc-modal__body'));
|
|
160
|
-
const rest = children.filter((child) => !header.includes(child) && !footer.includes(child) && !body.includes(child));
|
|
161
|
-
return { header, body: [...body, ...rest], footer };
|
|
162
|
-
}
|
|
163
|
-
getClassifiedChildren() {
|
|
164
|
-
const fromHost = this.classifyChildren(this.collectUserChildren());
|
|
165
|
-
if (fromHost.header.length || fromHost.body.length || fromHost.footer.length) {
|
|
166
|
-
return fromHost;
|
|
167
|
-
}
|
|
168
|
-
const header = Array.from(this.headerEl?.children || []).filter((child) => {
|
|
169
|
-
if (child === this.closeButton || child.classList.contains('designbase-wc-modal__header-row'))
|
|
170
|
-
return false;
|
|
171
|
-
return child.getAttribute('data-modal-part') === 'header' || child.classList.contains('designbase-wc-modal__header');
|
|
172
|
-
});
|
|
173
|
-
const body = this.collectContentParts('body');
|
|
174
|
-
const footer = this.collectContentParts('footer');
|
|
175
|
-
return { header, body, footer };
|
|
176
|
-
}
|
|
177
|
-
isBodyPart(child) {
|
|
178
|
-
return child.classList.contains('designbase-wc-modal__body') || child.getAttribute('data-modal-part') === 'body';
|
|
179
|
-
}
|
|
180
|
-
isFooterPart(child) {
|
|
181
|
-
return (child.classList.contains('designbase-wc-modal__footer') ||
|
|
182
|
-
child.getAttribute('data-modal-part') === 'footer' ||
|
|
183
|
-
child.getAttribute('slot') === 'footer');
|
|
184
|
-
}
|
|
185
|
-
collectContentParts(kind) {
|
|
186
|
-
if (!this.contentEl)
|
|
187
|
-
return [];
|
|
188
|
-
const matches = Array.from(this.contentEl.children).filter((child) => kind === 'body' ? this.isBodyPart(child) : this.isFooterPart(child));
|
|
189
|
-
if (matches.length > 0)
|
|
190
|
-
return matches;
|
|
191
|
-
return Array.from(this.children).filter((child) => kind === 'body' ? this.isBodyPart(child) : this.isFooterPart(child));
|
|
192
|
-
}
|
|
193
|
-
placeContentParts(kind, parts) {
|
|
194
|
-
if (!this.contentEl)
|
|
195
|
-
return;
|
|
196
|
-
parts.forEach((part) => {
|
|
197
|
-
if (part.parentElement === this.contentEl)
|
|
198
|
-
return;
|
|
199
|
-
if (kind === 'body') {
|
|
200
|
-
const anchor = this.contentEl.querySelector(':scope > .designbase-wc-modal__footer, :scope > [data-modal-part="footer"]') ||
|
|
201
|
-
null;
|
|
202
|
-
this.contentEl.insertBefore(part, anchor);
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
this.contentEl.append(part);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
restorePartsToHost() {
|
|
209
|
-
if (!this.contentEl)
|
|
210
|
-
return;
|
|
211
|
-
Array.from(this.contentEl.children)
|
|
212
|
-
.filter((child) => !child.classList.contains('designbase-wc-modal__integrated-content') &&
|
|
213
|
-
!child.hasAttribute('data-wc-internal'))
|
|
214
|
-
.forEach((child) => {
|
|
215
|
-
if (child.parentElement !== this) {
|
|
216
|
-
this.append(child);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
bindFooterActions() {
|
|
221
|
-
if (!this.contentEl || this.contentEl.dataset.modalActionsBound === 'true')
|
|
222
|
-
return;
|
|
223
|
-
this.contentEl.dataset.modalActionsBound = 'true';
|
|
224
|
-
const handleClose = (event) => {
|
|
225
|
-
const target = event.target?.closest('[data-modal-close]');
|
|
226
|
-
if (target && this.contentEl?.contains(target)) {
|
|
227
|
-
this.close();
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
this.contentEl.addEventListener('click', handleClose);
|
|
231
|
-
this.contentEl.addEventListener('db-click', handleClose);
|
|
232
|
-
}
|
|
233
|
-
ensureStructure() {
|
|
234
|
-
if (!this.root) {
|
|
235
|
-
this.root = document.createElement('div');
|
|
236
|
-
this.root.className = 'designbase-wc-modal__overlay';
|
|
237
|
-
this.root.setAttribute('data-wc-internal', '');
|
|
238
|
-
this.root.addEventListener('click', (event) => {
|
|
239
|
-
if (event.target === this.root && this.getAttribute('close-on-outside-click') !== 'false') {
|
|
240
|
-
this.close();
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
this.panel = document.createElement('div');
|
|
244
|
-
this.panel.className = 'designbase-wc-modal';
|
|
245
|
-
this.panel.setAttribute('role', 'dialog');
|
|
246
|
-
this.panel.setAttribute('aria-modal', 'true');
|
|
247
|
-
this.panel.addEventListener('click', (event) => event.stopPropagation());
|
|
248
|
-
this.headerEl = document.createElement('div');
|
|
249
|
-
this.headerEl.className = 'designbase-wc-modal__header';
|
|
250
|
-
this.headerContentEl = document.createElement('div');
|
|
251
|
-
this.headerContentEl.className = 'designbase-wc-modal__header-content';
|
|
252
|
-
this.titleEl = document.createElement('h2');
|
|
253
|
-
this.titleEl.className = 'designbase-wc-modal__title';
|
|
254
|
-
this.titleEl.id = this.titleId;
|
|
255
|
-
this.closeButton = document.createElement('button');
|
|
256
|
-
this.closeButton.type = 'button';
|
|
257
|
-
this.closeButton.className = 'designbase-wc-modal__close-button';
|
|
258
|
-
this.closeButton.setAttribute('aria-label', '모달 닫기');
|
|
259
|
-
this.closeButton.addEventListener('click', () => this.close());
|
|
260
|
-
this.navEl = document.createElement('div');
|
|
261
|
-
this.navEl.className = 'designbase-wc-modal__header-nav';
|
|
262
|
-
this.contentEl = document.createElement('div');
|
|
263
|
-
this.contentEl.className = 'designbase-wc-modal__content';
|
|
264
|
-
this.panel.append(this.headerEl, this.contentEl);
|
|
265
|
-
this.root.append(this.panel);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
renderCloseButton() {
|
|
269
|
-
if (!this.closeButton)
|
|
270
|
-
return;
|
|
271
|
-
const iconSize = this.closeIconSize();
|
|
272
|
-
this.closeButton.replaceChildren(createDbIcon('close', iconSize));
|
|
273
|
-
this.closeButton.hidden = this.getAttribute('show-close-button') === 'false';
|
|
274
|
-
}
|
|
275
|
-
renderDefaultHeader(customHeader) {
|
|
276
|
-
if (!this.headerEl || !this.headerContentEl || !this.titleEl || !this.closeButton)
|
|
277
|
-
return;
|
|
278
|
-
this.headerEl.className = 'designbase-wc-modal__header';
|
|
279
|
-
this.headerEl.replaceChildren();
|
|
280
|
-
if (customHeader.length > 0) {
|
|
281
|
-
customHeader.forEach((child) => this.headerEl.append(child));
|
|
282
|
-
if (this.getAttribute('show-close-button') !== 'false') {
|
|
283
|
-
this.headerEl.append(this.closeButton);
|
|
284
|
-
}
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
const title = this.getAttribute('title') || '';
|
|
288
|
-
this.titleEl.textContent = title;
|
|
289
|
-
this.titleEl.hidden = !title;
|
|
290
|
-
this.headerContentEl.replaceChildren();
|
|
291
|
-
if (title)
|
|
292
|
-
this.headerContentEl.append(this.titleEl);
|
|
293
|
-
this.renderCloseButton();
|
|
294
|
-
this.headerEl.append(this.headerContentEl);
|
|
295
|
-
if (this.getAttribute('show-close-button') !== 'false') {
|
|
296
|
-
this.headerEl.append(this.closeButton);
|
|
297
|
-
}
|
|
298
|
-
if (this.panel) {
|
|
299
|
-
if (title)
|
|
300
|
-
this.panel.setAttribute('aria-labelledby', this.titleId);
|
|
301
|
-
else
|
|
302
|
-
this.panel.removeAttribute('aria-labelledby');
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
renderNavHeader() {
|
|
306
|
-
if (!this.headerEl || !this.headerContentEl || !this.titleEl || !this.closeButton || !this.navEl)
|
|
307
|
-
return;
|
|
308
|
-
const variant = this.resolvedHeaderVariant();
|
|
309
|
-
const tabs = this.parsedTabs();
|
|
310
|
-
const segments = this.parsedSegments();
|
|
311
|
-
const navSize = NAV_SIZES.includes((this.getAttribute('nav-size') || 'm'))
|
|
312
|
-
? this.getAttribute('nav-size') || 'm'
|
|
313
|
-
: 's';
|
|
314
|
-
this.headerEl.className = [
|
|
315
|
-
'designbase-wc-modal__header',
|
|
316
|
-
variant === 'tabs' && 'designbase-wc-modal__header--tabs',
|
|
317
|
-
variant === 'segment' && 'designbase-wc-modal__header--segment',
|
|
318
|
-
]
|
|
319
|
-
.filter(Boolean)
|
|
320
|
-
.join(' ');
|
|
321
|
-
const title = this.getAttribute('title') || '';
|
|
322
|
-
this.titleEl.textContent = title;
|
|
323
|
-
this.titleEl.hidden = !title;
|
|
324
|
-
this.headerContentEl.replaceChildren();
|
|
325
|
-
if (title)
|
|
326
|
-
this.headerContentEl.append(this.titleEl);
|
|
327
|
-
this.renderCloseButton();
|
|
328
|
-
const headerRow = document.createElement('div');
|
|
329
|
-
headerRow.className = 'designbase-wc-modal__header-row';
|
|
330
|
-
headerRow.append(this.headerContentEl);
|
|
331
|
-
if (this.getAttribute('show-close-button') !== 'false') {
|
|
332
|
-
headerRow.append(this.closeButton);
|
|
333
|
-
}
|
|
334
|
-
this.headerEl.replaceChildren(headerRow);
|
|
335
|
-
this.navEl.replaceChildren();
|
|
336
|
-
if (variant === 'tabs' && tabs.length > 0) {
|
|
337
|
-
const tabsComponent = document.createElement('db-tabs');
|
|
338
|
-
tabsComponent.setAttribute('size', navSize);
|
|
339
|
-
tabsComponent.setAttribute('items', JSON.stringify(tabs.map((tab) => ({ id: tab.id, label: tab.label, disabled: tab.disabled }))));
|
|
340
|
-
tabsComponent.setAttribute('selected-id', this.activeTabId());
|
|
341
|
-
tabsComponent.addEventListener('db-change', (event) => {
|
|
342
|
-
const tabId = event.detail?.id;
|
|
343
|
-
if (!tabId)
|
|
344
|
-
return;
|
|
345
|
-
if (!this.hasAttribute('selected-tab-id')) {
|
|
346
|
-
this.internalTabId = tabId;
|
|
347
|
-
}
|
|
348
|
-
this.dispatchEvent(new CustomEvent('db-tab-change', {
|
|
349
|
-
detail: { tabId },
|
|
350
|
-
bubbles: true,
|
|
351
|
-
composed: true,
|
|
352
|
-
}));
|
|
353
|
-
this.renderBodyContent(this.getClassifiedChildren().body);
|
|
354
|
-
});
|
|
355
|
-
this.tabsEl = tabsComponent;
|
|
356
|
-
this.navEl.append(tabsComponent);
|
|
357
|
-
this.headerEl.append(this.navEl);
|
|
358
|
-
}
|
|
359
|
-
if (variant === 'segment' && segments.length > 0) {
|
|
360
|
-
const segmentComponent = document.createElement('db-segment-control');
|
|
361
|
-
segmentComponent.setAttribute('size', navSize);
|
|
362
|
-
segmentComponent.setAttribute('options', JSON.stringify(segments.map((segment) => ({ value: segment.value, label: segment.label, disabled: segment.disabled }))));
|
|
363
|
-
segmentComponent.setAttribute('value', this.activeSegmentValue());
|
|
364
|
-
if (this.getAttribute('segment-full-width') !== 'false') {
|
|
365
|
-
segmentComponent.setAttribute('full-width', '');
|
|
366
|
-
}
|
|
367
|
-
segmentComponent.addEventListener('db-change', (event) => {
|
|
368
|
-
const value = event.detail?.value;
|
|
369
|
-
if (!value)
|
|
370
|
-
return;
|
|
371
|
-
if (!this.hasAttribute('segment-value')) {
|
|
372
|
-
this.internalSegment = value;
|
|
373
|
-
}
|
|
374
|
-
this.dispatchEvent(new CustomEvent('db-segment-change', {
|
|
375
|
-
detail: { value },
|
|
376
|
-
bubbles: true,
|
|
377
|
-
composed: true,
|
|
378
|
-
}));
|
|
379
|
-
this.renderBodyContent(this.getClassifiedChildren().body);
|
|
380
|
-
});
|
|
381
|
-
this.segmentEl = segmentComponent;
|
|
382
|
-
this.navEl.append(segmentComponent);
|
|
383
|
-
this.headerEl.append(this.navEl);
|
|
384
|
-
}
|
|
385
|
-
if (this.panel) {
|
|
386
|
-
if (title)
|
|
387
|
-
this.panel.setAttribute('aria-labelledby', this.titleId);
|
|
388
|
-
else
|
|
389
|
-
this.panel.removeAttribute('aria-labelledby');
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
renderHeader(customHeader) {
|
|
393
|
-
if (!this.headerEl)
|
|
394
|
-
return;
|
|
395
|
-
if (customHeader.length > 0) {
|
|
396
|
-
this.headerEl.hidden = false;
|
|
397
|
-
this.renderDefaultHeader(customHeader);
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
if (this.usesIntegratedNav()) {
|
|
401
|
-
this.headerEl.hidden = false;
|
|
402
|
-
this.renderNavHeader();
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
const title = this.getAttribute('title') || '';
|
|
406
|
-
if (!title) {
|
|
407
|
-
this.headerEl.hidden = true;
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
this.headerEl.hidden = false;
|
|
411
|
-
this.renderDefaultHeader([]);
|
|
412
|
-
}
|
|
413
|
-
renderBodyContent(userBody = []) {
|
|
414
|
-
if (!this.contentEl)
|
|
415
|
-
return;
|
|
416
|
-
let integratedEl = this.contentEl.querySelector(':scope > .designbase-wc-modal__integrated-content');
|
|
417
|
-
let integratedText = '';
|
|
418
|
-
if (this.usesIntegratedNav()) {
|
|
419
|
-
const variant = this.resolvedHeaderVariant();
|
|
420
|
-
if (variant === 'tabs') {
|
|
421
|
-
const tab = this.parsedTabs().find((item) => item.id === this.activeTabId());
|
|
422
|
-
integratedText = tab?.content || '';
|
|
423
|
-
}
|
|
424
|
-
if (variant === 'segment') {
|
|
425
|
-
const segment = this.parsedSegments().find((item) => item.value === this.activeSegmentValue());
|
|
426
|
-
integratedText = segment?.content || '';
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
if (integratedText) {
|
|
430
|
-
if (!integratedEl) {
|
|
431
|
-
integratedEl = document.createElement('div');
|
|
432
|
-
integratedEl.className = 'designbase-wc-modal__integrated-content designbase-wc-modal__body';
|
|
433
|
-
this.contentEl.insertBefore(integratedEl, this.contentEl.firstChild);
|
|
434
|
-
}
|
|
435
|
-
integratedEl.textContent = integratedText;
|
|
436
|
-
}
|
|
437
|
-
else {
|
|
438
|
-
integratedEl?.remove();
|
|
439
|
-
}
|
|
440
|
-
const bodyWrappers = userBody.filter((child) => this.isBodyPart(child));
|
|
441
|
-
const looseBody = userBody.filter((child) => !this.isBodyPart(child) && !this.isFooterPart(child));
|
|
442
|
-
this.placeContentParts('body', bodyWrappers.length > 0 ? bodyWrappers : looseBody);
|
|
443
|
-
}
|
|
444
|
-
renderFooter(footerChildren) {
|
|
445
|
-
if (!this.contentEl)
|
|
446
|
-
return;
|
|
447
|
-
const footerWrappers = footerChildren.filter((child) => this.isFooterPart(child));
|
|
448
|
-
const looseFooter = footerChildren.filter((child) => !this.isFooterPart(child) && !this.isBodyPart(child));
|
|
449
|
-
const footerParts = footerWrappers.length > 0 ? footerWrappers : looseFooter;
|
|
450
|
-
this.placeContentParts('footer', footerParts);
|
|
451
|
-
footerParts.forEach((part) => {
|
|
452
|
-
part.hidden = false;
|
|
453
|
-
});
|
|
454
|
-
this.bindFooterActions();
|
|
455
|
-
}
|
|
456
|
-
render() {
|
|
457
|
-
this.ensureStructure();
|
|
458
|
-
const { header, body, footer } = this.getClassifiedChildren();
|
|
459
|
-
SIZES.forEach((size) => this.panel?.classList.remove(`designbase-wc-modal--${size}`));
|
|
460
|
-
this.panel?.classList.add(`designbase-wc-modal--${this.resolvedSize()}`);
|
|
461
|
-
this.renderHeader(header);
|
|
462
|
-
this.renderBodyContent(body);
|
|
463
|
-
this.renderFooter(footer);
|
|
464
|
-
}
|
|
465
|
-
syncVisibility() {
|
|
466
|
-
if (!this.root || !this.panel)
|
|
467
|
-
return;
|
|
468
|
-
if (this.open) {
|
|
469
|
-
this.root.setAttribute('data-state', 'entering');
|
|
470
|
-
this.panel.setAttribute('data-state', 'entering');
|
|
471
|
-
requestAnimationFrame(() => {
|
|
472
|
-
void this.panel?.offsetHeight;
|
|
473
|
-
requestAnimationFrame(() => {
|
|
474
|
-
if (!this.open || !this.root || !this.panel)
|
|
475
|
-
return;
|
|
476
|
-
this.root.setAttribute('data-state', 'entered');
|
|
477
|
-
this.panel.setAttribute('data-state', 'entered');
|
|
478
|
-
});
|
|
479
|
-
});
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
this.root.setAttribute('data-state', 'exiting');
|
|
483
|
-
this.panel.setAttribute('data-state', 'exiting');
|
|
484
|
-
}
|
|
485
|
-
syncOpenState() {
|
|
486
|
-
if (this.open) {
|
|
487
|
-
this.render();
|
|
488
|
-
if (this.root && !this.root.isConnected) {
|
|
489
|
-
document.body.append(this.root);
|
|
490
|
-
}
|
|
491
|
-
document.body.style.overflow = 'hidden';
|
|
492
|
-
this.isMounted = true;
|
|
493
|
-
this.syncVisibility();
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
if (!this.isMounted)
|
|
497
|
-
return;
|
|
498
|
-
this.syncVisibility();
|
|
499
|
-
document.body.style.overflow = '';
|
|
500
|
-
if (this.exitTimerId)
|
|
501
|
-
clearTimeout(this.exitTimerId);
|
|
502
|
-
this.exitTimerId = window.setTimeout(() => {
|
|
503
|
-
if (!this.open)
|
|
504
|
-
this.teardown();
|
|
505
|
-
}, 200);
|
|
506
|
-
}
|
|
507
|
-
teardown() {
|
|
508
|
-
this.restorePartsToHost();
|
|
509
|
-
this.root?.remove();
|
|
510
|
-
this.isMounted = false;
|
|
511
|
-
document.body.style.overflow = '';
|
|
512
|
-
}
|
|
513
|
-
close() {
|
|
514
|
-
this.open = false;
|
|
515
|
-
this.dispatchEvent(new CustomEvent('db-close', { bubbles: true, composed: true }));
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
if (!customElements.get('db-modal')) {
|
|
519
|
-
customElements.define('db-modal', DbModal);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
export { DbModal };
|
|
1
|
+
import{createDbIcon as t}from"./db-icons.js";const e=["s","m","l","xl","full"],s=["default","tabs","segment"],i=["s","m","l"];class DbModal extends HTMLElement{constructor(){super(...arguments),this.titleId=`db-modal-title-${Math.random().toString(36).slice(2,9)}`,this.isMounted=!1,this.internalTabId="",this.internalSegment="",this.exitTimerId=null,this.handleDocumentKeyDown=t=>{"Escape"===t.key&&this.open&&"false"!==this.getAttribute("close-on-escape")&&(t.preventDefault(),this.close())}}static get observedAttributes(){return["open","title","size","header-variant","tabs","segments","selected-tab-id","default-selected-tab-id","segment-value","default-segment-value","nav-size","segment-full-width","close-on-outside-click","close-on-escape","show-close-button"]}get open(){return this.hasAttribute("open")&&"false"!==this.getAttribute("open")}set open(t){t?this.setAttribute("open","true"):this.removeAttribute("open")}connectedCallback(){this.classList.add("designbase-wc-modal-host"),document.addEventListener("keydown",this.handleDocumentKeyDown),this.childObserver=new MutationObserver(()=>{this.open&&this.render()}),this.childObserver.observe(this,{childList:!0}),this.syncOpenState()}disconnectedCallback(){this.childObserver?.disconnect(),document.removeEventListener("keydown",this.handleDocumentKeyDown),this.exitTimerId&&clearTimeout(this.exitTimerId),this.teardown()}attributeChangedCallback(t){if(this.isConnected)if("open"!==t){if("selected-tab-id"===t||"segment-value"===t){const t=this.getClassifiedChildren();return this.renderBodyContent(t.body),void this.renderHeader(t.header)}this.render(),this.isMounted&&this.syncVisibility()}else this.syncOpenState()}resolvedSize(){return e.includes(this.size)?this.size:"m"}get size(){return this.getAttribute("size")||"m"}set size(t){t?this.setAttribute("size",t):this.removeAttribute("size")}resolvedHeaderVariant(){const t=this.getAttribute("header-variant")||"default";return s.includes(t)?t:"default"}parsedTabs(){const t=this.getAttribute("tabs");if(!t)return[];try{const e=JSON.parse(t);return Array.isArray(e)?e:[]}catch{return[]}}parsedSegments(){const t=this.getAttribute("segments");if(!t)return[];try{const e=JSON.parse(t);return Array.isArray(e)?e:[]}catch{return[]}}usesIntegratedNav(){const t=this.resolvedHeaderVariant();return"tabs"===t&&this.parsedTabs().length>0||"segment"===t&&this.parsedSegments().length>0}closeIconSize(){const t=this.resolvedSize();return"s"===t?16:"l"===t?20:"xl"===t?24:18}activeTabId(){return this.getAttribute("selected-tab-id")||this.internalTabId||this.getAttribute("default-selected-tab-id")||this.parsedTabs()[0]?.id||""}activeSegmentValue(){return this.getAttribute("segment-value")||this.internalSegment||this.getAttribute("default-segment-value")||this.parsedSegments()[0]?.value||""}collectUserChildren(){return Array.from(this.children).filter(t=>!t.hasAttribute("data-wc-internal"))}classifyChildren(t){const isPart=(t,e,s)=>t.classList.contains(s)||t.getAttribute("data-modal-part")===e,e=t.filter(t=>isPart(t,"header","designbase-wc-modal__header")),s=t.filter(t=>isPart(t,"footer","designbase-wc-modal__footer")||"footer"===t.getAttribute("slot")),i=t.filter(t=>isPart(t,"body","designbase-wc-modal__body")),n=t.filter(t=>!e.includes(t)&&!s.includes(t)&&!i.includes(t));return{header:e,body:[...i,...n],footer:s}}getClassifiedChildren(){const t=this.classifyChildren(this.collectUserChildren());if(t.header.length||t.body.length||t.footer.length)return t;return{header:Array.from(this.headerEl?.children||[]).filter(t=>t!==this.closeButton&&!t.classList.contains("designbase-wc-modal__header-row")&&("header"===t.getAttribute("data-modal-part")||t.classList.contains("designbase-wc-modal__header"))),body:this.collectContentParts("body"),footer:this.collectContentParts("footer")}}isBodyPart(t){return t.classList.contains("designbase-wc-modal__body")||"body"===t.getAttribute("data-modal-part")}isFooterPart(t){return t.classList.contains("designbase-wc-modal__footer")||"footer"===t.getAttribute("data-modal-part")||"footer"===t.getAttribute("slot")}collectContentParts(t){if(!this.contentEl)return[];const e=Array.from(this.contentEl.children).filter(e=>"body"===t?this.isBodyPart(e):this.isFooterPart(e));return e.length>0?e:Array.from(this.children).filter(e=>"body"===t?this.isBodyPart(e):this.isFooterPart(e))}placeContentParts(t,e){this.contentEl&&e.forEach(e=>{if(e.parentElement!==this.contentEl){if("body"===t){const t=this.contentEl.querySelector(':scope > .designbase-wc-modal__footer, :scope > [data-modal-part="footer"]')||null;return void this.contentEl.insertBefore(e,t)}this.contentEl.append(e)}})}restorePartsToHost(){this.contentEl&&Array.from(this.contentEl.children).filter(t=>!t.classList.contains("designbase-wc-modal__integrated-content")&&!t.hasAttribute("data-wc-internal")).forEach(t=>{t.parentElement!==this&&this.append(t)})}bindFooterActions(){if(!this.contentEl||"true"===this.contentEl.dataset.modalActionsBound)return;this.contentEl.dataset.modalActionsBound="true";const handleClose=t=>{const e=t.target?.closest("[data-modal-close]");e&&this.contentEl?.contains(e)&&this.close()};this.contentEl.addEventListener("click",handleClose),this.contentEl.addEventListener("db-click",handleClose)}ensureStructure(){this.root||(this.root=document.createElement("div"),this.root.className="designbase-wc-modal__overlay",this.root.setAttribute("data-wc-internal",""),this.root.addEventListener("click",t=>{t.target===this.root&&"false"!==this.getAttribute("close-on-outside-click")&&this.close()}),this.panel=document.createElement("div"),this.panel.className="designbase-wc-modal",this.panel.setAttribute("role","dialog"),this.panel.setAttribute("aria-modal","true"),this.panel.addEventListener("click",t=>t.stopPropagation()),this.headerEl=document.createElement("div"),this.headerEl.className="designbase-wc-modal__header",this.headerContentEl=document.createElement("div"),this.headerContentEl.className="designbase-wc-modal__header-content",this.titleEl=document.createElement("h2"),this.titleEl.className="designbase-wc-modal__title",this.titleEl.id=this.titleId,this.closeButton=document.createElement("button"),this.closeButton.type="button",this.closeButton.className="designbase-wc-modal__close-button",this.closeButton.setAttribute("aria-label","모달 닫기"),this.closeButton.addEventListener("click",()=>this.close()),this.navEl=document.createElement("div"),this.navEl.className="designbase-wc-modal__header-nav",this.contentEl=document.createElement("div"),this.contentEl.className="designbase-wc-modal__content",this.panel.append(this.headerEl,this.contentEl),this.root.append(this.panel))}renderCloseButton(){if(!this.closeButton)return;const e=this.closeIconSize();this.closeButton.replaceChildren(t("close",e)),this.closeButton.hidden="false"===this.getAttribute("show-close-button")}renderDefaultHeader(t){if(!(this.headerEl&&this.headerContentEl&&this.titleEl&&this.closeButton))return;if(this.headerEl.className="designbase-wc-modal__header",this.headerEl.replaceChildren(),t.length>0)return t.forEach(t=>this.headerEl.append(t)),void("false"!==this.getAttribute("show-close-button")&&this.headerEl.append(this.closeButton));const e=this.getAttribute("title")||"";this.titleEl.textContent=e,this.titleEl.hidden=!e,this.headerContentEl.replaceChildren(),e&&this.headerContentEl.append(this.titleEl),this.renderCloseButton(),this.headerEl.append(this.headerContentEl),"false"!==this.getAttribute("show-close-button")&&this.headerEl.append(this.closeButton),this.panel&&(e?this.panel.setAttribute("aria-labelledby",this.titleId):this.panel.removeAttribute("aria-labelledby"))}renderNavHeader(){if(!(this.headerEl&&this.headerContentEl&&this.titleEl&&this.closeButton&&this.navEl))return;const t=this.resolvedHeaderVariant(),e=this.parsedTabs(),s=this.parsedSegments(),n=i.includes(this.getAttribute("nav-size")||"m")?this.getAttribute("nav-size")||"m":"s";this.headerEl.className=["designbase-wc-modal__header","tabs"===t&&"designbase-wc-modal__header--tabs","segment"===t&&"designbase-wc-modal__header--segment"].filter(Boolean).join(" ");const a=this.getAttribute("title")||"";this.titleEl.textContent=a,this.titleEl.hidden=!a,this.headerContentEl.replaceChildren(),a&&this.headerContentEl.append(this.titleEl),this.renderCloseButton();const r=document.createElement("div");if(r.className="designbase-wc-modal__header-row",r.append(this.headerContentEl),"false"!==this.getAttribute("show-close-button")&&r.append(this.closeButton),this.headerEl.replaceChildren(r),this.navEl.replaceChildren(),"tabs"===t&&e.length>0){const t=document.createElement("db-tabs");t.setAttribute("size",n),t.setAttribute("items",JSON.stringify(e.map(t=>({id:t.id,label:t.label,disabled:t.disabled})))),t.setAttribute("selected-id",this.activeTabId()),t.addEventListener("db-change",t=>{const e=t.detail?.id;e&&(this.hasAttribute("selected-tab-id")||(this.internalTabId=e),this.dispatchEvent(new CustomEvent("db-tab-change",{detail:{tabId:e},bubbles:!0,composed:!0})),this.renderBodyContent(this.getClassifiedChildren().body))}),this.tabsEl=t,this.navEl.append(t),this.headerEl.append(this.navEl)}if("segment"===t&&s.length>0){const t=document.createElement("db-segment-control");t.setAttribute("size",n),t.setAttribute("options",JSON.stringify(s.map(t=>({value:t.value,label:t.label,disabled:t.disabled})))),t.setAttribute("value",this.activeSegmentValue()),"false"!==this.getAttribute("segment-full-width")&&t.setAttribute("full-width",""),t.addEventListener("db-change",t=>{const e=t.detail?.value;e&&(this.hasAttribute("segment-value")||(this.internalSegment=e),this.dispatchEvent(new CustomEvent("db-segment-change",{detail:{value:e},bubbles:!0,composed:!0})),this.renderBodyContent(this.getClassifiedChildren().body))}),this.segmentEl=t,this.navEl.append(t),this.headerEl.append(this.navEl)}this.panel&&(a?this.panel.setAttribute("aria-labelledby",this.titleId):this.panel.removeAttribute("aria-labelledby"))}renderHeader(t){if(!this.headerEl)return;if(t.length>0)return this.headerEl.hidden=!1,void this.renderDefaultHeader(t);if(this.usesIntegratedNav())return this.headerEl.hidden=!1,void this.renderNavHeader();this.getAttribute("title")||""?(this.headerEl.hidden=!1,this.renderDefaultHeader([])):this.headerEl.hidden=!0}renderBodyContent(t=[]){if(!this.contentEl)return;let e=this.contentEl.querySelector(":scope > .designbase-wc-modal__integrated-content"),s="";if(this.usesIntegratedNav()){const t=this.resolvedHeaderVariant();if("tabs"===t){const t=this.parsedTabs().find(t=>t.id===this.activeTabId());s=t?.content||""}if("segment"===t){const t=this.parsedSegments().find(t=>t.value===this.activeSegmentValue());s=t?.content||""}}s?(e||(e=document.createElement("div"),e.className="designbase-wc-modal__integrated-content designbase-wc-modal__body",this.contentEl.insertBefore(e,this.contentEl.firstChild)),e.textContent=s):e?.remove();const i=t.filter(t=>this.isBodyPart(t)),n=t.filter(t=>!this.isBodyPart(t)&&!this.isFooterPart(t));this.placeContentParts("body",i.length>0?i:n)}renderFooter(t){if(!this.contentEl)return;const e=t.filter(t=>this.isFooterPart(t)),s=t.filter(t=>!this.isFooterPart(t)&&!this.isBodyPart(t)),i=e.length>0?e:s;this.placeContentParts("footer",i),i.forEach(t=>{t.hidden=!1}),this.bindFooterActions()}render(){this.ensureStructure();const{header:t,body:s,footer:i}=this.getClassifiedChildren();e.forEach(t=>this.panel?.classList.remove(`designbase-wc-modal--${t}`)),this.panel?.classList.add(`designbase-wc-modal--${this.resolvedSize()}`),this.renderHeader(t),this.renderBodyContent(s),this.renderFooter(i)}syncVisibility(){if(this.root&&this.panel){if(this.open)return this.root.setAttribute("data-state","entering"),this.panel.setAttribute("data-state","entering"),void requestAnimationFrame(()=>{this.panel,requestAnimationFrame(()=>{this.open&&this.root&&this.panel&&(this.root.setAttribute("data-state","entered"),this.panel.setAttribute("data-state","entered"))})});this.root.setAttribute("data-state","exiting"),this.panel.setAttribute("data-state","exiting")}}syncOpenState(){if(this.open)return this.render(),this.root&&!this.root.isConnected&&document.body.append(this.root),document.body.style.overflow="hidden",this.isMounted=!0,void this.syncVisibility();this.isMounted&&(this.syncVisibility(),document.body.style.overflow="",this.exitTimerId&&clearTimeout(this.exitTimerId),this.exitTimerId=window.setTimeout(()=>{this.open||this.teardown()},200))}teardown(){this.restorePartsToHost(),this.root?.remove(),this.isMounted=!1,document.body.style.overflow=""}close(){this.open=!1,this.dispatchEvent(new CustomEvent("db-close",{bubbles:!0,composed:!0}))}}customElements.get("db-modal")||customElements.define("db-modal",DbModal);export{DbModal};
|