@designbasekorea/ui-wc 0.5.6 → 0.6.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/dist/chunks/lottie-0e23d630.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 +62 -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 +61 -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.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 +60 -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/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-bash.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-clike.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-css.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-javascript.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-json.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-jsx.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-markup.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-scss.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-tsx.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-typescript.js +1 -0
- package/dist/index.cjs +1 -55414
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1091 -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 +1620 -54
- package/dist/react/index.esm.js +1 -39373
- package/package.json +1 -1
- package/dist/chunks/lottie-e273b936.js +0 -17032
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +0 -235
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -31
- package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -64
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -172
- package/dist/esm/node_modules/prismjs/components/prism-json.js +0 -27
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +0 -143
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -186
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +0 -81
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +0 -15
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -60
- package/dist/react/chunks/lottie-72a4c6d4.js +0 -17032
|
@@ -1,385 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const SIZES = ['s', 'm', 'l'];
|
|
4
|
-
class DbSection extends HTMLElement {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.contentId = `db-section-${Math.random().toString(36).slice(2, 9)}`;
|
|
8
|
-
this.internalExpanded = true;
|
|
9
|
-
this.internalTabId = '';
|
|
10
|
-
this.handleToggle = () => {
|
|
11
|
-
if (!this.isCollapsible())
|
|
12
|
-
return;
|
|
13
|
-
const next = !this.isExpanded();
|
|
14
|
-
if (!this.hasAttribute('expanded')) {
|
|
15
|
-
this.internalExpanded = next;
|
|
16
|
-
}
|
|
17
|
-
this.dispatchEvent(new CustomEvent('db-expanded-change', {
|
|
18
|
-
bubbles: true,
|
|
19
|
-
composed: true,
|
|
20
|
-
detail: { expanded: next },
|
|
21
|
-
}));
|
|
22
|
-
if (!this.hasAttribute('expanded')) {
|
|
23
|
-
this.syncHostClasses();
|
|
24
|
-
this.syncCollapsibleState();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
this.handleTabChange = (event) => {
|
|
28
|
-
const detail = event.detail;
|
|
29
|
-
const tabId = detail?.id ??
|
|
30
|
-
this.parseTabs()[detail?.index ?? 0]?.id ??
|
|
31
|
-
String(detail?.index ?? 0);
|
|
32
|
-
this.internalTabId = tabId;
|
|
33
|
-
this.tabsEl?.setAttribute('selected-id', tabId);
|
|
34
|
-
this.dispatchEvent(new CustomEvent('db-tab-change', {
|
|
35
|
-
bubbles: true,
|
|
36
|
-
composed: true,
|
|
37
|
-
detail: { tabId },
|
|
38
|
-
}));
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
static get observedAttributes() {
|
|
42
|
-
return [
|
|
43
|
-
'title',
|
|
44
|
-
'subtitle',
|
|
45
|
-
'description',
|
|
46
|
-
'size',
|
|
47
|
-
'collapsible',
|
|
48
|
-
'default-expanded',
|
|
49
|
-
'expanded',
|
|
50
|
-
'no-padding',
|
|
51
|
-
'full-width',
|
|
52
|
-
'full-height',
|
|
53
|
-
'overflow-visible',
|
|
54
|
-
'tabs',
|
|
55
|
-
'selected-tab-id',
|
|
56
|
-
'default-selected-tab-id',
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
connectedCallback() {
|
|
60
|
-
this.internalExpanded = this.getAttribute('default-expanded') !== 'false';
|
|
61
|
-
this.syncDefaultTab();
|
|
62
|
-
this.ensureStructure();
|
|
63
|
-
this.sync();
|
|
64
|
-
this.observer = new MutationObserver(() => this.sync());
|
|
65
|
-
this.observer.observe(this, { childList: true });
|
|
66
|
-
}
|
|
67
|
-
disconnectedCallback() {
|
|
68
|
-
this.observer?.disconnect();
|
|
69
|
-
}
|
|
70
|
-
attributeChangedCallback(name) {
|
|
71
|
-
if (!this.isConnected)
|
|
72
|
-
return;
|
|
73
|
-
if (name === 'default-expanded' && !this.hasAttribute('expanded')) {
|
|
74
|
-
this.internalExpanded = this.getAttribute('default-expanded') !== 'false';
|
|
75
|
-
}
|
|
76
|
-
if (name === 'default-selected-tab-id' || name === 'tabs') {
|
|
77
|
-
this.syncDefaultTab();
|
|
78
|
-
}
|
|
79
|
-
if (name === 'selected-tab-id') {
|
|
80
|
-
const next = this.getAttribute('selected-tab-id');
|
|
81
|
-
if (next)
|
|
82
|
-
this.internalTabId = next;
|
|
83
|
-
}
|
|
84
|
-
this.sync();
|
|
85
|
-
}
|
|
86
|
-
syncDefaultTab() {
|
|
87
|
-
if (this.internalTabId)
|
|
88
|
-
return;
|
|
89
|
-
const tabs = this.parseTabs();
|
|
90
|
-
const defaultId = this.getAttribute('default-selected-tab-id') || '';
|
|
91
|
-
this.internalTabId = defaultId || tabs[0]?.id || '';
|
|
92
|
-
}
|
|
93
|
-
parseTabs() {
|
|
94
|
-
try {
|
|
95
|
-
const parsed = JSON.parse(this.getAttribute('tabs') || '[]');
|
|
96
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
return [];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
getActiveTabId() {
|
|
103
|
-
const attr = this.getAttribute('selected-tab-id');
|
|
104
|
-
if (attr && this.internalTabId && attr !== this.internalTabId) {
|
|
105
|
-
return this.internalTabId;
|
|
106
|
-
}
|
|
107
|
-
return attr || this.internalTabId || this.tabsEl?.getAttribute('selected-id') || '';
|
|
108
|
-
}
|
|
109
|
-
hasHeaderTabs() {
|
|
110
|
-
return this.parseTabs().length > 0 && !this.isCollapsible();
|
|
111
|
-
}
|
|
112
|
-
isCollapsible() {
|
|
113
|
-
return this.hasAttribute('collapsible');
|
|
114
|
-
}
|
|
115
|
-
isExpanded() {
|
|
116
|
-
if (!this.isCollapsible())
|
|
117
|
-
return true;
|
|
118
|
-
if (this.hasAttribute('expanded')) {
|
|
119
|
-
return this.getAttribute('expanded') !== 'false';
|
|
120
|
-
}
|
|
121
|
-
return this.internalExpanded;
|
|
122
|
-
}
|
|
123
|
-
isUserNode(node) {
|
|
124
|
-
return !node.hasAttribute('data-wc-internal');
|
|
125
|
-
}
|
|
126
|
-
collectSlotted(name) {
|
|
127
|
-
const direct = Array.from(this.querySelectorAll(`:scope > [slot="${name}"]`)).filter(this.isUserNode);
|
|
128
|
-
if (direct.length)
|
|
129
|
-
return direct;
|
|
130
|
-
if (name === 'actions' && this.actionsHostEl) {
|
|
131
|
-
return Array.from(this.actionsHostEl.children);
|
|
132
|
-
}
|
|
133
|
-
if (name === 'footer' && this.footerEl) {
|
|
134
|
-
return Array.from(this.footerEl.children);
|
|
135
|
-
}
|
|
136
|
-
if (name === 'header') {
|
|
137
|
-
const main = this.headerEl?.querySelector('.designbase-wc-section__header-main');
|
|
138
|
-
return main ? Array.from(main.children) : [];
|
|
139
|
-
}
|
|
140
|
-
if (name === 'description') {
|
|
141
|
-
const description = this.headerEl?.querySelector('.designbase-wc-section__description');
|
|
142
|
-
const child = description?.firstElementChild;
|
|
143
|
-
return child ? [child] : [];
|
|
144
|
-
}
|
|
145
|
-
return [];
|
|
146
|
-
}
|
|
147
|
-
collectContentNodes() {
|
|
148
|
-
const direct = Array.from(this.children).filter((child) => {
|
|
149
|
-
if (!this.isUserNode(child))
|
|
150
|
-
return false;
|
|
151
|
-
const slot = child.getAttribute('slot');
|
|
152
|
-
return !slot || slot === 'default';
|
|
153
|
-
});
|
|
154
|
-
if (direct.length)
|
|
155
|
-
return direct;
|
|
156
|
-
return this.contentEl ? Array.from(this.contentEl.children) : [];
|
|
157
|
-
}
|
|
158
|
-
ensureStructure() {
|
|
159
|
-
if (!this.headerEl) {
|
|
160
|
-
this.headerEl = document.createElement('div');
|
|
161
|
-
this.headerEl.className = 'designbase-wc-section__header';
|
|
162
|
-
this.headerEl.setAttribute('data-wc-internal', '');
|
|
163
|
-
}
|
|
164
|
-
if (!this.bodyEl) {
|
|
165
|
-
this.bodyEl = document.createElement('div');
|
|
166
|
-
this.bodyEl.className = 'designbase-wc-section__body';
|
|
167
|
-
this.bodyEl.id = this.contentId;
|
|
168
|
-
this.bodyEl.setAttribute('data-wc-internal', '');
|
|
169
|
-
this.bodyInnerEl = document.createElement('div');
|
|
170
|
-
this.bodyInnerEl.className = 'designbase-wc-section__body-inner';
|
|
171
|
-
this.bodyInnerEl.setAttribute('data-wc-internal', '');
|
|
172
|
-
this.bodyEl.append(this.bodyInnerEl);
|
|
173
|
-
}
|
|
174
|
-
if (!this.contentEl) {
|
|
175
|
-
this.contentEl = document.createElement('div');
|
|
176
|
-
this.contentEl.className = 'designbase-wc-section__content';
|
|
177
|
-
this.contentEl.setAttribute('data-wc-internal', '');
|
|
178
|
-
}
|
|
179
|
-
if (!this.footerEl) {
|
|
180
|
-
this.footerEl = document.createElement('div');
|
|
181
|
-
this.footerEl.className = 'designbase-wc-section__footer';
|
|
182
|
-
this.footerEl.setAttribute('data-wc-internal', '');
|
|
183
|
-
}
|
|
184
|
-
if (!this.headerEl.isConnected) {
|
|
185
|
-
this.append(this.headerEl);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
mountBody() {
|
|
189
|
-
const contentNodes = this.collectContentNodes();
|
|
190
|
-
const footerNodes = this.collectSlotted('footer');
|
|
191
|
-
this.contentEl.replaceChildren(...contentNodes);
|
|
192
|
-
this.footerEl.replaceChildren(...footerNodes);
|
|
193
|
-
this.footerEl.hidden = footerNodes.length === 0;
|
|
194
|
-
if (this.isCollapsible()) {
|
|
195
|
-
this.bodyInnerEl.replaceChildren(this.contentEl, this.footerEl);
|
|
196
|
-
if (!this.bodyEl.isConnected) {
|
|
197
|
-
this.append(this.bodyEl);
|
|
198
|
-
}
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
this.bodyEl?.remove();
|
|
202
|
-
if (!this.contentEl.isConnected) {
|
|
203
|
-
this.append(this.contentEl);
|
|
204
|
-
}
|
|
205
|
-
if (footerNodes.length) {
|
|
206
|
-
if (!this.footerEl.isConnected) {
|
|
207
|
-
this.append(this.footerEl);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
this.footerEl.remove();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
getChevronSize() {
|
|
215
|
-
const size = this.getAttribute('size') || 'm';
|
|
216
|
-
if (size === 's')
|
|
217
|
-
return 16;
|
|
218
|
-
if (size === 'l')
|
|
219
|
-
return 24;
|
|
220
|
-
return 20;
|
|
221
|
-
}
|
|
222
|
-
createTitleArea() {
|
|
223
|
-
const title = this.getAttribute('title');
|
|
224
|
-
const subtitle = this.getAttribute('subtitle');
|
|
225
|
-
const description = this.getAttribute('description');
|
|
226
|
-
const descriptionSlot = this.collectSlotted('description')[0];
|
|
227
|
-
if (!title && !subtitle && !description && !descriptionSlot)
|
|
228
|
-
return null;
|
|
229
|
-
const area = document.createElement('div');
|
|
230
|
-
area.className = 'designbase-wc-section__title-area';
|
|
231
|
-
if (title) {
|
|
232
|
-
const heading = document.createElement('h2');
|
|
233
|
-
heading.className = 'designbase-wc-section__title';
|
|
234
|
-
heading.textContent = title;
|
|
235
|
-
area.append(heading);
|
|
236
|
-
}
|
|
237
|
-
if (subtitle) {
|
|
238
|
-
const sub = document.createElement('h3');
|
|
239
|
-
sub.className = 'designbase-wc-section__subtitle';
|
|
240
|
-
sub.textContent = subtitle;
|
|
241
|
-
area.append(sub);
|
|
242
|
-
}
|
|
243
|
-
if (descriptionSlot) {
|
|
244
|
-
const body = document.createElement('p');
|
|
245
|
-
body.className = 'designbase-wc-section__description';
|
|
246
|
-
body.append(descriptionSlot);
|
|
247
|
-
area.append(body);
|
|
248
|
-
}
|
|
249
|
-
else if (description) {
|
|
250
|
-
const body = document.createElement('p');
|
|
251
|
-
body.className = 'designbase-wc-section__description';
|
|
252
|
-
body.textContent = description;
|
|
253
|
-
area.append(body);
|
|
254
|
-
}
|
|
255
|
-
return area;
|
|
256
|
-
}
|
|
257
|
-
createChevron() {
|
|
258
|
-
const chevron = document.createElement('span');
|
|
259
|
-
chevron.className = 'designbase-wc-section__chevron';
|
|
260
|
-
chevron.setAttribute('aria-hidden', 'true');
|
|
261
|
-
chevron.append(createDbIcon('chevron-down', this.getChevronSize()));
|
|
262
|
-
return chevron;
|
|
263
|
-
}
|
|
264
|
-
renderHeader() {
|
|
265
|
-
if (!this.headerEl)
|
|
266
|
-
return;
|
|
267
|
-
const headerSlot = this.collectSlotted('header')[0];
|
|
268
|
-
const actionNodes = this.collectSlotted('actions');
|
|
269
|
-
const titleArea = this.createTitleArea();
|
|
270
|
-
const hasTabs = this.hasHeaderTabs();
|
|
271
|
-
const hasHeader = Boolean(headerSlot || titleArea || actionNodes.length);
|
|
272
|
-
this.headerEl.replaceChildren();
|
|
273
|
-
this.headerEl.hidden = !hasHeader && !hasTabs;
|
|
274
|
-
this.headerEl.classList.toggle('designbase-wc-section__header--with-tabs', hasTabs);
|
|
275
|
-
if (!hasHeader && !hasTabs)
|
|
276
|
-
return;
|
|
277
|
-
if (this.isCollapsible()) {
|
|
278
|
-
if (headerSlot) {
|
|
279
|
-
const trigger = document.createElement('button');
|
|
280
|
-
trigger.type = 'button';
|
|
281
|
-
trigger.className = 'designbase-wc-section__header-trigger';
|
|
282
|
-
trigger.setAttribute('aria-expanded', String(this.isExpanded()));
|
|
283
|
-
trigger.setAttribute('aria-controls', this.contentId);
|
|
284
|
-
trigger.addEventListener('click', this.handleToggle);
|
|
285
|
-
const main = document.createElement('div');
|
|
286
|
-
main.className = 'designbase-wc-section__header-main';
|
|
287
|
-
main.append(headerSlot);
|
|
288
|
-
trigger.append(main, this.createChevron());
|
|
289
|
-
this.headerEl.append(trigger);
|
|
290
|
-
}
|
|
291
|
-
else {
|
|
292
|
-
const trigger = document.createElement('button');
|
|
293
|
-
trigger.type = 'button';
|
|
294
|
-
trigger.className = 'designbase-wc-section__header-trigger';
|
|
295
|
-
trigger.setAttribute('aria-expanded', String(this.isExpanded()));
|
|
296
|
-
trigger.setAttribute('aria-controls', this.contentId);
|
|
297
|
-
trigger.addEventListener('click', this.handleToggle);
|
|
298
|
-
if (titleArea)
|
|
299
|
-
trigger.append(titleArea);
|
|
300
|
-
trigger.append(this.createChevron());
|
|
301
|
-
this.headerEl.append(trigger);
|
|
302
|
-
if (actionNodes.length) {
|
|
303
|
-
this.actionsHostEl = document.createElement('div');
|
|
304
|
-
this.actionsHostEl.className = 'designbase-wc-section__actions';
|
|
305
|
-
this.actionsHostEl.addEventListener('click', (event) => event.stopPropagation());
|
|
306
|
-
actionNodes.forEach((node) => this.actionsHostEl.append(node));
|
|
307
|
-
this.headerEl.append(this.actionsHostEl);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
const appendHeaderMain = (container) => {
|
|
313
|
-
if (headerSlot) {
|
|
314
|
-
container.append(headerSlot);
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
if (titleArea)
|
|
318
|
-
container.append(titleArea);
|
|
319
|
-
if (actionNodes.length) {
|
|
320
|
-
this.actionsHostEl = document.createElement('div');
|
|
321
|
-
this.actionsHostEl.className = 'designbase-wc-section__actions';
|
|
322
|
-
actionNodes.forEach((node) => this.actionsHostEl.append(node));
|
|
323
|
-
container.append(this.actionsHostEl);
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
if (hasTabs) {
|
|
327
|
-
const row = document.createElement('div');
|
|
328
|
-
row.className = 'designbase-wc-section__header-row';
|
|
329
|
-
appendHeaderMain(row);
|
|
330
|
-
this.headerEl.append(row);
|
|
331
|
-
const tabsWrap = document.createElement('div');
|
|
332
|
-
tabsWrap.className = 'designbase-wc-section__header-tabs';
|
|
333
|
-
if (!this.tabsEl) {
|
|
334
|
-
this.tabsEl = document.createElement('db-tabs');
|
|
335
|
-
this.tabsEl.setAttribute('size', 'm');
|
|
336
|
-
this.tabsEl.addEventListener('db-change', this.handleTabChange);
|
|
337
|
-
}
|
|
338
|
-
this.tabsEl.setAttribute('items', JSON.stringify(this.parseTabs()));
|
|
339
|
-
this.tabsEl.setAttribute('selected-id', this.getActiveTabId());
|
|
340
|
-
tabsWrap.append(this.tabsEl);
|
|
341
|
-
this.headerEl.append(tabsWrap);
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
appendHeaderMain(this.headerEl);
|
|
345
|
-
}
|
|
346
|
-
syncHostClasses() {
|
|
347
|
-
const size = this.getAttribute('size') || 'm';
|
|
348
|
-
const safeSize = SIZES.includes(size) ? size : 'm';
|
|
349
|
-
const expanded = this.isExpanded();
|
|
350
|
-
this.className = [
|
|
351
|
-
'designbase-wc-section',
|
|
352
|
-
`designbase-wc-section--size-${safeSize}`,
|
|
353
|
-
this.hasAttribute('no-padding') && 'designbase-wc-section--no-padding',
|
|
354
|
-
this.hasHeaderTabs() && 'designbase-wc-section--has-header-tabs',
|
|
355
|
-
this.hasAttribute('full-width') && 'designbase-wc-section--full-width',
|
|
356
|
-
this.hasAttribute('full-height') && 'designbase-wc-section--full-height',
|
|
357
|
-
this.hasAttribute('overflow-visible') && 'designbase-wc-section--overflow-visible',
|
|
358
|
-
this.isCollapsible() && 'designbase-wc-section--collapsible',
|
|
359
|
-
this.isCollapsible() && expanded && 'designbase-wc-section--expanded',
|
|
360
|
-
this.isCollapsible() && !expanded && 'designbase-wc-section--collapsed',
|
|
361
|
-
]
|
|
362
|
-
.filter(Boolean)
|
|
363
|
-
.join(' ');
|
|
364
|
-
}
|
|
365
|
-
syncCollapsibleState() {
|
|
366
|
-
if (!this.isCollapsible() || !this.bodyEl)
|
|
367
|
-
return;
|
|
368
|
-
const expanded = this.isExpanded();
|
|
369
|
-
this.bodyEl.setAttribute('aria-hidden', String(!expanded));
|
|
370
|
-
const trigger = this.headerEl?.querySelector('.designbase-wc-section__header-trigger');
|
|
371
|
-
trigger?.setAttribute('aria-expanded', String(expanded));
|
|
372
|
-
}
|
|
373
|
-
sync() {
|
|
374
|
-
this.ensureStructure();
|
|
375
|
-
this.syncHostClasses();
|
|
376
|
-
this.renderHeader();
|
|
377
|
-
this.mountBody();
|
|
378
|
-
this.syncCollapsibleState();
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
if (!customElements.get('db-section')) {
|
|
382
|
-
customElements.define('db-section', DbSection);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
export { DbSection };
|
|
1
|
+
import{createDbIcon as e}from"./db-icons.js";const t=["s","m","l"];class DbSection extends HTMLElement{constructor(){super(...arguments),this.contentId=`db-section-${Math.random().toString(36).slice(2,9)}`,this.internalExpanded=!0,this.internalTabId="",this.handleToggle=()=>{if(!this.isCollapsible())return;const e=!this.isExpanded();this.hasAttribute("expanded")||(this.internalExpanded=e),this.dispatchEvent(new CustomEvent("db-expanded-change",{bubbles:!0,composed:!0,detail:{expanded:e}})),this.hasAttribute("expanded")||(this.syncHostClasses(),this.syncCollapsibleState())},this.handleTabChange=e=>{const t=e.detail,s=t?.id??this.parseTabs()[t?.index??0]?.id??String(t?.index??0);this.internalTabId=s,this.tabsEl?.setAttribute("selected-id",s),this.dispatchEvent(new CustomEvent("db-tab-change",{bubbles:!0,composed:!0,detail:{tabId:s}}))}}static get observedAttributes(){return["title","subtitle","description","size","collapsible","default-expanded","expanded","no-padding","full-width","full-height","overflow-visible","tabs","selected-tab-id","default-selected-tab-id"]}connectedCallback(){this.internalExpanded="false"!==this.getAttribute("default-expanded"),this.syncDefaultTab(),this.ensureStructure(),this.sync(),this.observer=new MutationObserver(()=>this.sync()),this.observer.observe(this,{childList:!0})}disconnectedCallback(){this.observer?.disconnect()}attributeChangedCallback(e){if(this.isConnected){if("default-expanded"!==e||this.hasAttribute("expanded")||(this.internalExpanded="false"!==this.getAttribute("default-expanded")),"default-selected-tab-id"!==e&&"tabs"!==e||this.syncDefaultTab(),"selected-tab-id"===e){const e=this.getAttribute("selected-tab-id");e&&(this.internalTabId=e)}this.sync()}}syncDefaultTab(){if(this.internalTabId)return;const e=this.parseTabs(),t=this.getAttribute("default-selected-tab-id")||"";this.internalTabId=t||e[0]?.id||""}parseTabs(){try{const e=JSON.parse(this.getAttribute("tabs")||"[]");return Array.isArray(e)?e:[]}catch{return[]}}getActiveTabId(){const e=this.getAttribute("selected-tab-id");return e&&this.internalTabId&&e!==this.internalTabId?this.internalTabId:e||this.internalTabId||this.tabsEl?.getAttribute("selected-id")||""}hasHeaderTabs(){return this.parseTabs().length>0&&!this.isCollapsible()}isCollapsible(){return this.hasAttribute("collapsible")}isExpanded(){return!this.isCollapsible()||(this.hasAttribute("expanded")?"false"!==this.getAttribute("expanded"):this.internalExpanded)}isUserNode(e){return!e.hasAttribute("data-wc-internal")}collectSlotted(e){const t=Array.from(this.querySelectorAll(`:scope > [slot="${e}"]`)).filter(this.isUserNode);if(t.length)return t;if("actions"===e&&this.actionsHostEl)return Array.from(this.actionsHostEl.children);if("footer"===e&&this.footerEl)return Array.from(this.footerEl.children);if("header"===e){const e=this.headerEl?.querySelector(".designbase-wc-section__header-main");return e?Array.from(e.children):[]}if("description"===e){const e=this.headerEl?.querySelector(".designbase-wc-section__description"),t=e?.firstElementChild;return t?[t]:[]}return[]}collectContentNodes(){const e=Array.from(this.children).filter(e=>{if(!this.isUserNode(e))return!1;const t=e.getAttribute("slot");return!t||"default"===t});return e.length?e:this.contentEl?Array.from(this.contentEl.children):[]}ensureStructure(){this.headerEl||(this.headerEl=document.createElement("div"),this.headerEl.className="designbase-wc-section__header",this.headerEl.setAttribute("data-wc-internal","")),this.bodyEl||(this.bodyEl=document.createElement("div"),this.bodyEl.className="designbase-wc-section__body",this.bodyEl.id=this.contentId,this.bodyEl.setAttribute("data-wc-internal",""),this.bodyInnerEl=document.createElement("div"),this.bodyInnerEl.className="designbase-wc-section__body-inner",this.bodyInnerEl.setAttribute("data-wc-internal",""),this.bodyEl.append(this.bodyInnerEl)),this.contentEl||(this.contentEl=document.createElement("div"),this.contentEl.className="designbase-wc-section__content",this.contentEl.setAttribute("data-wc-internal","")),this.footerEl||(this.footerEl=document.createElement("div"),this.footerEl.className="designbase-wc-section__footer",this.footerEl.setAttribute("data-wc-internal","")),this.headerEl.isConnected||this.append(this.headerEl)}mountBody(){const e=this.collectContentNodes(),t=this.collectSlotted("footer");if(this.contentEl.replaceChildren(...e),this.footerEl.replaceChildren(...t),this.footerEl.hidden=0===t.length,this.isCollapsible())return this.bodyInnerEl.replaceChildren(this.contentEl,this.footerEl),void(this.bodyEl.isConnected||this.append(this.bodyEl));this.bodyEl?.remove(),this.contentEl.isConnected||this.append(this.contentEl),t.length?this.footerEl.isConnected||this.append(this.footerEl):this.footerEl.remove()}getChevronSize(){const e=this.getAttribute("size")||"m";return"s"===e?16:"l"===e?24:20}createTitleArea(){const e=this.getAttribute("title"),t=this.getAttribute("subtitle"),s=this.getAttribute("description"),i=this.collectSlotted("description")[0];if(!(e||t||s||i))return null;const n=document.createElement("div");if(n.className="designbase-wc-section__title-area",e){const t=document.createElement("h2");t.className="designbase-wc-section__title",t.textContent=e,n.append(t)}if(t){const e=document.createElement("h3");e.className="designbase-wc-section__subtitle",e.textContent=t,n.append(e)}if(i){const e=document.createElement("p");e.className="designbase-wc-section__description",e.append(i),n.append(e)}else if(s){const e=document.createElement("p");e.className="designbase-wc-section__description",e.textContent=s,n.append(e)}return n}createChevron(){const t=document.createElement("span");return t.className="designbase-wc-section__chevron",t.setAttribute("aria-hidden","true"),t.append(e("chevron-down",this.getChevronSize())),t}renderHeader(){if(!this.headerEl)return;const e=this.collectSlotted("header")[0],t=this.collectSlotted("actions"),s=this.createTitleArea(),i=this.hasHeaderTabs(),n=Boolean(e||s||t.length);if(this.headerEl.replaceChildren(),this.headerEl.hidden=!n&&!i,this.headerEl.classList.toggle("designbase-wc-section__header--with-tabs",i),!n&&!i)return;if(this.isCollapsible()){if(e){const t=document.createElement("button");t.type="button",t.className="designbase-wc-section__header-trigger",t.setAttribute("aria-expanded",String(this.isExpanded())),t.setAttribute("aria-controls",this.contentId),t.addEventListener("click",this.handleToggle);const s=document.createElement("div");s.className="designbase-wc-section__header-main",s.append(e),t.append(s,this.createChevron()),this.headerEl.append(t)}else{const e=document.createElement("button");e.type="button",e.className="designbase-wc-section__header-trigger",e.setAttribute("aria-expanded",String(this.isExpanded())),e.setAttribute("aria-controls",this.contentId),e.addEventListener("click",this.handleToggle),s&&e.append(s),e.append(this.createChevron()),this.headerEl.append(e),t.length&&(this.actionsHostEl=document.createElement("div"),this.actionsHostEl.className="designbase-wc-section__actions",this.actionsHostEl.addEventListener("click",e=>e.stopPropagation()),t.forEach(e=>this.actionsHostEl.append(e)),this.headerEl.append(this.actionsHostEl))}return}const appendHeaderMain=i=>{e?i.append(e):(s&&i.append(s),t.length&&(this.actionsHostEl=document.createElement("div"),this.actionsHostEl.className="designbase-wc-section__actions",t.forEach(e=>this.actionsHostEl.append(e)),i.append(this.actionsHostEl)))};if(i){const e=document.createElement("div");e.className="designbase-wc-section__header-row",appendHeaderMain(e),this.headerEl.append(e);const t=document.createElement("div");return t.className="designbase-wc-section__header-tabs",this.tabsEl||(this.tabsEl=document.createElement("db-tabs"),this.tabsEl.setAttribute("size","m"),this.tabsEl.addEventListener("db-change",this.handleTabChange)),this.tabsEl.setAttribute("items",JSON.stringify(this.parseTabs())),this.tabsEl.setAttribute("selected-id",this.getActiveTabId()),t.append(this.tabsEl),void this.headerEl.append(t)}appendHeaderMain(this.headerEl)}syncHostClasses(){const e=this.getAttribute("size")||"m",s=t.includes(e)?e:"m",i=this.isExpanded();this.className=["designbase-wc-section",`designbase-wc-section--size-${s}`,this.hasAttribute("no-padding")&&"designbase-wc-section--no-padding",this.hasHeaderTabs()&&"designbase-wc-section--has-header-tabs",this.hasAttribute("full-width")&&"designbase-wc-section--full-width",this.hasAttribute("full-height")&&"designbase-wc-section--full-height",this.hasAttribute("overflow-visible")&&"designbase-wc-section--overflow-visible",this.isCollapsible()&&"designbase-wc-section--collapsible",this.isCollapsible()&&i&&"designbase-wc-section--expanded",this.isCollapsible()&&!i&&"designbase-wc-section--collapsed"].filter(Boolean).join(" ")}syncCollapsibleState(){if(!this.isCollapsible()||!this.bodyEl)return;const e=this.isExpanded();this.bodyEl.setAttribute("aria-hidden",String(!e));const t=this.headerEl?.querySelector(".designbase-wc-section__header-trigger");t?.setAttribute("aria-expanded",String(e))}sync(){this.ensureStructure(),this.syncHostClasses(),this.renderHeader(),this.mountBody(),this.syncCollapsibleState()}}customElements.get("db-section")||customElements.define("db-section",DbSection);export{DbSection};
|
|
@@ -1,231 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* SegmentControl Web Component
|
|
3
|
-
* packages/ui SegmentControl.tsx와 DOM·동작·스타일 1:1 동기화
|
|
4
|
-
*/
|
|
5
|
-
const CLASS = 'designbase-wc-segment-control';
|
|
6
|
-
const ICON_SVGS = {
|
|
7
|
-
bar: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="12" width="4" height="8"/><rect x="10" y="8" width="4" height="12"/><rect x="17" y="4" width="4" height="16"/></svg>',
|
|
8
|
-
line: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="4 16 9 10 14 13 20 6"/></svg>',
|
|
9
|
-
pie: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2v10l8.66 5"/><circle cx="12" cy="12" r="10"/></svg>',
|
|
10
|
-
donut: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="8"/><circle cx="12" cy="12" r="3"/></svg>',
|
|
11
|
-
radar: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="12 2 20 8 17 20 7 20 4 8"/></svg>',
|
|
12
|
-
};
|
|
13
|
-
class DbSegmentControl extends HTMLElement {
|
|
14
|
-
constructor() {
|
|
15
|
-
super(...arguments);
|
|
16
|
-
this.built = false;
|
|
17
|
-
this.indicatorEl = null;
|
|
18
|
-
this.segmentButtons = [];
|
|
19
|
-
this.focusedIndex = -1;
|
|
20
|
-
this.boundKeyDown = (e) => this.handleKeyDown(e);
|
|
21
|
-
this.boundResize = () => this.updateIndicator();
|
|
22
|
-
this.resizeObserver = null;
|
|
23
|
-
}
|
|
24
|
-
static get observedAttributes() {
|
|
25
|
-
return ['options', 'value', 'default-value', 'size', 'variant', 'appearance', 'full-width', 'disabled'];
|
|
26
|
-
}
|
|
27
|
-
connectedCallback() {
|
|
28
|
-
if (!this.built) {
|
|
29
|
-
this.built = true;
|
|
30
|
-
}
|
|
31
|
-
this.render();
|
|
32
|
-
this.addEventListener('keydown', this.boundKeyDown);
|
|
33
|
-
window.addEventListener('resize', this.boundResize);
|
|
34
|
-
this.resizeObserver = new ResizeObserver(() => this.updateIndicator());
|
|
35
|
-
this.resizeObserver.observe(this);
|
|
36
|
-
}
|
|
37
|
-
disconnectedCallback() {
|
|
38
|
-
this.removeEventListener('keydown', this.boundKeyDown);
|
|
39
|
-
window.removeEventListener('resize', this.boundResize);
|
|
40
|
-
this.resizeObserver?.disconnect();
|
|
41
|
-
this.resizeObserver = null;
|
|
42
|
-
}
|
|
43
|
-
attributeChangedCallback(name) {
|
|
44
|
-
if (!this.built)
|
|
45
|
-
return;
|
|
46
|
-
if (name === 'value') {
|
|
47
|
-
this.updateSelection();
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
this.render();
|
|
51
|
-
}
|
|
52
|
-
get options() {
|
|
53
|
-
return this.parseOptions(this.getAttribute('options'));
|
|
54
|
-
}
|
|
55
|
-
set options(value) {
|
|
56
|
-
this.setAttribute('options', typeof value === 'string' ? value : JSON.stringify(value));
|
|
57
|
-
}
|
|
58
|
-
get value() {
|
|
59
|
-
return this.getAttribute('value') || this.getAttribute('default-value') || this.options[0]?.value || '';
|
|
60
|
-
}
|
|
61
|
-
set value(value) {
|
|
62
|
-
this.setAttribute('value', value);
|
|
63
|
-
}
|
|
64
|
-
parseOptions(raw) {
|
|
65
|
-
if (!raw)
|
|
66
|
-
return [];
|
|
67
|
-
try {
|
|
68
|
-
const parsed = JSON.parse(raw);
|
|
69
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
render() {
|
|
76
|
-
const size = this.getAttribute('size') || 'm';
|
|
77
|
-
const variant = this.getAttribute('variant') || 'default';
|
|
78
|
-
const appearance = this.getAttribute('appearance') || 'pill';
|
|
79
|
-
const disabled = this.hasAttribute('disabled');
|
|
80
|
-
const options = this.options;
|
|
81
|
-
const selected = this.value;
|
|
82
|
-
this.className = [
|
|
83
|
-
CLASS,
|
|
84
|
-
`${CLASS}--${size}`,
|
|
85
|
-
`${CLASS}--${variant}`,
|
|
86
|
-
appearance === 'rounded' && `${CLASS}--appearance-rounded`,
|
|
87
|
-
this.hasAttribute('full-width') && `${CLASS}--full-width`,
|
|
88
|
-
disabled && `${CLASS}--disabled`,
|
|
89
|
-
]
|
|
90
|
-
.filter(Boolean)
|
|
91
|
-
.join(' ');
|
|
92
|
-
this.setAttribute('role', 'tablist');
|
|
93
|
-
this.setAttribute('aria-label', '세그먼트 컨트롤');
|
|
94
|
-
this.replaceChildren();
|
|
95
|
-
this.segmentButtons = [];
|
|
96
|
-
options.forEach((option, index) => {
|
|
97
|
-
const isSelected = option.value === selected;
|
|
98
|
-
const isDisabled = Boolean(disabled || option.disabled);
|
|
99
|
-
const button = document.createElement('button');
|
|
100
|
-
button.type = 'button';
|
|
101
|
-
button.className = [
|
|
102
|
-
`${CLASS}__segment`,
|
|
103
|
-
isSelected && `${CLASS}__segment--selected`,
|
|
104
|
-
isDisabled && `${CLASS}__segment--disabled`,
|
|
105
|
-
]
|
|
106
|
-
.filter(Boolean)
|
|
107
|
-
.join(' ');
|
|
108
|
-
button.setAttribute('role', 'tab');
|
|
109
|
-
button.setAttribute('aria-selected', String(isSelected));
|
|
110
|
-
button.setAttribute('aria-disabled', String(isDisabled));
|
|
111
|
-
button.setAttribute('tabindex', isSelected ? '0' : '-1');
|
|
112
|
-
button.disabled = isDisabled;
|
|
113
|
-
if (option.icon && ICON_SVGS[option.icon]) {
|
|
114
|
-
const iconWrap = document.createElement('span');
|
|
115
|
-
iconWrap.className = `${CLASS}__segment-icon`;
|
|
116
|
-
iconWrap.innerHTML = ICON_SVGS[option.icon];
|
|
117
|
-
button.appendChild(iconWrap);
|
|
118
|
-
}
|
|
119
|
-
const label = document.createElement('span');
|
|
120
|
-
label.className = `${CLASS}__segment-label`;
|
|
121
|
-
label.textContent = option.label;
|
|
122
|
-
if (variant === 'icon-only') {
|
|
123
|
-
label.setAttribute('aria-label', option.label);
|
|
124
|
-
}
|
|
125
|
-
button.appendChild(label);
|
|
126
|
-
button.addEventListener('click', () => this.select(option.value));
|
|
127
|
-
button.addEventListener('focus', () => {
|
|
128
|
-
this.focusedIndex = index;
|
|
129
|
-
button.classList.add(`${CLASS}__segment--focused`);
|
|
130
|
-
});
|
|
131
|
-
button.addEventListener('blur', () => {
|
|
132
|
-
this.focusedIndex = -1;
|
|
133
|
-
button.classList.remove(`${CLASS}__segment--focused`);
|
|
134
|
-
});
|
|
135
|
-
this.appendChild(button);
|
|
136
|
-
this.segmentButtons.push(button);
|
|
137
|
-
});
|
|
138
|
-
this.indicatorEl = document.createElement('div');
|
|
139
|
-
this.indicatorEl.className = `${CLASS}__indicator`;
|
|
140
|
-
this.appendChild(this.indicatorEl);
|
|
141
|
-
this.updateSelection();
|
|
142
|
-
}
|
|
143
|
-
updateSelection() {
|
|
144
|
-
const options = this.options;
|
|
145
|
-
const selected = this.value;
|
|
146
|
-
const selectedIndex = options.findIndex((option) => option.value === selected);
|
|
147
|
-
this.segmentButtons.forEach((button, index) => {
|
|
148
|
-
const option = options[index];
|
|
149
|
-
const isSelected = option?.value === selected;
|
|
150
|
-
button.classList.toggle(`${CLASS}__segment--selected`, isSelected);
|
|
151
|
-
button.setAttribute('aria-selected', String(isSelected));
|
|
152
|
-
button.setAttribute('tabindex', isSelected ? '0' : '-1');
|
|
153
|
-
});
|
|
154
|
-
if (this.indicatorEl && options.length > 0 && selectedIndex >= 0) {
|
|
155
|
-
requestAnimationFrame(() => this.updateIndicator());
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
updateIndicator() {
|
|
159
|
-
const selectedIndex = this.options.findIndex((option) => option.value === this.value);
|
|
160
|
-
const activeButton = this.segmentButtons[selectedIndex];
|
|
161
|
-
if (!this.indicatorEl || !activeButton)
|
|
162
|
-
return;
|
|
163
|
-
this.indicatorEl.style.width = `${activeButton.offsetWidth}px`;
|
|
164
|
-
this.indicatorEl.style.transform = `translateX(${activeButton.offsetLeft}px)`;
|
|
165
|
-
}
|
|
166
|
-
select(value) {
|
|
167
|
-
if (this.hasAttribute('disabled'))
|
|
168
|
-
return;
|
|
169
|
-
const option = this.options.find((item) => item.value === value);
|
|
170
|
-
if (!option || option.disabled)
|
|
171
|
-
return;
|
|
172
|
-
this.setAttribute('value', value);
|
|
173
|
-
this.dispatchEvent(new CustomEvent('db-change', {
|
|
174
|
-
detail: { value },
|
|
175
|
-
bubbles: true,
|
|
176
|
-
composed: true,
|
|
177
|
-
}));
|
|
178
|
-
}
|
|
179
|
-
handleKeyDown(event) {
|
|
180
|
-
if (this.hasAttribute('disabled'))
|
|
181
|
-
return;
|
|
182
|
-
const options = this.options;
|
|
183
|
-
const currentIndex = options.findIndex((option) => option.value === this.value);
|
|
184
|
-
if (currentIndex === -1)
|
|
185
|
-
return;
|
|
186
|
-
let nextIndex = currentIndex;
|
|
187
|
-
switch (event.key) {
|
|
188
|
-
case 'ArrowLeft':
|
|
189
|
-
event.preventDefault();
|
|
190
|
-
nextIndex = currentIndex > 0 ? currentIndex - 1 : options.length - 1;
|
|
191
|
-
break;
|
|
192
|
-
case 'ArrowRight':
|
|
193
|
-
event.preventDefault();
|
|
194
|
-
nextIndex = currentIndex < options.length - 1 ? currentIndex + 1 : 0;
|
|
195
|
-
break;
|
|
196
|
-
case 'Home':
|
|
197
|
-
event.preventDefault();
|
|
198
|
-
nextIndex = 0;
|
|
199
|
-
break;
|
|
200
|
-
case 'End':
|
|
201
|
-
event.preventDefault();
|
|
202
|
-
nextIndex = options.length - 1;
|
|
203
|
-
break;
|
|
204
|
-
case 'Enter':
|
|
205
|
-
case ' ':
|
|
206
|
-
event.preventDefault();
|
|
207
|
-
this.select(options[nextIndex]?.value ?? this.value);
|
|
208
|
-
return;
|
|
209
|
-
default:
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
while (nextIndex !== currentIndex) {
|
|
213
|
-
const nextOption = options[nextIndex];
|
|
214
|
-
if (nextOption && !nextOption.disabled) {
|
|
215
|
-
this.segmentButtons[nextIndex]?.focus();
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
if (event.key === 'ArrowLeft' || event.key === 'Home') {
|
|
219
|
-
nextIndex = nextIndex > 0 ? nextIndex - 1 : options.length - 1;
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
nextIndex = nextIndex < options.length - 1 ? nextIndex + 1 : 0;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (!customElements.get('db-segment-control')) {
|
|
228
|
-
customElements.define('db-segment-control', DbSegmentControl);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export { DbSegmentControl };
|
|
1
|
+
const e="designbase-wc-segment-control",t={bar:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="12" width="4" height="8"/><rect x="10" y="8" width="4" height="12"/><rect x="17" y="4" width="4" height="16"/></svg>',line:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="4 16 9 10 14 13 20 6"/></svg>',pie:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2v10l8.66 5"/><circle cx="12" cy="12" r="10"/></svg>',donut:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="8"/><circle cx="12" cy="12" r="3"/></svg>',radar:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="12 2 20 8 17 20 7 20 4 8"/></svg>'};class DbSegmentControl extends HTMLElement{constructor(){super(...arguments),this.built=!1,this.indicatorEl=null,this.segmentButtons=[],this.focusedIndex=-1,this.boundKeyDown=e=>this.handleKeyDown(e),this.boundResize=()=>this.updateIndicator(),this.resizeObserver=null}static get observedAttributes(){return["options","value","default-value","size","variant","appearance","full-width","disabled"]}connectedCallback(){this.built||(this.built=!0),this.render(),this.addEventListener("keydown",this.boundKeyDown),window.addEventListener("resize",this.boundResize),this.resizeObserver=new ResizeObserver(()=>this.updateIndicator()),this.resizeObserver.observe(this)}disconnectedCallback(){this.removeEventListener("keydown",this.boundKeyDown),window.removeEventListener("resize",this.boundResize),this.resizeObserver?.disconnect(),this.resizeObserver=null}attributeChangedCallback(e){this.built&&("value"!==e?this.render():this.updateSelection())}get options(){return this.parseOptions(this.getAttribute("options"))}set options(e){this.setAttribute("options","string"==typeof e?e:JSON.stringify(e))}get value(){return this.getAttribute("value")||this.getAttribute("default-value")||this.options[0]?.value||""}set value(e){this.setAttribute("value",e)}parseOptions(e){if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}render(){const i=this.getAttribute("size")||"m",s=this.getAttribute("variant")||"default",n=this.getAttribute("appearance")||"pill",r=this.hasAttribute("disabled"),o=this.options,a=this.value;this.className=[e,`${e}--${i}`,`${e}--${s}`,"rounded"===n&&`${e}--appearance-rounded`,this.hasAttribute("full-width")&&`${e}--full-width`,r&&`${e}--disabled`].filter(Boolean).join(" "),this.setAttribute("role","tablist"),this.setAttribute("aria-label","세그먼트 컨트롤"),this.replaceChildren(),this.segmentButtons=[],o.forEach((i,n)=>{const o=i.value===a,l=Boolean(r||i.disabled),d=document.createElement("button");if(d.type="button",d.className=[`${e}__segment`,o&&`${e}__segment--selected`,l&&`${e}__segment--disabled`].filter(Boolean).join(" "),d.setAttribute("role","tab"),d.setAttribute("aria-selected",String(o)),d.setAttribute("aria-disabled",String(l)),d.setAttribute("tabindex",o?"0":"-1"),d.disabled=l,i.icon&&t[i.icon]){const s=document.createElement("span");s.className=`${e}__segment-icon`,s.innerHTML=t[i.icon],d.appendChild(s)}const h=document.createElement("span");h.className=`${e}__segment-label`,h.textContent=i.label,"icon-only"===s&&h.setAttribute("aria-label",i.label),d.appendChild(h),d.addEventListener("click",()=>this.select(i.value)),d.addEventListener("focus",()=>{this.focusedIndex=n,d.classList.add(`${e}__segment--focused`)}),d.addEventListener("blur",()=>{this.focusedIndex=-1,d.classList.remove(`${e}__segment--focused`)}),this.appendChild(d),this.segmentButtons.push(d)}),this.indicatorEl=document.createElement("div"),this.indicatorEl.className=`${e}__indicator`,this.appendChild(this.indicatorEl),this.updateSelection()}updateSelection(){const t=this.options,i=this.value,s=t.findIndex(e=>e.value===i);this.segmentButtons.forEach((s,n)=>{const r=t[n],o=r?.value===i;s.classList.toggle(`${e}__segment--selected`,o),s.setAttribute("aria-selected",String(o)),s.setAttribute("tabindex",o?"0":"-1")}),this.indicatorEl&&t.length>0&&s>=0&&requestAnimationFrame(()=>this.updateIndicator())}updateIndicator(){const e=this.options.findIndex(e=>e.value===this.value),t=this.segmentButtons[e];this.indicatorEl&&t&&(this.indicatorEl.style.width=`${t.offsetWidth}px`,this.indicatorEl.style.transform=`translateX(${t.offsetLeft}px)`)}select(e){if(this.hasAttribute("disabled"))return;const t=this.options.find(t=>t.value===e);t&&!t.disabled&&(this.setAttribute("value",e),this.dispatchEvent(new CustomEvent("db-change",{detail:{value:e},bubbles:!0,composed:!0})))}handleKeyDown(e){if(this.hasAttribute("disabled"))return;const t=this.options,i=t.findIndex(e=>e.value===this.value);if(-1===i)return;let s=i;switch(e.key){case"ArrowLeft":e.preventDefault(),s=i>0?i-1:t.length-1;break;case"ArrowRight":e.preventDefault(),s=i<t.length-1?i+1:0;break;case"Home":e.preventDefault(),s=0;break;case"End":e.preventDefault(),s=t.length-1;break;case"Enter":case" ":return e.preventDefault(),void this.select(t[s]?.value??this.value);default:return}for(;s!==i;){const i=t[s];if(i&&!i.disabled){this.segmentButtons[s]?.focus();break}s="ArrowLeft"===e.key||"Home"===e.key?s>0?s-1:t.length-1:s<t.length-1?s+1:0}}}customElements.get("db-segment-control")||customElements.define("db-segment-control",DbSegmentControl);export{DbSegmentControl};
|