@designbasekorea/ui-wc 0.5.3 → 0.5.6
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-e273b936.js +17032 -0
- package/dist/esm/components/animation-background/canvas-controller.js +121 -1
- package/dist/esm/components/animation-background/controls.js +180 -1
- package/dist/esm/components/animation-background/graphite-controller.js +196 -1
- package/dist/esm/components/animation-background/graphite-presets.js +42 -1
- package/dist/esm/components/animation-background/graphite-shader.js +111 -1
- package/dist/esm/components/animation-background/layers.js +369 -1
- package/dist/esm/components/animation-background/lumina-presets.js +53 -1
- package/dist/esm/components/animation-background/lumina-shaders.js +181 -1
- package/dist/esm/components/animation-background/lumina-utils.js +60 -1
- package/dist/esm/components/animation-background/particle-defaults.js +36 -1
- package/dist/esm/components/animation-background/renderers.js +167 -1
- package/dist/esm/components/animation-background/shader-controller.js +154 -1
- package/dist/esm/components/color-picker-utils.js +134 -1
- package/dist/esm/components/date-picker-utils.js +140 -1
- package/dist/esm/components/db-accordion.js +304 -1
- package/dist/esm/components/db-ad-banner.js +455 -1
- package/dist/esm/components/db-alert.js +149 -1
- package/dist/esm/components/db-animation-background.js +486 -1
- package/dist/esm/components/db-animation-text.js +601 -1
- package/dist/esm/components/db-app-badge.js +88 -1
- package/dist/esm/components/db-audio-player.js +752 -1
- package/dist/esm/components/db-avatar.js +188 -1
- package/dist/esm/components/db-backdrop.js +139 -1
- package/dist/esm/components/db-badge.js +91 -1
- package/dist/esm/components/db-banner.js +188 -1
- package/dist/esm/components/db-bottom-navigation.js +146 -1
- package/dist/esm/components/db-bottom-sheet.js +481 -1
- package/dist/esm/components/db-breadcrumbs.js +329 -1
- package/dist/esm/components/db-button.js +316 -1
- package/dist/esm/components/db-calendar.js +675 -1
- package/dist/esm/components/db-card.js +265 -1
- package/dist/esm/components/db-carousel.js +264 -1
- package/dist/esm/components/db-checkbox.js +202 -1
- package/dist/esm/components/db-chip.js +104 -1
- package/dist/esm/components/db-code-block.js +304 -1
- package/dist/esm/components/db-color-picker.js +746 -1
- package/dist/esm/components/db-confirm.js +191 -1
- package/dist/esm/components/db-container.js +39 -1
- package/dist/esm/components/db-context-menu.js +265 -1
- package/dist/esm/components/db-countdown.js +146 -1
- package/dist/esm/components/db-cursor-follower.js +173 -1
- package/dist/esm/components/db-date-picker.js +837 -1
- package/dist/esm/components/db-divider.js +66 -1
- package/dist/esm/components/db-drawer.js +245 -1
- package/dist/esm/components/db-dropdown.js +493 -1
- package/dist/esm/components/db-dropzone.js +266 -1
- package/dist/esm/components/db-empty-state.js +97 -1
- package/dist/esm/components/db-file-uploader.js +256 -1
- package/dist/esm/components/db-floating-action-button.js +139 -1
- package/dist/esm/components/db-footer.js +385 -1
- package/dist/esm/components/db-form.js +566 -1
- package/dist/esm/components/db-gantt.js +882 -1
- package/dist/esm/components/db-gradient.js +133 -1
- package/dist/esm/components/db-grid-background.js +909 -1
- package/dist/esm/components/db-grid.js +73 -1
- package/dist/esm/components/db-icons.js +82 -1
- package/dist/esm/components/db-image-list.js +214 -1
- package/dist/esm/components/db-image-placeholder.js +96 -1
- package/dist/esm/components/db-image.js +289 -1
- package/dist/esm/components/db-indicator.js +517 -1
- package/dist/esm/components/db-input.js +420 -1
- package/dist/esm/components/db-kanban.js +538 -1
- package/dist/esm/components/db-label.js +66 -1
- package/dist/esm/components/db-lightbox.js +372 -1
- package/dist/esm/components/db-list.js +340 -1
- package/dist/esm/components/db-logo-svg.js +72 -1
- package/dist/esm/components/db-logo.js +106 -1
- package/dist/esm/components/db-lottie.js +109 -1
- package/dist/esm/components/db-markdown-editor.js +458 -1
- package/dist/esm/components/db-marquee.js +402 -1
- package/dist/esm/components/db-masonry.js +94 -1
- package/dist/esm/components/db-menu-item.js +211 -1
- package/dist/esm/components/db-modal.js +522 -1
- package/dist/esm/components/db-navbar.js +680 -1
- package/dist/esm/components/db-onboarding-modal.js +322 -1
- package/dist/esm/components/db-page-header.js +312 -1
- package/dist/esm/components/db-pagination.js +271 -1
- package/dist/esm/components/db-popover.js +580 -1
- package/dist/esm/components/db-progress-step.js +166 -1
- package/dist/esm/components/db-progress.js +171 -1
- package/dist/esm/components/db-progressbar.js +72 -1
- package/dist/esm/components/db-radio.js +172 -1
- package/dist/esm/components/db-random-gradient.js +121 -1
- package/dist/esm/components/db-range-slider.js +811 -1
- package/dist/esm/components/db-rating.js +325 -1
- package/dist/esm/components/db-reorder.js +286 -1
- package/dist/esm/components/db-resizable-panels.js +282 -1
- package/dist/esm/components/db-scroll-area.js +126 -1
- package/dist/esm/components/db-search-bar.js +668 -1
- package/dist/esm/components/db-section-app-download.js +101 -1
- package/dist/esm/components/db-section-contact.js +102 -1
- package/dist/esm/components/db-section-cta.js +150 -1
- package/dist/esm/components/db-section-faq.js +120 -1
- package/dist/esm/components/db-section-feature-grid.js +137 -1
- package/dist/esm/components/db-section-feature.js +179 -1
- package/dist/esm/components/db-section-hero.js +243 -1
- package/dist/esm/components/db-section-logo-cloud.js +138 -1
- package/dist/esm/components/db-section-pricing.js +166 -1
- package/dist/esm/components/db-section-stats.js +129 -1
- package/dist/esm/components/db-section-testimonials.js +252 -1
- package/dist/esm/components/db-section.js +385 -1
- package/dist/esm/components/db-segment-control.js +231 -1
- package/dist/esm/components/db-select.js +571 -1
- package/dist/esm/components/db-share-icons.js +40 -1
- package/dist/esm/components/db-share.js +489 -1
- package/dist/esm/components/db-sidebar.js +1068 -1
- package/dist/esm/components/db-skeleton.js +94 -1
- package/dist/esm/components/db-spinner.js +102 -1
- package/dist/esm/components/db-split-view.js +297 -1
- package/dist/esm/components/db-stack.js +46 -1
- package/dist/esm/components/db-stat.js +218 -1
- package/dist/esm/components/db-stepper.js +398 -1
- package/dist/esm/components/db-table.js +412 -1
- package/dist/esm/components/db-tabs.js +335 -1
- package/dist/esm/components/db-testimonial.js +162 -1
- package/dist/esm/components/db-textarea.js +233 -1
- package/dist/esm/components/db-time-picker.js +523 -1
- package/dist/esm/components/db-timeline.js +174 -1
- package/dist/esm/components/db-toast.js +158 -1
- package/dist/esm/components/db-toggle.js +162 -1
- package/dist/esm/components/db-toolbar.js +94 -1
- package/dist/esm/components/db-tooltip.js +440 -1
- package/dist/esm/components/db-top-banner.js +121 -1
- package/dist/esm/components/db-tutorial.js +324 -1
- package/dist/esm/components/db-video-player.js +503 -1
- package/dist/esm/components/db-youtube-player.js +194 -1
- package/dist/esm/components/highlight-code.js +65 -1
- package/dist/esm/components/input-validation.js +50 -1
- package/dist/esm/components/marketing-block-host-utils.js +9 -1
- package/dist/esm/components/number-scrub.js +117 -1
- package/dist/esm/components/random-gradient-palettes.js +67 -1
- package/dist/esm/components/section-block-header-utils.js +48 -1
- package/dist/esm/helpers/confirm.js +52 -1
- package/dist/esm/helpers/toast.js +73 -1
- package/dist/esm/index.js +111 -1
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +235 -1
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +31 -1
- package/dist/esm/node_modules/prismjs/components/prism-css.js +64 -1
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +172 -1
- package/dist/esm/node_modules/prismjs/components/prism-json.js +27 -1
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +143 -1
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +186 -1
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +81 -1
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +15 -1
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +60 -1
- package/dist/index.cjs +55414 -1
- package/dist/index.css +1 -1
- package/dist/index.esm.js +38284 -1
- package/dist/react/chunks/lottie-72a4c6d4.js +17032 -0
- package/dist/react/index.cjs +56503 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.esm.js +39373 -1
- package/package.json +1 -1
- package/dist/chunks/lottie-2d1f6278.js +0 -1
- package/dist/react/chunks/lottie-14e7addb.js +0 -1
|
@@ -1 +1,335 @@
|
|
|
1
|
-
import{createDbIcon
|
|
1
|
+
import { createDbIcon } from './db-icons.js';
|
|
2
|
+
|
|
3
|
+
const SIZES = ['s', 'm', 'l'];
|
|
4
|
+
const ORIENTATIONS = ['horizontal', 'vertical'];
|
|
5
|
+
const VARIANTS = ['default', 'pills'];
|
|
6
|
+
class DbTabs extends HTMLElement {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.tabButtons = [];
|
|
10
|
+
this.inactivePanels = document.createDocumentFragment();
|
|
11
|
+
this.isRendering = false;
|
|
12
|
+
this.handleListScroll = () => {
|
|
13
|
+
if (!this.list)
|
|
14
|
+
return;
|
|
15
|
+
const isScrollable = this.list.scrollWidth > this.list.clientWidth;
|
|
16
|
+
const isScrolledToEnd = this.list.scrollLeft + this.list.clientWidth >= this.list.scrollWidth - 5;
|
|
17
|
+
this.list.classList.toggle('designbase-wc-tabs__list--show-gradient', isScrollable && !isScrolledToEnd && this.orientation === 'horizontal');
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
static get observedAttributes() {
|
|
21
|
+
return ['labels', 'items', 'active-index', 'selected-id', 'orientation', 'size', 'variant', 'full-width'];
|
|
22
|
+
}
|
|
23
|
+
get labels() {
|
|
24
|
+
const fromItems = this.tabItems.map((item) => item.label);
|
|
25
|
+
if (fromItems.length)
|
|
26
|
+
return fromItems;
|
|
27
|
+
return (this.getAttribute('labels') || '')
|
|
28
|
+
.split(',')
|
|
29
|
+
.map((label) => label.trim())
|
|
30
|
+
.filter(Boolean);
|
|
31
|
+
}
|
|
32
|
+
set labels(value) {
|
|
33
|
+
this.setAttribute('labels', Array.isArray(value) ? value.join(',') : value);
|
|
34
|
+
}
|
|
35
|
+
get tabItems() {
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(this.getAttribute('items') || '[]');
|
|
38
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
get items() {
|
|
45
|
+
return this.tabItems;
|
|
46
|
+
}
|
|
47
|
+
set items(value) {
|
|
48
|
+
this.setAttribute('items', typeof value === 'string' ? value : JSON.stringify(value));
|
|
49
|
+
}
|
|
50
|
+
set tabItems(value) {
|
|
51
|
+
this.setAttribute('items', typeof value === 'string' ? value : JSON.stringify(value));
|
|
52
|
+
}
|
|
53
|
+
get activeIndex() {
|
|
54
|
+
const selectedId = this.getAttribute('selected-id');
|
|
55
|
+
if (selectedId) {
|
|
56
|
+
const index = this.tabItems.findIndex((item, idx) => (item.id || String(idx)) === selectedId);
|
|
57
|
+
if (index >= 0)
|
|
58
|
+
return index;
|
|
59
|
+
}
|
|
60
|
+
return Number(this.getAttribute('active-index') || 0);
|
|
61
|
+
}
|
|
62
|
+
set activeIndex(value) {
|
|
63
|
+
this.setAttribute('active-index', String(value));
|
|
64
|
+
}
|
|
65
|
+
get orientation() {
|
|
66
|
+
return this.getAttribute('orientation') || 'horizontal';
|
|
67
|
+
}
|
|
68
|
+
set orientation(value) {
|
|
69
|
+
this.setAttribute('orientation', value);
|
|
70
|
+
}
|
|
71
|
+
get size() {
|
|
72
|
+
return this.getAttribute('size') || 'm';
|
|
73
|
+
}
|
|
74
|
+
set size(value) {
|
|
75
|
+
this.setAttribute('size', value);
|
|
76
|
+
}
|
|
77
|
+
get variant() {
|
|
78
|
+
return this.getAttribute('variant') || 'default';
|
|
79
|
+
}
|
|
80
|
+
set variant(value) {
|
|
81
|
+
this.setAttribute('variant', value);
|
|
82
|
+
}
|
|
83
|
+
get fullWidth() {
|
|
84
|
+
return this.hasAttribute('full-width');
|
|
85
|
+
}
|
|
86
|
+
set fullWidth(value) {
|
|
87
|
+
this.toggleAttribute('full-width', Boolean(value));
|
|
88
|
+
}
|
|
89
|
+
connectedCallback() {
|
|
90
|
+
this.render();
|
|
91
|
+
this.list?.addEventListener('scroll', this.handleListScroll, { passive: true });
|
|
92
|
+
window.addEventListener('resize', this.handleListScroll);
|
|
93
|
+
this.childObserver = new MutationObserver((mutations) => {
|
|
94
|
+
if (this.isRendering)
|
|
95
|
+
return;
|
|
96
|
+
const hasPanelChange = mutations.some((mutation) => Array.from(mutation.addedNodes).some((node) => node instanceof HTMLElement &&
|
|
97
|
+
(node.hasAttribute('slot') || node.dataset.panelIndex !== undefined)));
|
|
98
|
+
if (hasPanelChange)
|
|
99
|
+
this.render();
|
|
100
|
+
});
|
|
101
|
+
this.childObserver.observe(this, { childList: true });
|
|
102
|
+
}
|
|
103
|
+
disconnectedCallback() {
|
|
104
|
+
this.list?.removeEventListener('scroll', this.handleListScroll);
|
|
105
|
+
window.removeEventListener('resize', this.handleListScroll);
|
|
106
|
+
this.childObserver?.disconnect();
|
|
107
|
+
}
|
|
108
|
+
attributeChangedCallback() {
|
|
109
|
+
if (!this.isConnected)
|
|
110
|
+
return;
|
|
111
|
+
this.render();
|
|
112
|
+
}
|
|
113
|
+
collectPanelContent() {
|
|
114
|
+
const map = new Map();
|
|
115
|
+
const register = (node, index) => {
|
|
116
|
+
if (!(node instanceof HTMLElement) || node.tagName === 'SLOT')
|
|
117
|
+
return;
|
|
118
|
+
if (!map.has(index))
|
|
119
|
+
map.set(index, []);
|
|
120
|
+
const list = map.get(index);
|
|
121
|
+
if (!list.includes(node))
|
|
122
|
+
list.push(node);
|
|
123
|
+
};
|
|
124
|
+
Array.from(this.children).forEach((child) => {
|
|
125
|
+
const slotMatch = child.getAttribute('slot')?.match(/^panel-(\d+)$/);
|
|
126
|
+
if (slotMatch) {
|
|
127
|
+
register(child, Number(slotMatch[1]));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const panelIndex = child.dataset.panelIndex;
|
|
131
|
+
if (panelIndex !== undefined)
|
|
132
|
+
register(child, Number(panelIndex));
|
|
133
|
+
});
|
|
134
|
+
this.panel
|
|
135
|
+
?.querySelectorAll(':scope > .designbase-wc-tabs__panel-inner > [data-panel-index]')
|
|
136
|
+
.forEach((child) => {
|
|
137
|
+
if (child instanceof HTMLElement) {
|
|
138
|
+
register(child, Number(child.dataset.panelIndex));
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
Array.from(this.inactivePanels.children).forEach((child) => {
|
|
142
|
+
if (child instanceof HTMLElement && child.dataset.panelIndex !== undefined) {
|
|
143
|
+
register(child, Number(child.dataset.panelIndex));
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return map;
|
|
147
|
+
}
|
|
148
|
+
render() {
|
|
149
|
+
this.isRendering = true;
|
|
150
|
+
const panelContent = this.collectPanelContent();
|
|
151
|
+
const labels = this.labels;
|
|
152
|
+
const tabItems = this.tabItems;
|
|
153
|
+
const activeIndex = Math.min(Math.max(this.activeIndex, 0), Math.max(labels.length - 1, 0));
|
|
154
|
+
const resolvedSize = SIZES.includes(this.size) ? this.size : 'm';
|
|
155
|
+
const resolvedOrientation = ORIENTATIONS.includes(this.orientation)
|
|
156
|
+
? this.orientation
|
|
157
|
+
: 'horizontal';
|
|
158
|
+
const resolvedVariant = VARIANTS.includes(this.variant)
|
|
159
|
+
? this.variant
|
|
160
|
+
: 'default';
|
|
161
|
+
const showIndicator = resolvedVariant === 'default';
|
|
162
|
+
this.className = [
|
|
163
|
+
'designbase-wc-tabs',
|
|
164
|
+
`designbase-wc-tabs--${resolvedOrientation}`,
|
|
165
|
+
`designbase-wc-tabs--${resolvedSize}`,
|
|
166
|
+
`designbase-wc-tabs--${resolvedVariant}`,
|
|
167
|
+
this.fullWidth && 'designbase-wc-tabs--full-width',
|
|
168
|
+
]
|
|
169
|
+
.filter(Boolean)
|
|
170
|
+
.join(' ');
|
|
171
|
+
this.querySelectorAll(':scope > .designbase-wc-tabs__list, :scope > .designbase-wc-tabs__panel').forEach((node) => node.remove());
|
|
172
|
+
this.list = document.createElement('div');
|
|
173
|
+
this.list.className = [
|
|
174
|
+
'designbase-wc-tabs__list',
|
|
175
|
+
`designbase-wc-tabs__list--${resolvedOrientation}`,
|
|
176
|
+
this.fullWidth && 'designbase-wc-tabs__list--full-width',
|
|
177
|
+
]
|
|
178
|
+
.filter(Boolean)
|
|
179
|
+
.join(' ');
|
|
180
|
+
this.list.setAttribute('role', 'tablist');
|
|
181
|
+
this.list.setAttribute('aria-orientation', resolvedOrientation);
|
|
182
|
+
this.list.setAttribute('aria-label', '탭 목록');
|
|
183
|
+
this.tabButtons = [];
|
|
184
|
+
labels.forEach((label, index) => {
|
|
185
|
+
const config = tabItems[index];
|
|
186
|
+
const disabled = Boolean(config?.disabled);
|
|
187
|
+
const isSelected = index === activeIndex;
|
|
188
|
+
const button = document.createElement('button');
|
|
189
|
+
button.type = 'button';
|
|
190
|
+
button.className = [
|
|
191
|
+
'designbase-wc-tabs__tab',
|
|
192
|
+
isSelected && 'designbase-wc-tabs__tab--selected',
|
|
193
|
+
disabled && 'designbase-wc-tabs__tab--disabled',
|
|
194
|
+
]
|
|
195
|
+
.filter(Boolean)
|
|
196
|
+
.join(' ');
|
|
197
|
+
button.setAttribute('role', 'tab');
|
|
198
|
+
button.setAttribute('aria-selected', String(isSelected));
|
|
199
|
+
button.setAttribute('aria-controls', `panel-${index}`);
|
|
200
|
+
button.id = `tab-${index}`;
|
|
201
|
+
button.tabIndex = isSelected ? 0 : -1;
|
|
202
|
+
button.disabled = disabled;
|
|
203
|
+
if (config?.icon) {
|
|
204
|
+
const iconWrap = document.createElement('span');
|
|
205
|
+
iconWrap.className = 'designbase-wc-tabs__tab-icon';
|
|
206
|
+
const iconSize = resolvedSize === 's' ? 16 : resolvedSize === 'l' ? 20 : 18;
|
|
207
|
+
iconWrap.append(createDbIcon(config.icon, iconSize));
|
|
208
|
+
button.append(iconWrap);
|
|
209
|
+
}
|
|
210
|
+
const labelEl = document.createElement('span');
|
|
211
|
+
labelEl.className = 'designbase-wc-tabs__tab-label';
|
|
212
|
+
labelEl.textContent = label;
|
|
213
|
+
button.append(labelEl);
|
|
214
|
+
button.addEventListener('click', () => this.select(index));
|
|
215
|
+
button.addEventListener('keydown', (event) => this.handleKeyDown(event, index));
|
|
216
|
+
this.list?.append(button);
|
|
217
|
+
this.tabButtons.push(button);
|
|
218
|
+
});
|
|
219
|
+
if (showIndicator) {
|
|
220
|
+
this.indicator = document.createElement('span');
|
|
221
|
+
this.indicator.className = 'designbase-wc-tabs__indicator designbase-wc-tabs__indicator--no-transition';
|
|
222
|
+
this.list.append(this.indicator);
|
|
223
|
+
requestAnimationFrame(() => this.updateIndicator(false));
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
this.indicator = undefined;
|
|
227
|
+
}
|
|
228
|
+
this.panel = document.createElement('div');
|
|
229
|
+
this.panel.className = 'designbase-wc-tabs__panel';
|
|
230
|
+
this.panel.setAttribute('role', 'tabpanel');
|
|
231
|
+
this.panel.id = `panel-${activeIndex}`;
|
|
232
|
+
this.panel.setAttribute('aria-labelledby', `tab-${activeIndex}`);
|
|
233
|
+
this.panel.tabIndex = 0;
|
|
234
|
+
const panelInner = document.createElement('div');
|
|
235
|
+
panelInner.className = 'designbase-wc-tabs__panel-inner';
|
|
236
|
+
panelContent.forEach((nodes, index) => {
|
|
237
|
+
nodes.forEach((node) => {
|
|
238
|
+
node.removeAttribute('slot');
|
|
239
|
+
node.dataset.panelIndex = String(index);
|
|
240
|
+
if (index === activeIndex) {
|
|
241
|
+
panelInner.append(node);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
this.inactivePanels.append(node);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
this.panel.append(panelInner);
|
|
249
|
+
this.append(this.list, this.panel);
|
|
250
|
+
requestAnimationFrame(() => {
|
|
251
|
+
this.handleListScroll();
|
|
252
|
+
if (showIndicator)
|
|
253
|
+
this.updateIndicator(false);
|
|
254
|
+
});
|
|
255
|
+
this.isRendering = false;
|
|
256
|
+
}
|
|
257
|
+
select(index) {
|
|
258
|
+
const labels = this.labels;
|
|
259
|
+
const tabItems = this.tabItems;
|
|
260
|
+
if (!labels[index] || tabItems[index]?.disabled)
|
|
261
|
+
return;
|
|
262
|
+
this.activeIndex = index;
|
|
263
|
+
const id = tabItems[index]?.id || String(index);
|
|
264
|
+
this.setAttribute('selected-id', id);
|
|
265
|
+
this.dispatchEvent(new CustomEvent('db-change', {
|
|
266
|
+
detail: { index, label: labels[index], id },
|
|
267
|
+
bubbles: true,
|
|
268
|
+
composed: true,
|
|
269
|
+
}));
|
|
270
|
+
this.render();
|
|
271
|
+
}
|
|
272
|
+
handleKeyDown(event, index) {
|
|
273
|
+
const labels = this.labels;
|
|
274
|
+
const tabItems = this.tabItems;
|
|
275
|
+
let nextIndex = index;
|
|
276
|
+
if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {
|
|
277
|
+
nextIndex = (index + 1) % labels.length;
|
|
278
|
+
}
|
|
279
|
+
else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {
|
|
280
|
+
nextIndex = (index - 1 + labels.length) % labels.length;
|
|
281
|
+
}
|
|
282
|
+
else if (event.key === 'Home') {
|
|
283
|
+
nextIndex = 0;
|
|
284
|
+
}
|
|
285
|
+
else if (event.key === 'End') {
|
|
286
|
+
nextIndex = labels.length - 1;
|
|
287
|
+
}
|
|
288
|
+
else if (event.key === 'Enter' || event.key === ' ') {
|
|
289
|
+
event.preventDefault();
|
|
290
|
+
this.select(index);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
event.preventDefault();
|
|
297
|
+
let attempts = 0;
|
|
298
|
+
while (tabItems[nextIndex]?.disabled && attempts < labels.length) {
|
|
299
|
+
if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {
|
|
300
|
+
nextIndex = (nextIndex - 1 + labels.length) % labels.length;
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
nextIndex = (nextIndex + 1) % labels.length;
|
|
304
|
+
}
|
|
305
|
+
attempts += 1;
|
|
306
|
+
}
|
|
307
|
+
this.tabButtons[nextIndex]?.focus();
|
|
308
|
+
}
|
|
309
|
+
updateIndicator(animate = false) {
|
|
310
|
+
const active = this.list?.querySelector('.designbase-wc-tabs__tab--selected');
|
|
311
|
+
if (!active || !this.indicator)
|
|
312
|
+
return;
|
|
313
|
+
const isVertical = this.orientation === 'vertical';
|
|
314
|
+
this.indicator.classList.toggle('designbase-wc-tabs__indicator--no-transition', !animate);
|
|
315
|
+
this.indicator.classList.add(isVertical
|
|
316
|
+
? 'designbase-wc-tabs__indicator--vertical'
|
|
317
|
+
: 'designbase-wc-tabs__indicator--horizontal');
|
|
318
|
+
this.indicator.classList.add('designbase-wc-tabs__indicator--ready');
|
|
319
|
+
if (isVertical) {
|
|
320
|
+
this.indicator.style.width = '2px';
|
|
321
|
+
this.indicator.style.height = `${active.offsetHeight}px`;
|
|
322
|
+
this.indicator.style.transform = `translate3d(0, ${active.offsetTop}px, 0)`;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
this.indicator.style.width = `${active.offsetWidth}px`;
|
|
326
|
+
this.indicator.style.height = '2px';
|
|
327
|
+
this.indicator.style.transform = `translate3d(${active.offsetLeft}px, 0, 0)`;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (!customElements.get('db-tabs')) {
|
|
332
|
+
customElements.define('db-tabs', DbTabs);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export { DbTabs };
|
|
@@ -1 +1,162 @@
|
|
|
1
|
-
const
|
|
1
|
+
const CLASS = 'designbase-wc-testimonial';
|
|
2
|
+
const VARIANTS = ['list', 'card'];
|
|
3
|
+
function clampRating(rating, maxRating) {
|
|
4
|
+
if (typeof rating !== 'number' || Number.isNaN(rating))
|
|
5
|
+
return undefined;
|
|
6
|
+
if (rating < 0)
|
|
7
|
+
return 0;
|
|
8
|
+
if (rating > maxRating)
|
|
9
|
+
return maxRating;
|
|
10
|
+
return Math.round(rating * 10) / 10;
|
|
11
|
+
}
|
|
12
|
+
class DbTestimonial extends HTMLElement {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.built = false;
|
|
16
|
+
}
|
|
17
|
+
static get observedAttributes() {
|
|
18
|
+
return [
|
|
19
|
+
'quote',
|
|
20
|
+
'author',
|
|
21
|
+
'role',
|
|
22
|
+
'company',
|
|
23
|
+
'avatar',
|
|
24
|
+
'avatar-initials',
|
|
25
|
+
'rating',
|
|
26
|
+
'max-rating',
|
|
27
|
+
'variant',
|
|
28
|
+
'align',
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
connectedCallback() {
|
|
32
|
+
if (!this.built) {
|
|
33
|
+
this.built = true;
|
|
34
|
+
this.build();
|
|
35
|
+
}
|
|
36
|
+
this.updateUI();
|
|
37
|
+
}
|
|
38
|
+
attributeChangedCallback() {
|
|
39
|
+
if (!this.built)
|
|
40
|
+
return;
|
|
41
|
+
this.updateUI();
|
|
42
|
+
}
|
|
43
|
+
build() {
|
|
44
|
+
this.innerEl = document.createElement('div');
|
|
45
|
+
this.quoteEl = document.createElement('p');
|
|
46
|
+
this.quoteEl.className = `${CLASS}__quote`;
|
|
47
|
+
this.footerEl = document.createElement('div');
|
|
48
|
+
this.footerEl.className = `${CLASS}__footer`;
|
|
49
|
+
this.avatarWrapEl = document.createElement('div');
|
|
50
|
+
this.avatarWrapEl.className = `${CLASS}__avatar`;
|
|
51
|
+
this.avatarEl = document.createElement('db-avatar');
|
|
52
|
+
this.avatarEl.className = `${CLASS}__avatar-image`;
|
|
53
|
+
this.avatarWrapEl.append(this.avatarEl);
|
|
54
|
+
const meta = document.createElement('div');
|
|
55
|
+
meta.className = `${CLASS}__meta`;
|
|
56
|
+
this.authorEl = document.createElement('span');
|
|
57
|
+
this.authorEl.className = `${CLASS}__author`;
|
|
58
|
+
this.roleEl = document.createElement('span');
|
|
59
|
+
this.roleEl.className = `${CLASS}__role`;
|
|
60
|
+
this.ratingEl = document.createElement('db-rating');
|
|
61
|
+
this.ratingEl.className = `${CLASS}__rating`;
|
|
62
|
+
this.ratingEl.setAttribute('display', 'stars');
|
|
63
|
+
this.ratingEl.setAttribute('variant', 'inline');
|
|
64
|
+
this.ratingEl.setAttribute('allow-half', '');
|
|
65
|
+
this.ratingEl.setAttribute('readonly', '');
|
|
66
|
+
this.ratingEl.setAttribute('hover-effect', 'false');
|
|
67
|
+
this.ratingEl.setAttribute('color', 'primary');
|
|
68
|
+
this.ratingEl.hidden = true;
|
|
69
|
+
meta.append(this.authorEl, this.roleEl, this.ratingEl);
|
|
70
|
+
this.footerEl.append(this.avatarWrapEl, meta);
|
|
71
|
+
this.extraEl = document.createElement('div');
|
|
72
|
+
this.extraEl.className = `${CLASS}__extra`;
|
|
73
|
+
this.extraEl.hidden = true;
|
|
74
|
+
this.innerEl.append(this.quoteEl, this.footerEl, this.extraEl);
|
|
75
|
+
this.append(this.innerEl);
|
|
76
|
+
}
|
|
77
|
+
getVariant() {
|
|
78
|
+
const value = this.getAttribute('variant') || 'card';
|
|
79
|
+
return VARIANTS.includes(value) ? value : 'card';
|
|
80
|
+
}
|
|
81
|
+
getAvatarSize() {
|
|
82
|
+
return this.getVariant() === 'list' ? 's' : 'm';
|
|
83
|
+
}
|
|
84
|
+
syncExtraContent() {
|
|
85
|
+
if (!this.extraEl)
|
|
86
|
+
return;
|
|
87
|
+
const slotted = Array.from(this.childNodes).filter((node) => node !== this.innerEl &&
|
|
88
|
+
(node.nodeType === Node.ELEMENT_NODE ||
|
|
89
|
+
(node.nodeType === Node.TEXT_NODE && node.textContent?.trim())));
|
|
90
|
+
if (slotted.length === 0) {
|
|
91
|
+
this.extraEl.hidden = true;
|
|
92
|
+
this.extraEl.replaceChildren();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.extraEl.hidden = false;
|
|
96
|
+
this.extraEl.replaceChildren(...slotted.map((node) => node.cloneNode(true)));
|
|
97
|
+
}
|
|
98
|
+
updateUI() {
|
|
99
|
+
const quote = this.getAttribute('quote') || '';
|
|
100
|
+
const author = this.getAttribute('author') || '';
|
|
101
|
+
const role = this.getAttribute('role') || '';
|
|
102
|
+
const company = this.getAttribute('company') || '';
|
|
103
|
+
const avatar = this.getAttribute('avatar') || '';
|
|
104
|
+
const avatarInitials = this.getAttribute('avatar-initials') || '';
|
|
105
|
+
const ratingRaw = this.getAttribute('rating');
|
|
106
|
+
const maxRating = Number(this.getAttribute('max-rating') || 5);
|
|
107
|
+
const rating = ratingRaw !== null && ratingRaw !== '' ? clampRating(Number(ratingRaw), maxRating) : undefined;
|
|
108
|
+
const variant = this.getVariant();
|
|
109
|
+
const align = this.getAttribute('align') || 'left';
|
|
110
|
+
const className = [
|
|
111
|
+
CLASS,
|
|
112
|
+
`${CLASS}--variant-${variant}`,
|
|
113
|
+
align !== 'left' ? `${CLASS}--align-${align}` : '',
|
|
114
|
+
]
|
|
115
|
+
.filter(Boolean)
|
|
116
|
+
.join(' ');
|
|
117
|
+
this.className = className;
|
|
118
|
+
if (this.innerEl)
|
|
119
|
+
this.innerEl.className = `${CLASS}__inner`;
|
|
120
|
+
if (this.quoteEl) {
|
|
121
|
+
this.quoteEl.textContent = quote ? `“${quote}”` : '';
|
|
122
|
+
}
|
|
123
|
+
if (this.authorEl)
|
|
124
|
+
this.authorEl.textContent = author;
|
|
125
|
+
const roleText = [role, company].filter(Boolean).join(' · ');
|
|
126
|
+
if (this.roleEl) {
|
|
127
|
+
this.roleEl.textContent = roleText;
|
|
128
|
+
this.roleEl.hidden = !roleText;
|
|
129
|
+
}
|
|
130
|
+
const shouldRenderAvatar = Boolean(avatar || avatarInitials);
|
|
131
|
+
if (this.avatarWrapEl)
|
|
132
|
+
this.avatarWrapEl.hidden = !shouldRenderAvatar;
|
|
133
|
+
if (this.avatarEl && shouldRenderAvatar) {
|
|
134
|
+
this.avatarEl.setAttribute('size', this.getAvatarSize());
|
|
135
|
+
if (avatar)
|
|
136
|
+
this.avatarEl.setAttribute('src', avatar);
|
|
137
|
+
else
|
|
138
|
+
this.avatarEl.removeAttribute('src');
|
|
139
|
+
if (avatarInitials)
|
|
140
|
+
this.avatarEl.setAttribute('initials', avatarInitials);
|
|
141
|
+
else
|
|
142
|
+
this.avatarEl.removeAttribute('initials');
|
|
143
|
+
this.avatarEl.setAttribute('alt', `${author} 프로필 이미지`);
|
|
144
|
+
}
|
|
145
|
+
if (this.ratingEl) {
|
|
146
|
+
if (typeof rating === 'number') {
|
|
147
|
+
this.ratingEl.hidden = false;
|
|
148
|
+
this.ratingEl.setAttribute('value', String(rating));
|
|
149
|
+
this.ratingEl.setAttribute('max-value', String(maxRating));
|
|
150
|
+
this.ratingEl.setAttribute('size', 's');
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.ratingEl.hidden = true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
this.syncExtraContent();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (!customElements.get('db-testimonial'))
|
|
160
|
+
customElements.define('db-testimonial', DbTestimonial);
|
|
161
|
+
|
|
162
|
+
export { DbTestimonial };
|