@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,571 +1 @@
|
|
|
1
|
-
import { getDbComponentIconSize, createDbIcon } from './db-icons.js';
|
|
2
|
-
import './db-checkbox.js';
|
|
3
|
-
|
|
4
|
-
const SIZES = ['s', 'm', 'l'];
|
|
5
|
-
class DbSelect extends HTMLElement {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.internals = this.attachInternals();
|
|
9
|
-
this.built = false;
|
|
10
|
-
this.searchTerm = '';
|
|
11
|
-
this.focusedIndex = -1;
|
|
12
|
-
this.handleTriggerClick = () => {
|
|
13
|
-
if (this.hasAttribute('disabled') || this.hasAttribute('readonly'))
|
|
14
|
-
return;
|
|
15
|
-
this.open = !this.open;
|
|
16
|
-
if (this.open && this.searchable) {
|
|
17
|
-
setTimeout(() => this.searchInput?.focus(), 0);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
this.handleTriggerFocus = () => {
|
|
21
|
-
this.trigger?.classList.add('designbase-wc-select__trigger--focused');
|
|
22
|
-
};
|
|
23
|
-
this.handleTriggerBlur = () => {
|
|
24
|
-
this.trigger?.classList.remove('designbase-wc-select__trigger--focused');
|
|
25
|
-
};
|
|
26
|
-
this.handleClear = (event) => {
|
|
27
|
-
event.stopPropagation();
|
|
28
|
-
const next = [];
|
|
29
|
-
this.setSelectedValues(next);
|
|
30
|
-
this.syncTrigger();
|
|
31
|
-
this.syncOptions();
|
|
32
|
-
this.dispatchChange(next);
|
|
33
|
-
};
|
|
34
|
-
this.handleSearchInput = () => {
|
|
35
|
-
this.searchTerm = this.searchInput?.value || '';
|
|
36
|
-
this.focusedIndex = -1;
|
|
37
|
-
this.syncOptions();
|
|
38
|
-
};
|
|
39
|
-
this.handleDocumentMouseDown = (event) => {
|
|
40
|
-
if (!this.contains(event.target)) {
|
|
41
|
-
this.open = false;
|
|
42
|
-
this.searchTerm = '';
|
|
43
|
-
if (this.searchInput)
|
|
44
|
-
this.searchInput.value = '';
|
|
45
|
-
this.focusedIndex = -1;
|
|
46
|
-
this.syncOptions();
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
this.handleDocumentKeyDown = (event) => {
|
|
50
|
-
if (!this.contains(document.activeElement))
|
|
51
|
-
return;
|
|
52
|
-
if (!this.open) {
|
|
53
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
54
|
-
event.preventDefault();
|
|
55
|
-
this.open = true;
|
|
56
|
-
}
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const filtered = this.getFilteredOptions();
|
|
60
|
-
switch (event.key) {
|
|
61
|
-
case 'Escape':
|
|
62
|
-
event.preventDefault();
|
|
63
|
-
this.open = false;
|
|
64
|
-
this.searchTerm = '';
|
|
65
|
-
if (this.searchInput)
|
|
66
|
-
this.searchInput.value = '';
|
|
67
|
-
this.focusedIndex = -1;
|
|
68
|
-
this.syncOptions();
|
|
69
|
-
break;
|
|
70
|
-
case 'ArrowDown':
|
|
71
|
-
event.preventDefault();
|
|
72
|
-
this.focusedIndex = Math.min(this.focusedIndex + 1, filtered.length - 1);
|
|
73
|
-
this.syncOptions();
|
|
74
|
-
break;
|
|
75
|
-
case 'ArrowUp':
|
|
76
|
-
event.preventDefault();
|
|
77
|
-
this.focusedIndex = Math.max(this.focusedIndex - 1, 0);
|
|
78
|
-
this.syncOptions();
|
|
79
|
-
break;
|
|
80
|
-
case 'Enter':
|
|
81
|
-
event.preventDefault();
|
|
82
|
-
if (this.focusedIndex >= 0 && filtered[this.focusedIndex]) {
|
|
83
|
-
this.selectOption(filtered[this.focusedIndex]);
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
static get observedAttributes() {
|
|
90
|
-
return [
|
|
91
|
-
'options',
|
|
92
|
-
'value',
|
|
93
|
-
'placeholder',
|
|
94
|
-
'label',
|
|
95
|
-
'size',
|
|
96
|
-
'full-width',
|
|
97
|
-
'disabled',
|
|
98
|
-
'readonly',
|
|
99
|
-
'required',
|
|
100
|
-
'error',
|
|
101
|
-
'error-message',
|
|
102
|
-
'helper-text',
|
|
103
|
-
'multiple',
|
|
104
|
-
'searchable',
|
|
105
|
-
'show-clear-button',
|
|
106
|
-
'open',
|
|
107
|
-
'max-height',
|
|
108
|
-
'position',
|
|
109
|
-
'dropdown-width',
|
|
110
|
-
'name',
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
|
-
get name() {
|
|
114
|
-
return this.getAttribute('name') ?? '';
|
|
115
|
-
}
|
|
116
|
-
set name(value) {
|
|
117
|
-
this.setAttribute('name', value);
|
|
118
|
-
}
|
|
119
|
-
get open() {
|
|
120
|
-
return this.hasAttribute('open');
|
|
121
|
-
}
|
|
122
|
-
set open(value) {
|
|
123
|
-
this.toggleAttribute('open', value);
|
|
124
|
-
this.syncOpenState();
|
|
125
|
-
}
|
|
126
|
-
get value() {
|
|
127
|
-
return this.getAttribute('value') || '';
|
|
128
|
-
}
|
|
129
|
-
set value(value) {
|
|
130
|
-
if (value)
|
|
131
|
-
this.setAttribute('value', value);
|
|
132
|
-
else
|
|
133
|
-
this.removeAttribute('value');
|
|
134
|
-
this.syncTrigger();
|
|
135
|
-
this.syncOptions();
|
|
136
|
-
}
|
|
137
|
-
connectedCallback() {
|
|
138
|
-
if (!this.built) {
|
|
139
|
-
this.build();
|
|
140
|
-
}
|
|
141
|
-
this.syncState();
|
|
142
|
-
document.addEventListener('mousedown', this.handleDocumentMouseDown);
|
|
143
|
-
document.addEventListener('keydown', this.handleDocumentKeyDown);
|
|
144
|
-
}
|
|
145
|
-
disconnectedCallback() {
|
|
146
|
-
document.removeEventListener('mousedown', this.handleDocumentMouseDown);
|
|
147
|
-
document.removeEventListener('keydown', this.handleDocumentKeyDown);
|
|
148
|
-
}
|
|
149
|
-
formResetCallback() {
|
|
150
|
-
this.removeAttribute('value');
|
|
151
|
-
this.internals.setFormValue(null);
|
|
152
|
-
if (this.built) {
|
|
153
|
-
this.syncTrigger();
|
|
154
|
-
this.syncOptions();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
formDisabledCallback(disabled) {
|
|
158
|
-
this.toggleAttribute('disabled', disabled);
|
|
159
|
-
}
|
|
160
|
-
attributeChangedCallback(name) {
|
|
161
|
-
if (!this.built)
|
|
162
|
-
return;
|
|
163
|
-
if (name === 'open') {
|
|
164
|
-
this.syncOpenState();
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
if (name === 'value') {
|
|
168
|
-
this.syncTrigger();
|
|
169
|
-
this.syncOptions();
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
this.syncState();
|
|
173
|
-
}
|
|
174
|
-
get multiple() {
|
|
175
|
-
return this.hasAttribute('multiple');
|
|
176
|
-
}
|
|
177
|
-
set multiple(value) {
|
|
178
|
-
this.toggleAttribute('multiple', Boolean(value));
|
|
179
|
-
}
|
|
180
|
-
get searchable() {
|
|
181
|
-
return this.hasAttribute('searchable');
|
|
182
|
-
}
|
|
183
|
-
set searchable(value) {
|
|
184
|
-
this.toggleAttribute('searchable', Boolean(value));
|
|
185
|
-
}
|
|
186
|
-
get showClearButton() {
|
|
187
|
-
if (!this.hasAttribute('show-clear-button')) {
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
return this.getAttribute('show-clear-button') !== 'false';
|
|
191
|
-
}
|
|
192
|
-
parseOptions() {
|
|
193
|
-
const raw = this.getAttribute('options') || '[]';
|
|
194
|
-
try {
|
|
195
|
-
const parsed = JSON.parse(raw);
|
|
196
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
197
|
-
}
|
|
198
|
-
catch {
|
|
199
|
-
return raw.split(',').map((item) => item.trim()).filter(Boolean).map((label) => ({ value: label, label }));
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
parseSelectedValues() {
|
|
203
|
-
const raw = this.getAttribute('value') || '';
|
|
204
|
-
if (!raw)
|
|
205
|
-
return [];
|
|
206
|
-
if (this.multiple) {
|
|
207
|
-
try {
|
|
208
|
-
const parsed = JSON.parse(raw);
|
|
209
|
-
return Array.isArray(parsed) ? parsed.map(String) : [];
|
|
210
|
-
}
|
|
211
|
-
catch {
|
|
212
|
-
return raw.split(',').map((item) => item.trim()).filter(Boolean);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return raw ? [raw] : [];
|
|
216
|
-
}
|
|
217
|
-
setSelectedValues(values) {
|
|
218
|
-
if (this.multiple) {
|
|
219
|
-
if (values.length)
|
|
220
|
-
this.setAttribute('value', JSON.stringify(values));
|
|
221
|
-
else
|
|
222
|
-
this.removeAttribute('value');
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
if (values[0])
|
|
226
|
-
this.setAttribute('value', values[0]);
|
|
227
|
-
else
|
|
228
|
-
this.removeAttribute('value');
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
getIconSize() {
|
|
232
|
-
const size = this.getAttribute('size') || 'm';
|
|
233
|
-
return getDbComponentIconSize(SIZES.includes(size) ? size : 'm');
|
|
234
|
-
}
|
|
235
|
-
syncIndicatorIcons() {
|
|
236
|
-
const iconPx = this.getIconSize();
|
|
237
|
-
this.clearButton?.replaceChildren(createDbIcon('close', iconPx));
|
|
238
|
-
if (this.chevronEl) {
|
|
239
|
-
this.chevronEl.replaceChildren(createDbIcon(this.open ? 'chevron-up' : 'chevron-down', iconPx));
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
build() {
|
|
243
|
-
const id = this.getAttribute('id') || `db-select-${Math.random().toString(36).slice(2)}`;
|
|
244
|
-
const listboxId = `${id}-listbox`;
|
|
245
|
-
if (!this.hasAttribute('id'))
|
|
246
|
-
this.setAttribute('id', id);
|
|
247
|
-
this.labelEl = document.createElement('label');
|
|
248
|
-
this.labelEl.className = 'designbase-wc-select__label';
|
|
249
|
-
this.trigger = document.createElement('div');
|
|
250
|
-
this.trigger.className = 'designbase-wc-select__trigger';
|
|
251
|
-
this.trigger.tabIndex = 0;
|
|
252
|
-
this.trigger.setAttribute('role', 'combobox');
|
|
253
|
-
this.trigger.setAttribute('aria-haspopup', 'listbox');
|
|
254
|
-
this.trigger.setAttribute('aria-controls', listboxId);
|
|
255
|
-
this.trigger.addEventListener('click', this.handleTriggerClick);
|
|
256
|
-
this.trigger.addEventListener('focus', this.handleTriggerFocus);
|
|
257
|
-
this.trigger.addEventListener('blur', this.handleTriggerBlur);
|
|
258
|
-
this.valueEl = document.createElement('div');
|
|
259
|
-
this.valueEl.className = 'designbase-wc-select__value';
|
|
260
|
-
this.indicatorsEl = document.createElement('div');
|
|
261
|
-
this.indicatorsEl.className = 'designbase-wc-select__indicators';
|
|
262
|
-
this.clearButton = document.createElement('button');
|
|
263
|
-
this.clearButton.type = 'button';
|
|
264
|
-
this.clearButton.className = 'designbase-wc-select__clear-button';
|
|
265
|
-
this.clearButton.setAttribute('aria-label', '모든 값 지우기');
|
|
266
|
-
this.clearButton.hidden = true;
|
|
267
|
-
this.clearButton.appendChild(createDbIcon('close', this.getIconSize()));
|
|
268
|
-
this.clearButton.addEventListener('click', this.handleClear);
|
|
269
|
-
this.chevronEl = document.createElement('div');
|
|
270
|
-
this.chevronEl.className = 'designbase-wc-select__chevron';
|
|
271
|
-
this.indicatorsEl.append(this.clearButton, this.chevronEl);
|
|
272
|
-
this.trigger.append(this.valueEl, this.indicatorsEl);
|
|
273
|
-
this.dropdown = document.createElement('div');
|
|
274
|
-
this.dropdown.className = 'designbase-wc-select__dropdown';
|
|
275
|
-
this.searchWrap = document.createElement('div');
|
|
276
|
-
this.searchWrap.className = 'designbase-wc-select__search';
|
|
277
|
-
this.searchWrap.hidden = true;
|
|
278
|
-
this.searchInput = document.createElement('input');
|
|
279
|
-
this.searchInput.type = 'text';
|
|
280
|
-
this.searchInput.className = 'designbase-wc-select__search-input';
|
|
281
|
-
this.searchInput.placeholder = '옵션 검색';
|
|
282
|
-
this.searchInput.addEventListener('input', this.handleSearchInput);
|
|
283
|
-
this.searchInput.addEventListener('mousedown', (event) => event.stopPropagation());
|
|
284
|
-
this.searchInput.addEventListener('click', (event) => event.stopPropagation());
|
|
285
|
-
this.searchWrap.appendChild(this.searchInput);
|
|
286
|
-
this.optionsEl = document.createElement('div');
|
|
287
|
-
this.optionsEl.className = 'designbase-wc-select__options';
|
|
288
|
-
this.optionsEl.id = listboxId;
|
|
289
|
-
this.optionsEl.setAttribute('role', 'listbox');
|
|
290
|
-
this.dropdown.append(this.searchWrap, this.optionsEl);
|
|
291
|
-
this.helperEl = document.createElement('p');
|
|
292
|
-
this.helperEl.className = 'designbase-wc-select__helper-text';
|
|
293
|
-
this.errorEl = document.createElement('p');
|
|
294
|
-
this.errorEl.className = 'designbase-wc-select__error-message';
|
|
295
|
-
this.append(this.labelEl, this.trigger, this.dropdown, this.helperEl, this.errorEl);
|
|
296
|
-
this.built = true;
|
|
297
|
-
}
|
|
298
|
-
getFilteredOptions() {
|
|
299
|
-
const options = this.parseOptions();
|
|
300
|
-
if (!this.searchable || !this.searchTerm)
|
|
301
|
-
return options;
|
|
302
|
-
const term = this.searchTerm.toLowerCase();
|
|
303
|
-
return options.filter((option) => option.label.toLowerCase().includes(term));
|
|
304
|
-
}
|
|
305
|
-
selectOption(option) {
|
|
306
|
-
if (option.disabled)
|
|
307
|
-
return;
|
|
308
|
-
const selected = this.parseSelectedValues();
|
|
309
|
-
let next;
|
|
310
|
-
if (this.multiple) {
|
|
311
|
-
next = selected.includes(option.value)
|
|
312
|
-
? selected.filter((value) => value !== option.value)
|
|
313
|
-
: [...selected, option.value];
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
next = [option.value];
|
|
317
|
-
this.open = false;
|
|
318
|
-
this.searchTerm = '';
|
|
319
|
-
if (this.searchInput)
|
|
320
|
-
this.searchInput.value = '';
|
|
321
|
-
this.focusedIndex = -1;
|
|
322
|
-
}
|
|
323
|
-
this.setSelectedValues(next);
|
|
324
|
-
this.syncTrigger();
|
|
325
|
-
this.syncOptions();
|
|
326
|
-
this.dispatchChange(next);
|
|
327
|
-
}
|
|
328
|
-
dispatchChange(values) {
|
|
329
|
-
const options = this.parseOptions();
|
|
330
|
-
if (this.multiple) {
|
|
331
|
-
const formData = new FormData();
|
|
332
|
-
values.forEach((v) => formData.append(this.name || 'select', v));
|
|
333
|
-
this.internals.setFormValue(values.length ? formData : null);
|
|
334
|
-
this.dispatchEvent(new Event('change', { bubbles: true }));
|
|
335
|
-
this.dispatchEvent(new CustomEvent('db-change', {
|
|
336
|
-
detail: {
|
|
337
|
-
value: values,
|
|
338
|
-
labels: values.map((value) => options.find((option) => option.value === value)?.label || value),
|
|
339
|
-
},
|
|
340
|
-
bubbles: true,
|
|
341
|
-
composed: true,
|
|
342
|
-
}));
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
const value = values[0] || '';
|
|
346
|
-
const label = options.find((option) => option.value === value)?.label || '';
|
|
347
|
-
this.internals.setFormValue(value || null);
|
|
348
|
-
this.dispatchEvent(new Event('change', { bubbles: true }));
|
|
349
|
-
this.dispatchEvent(new CustomEvent('db-change', {
|
|
350
|
-
detail: { value, label },
|
|
351
|
-
bubbles: true,
|
|
352
|
-
composed: true,
|
|
353
|
-
}));
|
|
354
|
-
}
|
|
355
|
-
syncState() {
|
|
356
|
-
if (!this.trigger || !this.dropdown || !this.optionsEl)
|
|
357
|
-
return;
|
|
358
|
-
const size = SIZES.includes((this.getAttribute('size') || 'm'))
|
|
359
|
-
? (this.getAttribute('size') || 'm')
|
|
360
|
-
: 'm';
|
|
361
|
-
const position = this.getAttribute('position') === 'top' ? 'top' : 'bottom';
|
|
362
|
-
const dropdownWidth = this.getAttribute('dropdown-width') === 'full' ? 'full' : 'auto';
|
|
363
|
-
const maxHeight = Number(this.getAttribute('max-height') || 200);
|
|
364
|
-
const label = this.getAttribute('label') || '';
|
|
365
|
-
const helperText = this.getAttribute('helper-text') || '';
|
|
366
|
-
const errorMessage = this.getAttribute('error-message') || '';
|
|
367
|
-
const hasError = this.hasAttribute('error');
|
|
368
|
-
const id = this.getAttribute('id') || '';
|
|
369
|
-
this.className = [
|
|
370
|
-
'designbase-wc-select',
|
|
371
|
-
`designbase-wc-select--${size}`,
|
|
372
|
-
this.open && 'designbase-wc-select--open',
|
|
373
|
-
hasError && 'designbase-wc-select--error',
|
|
374
|
-
this.hasAttribute('disabled') && 'designbase-wc-select--disabled',
|
|
375
|
-
this.hasAttribute('readonly') && 'designbase-wc-select--readonly',
|
|
376
|
-
this.hasAttribute('full-width') && 'designbase-wc-select--full-width',
|
|
377
|
-
this.multiple && 'designbase-wc-select--multiple',
|
|
378
|
-
this.searchable && 'designbase-wc-select--searchable',
|
|
379
|
-
].filter(Boolean).join(' ');
|
|
380
|
-
const selectedForState = this.parseSelectedValues();
|
|
381
|
-
this.classList.toggle('designbase-wc-select--has-value', selectedForState.length > 0);
|
|
382
|
-
if (this.labelEl) {
|
|
383
|
-
const requiredMark = this.hasAttribute('required') ? '<span class="designbase-wc-select__required" aria-hidden="true">*</span>' : '';
|
|
384
|
-
this.labelEl.innerHTML = label ? `${this.escape(label)}${requiredMark}` : '';
|
|
385
|
-
this.labelEl.hidden = !label;
|
|
386
|
-
}
|
|
387
|
-
this.dropdown.className = [
|
|
388
|
-
'designbase-wc-select__dropdown',
|
|
389
|
-
`designbase-wc-select__dropdown--${dropdownWidth}`,
|
|
390
|
-
`designbase-wc-select__dropdown--${position}`,
|
|
391
|
-
this.open && 'designbase-wc-select__dropdown--open',
|
|
392
|
-
].filter(Boolean).join(' ');
|
|
393
|
-
this.optionsEl.style.maxHeight = `${maxHeight}px`;
|
|
394
|
-
if (this.searchWrap) {
|
|
395
|
-
this.searchWrap.hidden = !this.searchable;
|
|
396
|
-
}
|
|
397
|
-
const helperId = `${id}-helper`;
|
|
398
|
-
const errorId = `${id}-error`;
|
|
399
|
-
if (hasError && errorMessage) {
|
|
400
|
-
this.errorEl.id = errorId;
|
|
401
|
-
this.errorEl.textContent = errorMessage;
|
|
402
|
-
this.errorEl.hidden = false;
|
|
403
|
-
this.helperEl.hidden = true;
|
|
404
|
-
this.trigger.setAttribute('aria-describedby', errorId);
|
|
405
|
-
this.trigger.setAttribute('aria-invalid', 'true');
|
|
406
|
-
}
|
|
407
|
-
else if (helperText) {
|
|
408
|
-
this.helperEl.id = helperId;
|
|
409
|
-
this.helperEl.textContent = helperText;
|
|
410
|
-
this.helperEl.hidden = false;
|
|
411
|
-
this.errorEl.hidden = true;
|
|
412
|
-
this.trigger.setAttribute('aria-describedby', helperId);
|
|
413
|
-
this.trigger.removeAttribute('aria-invalid');
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
this.helperEl.hidden = true;
|
|
417
|
-
this.errorEl.hidden = true;
|
|
418
|
-
this.trigger.removeAttribute('aria-describedby');
|
|
419
|
-
this.trigger.removeAttribute('aria-invalid');
|
|
420
|
-
}
|
|
421
|
-
if (this.hasAttribute('disabled') || this.hasAttribute('readonly')) {
|
|
422
|
-
this.trigger.tabIndex = -1;
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
this.trigger.tabIndex = 0;
|
|
426
|
-
}
|
|
427
|
-
this.syncOpenState();
|
|
428
|
-
this.syncTrigger();
|
|
429
|
-
this.syncOptions();
|
|
430
|
-
this.syncIndicatorIcons();
|
|
431
|
-
}
|
|
432
|
-
syncOpenState() {
|
|
433
|
-
if (!this.trigger || !this.dropdown || !this.chevronEl)
|
|
434
|
-
return;
|
|
435
|
-
this.trigger.setAttribute('aria-expanded', String(this.open));
|
|
436
|
-
this.classList.toggle('designbase-wc-select--open', this.open);
|
|
437
|
-
this.dropdown.classList.toggle('designbase-wc-select__dropdown--open', this.open);
|
|
438
|
-
this.syncIndicatorIcons();
|
|
439
|
-
}
|
|
440
|
-
syncTrigger() {
|
|
441
|
-
if (!this.valueEl || !this.clearButton)
|
|
442
|
-
return;
|
|
443
|
-
const options = this.parseOptions();
|
|
444
|
-
const selected = this.parseSelectedValues();
|
|
445
|
-
const placeholder = this.getAttribute('placeholder') || '선택하세요';
|
|
446
|
-
const hasValue = selected.length > 0;
|
|
447
|
-
const showClear = hasValue
|
|
448
|
-
&& this.showClearButton
|
|
449
|
-
&& !this.hasAttribute('disabled')
|
|
450
|
-
&& !this.hasAttribute('readonly');
|
|
451
|
-
this.valueEl.replaceChildren();
|
|
452
|
-
if (this.multiple) {
|
|
453
|
-
if (selected.length === 0) {
|
|
454
|
-
const placeholderEl = document.createElement('span');
|
|
455
|
-
placeholderEl.className = 'designbase-wc-select__placeholder';
|
|
456
|
-
placeholderEl.textContent = placeholder;
|
|
457
|
-
this.valueEl.appendChild(placeholderEl);
|
|
458
|
-
}
|
|
459
|
-
else {
|
|
460
|
-
const tags = document.createElement('div');
|
|
461
|
-
tags.className = 'designbase-wc-select__tags';
|
|
462
|
-
selected.forEach((value) => {
|
|
463
|
-
const option = options.find((item) => item.value === value);
|
|
464
|
-
const tag = document.createElement('span');
|
|
465
|
-
tag.className = 'designbase-wc-select__tag';
|
|
466
|
-
const tagLabel = document.createElement('span');
|
|
467
|
-
tagLabel.className = 'designbase-wc-select__tag-label';
|
|
468
|
-
tagLabel.textContent = option?.label || value;
|
|
469
|
-
const removeButton = document.createElement('button');
|
|
470
|
-
removeButton.type = 'button';
|
|
471
|
-
removeButton.className = 'designbase-wc-select__tag-remove';
|
|
472
|
-
removeButton.setAttribute('aria-label', `${option?.label || value} 제거`);
|
|
473
|
-
removeButton.appendChild(createDbIcon('close', 12));
|
|
474
|
-
removeButton.addEventListener('click', (event) => {
|
|
475
|
-
event.stopPropagation();
|
|
476
|
-
const next = selected.filter((item) => item !== value);
|
|
477
|
-
this.setSelectedValues(next);
|
|
478
|
-
this.syncTrigger();
|
|
479
|
-
this.syncOptions();
|
|
480
|
-
this.dispatchChange(next);
|
|
481
|
-
});
|
|
482
|
-
tag.append(tagLabel, removeButton);
|
|
483
|
-
tags.appendChild(tag);
|
|
484
|
-
});
|
|
485
|
-
this.valueEl.appendChild(tags);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
const single = document.createElement('span');
|
|
490
|
-
single.className = 'designbase-wc-select__single-value';
|
|
491
|
-
const selectedOption = options.find((option) => option.value === selected[0]);
|
|
492
|
-
single.textContent = hasValue ? (selectedOption?.label || selected[0]) : placeholder;
|
|
493
|
-
if (!hasValue) {
|
|
494
|
-
single.classList.add('designbase-wc-select__placeholder');
|
|
495
|
-
}
|
|
496
|
-
this.valueEl.appendChild(single);
|
|
497
|
-
}
|
|
498
|
-
this.clearButton.hidden = !showClear;
|
|
499
|
-
this.clearButton.setAttribute('aria-hidden', showClear ? 'false' : 'true');
|
|
500
|
-
this.classList.toggle('designbase-wc-select--has-value', hasValue);
|
|
501
|
-
}
|
|
502
|
-
syncOptions() {
|
|
503
|
-
if (!this.optionsEl)
|
|
504
|
-
return;
|
|
505
|
-
const options = this.getFilteredOptions();
|
|
506
|
-
const selected = this.parseSelectedValues();
|
|
507
|
-
const id = this.getAttribute('id') || 'db-select';
|
|
508
|
-
this.optionsEl.replaceChildren();
|
|
509
|
-
if (options.length === 0) {
|
|
510
|
-
const empty = document.createElement('div');
|
|
511
|
-
empty.className = 'designbase-wc-select__no-options';
|
|
512
|
-
empty.textContent = this.searchTerm ? '검색 결과가 없습니다.' : '옵션이 없습니다.';
|
|
513
|
-
this.optionsEl.appendChild(empty);
|
|
514
|
-
return;
|
|
515
|
-
}
|
|
516
|
-
options.forEach((option, index) => {
|
|
517
|
-
const isSelected = selected.includes(option.value);
|
|
518
|
-
const isFocused = index === this.focusedIndex;
|
|
519
|
-
const optionEl = document.createElement('div');
|
|
520
|
-
optionEl.className = [
|
|
521
|
-
'designbase-wc-select__option',
|
|
522
|
-
isSelected && 'designbase-wc-select__option--selected',
|
|
523
|
-
isFocused && 'designbase-wc-select__option--focused',
|
|
524
|
-
option.disabled && 'designbase-wc-select__option--disabled',
|
|
525
|
-
].filter(Boolean).join(' ');
|
|
526
|
-
optionEl.id = `${id}-option-${index}`;
|
|
527
|
-
optionEl.setAttribute('role', 'option');
|
|
528
|
-
optionEl.setAttribute('aria-selected', String(isSelected));
|
|
529
|
-
optionEl.addEventListener('click', () => this.selectOption(option));
|
|
530
|
-
if (this.multiple) {
|
|
531
|
-
const checkboxWrap = document.createElement('div');
|
|
532
|
-
checkboxWrap.className = 'designbase-wc-select__checkbox';
|
|
533
|
-
const checkbox = document.createElement('db-checkbox');
|
|
534
|
-
checkbox.setAttribute('size', 's');
|
|
535
|
-
checkbox.setAttribute('has-label', 'false');
|
|
536
|
-
if (isSelected)
|
|
537
|
-
checkbox.setAttribute('checked', '');
|
|
538
|
-
if (option.disabled)
|
|
539
|
-
checkbox.setAttribute('disabled', '');
|
|
540
|
-
checkboxWrap.appendChild(checkbox);
|
|
541
|
-
optionEl.appendChild(checkboxWrap);
|
|
542
|
-
}
|
|
543
|
-
const label = document.createElement('span');
|
|
544
|
-
label.className = 'designbase-wc-select__option-label';
|
|
545
|
-
label.textContent = option.label;
|
|
546
|
-
optionEl.appendChild(label);
|
|
547
|
-
this.optionsEl.appendChild(optionEl);
|
|
548
|
-
});
|
|
549
|
-
if (this.focusedIndex >= 0) {
|
|
550
|
-
this.trigger?.setAttribute('aria-activedescendant', `${id}-option-${this.focusedIndex}`);
|
|
551
|
-
}
|
|
552
|
-
else {
|
|
553
|
-
this.trigger?.removeAttribute('aria-activedescendant');
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
escape(value) {
|
|
557
|
-
return value.replace(/[&<>"']/g, (char) => ({
|
|
558
|
-
'&': '&',
|
|
559
|
-
'<': '<',
|
|
560
|
-
'>': '>',
|
|
561
|
-
'"': '"',
|
|
562
|
-
"'": ''',
|
|
563
|
-
}[char] || char));
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
DbSelect.formAssociated = true;
|
|
567
|
-
if (!customElements.get('db-select')) {
|
|
568
|
-
customElements.define('db-select', DbSelect);
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
export { DbSelect };
|
|
1
|
+
import{getDbComponentIconSize as e,createDbIcon as t}from"./db-icons.js";import"./db-checkbox.js";const s=["s","m","l"];class DbSelect extends HTMLElement{constructor(){super(...arguments),this.internals=this.attachInternals(),this.built=!1,this.searchTerm="",this.focusedIndex=-1,this.handleTriggerClick=()=>{this.hasAttribute("disabled")||this.hasAttribute("readonly")||(this.open=!this.open,this.open&&this.searchable&&setTimeout(()=>this.searchInput?.focus(),0))},this.handleTriggerFocus=()=>{this.trigger?.classList.add("designbase-wc-select__trigger--focused")},this.handleTriggerBlur=()=>{this.trigger?.classList.remove("designbase-wc-select__trigger--focused")},this.handleClear=e=>{e.stopPropagation();const t=[];this.setSelectedValues(t),this.syncTrigger(),this.syncOptions(),this.dispatchChange(t)},this.handleSearchInput=()=>{this.searchTerm=this.searchInput?.value||"",this.focusedIndex=-1,this.syncOptions()},this.handleDocumentMouseDown=e=>{this.contains(e.target)||(this.open=!1,this.searchTerm="",this.searchInput&&(this.searchInput.value=""),this.focusedIndex=-1,this.syncOptions())},this.handleDocumentKeyDown=e=>{if(!this.contains(document.activeElement))return;if(!this.open)return void("Enter"!==e.key&&" "!==e.key||(e.preventDefault(),this.open=!0));const t=this.getFilteredOptions();switch(e.key){case"Escape":e.preventDefault(),this.open=!1,this.searchTerm="",this.searchInput&&(this.searchInput.value=""),this.focusedIndex=-1,this.syncOptions();break;case"ArrowDown":e.preventDefault(),this.focusedIndex=Math.min(this.focusedIndex+1,t.length-1),this.syncOptions();break;case"ArrowUp":e.preventDefault(),this.focusedIndex=Math.max(this.focusedIndex-1,0),this.syncOptions();break;case"Enter":e.preventDefault(),this.focusedIndex>=0&&t[this.focusedIndex]&&this.selectOption(t[this.focusedIndex])}}}static get observedAttributes(){return["options","value","placeholder","label","size","full-width","disabled","readonly","required","error","error-message","helper-text","multiple","searchable","show-clear-button","open","max-height","position","dropdown-width","name"]}get name(){return this.getAttribute("name")??""}set name(e){this.setAttribute("name",e)}get open(){return this.hasAttribute("open")}set open(e){this.toggleAttribute("open",e),this.syncOpenState()}get value(){return this.getAttribute("value")||""}set value(e){e?this.setAttribute("value",e):this.removeAttribute("value"),this.syncTrigger(),this.syncOptions()}connectedCallback(){this.built||this.build(),this.syncState(),document.addEventListener("mousedown",this.handleDocumentMouseDown),document.addEventListener("keydown",this.handleDocumentKeyDown)}disconnectedCallback(){document.removeEventListener("mousedown",this.handleDocumentMouseDown),document.removeEventListener("keydown",this.handleDocumentKeyDown)}formResetCallback(){this.removeAttribute("value"),this.internals.setFormValue(null),this.built&&(this.syncTrigger(),this.syncOptions())}formDisabledCallback(e){this.toggleAttribute("disabled",e)}attributeChangedCallback(e){if(this.built){if("open"!==e)return"value"===e?(this.syncTrigger(),void this.syncOptions()):void this.syncState();this.syncOpenState()}}get multiple(){return this.hasAttribute("multiple")}set multiple(e){this.toggleAttribute("multiple",Boolean(e))}get searchable(){return this.hasAttribute("searchable")}set searchable(e){this.toggleAttribute("searchable",Boolean(e))}get showClearButton(){return!this.hasAttribute("show-clear-button")||"false"!==this.getAttribute("show-clear-button")}parseOptions(){const e=this.getAttribute("options")||"[]";try{const t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return e.split(",").map(e=>e.trim()).filter(Boolean).map(e=>({value:e,label:e}))}}parseSelectedValues(){const e=this.getAttribute("value")||"";if(!e)return[];if(this.multiple)try{const t=JSON.parse(e);return Array.isArray(t)?t.map(String):[]}catch{return e.split(",").map(e=>e.trim()).filter(Boolean)}return e?[e]:[]}setSelectedValues(e){this.multiple?e.length?this.setAttribute("value",JSON.stringify(e)):this.removeAttribute("value"):e[0]?this.setAttribute("value",e[0]):this.removeAttribute("value")}getIconSize(){const t=this.getAttribute("size")||"m";return e(s.includes(t)?t:"m")}syncIndicatorIcons(){const e=this.getIconSize();this.clearButton?.replaceChildren(t("close",e)),this.chevronEl&&this.chevronEl.replaceChildren(t(this.open?"chevron-up":"chevron-down",e))}build(){const e=this.getAttribute("id")||`db-select-${Math.random().toString(36).slice(2)}`,s=`${e}-listbox`;this.hasAttribute("id")||this.setAttribute("id",e),this.labelEl=document.createElement("label"),this.labelEl.className="designbase-wc-select__label",this.trigger=document.createElement("div"),this.trigger.className="designbase-wc-select__trigger",this.trigger.tabIndex=0,this.trigger.setAttribute("role","combobox"),this.trigger.setAttribute("aria-haspopup","listbox"),this.trigger.setAttribute("aria-controls",s),this.trigger.addEventListener("click",this.handleTriggerClick),this.trigger.addEventListener("focus",this.handleTriggerFocus),this.trigger.addEventListener("blur",this.handleTriggerBlur),this.valueEl=document.createElement("div"),this.valueEl.className="designbase-wc-select__value",this.indicatorsEl=document.createElement("div"),this.indicatorsEl.className="designbase-wc-select__indicators",this.clearButton=document.createElement("button"),this.clearButton.type="button",this.clearButton.className="designbase-wc-select__clear-button",this.clearButton.setAttribute("aria-label","모든 값 지우기"),this.clearButton.hidden=!0,this.clearButton.appendChild(t("close",this.getIconSize())),this.clearButton.addEventListener("click",this.handleClear),this.chevronEl=document.createElement("div"),this.chevronEl.className="designbase-wc-select__chevron",this.indicatorsEl.append(this.clearButton,this.chevronEl),this.trigger.append(this.valueEl,this.indicatorsEl),this.dropdown=document.createElement("div"),this.dropdown.className="designbase-wc-select__dropdown",this.searchWrap=document.createElement("div"),this.searchWrap.className="designbase-wc-select__search",this.searchWrap.hidden=!0,this.searchInput=document.createElement("input"),this.searchInput.type="text",this.searchInput.className="designbase-wc-select__search-input",this.searchInput.placeholder="옵션 검색",this.searchInput.addEventListener("input",this.handleSearchInput),this.searchInput.addEventListener("mousedown",e=>e.stopPropagation()),this.searchInput.addEventListener("click",e=>e.stopPropagation()),this.searchWrap.appendChild(this.searchInput),this.optionsEl=document.createElement("div"),this.optionsEl.className="designbase-wc-select__options",this.optionsEl.id=s,this.optionsEl.setAttribute("role","listbox"),this.dropdown.append(this.searchWrap,this.optionsEl),this.helperEl=document.createElement("p"),this.helperEl.className="designbase-wc-select__helper-text",this.errorEl=document.createElement("p"),this.errorEl.className="designbase-wc-select__error-message",this.append(this.labelEl,this.trigger,this.dropdown,this.helperEl,this.errorEl),this.built=!0}getFilteredOptions(){const e=this.parseOptions();if(!this.searchable||!this.searchTerm)return e;const t=this.searchTerm.toLowerCase();return e.filter(e=>e.label.toLowerCase().includes(t))}selectOption(e){if(e.disabled)return;const t=this.parseSelectedValues();let s;this.multiple?s=t.includes(e.value)?t.filter(t=>t!==e.value):[...t,e.value]:(s=[e.value],this.open=!1,this.searchTerm="",this.searchInput&&(this.searchInput.value=""),this.focusedIndex=-1),this.setSelectedValues(s),this.syncTrigger(),this.syncOptions(),this.dispatchChange(s)}dispatchChange(e){const t=this.parseOptions();if(this.multiple){const s=new FormData;return e.forEach(e=>s.append(this.name||"select",e)),this.internals.setFormValue(e.length?s:null),this.dispatchEvent(new Event("change",{bubbles:!0})),void this.dispatchEvent(new CustomEvent("db-change",{detail:{value:e,labels:e.map(e=>t.find(t=>t.value===e)?.label||e)},bubbles:!0,composed:!0}))}const s=e[0]||"",i=t.find(e=>e.value===s)?.label||"";this.internals.setFormValue(s||null),this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new CustomEvent("db-change",{detail:{value:s,label:i},bubbles:!0,composed:!0}))}syncState(){if(!this.trigger||!this.dropdown||!this.optionsEl)return;const e=s.includes(this.getAttribute("size")||"m")&&this.getAttribute("size")||"m",t="top"===this.getAttribute("position")?"top":"bottom",i="full"===this.getAttribute("dropdown-width")?"full":"auto",n=Number(this.getAttribute("max-height")||200),a=this.getAttribute("label")||"",r=this.getAttribute("helper-text")||"",l=this.getAttribute("error-message")||"",h=this.hasAttribute("error"),c=this.getAttribute("id")||"";this.className=["designbase-wc-select",`designbase-wc-select--${e}`,this.open&&"designbase-wc-select--open",h&&"designbase-wc-select--error",this.hasAttribute("disabled")&&"designbase-wc-select--disabled",this.hasAttribute("readonly")&&"designbase-wc-select--readonly",this.hasAttribute("full-width")&&"designbase-wc-select--full-width",this.multiple&&"designbase-wc-select--multiple",this.searchable&&"designbase-wc-select--searchable"].filter(Boolean).join(" ");const o=this.parseSelectedValues();if(this.classList.toggle("designbase-wc-select--has-value",o.length>0),this.labelEl){const e=this.hasAttribute("required")?'<span class="designbase-wc-select__required" aria-hidden="true">*</span>':"";this.labelEl.innerHTML=a?`${this.escape(a)}${e}`:"",this.labelEl.hidden=!a}this.dropdown.className=["designbase-wc-select__dropdown",`designbase-wc-select__dropdown--${i}`,`designbase-wc-select__dropdown--${t}`,this.open&&"designbase-wc-select__dropdown--open"].filter(Boolean).join(" "),this.optionsEl.style.maxHeight=`${n}px`,this.searchWrap&&(this.searchWrap.hidden=!this.searchable);const d=`${c}-helper`,u=`${c}-error`;h&&l?(this.errorEl.id=u,this.errorEl.textContent=l,this.errorEl.hidden=!1,this.helperEl.hidden=!0,this.trigger.setAttribute("aria-describedby",u),this.trigger.setAttribute("aria-invalid","true")):r?(this.helperEl.id=d,this.helperEl.textContent=r,this.helperEl.hidden=!1,this.errorEl.hidden=!0,this.trigger.setAttribute("aria-describedby",d),this.trigger.removeAttribute("aria-invalid")):(this.helperEl.hidden=!0,this.errorEl.hidden=!0,this.trigger.removeAttribute("aria-describedby"),this.trigger.removeAttribute("aria-invalid")),this.hasAttribute("disabled")||this.hasAttribute("readonly")?this.trigger.tabIndex=-1:this.trigger.tabIndex=0,this.syncOpenState(),this.syncTrigger(),this.syncOptions(),this.syncIndicatorIcons()}syncOpenState(){this.trigger&&this.dropdown&&this.chevronEl&&(this.trigger.setAttribute("aria-expanded",String(this.open)),this.classList.toggle("designbase-wc-select--open",this.open),this.dropdown.classList.toggle("designbase-wc-select__dropdown--open",this.open),this.syncIndicatorIcons())}syncTrigger(){if(!this.valueEl||!this.clearButton)return;const e=this.parseOptions(),s=this.parseSelectedValues(),i=this.getAttribute("placeholder")||"선택하세요",n=s.length>0,a=n&&this.showClearButton&&!this.hasAttribute("disabled")&&!this.hasAttribute("readonly");if(this.valueEl.replaceChildren(),this.multiple)if(0===s.length){const e=document.createElement("span");e.className="designbase-wc-select__placeholder",e.textContent=i,this.valueEl.appendChild(e)}else{const i=document.createElement("div");i.className="designbase-wc-select__tags",s.forEach(n=>{const a=e.find(e=>e.value===n),r=document.createElement("span");r.className="designbase-wc-select__tag";const l=document.createElement("span");l.className="designbase-wc-select__tag-label",l.textContent=a?.label||n;const h=document.createElement("button");h.type="button",h.className="designbase-wc-select__tag-remove",h.setAttribute("aria-label",`${a?.label||n} 제거`),h.appendChild(t("close",12)),h.addEventListener("click",e=>{e.stopPropagation();const t=s.filter(e=>e!==n);this.setSelectedValues(t),this.syncTrigger(),this.syncOptions(),this.dispatchChange(t)}),r.append(l,h),i.appendChild(r)}),this.valueEl.appendChild(i)}else{const t=document.createElement("span");t.className="designbase-wc-select__single-value";const a=e.find(e=>e.value===s[0]);t.textContent=n?a?.label||s[0]:i,n||t.classList.add("designbase-wc-select__placeholder"),this.valueEl.appendChild(t)}this.clearButton.hidden=!a,this.clearButton.setAttribute("aria-hidden",a?"false":"true"),this.classList.toggle("designbase-wc-select--has-value",n)}syncOptions(){if(!this.optionsEl)return;const e=this.getFilteredOptions(),t=this.parseSelectedValues(),s=this.getAttribute("id")||"db-select";if(this.optionsEl.replaceChildren(),0===e.length){const e=document.createElement("div");return e.className="designbase-wc-select__no-options",e.textContent=this.searchTerm?"검색 결과가 없습니다.":"옵션이 없습니다.",void this.optionsEl.appendChild(e)}e.forEach((e,i)=>{const n=t.includes(e.value),a=i===this.focusedIndex,r=document.createElement("div");if(r.className=["designbase-wc-select__option",n&&"designbase-wc-select__option--selected",a&&"designbase-wc-select__option--focused",e.disabled&&"designbase-wc-select__option--disabled"].filter(Boolean).join(" "),r.id=`${s}-option-${i}`,r.setAttribute("role","option"),r.setAttribute("aria-selected",String(n)),r.addEventListener("click",()=>this.selectOption(e)),this.multiple){const t=document.createElement("div");t.className="designbase-wc-select__checkbox";const s=document.createElement("db-checkbox");s.setAttribute("size","s"),s.setAttribute("has-label","false"),n&&s.setAttribute("checked",""),e.disabled&&s.setAttribute("disabled",""),t.appendChild(s),r.appendChild(t)}const l=document.createElement("span");l.className="designbase-wc-select__option-label",l.textContent=e.label,r.appendChild(l),this.optionsEl.appendChild(r)}),this.focusedIndex>=0?this.trigger?.setAttribute("aria-activedescendant",`${s}-option-${this.focusedIndex}`):this.trigger?.removeAttribute("aria-activedescendant")}escape(e){return e.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[e]||e))}}DbSelect.formAssociated=!0,customElements.get("db-select")||customElements.define("db-select",DbSelect);export{DbSelect};
|