@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,420 +1 @@
|
|
|
1
|
-
import { getDbComponentIconSize, createDbIcon } from './db-icons.js';
|
|
2
|
-
import { getPasswordValidation } from './input-validation.js';
|
|
3
|
-
import { attachNumberScrub, readNumericAttribute } from './number-scrub.js';
|
|
4
|
-
|
|
5
|
-
const TYPES = ['text', 'email', 'password', 'url', 'search', 'tel', 'number'];
|
|
6
|
-
const SIZES = ['s', 'm', 'l'];
|
|
7
|
-
const ICON_NAMES = new Set([
|
|
8
|
-
'arrow-bar-left', 'arrow-bar-right', 'caret-down-filled', 'chevron-down', 'chevron-left',
|
|
9
|
-
'chevron-right', 'circle-checked', 'close', 'error-filled', 'edit', 'hide', 'info-filled',
|
|
10
|
-
'lock', 'mail', 'plus', 'search', 'share-alt', 'show', 'sparkle', 'trash', 'user', 'warning-filled',
|
|
11
|
-
]);
|
|
12
|
-
class DbInput extends HTMLElement {
|
|
13
|
-
constructor() {
|
|
14
|
-
super(...arguments);
|
|
15
|
-
this.passwordVisible = false;
|
|
16
|
-
this.isFocused = false;
|
|
17
|
-
this.touched = false;
|
|
18
|
-
this.isScrubbing = false;
|
|
19
|
-
this.handleInput = (event) => {
|
|
20
|
-
event.stopPropagation();
|
|
21
|
-
const target = event.target;
|
|
22
|
-
this.updateDynamicUI();
|
|
23
|
-
this.dispatchEvent(new InputEvent('input', { bubbles: true, composed: true }));
|
|
24
|
-
this.dispatchEvent(new CustomEvent('db-input', {
|
|
25
|
-
detail: { value: target.value, nativeEvent: event },
|
|
26
|
-
bubbles: true,
|
|
27
|
-
composed: true,
|
|
28
|
-
}));
|
|
29
|
-
};
|
|
30
|
-
this.handleChange = (event) => {
|
|
31
|
-
event.stopPropagation();
|
|
32
|
-
const target = event.target;
|
|
33
|
-
this.dispatchEvent(new Event('change', { bubbles: true }));
|
|
34
|
-
this.dispatchEvent(new CustomEvent('db-change', {
|
|
35
|
-
detail: { value: target.value, nativeEvent: event },
|
|
36
|
-
bubbles: true,
|
|
37
|
-
composed: true,
|
|
38
|
-
}));
|
|
39
|
-
};
|
|
40
|
-
this.handleFocus = (event) => {
|
|
41
|
-
this.isFocused = true;
|
|
42
|
-
this.updateDynamicUI();
|
|
43
|
-
this.dispatchEvent(new CustomEvent('db-focus', {
|
|
44
|
-
detail: { nativeEvent: event },
|
|
45
|
-
bubbles: true,
|
|
46
|
-
composed: true,
|
|
47
|
-
}));
|
|
48
|
-
};
|
|
49
|
-
this.handleBlur = (event) => {
|
|
50
|
-
this.isFocused = false;
|
|
51
|
-
this.touched = true;
|
|
52
|
-
this.updateDynamicUI();
|
|
53
|
-
this.dispatchEvent(new CustomEvent('db-blur', {
|
|
54
|
-
detail: { nativeEvent: event },
|
|
55
|
-
bubbles: true,
|
|
56
|
-
composed: true,
|
|
57
|
-
}));
|
|
58
|
-
};
|
|
59
|
-
this.handlePasswordToggle = () => {
|
|
60
|
-
this.passwordVisible = !this.passwordVisible;
|
|
61
|
-
this.render();
|
|
62
|
-
};
|
|
63
|
-
this.handleSearchClear = () => {
|
|
64
|
-
if (!this.input)
|
|
65
|
-
return;
|
|
66
|
-
this.input.value = '';
|
|
67
|
-
this.setAttribute('value', '');
|
|
68
|
-
this.input.focus();
|
|
69
|
-
this.updateDynamicUI();
|
|
70
|
-
this.dispatchEvent(new CustomEvent('db-input', {
|
|
71
|
-
detail: { value: '', nativeEvent: null },
|
|
72
|
-
bubbles: true,
|
|
73
|
-
composed: true,
|
|
74
|
-
}));
|
|
75
|
-
this.dispatchEvent(new CustomEvent('db-clear', {
|
|
76
|
-
bubbles: true,
|
|
77
|
-
composed: true,
|
|
78
|
-
}));
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
static get observedAttributes() {
|
|
82
|
-
return [
|
|
83
|
-
'type',
|
|
84
|
-
'label',
|
|
85
|
-
'placeholder',
|
|
86
|
-
'value',
|
|
87
|
-
'default-value',
|
|
88
|
-
'size',
|
|
89
|
-
'disabled',
|
|
90
|
-
'readonly',
|
|
91
|
-
'required',
|
|
92
|
-
'error',
|
|
93
|
-
'error-message',
|
|
94
|
-
'helper-text',
|
|
95
|
-
'full-width',
|
|
96
|
-
'name',
|
|
97
|
-
'start-icon',
|
|
98
|
-
'end-icon',
|
|
99
|
-
'validate',
|
|
100
|
-
'validation-visibility',
|
|
101
|
-
'validate-on-blur',
|
|
102
|
-
'password-min-length',
|
|
103
|
-
'scrubbable',
|
|
104
|
-
'scrub-step',
|
|
105
|
-
'scrub-sensitivity',
|
|
106
|
-
'min',
|
|
107
|
-
'max',
|
|
108
|
-
'step',
|
|
109
|
-
];
|
|
110
|
-
}
|
|
111
|
-
get value() {
|
|
112
|
-
return this.input?.value ?? this.getAttribute('value') ?? '';
|
|
113
|
-
}
|
|
114
|
-
set value(value) {
|
|
115
|
-
this.setAttribute('value', value);
|
|
116
|
-
if (this.input)
|
|
117
|
-
this.input.value = value;
|
|
118
|
-
this.updateDynamicUI();
|
|
119
|
-
}
|
|
120
|
-
get type() {
|
|
121
|
-
return this.getAttribute('type') || 'text';
|
|
122
|
-
}
|
|
123
|
-
set type(value) {
|
|
124
|
-
this.setAttribute('type', value);
|
|
125
|
-
}
|
|
126
|
-
get size() {
|
|
127
|
-
return this.getAttribute('size') || 'm';
|
|
128
|
-
}
|
|
129
|
-
set size(value) {
|
|
130
|
-
this.setAttribute('size', value);
|
|
131
|
-
}
|
|
132
|
-
get disabled() {
|
|
133
|
-
return this.hasAttribute('disabled');
|
|
134
|
-
}
|
|
135
|
-
set disabled(value) {
|
|
136
|
-
this.toggleAttribute('disabled', value);
|
|
137
|
-
}
|
|
138
|
-
get readOnly() {
|
|
139
|
-
return this.hasAttribute('readonly');
|
|
140
|
-
}
|
|
141
|
-
set readOnly(value) {
|
|
142
|
-
this.toggleAttribute('readonly', value);
|
|
143
|
-
}
|
|
144
|
-
connectedCallback() {
|
|
145
|
-
this.render();
|
|
146
|
-
}
|
|
147
|
-
disconnectedCallback() {
|
|
148
|
-
this.detachScrub?.();
|
|
149
|
-
this.detachScrub = undefined;
|
|
150
|
-
}
|
|
151
|
-
attributeChangedCallback(name) {
|
|
152
|
-
if (name === 'value' && this.isScrubbing)
|
|
153
|
-
return;
|
|
154
|
-
if (name === 'value' && this.input) {
|
|
155
|
-
const next = this.getAttribute('value') ?? '';
|
|
156
|
-
if (this.input.value !== next)
|
|
157
|
-
this.input.value = next;
|
|
158
|
-
this.updateDynamicUI();
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
this.render();
|
|
162
|
-
}
|
|
163
|
-
focus() {
|
|
164
|
-
this.input?.focus();
|
|
165
|
-
}
|
|
166
|
-
get passwordMinLength() {
|
|
167
|
-
return Number(this.getAttribute('password-min-length') || 8);
|
|
168
|
-
}
|
|
169
|
-
get validationVisibility() {
|
|
170
|
-
return this.getAttribute('validation-visibility') || 'focus';
|
|
171
|
-
}
|
|
172
|
-
get validateOnBlur() {
|
|
173
|
-
return !this.hasAttribute('validate-on-blur') || this.getAttribute('validate-on-blur') !== 'false';
|
|
174
|
-
}
|
|
175
|
-
get isValidationEnabled() {
|
|
176
|
-
return this.hasAttribute('validate');
|
|
177
|
-
}
|
|
178
|
-
getIconSize() {
|
|
179
|
-
return getDbComponentIconSize(this.size);
|
|
180
|
-
}
|
|
181
|
-
resolveIconName(attribute) {
|
|
182
|
-
const value = this.getAttribute(attribute);
|
|
183
|
-
if (value && ICON_NAMES.has(value))
|
|
184
|
-
return value;
|
|
185
|
-
return undefined;
|
|
186
|
-
}
|
|
187
|
-
resolveStartIcon() {
|
|
188
|
-
const explicit = this.resolveIconName('start-icon');
|
|
189
|
-
if (explicit)
|
|
190
|
-
return explicit;
|
|
191
|
-
if (this.type === 'search')
|
|
192
|
-
return 'search';
|
|
193
|
-
return undefined;
|
|
194
|
-
}
|
|
195
|
-
getCurrentValue() {
|
|
196
|
-
return this.input?.value ?? this.getAttribute('value') ?? this.getAttribute('default-value') ?? '';
|
|
197
|
-
}
|
|
198
|
-
render() {
|
|
199
|
-
const value = this.getCurrentValue();
|
|
200
|
-
const type = TYPES.includes(this.type) ? this.type : 'text';
|
|
201
|
-
const isSearch = type === 'search';
|
|
202
|
-
const isPassword = type === 'password';
|
|
203
|
-
const actualType = isPassword && this.passwordVisible ? 'text' : isSearch ? 'text' : type;
|
|
204
|
-
const label = this.getAttribute('label') || '';
|
|
205
|
-
const helperText = this.getAttribute('helper-text') || '';
|
|
206
|
-
const errorMessage = this.getAttribute('error-message') || '';
|
|
207
|
-
const hasError = this.hasAttribute('error');
|
|
208
|
-
const startIcon = this.resolveStartIcon();
|
|
209
|
-
const endIcon = this.resolveIconName('end-icon');
|
|
210
|
-
this.classList.add('designbase-wc-input');
|
|
211
|
-
SIZES.forEach((size) => this.classList.remove(`designbase-wc-input--${size}`));
|
|
212
|
-
this.classList.add(`designbase-wc-input--${SIZES.includes(this.size) ? this.size : 'm'}`);
|
|
213
|
-
this.classList.toggle('designbase-wc-input--error', hasError);
|
|
214
|
-
this.classList.toggle('designbase-wc-input--disabled', this.disabled);
|
|
215
|
-
this.classList.toggle('designbase-wc-input--readonly', this.readOnly);
|
|
216
|
-
this.classList.toggle('designbase-wc-input--full-width', this.hasAttribute('full-width'));
|
|
217
|
-
this.classList.toggle('designbase-wc-input--with-start-icon', Boolean(startIcon));
|
|
218
|
-
const showSearchClear = isSearch && value.length > 0 && !this.disabled && !this.readOnly;
|
|
219
|
-
this.classList.toggle('designbase-wc-input--with-end-icon', Boolean(endIcon && !isPassword && !isSearch) || isPassword || showSearchClear);
|
|
220
|
-
this.classList.toggle('designbase-wc-input--with-password-toggle', isPassword);
|
|
221
|
-
this.classList.toggle('designbase-wc-input--with-search-clear', showSearchClear);
|
|
222
|
-
const isScrubbable = this.hasAttribute('scrubbable') && type === 'number' && !this.disabled && !this.readOnly;
|
|
223
|
-
this.classList.toggle('designbase-wc-input--scrubbable', isScrubbable);
|
|
224
|
-
this.classList.toggle('designbase-wc-input--scrubbing', this.isScrubbing);
|
|
225
|
-
const id = this.getAttribute('id') || `db-input-${Math.random().toString(36).slice(2)}`;
|
|
226
|
-
if (!this.hasAttribute('id'))
|
|
227
|
-
this.setAttribute('id', id);
|
|
228
|
-
const fieldId = `${id}-field`;
|
|
229
|
-
const helperId = `${id}-helper`;
|
|
230
|
-
const errorId = `${id}-error`;
|
|
231
|
-
const validationId = `${id}-validation`;
|
|
232
|
-
const min = this.getAttribute('min');
|
|
233
|
-
const max = this.getAttribute('max');
|
|
234
|
-
const step = this.getAttribute('step');
|
|
235
|
-
this.innerHTML = `
|
|
236
|
-
${label ? `<label class="designbase-wc-input__label" for="${fieldId}">${this.escape(label)}${this.hasAttribute('required') ? '<span aria-hidden="true"> *</span>' : ''}</label>` : ''}
|
|
237
|
-
<span class="designbase-wc-input__wrapper">
|
|
238
|
-
${startIcon ? '<span class="designbase-wc-input__start-icon" aria-hidden="true"></span>' : ''}
|
|
239
|
-
<input
|
|
240
|
-
id="${fieldId}"
|
|
241
|
-
class="designbase-wc-input__field"
|
|
242
|
-
type="${actualType}"
|
|
243
|
-
value="${this.escape(value)}"
|
|
244
|
-
placeholder="${this.escape(this.getAttribute('placeholder') || '')}"
|
|
245
|
-
${isSearch ? 'role="searchbox"' : ''}
|
|
246
|
-
${this.getAttribute('name') ? `name="${this.escape(this.getAttribute('name') || '')}"` : ''}
|
|
247
|
-
${this.disabled ? 'disabled' : ''}
|
|
248
|
-
${this.readOnly ? 'readonly' : ''}
|
|
249
|
-
${this.hasAttribute('required') ? 'required' : ''}
|
|
250
|
-
${min !== null ? `min="${this.escape(min)}"` : ''}
|
|
251
|
-
${max !== null ? `max="${this.escape(max)}"` : ''}
|
|
252
|
-
${step !== null ? `step="${this.escape(step)}"` : ''}
|
|
253
|
-
aria-invalid="${String(hasError)}"
|
|
254
|
-
/>
|
|
255
|
-
${isPassword ? `<button type="button" class="designbase-wc-input__password-toggle" ${this.disabled ? 'disabled' : ''} aria-label="${this.passwordVisible ? '비밀번호 숨기기' : '비밀번호 보기'}"></button>` : ''}
|
|
256
|
-
${isSearch ? `<button type="button" class="designbase-wc-input__clear-button" hidden aria-label="검색어 지우기"></button>` : ''}
|
|
257
|
-
${endIcon && !isPassword && !isSearch ? '<span class="designbase-wc-input__end-icon" aria-hidden="true"></span>' : ''}
|
|
258
|
-
</span>
|
|
259
|
-
${this.isValidationEnabled && isPassword ? `<div class="designbase-wc-input__validation-slot" id="${validationId}"></div>` : ''}
|
|
260
|
-
${helperText && !hasError ? `<p id="${helperId}" class="designbase-wc-input__helper-text">${this.escape(helperText)}</p>` : ''}
|
|
261
|
-
${hasError && errorMessage ? `<p id="${errorId}" class="designbase-wc-input__error-message">${this.escape(errorMessage)}</p>` : ''}
|
|
262
|
-
`;
|
|
263
|
-
this.mountIcons(startIcon, endIcon && !isPassword && !isSearch ? endIcon : undefined, isPassword);
|
|
264
|
-
this.input = this.querySelector('input') || undefined;
|
|
265
|
-
if (this.input) {
|
|
266
|
-
this.input.value = value;
|
|
267
|
-
this.input.addEventListener('input', this.handleInput);
|
|
268
|
-
this.input.addEventListener('change', this.handleChange);
|
|
269
|
-
this.input.addEventListener('focus', this.handleFocus);
|
|
270
|
-
this.input.addEventListener('blur', this.handleBlur);
|
|
271
|
-
}
|
|
272
|
-
this.querySelector('.designbase-wc-input__password-toggle')
|
|
273
|
-
?.addEventListener('click', this.handlePasswordToggle);
|
|
274
|
-
this.querySelector('.designbase-wc-input__clear-button')
|
|
275
|
-
?.addEventListener('click', this.handleSearchClear);
|
|
276
|
-
this.detachScrub?.();
|
|
277
|
-
this.detachScrub = undefined;
|
|
278
|
-
if (isScrubbable && this.input) {
|
|
279
|
-
this.detachScrub = attachNumberScrub(this.input, {
|
|
280
|
-
isEnabled: () => this.hasAttribute('scrubbable') && this.type === 'number',
|
|
281
|
-
isInteractive: () => !this.disabled && !this.readOnly,
|
|
282
|
-
getValue: () => this.getCurrentValue(),
|
|
283
|
-
getStep: () => readNumericAttribute(this, 'scrub-step') ?? readNumericAttribute(this, 'step') ?? 1,
|
|
284
|
-
getMin: () => readNumericAttribute(this, 'min'),
|
|
285
|
-
getMax: () => readNumericAttribute(this, 'max'),
|
|
286
|
-
getSensitivity: () => readNumericAttribute(this, 'scrub-sensitivity') ?? 4,
|
|
287
|
-
onValueChange: (nextValue) => this.applyScrubValue(nextValue),
|
|
288
|
-
onScrubStateChange: (active) => {
|
|
289
|
-
this.isScrubbing = active;
|
|
290
|
-
this.classList.toggle('designbase-wc-input--scrubbing', active);
|
|
291
|
-
if (!active && this.input) {
|
|
292
|
-
this.dispatchEvent(new CustomEvent('db-change', {
|
|
293
|
-
detail: { value: this.input.value, nativeEvent: null },
|
|
294
|
-
bubbles: true,
|
|
295
|
-
composed: true,
|
|
296
|
-
}));
|
|
297
|
-
}
|
|
298
|
-
},
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
this.updateDynamicUI();
|
|
302
|
-
}
|
|
303
|
-
mountIcons(startIcon, endIcon, isPassword = false) {
|
|
304
|
-
const iconSize = this.getIconSize();
|
|
305
|
-
if (startIcon) {
|
|
306
|
-
const host = this.querySelector('.designbase-wc-input__start-icon');
|
|
307
|
-
host?.replaceChildren(createDbIcon(startIcon, iconSize));
|
|
308
|
-
}
|
|
309
|
-
if (endIcon) {
|
|
310
|
-
const host = this.querySelector('.designbase-wc-input__end-icon');
|
|
311
|
-
host?.replaceChildren(createDbIcon(endIcon, iconSize));
|
|
312
|
-
}
|
|
313
|
-
if (isPassword) {
|
|
314
|
-
const toggle = this.querySelector('.designbase-wc-input__password-toggle');
|
|
315
|
-
toggle?.replaceChildren(createDbIcon(this.passwordVisible ? 'hide' : 'show', iconSize));
|
|
316
|
-
}
|
|
317
|
-
const clearButton = this.querySelector('.designbase-wc-input__clear-button');
|
|
318
|
-
clearButton?.replaceChildren(createDbIcon('close', iconSize));
|
|
319
|
-
}
|
|
320
|
-
shouldShowPasswordValidation(value) {
|
|
321
|
-
if (!this.isValidationEnabled || this.type !== 'password')
|
|
322
|
-
return false;
|
|
323
|
-
if (this.validationVisibility === 'never')
|
|
324
|
-
return false;
|
|
325
|
-
if (this.validationVisibility === 'always')
|
|
326
|
-
return true;
|
|
327
|
-
return this.isFocused || value.length > 0;
|
|
328
|
-
}
|
|
329
|
-
renderValidationMarkup(value) {
|
|
330
|
-
const validation = getPasswordValidation(value, this.passwordMinLength);
|
|
331
|
-
const segments = Array.from({ length: 4 }, (_, index) => {
|
|
332
|
-
const active = index < validation.score;
|
|
333
|
-
const levelClass = active ? ` designbase-wc-input__password-strength-segment--${validation.level}` : '';
|
|
334
|
-
return `<span class="designbase-wc-input__password-strength-segment${levelClass}"></span>`;
|
|
335
|
-
}).join('');
|
|
336
|
-
const requirements = validation.requirements.map((requirement) => {
|
|
337
|
-
const metClass = requirement.met ? ' designbase-wc-input__password-requirement--met' : '';
|
|
338
|
-
const icon = requirement.met
|
|
339
|
-
? '<span class="designbase-wc-input__password-requirement-icon" aria-hidden="true"></span>'
|
|
340
|
-
: '<span class="designbase-wc-input__password-requirement-icon" aria-hidden="true"><span class="designbase-wc-input__password-requirement-dot"></span></span>';
|
|
341
|
-
return `<li class="designbase-wc-input__password-requirement${metClass}">${icon}<span class="designbase-wc-input__password-requirement-label">${this.escape(requirement.label)}</span></li>`;
|
|
342
|
-
}).join('');
|
|
343
|
-
return `
|
|
344
|
-
<div class="designbase-wc-input__validation" aria-live="polite">
|
|
345
|
-
<div class="designbase-wc-input__password-strength">
|
|
346
|
-
<div class="designbase-wc-input__password-strength-bar" role="progressbar" aria-valuemin="0" aria-valuemax="4" aria-valuenow="${validation.score}" aria-label="비밀번호 강도">${segments}</div>
|
|
347
|
-
<span class="designbase-wc-input__password-strength-label designbase-wc-input__password-strength-label--${validation.level}">${validation.levelLabel}</span>
|
|
348
|
-
</div>
|
|
349
|
-
<ul class="designbase-wc-input__password-requirements">${requirements}</ul>
|
|
350
|
-
</div>
|
|
351
|
-
`;
|
|
352
|
-
}
|
|
353
|
-
updateDynamicUI() {
|
|
354
|
-
const value = this.getCurrentValue();
|
|
355
|
-
const isSearch = this.type === 'search';
|
|
356
|
-
const showSearchClear = isSearch && value.length > 0 && !this.disabled && !this.readOnly;
|
|
357
|
-
this.classList.toggle('designbase-wc-input--with-search-clear', showSearchClear);
|
|
358
|
-
const clearButton = this.querySelector('.designbase-wc-input__clear-button');
|
|
359
|
-
if (clearButton) {
|
|
360
|
-
clearButton.hidden = !showSearchClear;
|
|
361
|
-
clearButton.replaceChildren(createDbIcon('close', this.getIconSize()));
|
|
362
|
-
}
|
|
363
|
-
const validationSlot = this.querySelector('.designbase-wc-input__validation-slot');
|
|
364
|
-
if (validationSlot) {
|
|
365
|
-
if (this.shouldShowPasswordValidation(value)) {
|
|
366
|
-
validationSlot.innerHTML = this.renderValidationMarkup(value);
|
|
367
|
-
validationSlot.querySelectorAll('.designbase-wc-input__password-requirement--met .designbase-wc-input__password-requirement-icon')
|
|
368
|
-
.forEach((iconHost) => {
|
|
369
|
-
iconHost.replaceChildren(createDbIcon('circle-checked', 12));
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
validationSlot.innerHTML = '';
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (this.input) {
|
|
377
|
-
const helperId = `${this.getAttribute('id')}-helper`;
|
|
378
|
-
const errorId = `${this.getAttribute('id')}-error`;
|
|
379
|
-
const validationId = `${this.getAttribute('id')}-validation`;
|
|
380
|
-
const helperText = this.getAttribute('helper-text') || '';
|
|
381
|
-
const errorMessage = this.getAttribute('error-message') || '';
|
|
382
|
-
const hasError = this.hasAttribute('error');
|
|
383
|
-
const describedBy = [
|
|
384
|
-
helperText && !hasError ? helperId : '',
|
|
385
|
-
this.shouldShowPasswordValidation(value) ? validationId : '',
|
|
386
|
-
hasError && errorMessage ? errorId : '',
|
|
387
|
-
].filter(Boolean).join(' ') || undefined;
|
|
388
|
-
if (describedBy)
|
|
389
|
-
this.input.setAttribute('aria-describedby', describedBy);
|
|
390
|
-
else
|
|
391
|
-
this.input.removeAttribute('aria-describedby');
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
applyScrubValue(nextValue) {
|
|
395
|
-
if (!this.input)
|
|
396
|
-
return;
|
|
397
|
-
this.input.value = nextValue;
|
|
398
|
-
this.setAttribute('value', nextValue);
|
|
399
|
-
this.updateDynamicUI();
|
|
400
|
-
this.dispatchEvent(new CustomEvent('db-input', {
|
|
401
|
-
detail: { value: nextValue, nativeEvent: null },
|
|
402
|
-
bubbles: true,
|
|
403
|
-
composed: true,
|
|
404
|
-
}));
|
|
405
|
-
}
|
|
406
|
-
escape(value) {
|
|
407
|
-
return value.replace(/[&<>"']/g, (char) => ({
|
|
408
|
-
'&': '&',
|
|
409
|
-
'<': '<',
|
|
410
|
-
'>': '>',
|
|
411
|
-
'"': '"',
|
|
412
|
-
"'": ''',
|
|
413
|
-
}[char] || char));
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
if (!customElements.get('db-input')) {
|
|
417
|
-
customElements.define('db-input', DbInput);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
export { DbInput };
|
|
1
|
+
import{getDbComponentIconSize as t,createDbIcon as e}from"./db-icons.js";import{getPasswordValidation as s}from"./input-validation.js";import{attachNumberScrub as i,readNumericAttribute as n}from"./number-scrub.js";const a=["text","email","password","url","search","tel","number"],r=["s","m","l"],l=new Set(["arrow-bar-left","arrow-bar-right","caret-down-filled","chevron-down","chevron-left","chevron-right","circle-checked","close","error-filled","edit","hide","info-filled","lock","mail","plus","search","share-alt","show","sparkle","trash","user","warning-filled"]);class DbInput extends HTMLElement{constructor(){super(...arguments),this.passwordVisible=!1,this.isFocused=!1,this.touched=!1,this.isScrubbing=!1,this.handleInput=t=>{t.stopPropagation();const e=t.target;this.updateDynamicUI(),this.dispatchEvent(new InputEvent("input",{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("db-input",{detail:{value:e.value,nativeEvent:t},bubbles:!0,composed:!0}))},this.handleChange=t=>{t.stopPropagation();const e=t.target;this.dispatchEvent(new Event("change",{bubbles:!0})),this.dispatchEvent(new CustomEvent("db-change",{detail:{value:e.value,nativeEvent:t},bubbles:!0,composed:!0}))},this.handleFocus=t=>{this.isFocused=!0,this.updateDynamicUI(),this.dispatchEvent(new CustomEvent("db-focus",{detail:{nativeEvent:t},bubbles:!0,composed:!0}))},this.handleBlur=t=>{this.isFocused=!1,this.touched=!0,this.updateDynamicUI(),this.dispatchEvent(new CustomEvent("db-blur",{detail:{nativeEvent:t},bubbles:!0,composed:!0}))},this.handlePasswordToggle=()=>{this.passwordVisible=!this.passwordVisible,this.render()},this.handleSearchClear=()=>{this.input&&(this.input.value="",this.setAttribute("value",""),this.input.focus(),this.updateDynamicUI(),this.dispatchEvent(new CustomEvent("db-input",{detail:{value:"",nativeEvent:null},bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("db-clear",{bubbles:!0,composed:!0})))}}static get observedAttributes(){return["type","label","placeholder","value","default-value","size","disabled","readonly","required","error","error-message","helper-text","full-width","name","start-icon","end-icon","validate","validation-visibility","validate-on-blur","password-min-length","scrubbable","scrub-step","scrub-sensitivity","min","max","step"]}get value(){return this.input?.value??this.getAttribute("value")??""}set value(t){this.setAttribute("value",t),this.input&&(this.input.value=t),this.updateDynamicUI()}get type(){return this.getAttribute("type")||"text"}set type(t){this.setAttribute("type",t)}get size(){return this.getAttribute("size")||"m"}set size(t){this.setAttribute("size",t)}get disabled(){return this.hasAttribute("disabled")}set disabled(t){this.toggleAttribute("disabled",t)}get readOnly(){return this.hasAttribute("readonly")}set readOnly(t){this.toggleAttribute("readonly",t)}connectedCallback(){this.render()}disconnectedCallback(){this.detachScrub?.(),this.detachScrub=void 0}attributeChangedCallback(t){if("value"!==t||!this.isScrubbing){if("value"===t&&this.input){const t=this.getAttribute("value")??"";return this.input.value!==t&&(this.input.value=t),void this.updateDynamicUI()}this.render()}}focus(){this.input?.focus()}get passwordMinLength(){return Number(this.getAttribute("password-min-length")||8)}get validationVisibility(){return this.getAttribute("validation-visibility")||"focus"}get validateOnBlur(){return!this.hasAttribute("validate-on-blur")||"false"!==this.getAttribute("validate-on-blur")}get isValidationEnabled(){return this.hasAttribute("validate")}getIconSize(){return t(this.size)}resolveIconName(t){const e=this.getAttribute(t);if(e&&l.has(e))return e}resolveStartIcon(){const t=this.resolveIconName("start-icon");return t||("search"===this.type?"search":void 0)}getCurrentValue(){return this.input?.value??this.getAttribute("value")??this.getAttribute("default-value")??""}render(){const t=this.getCurrentValue(),e=a.includes(this.type)?this.type:"text",s="search"===e,l="password"===e,u=l&&this.passwordVisible||s?"text":e,d=this.getAttribute("label")||"",h=this.getAttribute("helper-text")||"",c=this.getAttribute("error-message")||"",o=this.hasAttribute("error"),b=this.resolveStartIcon(),p=this.resolveIconName("end-icon");this.classList.add("designbase-wc-input"),r.forEach(t=>this.classList.remove(`designbase-wc-input--${t}`)),this.classList.add(`designbase-wc-input--${r.includes(this.size)?this.size:"m"}`),this.classList.toggle("designbase-wc-input--error",o),this.classList.toggle("designbase-wc-input--disabled",this.disabled),this.classList.toggle("designbase-wc-input--readonly",this.readOnly),this.classList.toggle("designbase-wc-input--full-width",this.hasAttribute("full-width")),this.classList.toggle("designbase-wc-input--with-start-icon",Boolean(b));const g=s&&t.length>0&&!this.disabled&&!this.readOnly;this.classList.toggle("designbase-wc-input--with-end-icon",Boolean(p&&!l&&!s)||l||g),this.classList.toggle("designbase-wc-input--with-password-toggle",l),this.classList.toggle("designbase-wc-input--with-search-clear",g);const v=this.hasAttribute("scrubbable")&&"number"===e&&!this.disabled&&!this.readOnly;this.classList.toggle("designbase-wc-input--scrubbable",v),this.classList.toggle("designbase-wc-input--scrubbing",this.isScrubbing);const w=this.getAttribute("id")||`db-input-${Math.random().toString(36).slice(2)}`;this.hasAttribute("id")||this.setAttribute("id",w);const m=`${w}-field`,_=`${w}-helper`,y=`${w}-error`,$=`${w}-validation`,A=this.getAttribute("min"),E=this.getAttribute("max"),S=this.getAttribute("step");this.innerHTML=`\n ${d?`<label class="designbase-wc-input__label" for="${m}">${this.escape(d)}${this.hasAttribute("required")?'<span aria-hidden="true"> *</span>':""}</label>`:""}\n <span class="designbase-wc-input__wrapper">\n ${b?'<span class="designbase-wc-input__start-icon" aria-hidden="true"></span>':""}\n <input\n id="${m}"\n class="designbase-wc-input__field"\n type="${u}"\n value="${this.escape(t)}"\n placeholder="${this.escape(this.getAttribute("placeholder")||"")}"\n ${s?'role="searchbox"':""}\n ${this.getAttribute("name")?`name="${this.escape(this.getAttribute("name")||"")}"`:""}\n ${this.disabled?"disabled":""}\n ${this.readOnly?"readonly":""}\n ${this.hasAttribute("required")?"required":""}\n ${null!==A?`min="${this.escape(A)}"`:""}\n ${null!==E?`max="${this.escape(E)}"`:""}\n ${null!==S?`step="${this.escape(S)}"`:""}\n aria-invalid="${String(o)}"\n />\n ${l?`<button type="button" class="designbase-wc-input__password-toggle" ${this.disabled?"disabled":""} aria-label="${this.passwordVisible?"비밀번호 숨기기":"비밀번호 보기"}"></button>`:""}\n ${s?'<button type="button" class="designbase-wc-input__clear-button" hidden aria-label="검색어 지우기"></button>':""}\n ${!p||l||s?"":'<span class="designbase-wc-input__end-icon" aria-hidden="true"></span>'}\n </span>\n ${this.isValidationEnabled&&l?`<div class="designbase-wc-input__validation-slot" id="${$}"></div>`:""}\n ${h&&!o?`<p id="${_}" class="designbase-wc-input__helper-text">${this.escape(h)}</p>`:""}\n ${o&&c?`<p id="${y}" class="designbase-wc-input__error-message">${this.escape(c)}</p>`:""}\n `,this.mountIcons(b,!p||l||s?void 0:p,l),this.input=this.querySelector("input")||void 0,this.input&&(this.input.value=t,this.input.addEventListener("input",this.handleInput),this.input.addEventListener("change",this.handleChange),this.input.addEventListener("focus",this.handleFocus),this.input.addEventListener("blur",this.handleBlur)),this.querySelector(".designbase-wc-input__password-toggle")?.addEventListener("click",this.handlePasswordToggle),this.querySelector(".designbase-wc-input__clear-button")?.addEventListener("click",this.handleSearchClear),this.detachScrub?.(),this.detachScrub=void 0,v&&this.input&&(this.detachScrub=i(this.input,{isEnabled:()=>this.hasAttribute("scrubbable")&&"number"===this.type,isInteractive:()=>!this.disabled&&!this.readOnly,getValue:()=>this.getCurrentValue(),getStep:()=>n(this,"scrub-step")??n(this,"step")??1,getMin:()=>n(this,"min"),getMax:()=>n(this,"max"),getSensitivity:()=>n(this,"scrub-sensitivity")??4,onValueChange:t=>this.applyScrubValue(t),onScrubStateChange:t=>{this.isScrubbing=t,this.classList.toggle("designbase-wc-input--scrubbing",t),!t&&this.input&&this.dispatchEvent(new CustomEvent("db-change",{detail:{value:this.input.value,nativeEvent:null},bubbles:!0,composed:!0}))}})),this.updateDynamicUI()}mountIcons(t,s,i=!1){const n=this.getIconSize();if(t){const s=this.querySelector(".designbase-wc-input__start-icon");s?.replaceChildren(e(t,n))}if(s){const t=this.querySelector(".designbase-wc-input__end-icon");t?.replaceChildren(e(s,n))}if(i){const t=this.querySelector(".designbase-wc-input__password-toggle");t?.replaceChildren(e(this.passwordVisible?"hide":"show",n))}const a=this.querySelector(".designbase-wc-input__clear-button");a?.replaceChildren(e("close",n))}shouldShowPasswordValidation(t){return!(!this.isValidationEnabled||"password"!==this.type)&&("never"!==this.validationVisibility&&("always"===this.validationVisibility||(this.isFocused||t.length>0)))}renderValidationMarkup(t){const e=s(t,this.passwordMinLength),i=Array.from({length:4},(t,s)=>`<span class="designbase-wc-input__password-strength-segment${s<e.score?` designbase-wc-input__password-strength-segment--${e.level}`:""}"></span>`).join(""),n=e.requirements.map(t=>`<li class="designbase-wc-input__password-requirement${t.met?" designbase-wc-input__password-requirement--met":""}">${t.met?'<span class="designbase-wc-input__password-requirement-icon" aria-hidden="true"></span>':'<span class="designbase-wc-input__password-requirement-icon" aria-hidden="true"><span class="designbase-wc-input__password-requirement-dot"></span></span>'}<span class="designbase-wc-input__password-requirement-label">${this.escape(t.label)}</span></li>`).join("");return`\n <div class="designbase-wc-input__validation" aria-live="polite">\n <div class="designbase-wc-input__password-strength">\n <div class="designbase-wc-input__password-strength-bar" role="progressbar" aria-valuemin="0" aria-valuemax="4" aria-valuenow="${e.score}" aria-label="비밀번호 강도">${i}</div>\n <span class="designbase-wc-input__password-strength-label designbase-wc-input__password-strength-label--${e.level}">${e.levelLabel}</span>\n </div>\n <ul class="designbase-wc-input__password-requirements">${n}</ul>\n </div>\n `}updateDynamicUI(){const t=this.getCurrentValue(),s="search"===this.type&&t.length>0&&!this.disabled&&!this.readOnly;this.classList.toggle("designbase-wc-input--with-search-clear",s);const i=this.querySelector(".designbase-wc-input__clear-button");i&&(i.hidden=!s,i.replaceChildren(e("close",this.getIconSize())));const n=this.querySelector(".designbase-wc-input__validation-slot");if(n&&(this.shouldShowPasswordValidation(t)?(n.innerHTML=this.renderValidationMarkup(t),n.querySelectorAll(".designbase-wc-input__password-requirement--met .designbase-wc-input__password-requirement-icon").forEach(t=>{t.replaceChildren(e("circle-checked",12))})):n.innerHTML=""),this.input){const e=`${this.getAttribute("id")}-helper`,s=`${this.getAttribute("id")}-error`,i=`${this.getAttribute("id")}-validation`,n=this.getAttribute("helper-text")||"",a=this.getAttribute("error-message")||"",r=this.hasAttribute("error"),l=[n&&!r?e:"",this.shouldShowPasswordValidation(t)?i:"",r&&a?s:""].filter(Boolean).join(" ")||void 0;l?this.input.setAttribute("aria-describedby",l):this.input.removeAttribute("aria-describedby")}}applyScrubValue(t){this.input&&(this.input.value=t,this.setAttribute("value",t),this.updateDynamicUI(),this.dispatchEvent(new CustomEvent("db-input",{detail:{value:t,nativeEvent:null},bubbles:!0,composed:!0})))}escape(t){return t.replace(/[&<>"']/g,t=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[t]||t))}}customElements.get("db-input")||customElements.define("db-input",DbInput);export{DbInput};
|