@designbasekorea/ui-wc 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/lottie-e273b936.js +17032 -0
- package/dist/esm/components/animation-background/canvas-controller.js +121 -1
- package/dist/esm/components/animation-background/controls.js +180 -1
- package/dist/esm/components/animation-background/graphite-controller.js +196 -1
- package/dist/esm/components/animation-background/graphite-presets.js +42 -1
- package/dist/esm/components/animation-background/graphite-shader.js +111 -1
- package/dist/esm/components/animation-background/layers.js +369 -1
- package/dist/esm/components/animation-background/lumina-presets.js +53 -1
- package/dist/esm/components/animation-background/lumina-shaders.js +181 -1
- package/dist/esm/components/animation-background/lumina-utils.js +60 -1
- package/dist/esm/components/animation-background/particle-defaults.js +36 -1
- package/dist/esm/components/animation-background/renderers.js +167 -1
- package/dist/esm/components/animation-background/shader-controller.js +154 -1
- package/dist/esm/components/color-picker-utils.js +134 -1
- package/dist/esm/components/date-picker-utils.js +140 -1
- package/dist/esm/components/db-accordion.js +304 -1
- package/dist/esm/components/db-ad-banner.js +455 -1
- package/dist/esm/components/db-alert.js +149 -1
- package/dist/esm/components/db-animation-background.js +486 -1
- package/dist/esm/components/db-animation-text.js +601 -1
- package/dist/esm/components/db-app-badge.js +88 -1
- package/dist/esm/components/db-audio-player.js +752 -1
- package/dist/esm/components/db-avatar.js +188 -1
- package/dist/esm/components/db-backdrop.js +139 -1
- package/dist/esm/components/db-badge.js +91 -1
- package/dist/esm/components/db-banner.js +188 -1
- package/dist/esm/components/db-bottom-navigation.js +146 -1
- package/dist/esm/components/db-bottom-sheet.js +481 -1
- package/dist/esm/components/db-breadcrumbs.js +329 -1
- package/dist/esm/components/db-button.js +316 -1
- package/dist/esm/components/db-calendar.js +675 -1
- package/dist/esm/components/db-card.js +265 -1
- package/dist/esm/components/db-carousel.js +264 -1
- package/dist/esm/components/db-checkbox.js +202 -1
- package/dist/esm/components/db-chip.js +104 -1
- package/dist/esm/components/db-code-block.js +304 -1
- package/dist/esm/components/db-color-picker.js +746 -1
- package/dist/esm/components/db-confirm.js +191 -1
- package/dist/esm/components/db-container.js +39 -1
- package/dist/esm/components/db-context-menu.js +265 -1
- package/dist/esm/components/db-countdown.js +146 -1
- package/dist/esm/components/db-cursor-follower.js +173 -1
- package/dist/esm/components/db-date-picker.js +837 -1
- package/dist/esm/components/db-divider.js +66 -1
- package/dist/esm/components/db-drawer.js +245 -1
- package/dist/esm/components/db-dropdown.js +493 -1
- package/dist/esm/components/db-dropzone.js +266 -1
- package/dist/esm/components/db-empty-state.js +97 -1
- package/dist/esm/components/db-file-uploader.js +256 -1
- package/dist/esm/components/db-floating-action-button.js +139 -1
- package/dist/esm/components/db-footer.js +385 -1
- package/dist/esm/components/db-form.js +566 -1
- package/dist/esm/components/db-gantt.js +882 -1
- package/dist/esm/components/db-gradient.js +133 -1
- package/dist/esm/components/db-grid-background.js +909 -1
- package/dist/esm/components/db-grid.js +73 -1
- package/dist/esm/components/db-icons.js +82 -1
- package/dist/esm/components/db-image-list.js +214 -1
- package/dist/esm/components/db-image-placeholder.js +96 -1
- package/dist/esm/components/db-image.js +289 -1
- package/dist/esm/components/db-indicator.js +517 -1
- package/dist/esm/components/db-input.js +420 -1
- package/dist/esm/components/db-kanban.js +538 -1
- package/dist/esm/components/db-label.js +66 -1
- package/dist/esm/components/db-lightbox.js +372 -1
- package/dist/esm/components/db-list.js +340 -1
- package/dist/esm/components/db-logo-svg.js +72 -1
- package/dist/esm/components/db-logo.js +106 -1
- package/dist/esm/components/db-lottie.js +109 -1
- package/dist/esm/components/db-markdown-editor.js +458 -1
- package/dist/esm/components/db-marquee.js +402 -1
- package/dist/esm/components/db-masonry.js +94 -1
- package/dist/esm/components/db-menu-item.js +211 -1
- package/dist/esm/components/db-modal.js +522 -1
- package/dist/esm/components/db-navbar.js +680 -1
- package/dist/esm/components/db-onboarding-modal.js +322 -1
- package/dist/esm/components/db-page-header.js +312 -1
- package/dist/esm/components/db-pagination.js +271 -1
- package/dist/esm/components/db-popover.js +580 -1
- package/dist/esm/components/db-progress-step.js +166 -1
- package/dist/esm/components/db-progress.js +171 -1
- package/dist/esm/components/db-progressbar.js +72 -1
- package/dist/esm/components/db-radio.js +172 -1
- package/dist/esm/components/db-random-gradient.js +121 -1
- package/dist/esm/components/db-range-slider.js +811 -1
- package/dist/esm/components/db-rating.js +325 -1
- package/dist/esm/components/db-reorder.js +286 -1
- package/dist/esm/components/db-resizable-panels.js +282 -1
- package/dist/esm/components/db-scroll-area.js +126 -1
- package/dist/esm/components/db-search-bar.js +668 -1
- package/dist/esm/components/db-section-app-download.js +101 -1
- package/dist/esm/components/db-section-contact.js +102 -1
- package/dist/esm/components/db-section-cta.js +150 -1
- package/dist/esm/components/db-section-faq.js +120 -1
- package/dist/esm/components/db-section-feature-grid.js +137 -1
- package/dist/esm/components/db-section-feature.js +179 -1
- package/dist/esm/components/db-section-hero.js +243 -1
- package/dist/esm/components/db-section-logo-cloud.js +138 -1
- package/dist/esm/components/db-section-pricing.js +166 -1
- package/dist/esm/components/db-section-stats.js +129 -1
- package/dist/esm/components/db-section-testimonials.js +252 -1
- package/dist/esm/components/db-section.js +385 -1
- package/dist/esm/components/db-segment-control.js +231 -1
- package/dist/esm/components/db-select.js +571 -1
- package/dist/esm/components/db-share-icons.js +40 -1
- package/dist/esm/components/db-share.js +489 -1
- package/dist/esm/components/db-sidebar.js +1068 -1
- package/dist/esm/components/db-skeleton.js +94 -1
- package/dist/esm/components/db-spinner.js +102 -1
- package/dist/esm/components/db-split-view.js +297 -1
- package/dist/esm/components/db-stack.js +46 -1
- package/dist/esm/components/db-stat.js +218 -1
- package/dist/esm/components/db-stepper.js +398 -1
- package/dist/esm/components/db-table.js +412 -1
- package/dist/esm/components/db-tabs.js +335 -1
- package/dist/esm/components/db-testimonial.js +162 -1
- package/dist/esm/components/db-textarea.js +233 -1
- package/dist/esm/components/db-time-picker.js +523 -1
- package/dist/esm/components/db-timeline.js +174 -1
- package/dist/esm/components/db-toast.js +158 -1
- package/dist/esm/components/db-toggle.js +162 -1
- package/dist/esm/components/db-toolbar.js +94 -1
- package/dist/esm/components/db-tooltip.js +440 -1
- package/dist/esm/components/db-top-banner.js +121 -1
- package/dist/esm/components/db-tutorial.js +324 -1
- package/dist/esm/components/db-video-player.js +503 -1
- package/dist/esm/components/db-youtube-player.js +194 -1
- package/dist/esm/components/highlight-code.js +65 -1
- package/dist/esm/components/input-validation.js +50 -1
- package/dist/esm/components/marketing-block-host-utils.js +9 -1
- package/dist/esm/components/number-scrub.js +117 -1
- package/dist/esm/components/random-gradient-palettes.js +67 -1
- package/dist/esm/components/section-block-header-utils.js +48 -1
- package/dist/esm/helpers/confirm.js +52 -1
- package/dist/esm/helpers/toast.js +73 -1
- package/dist/esm/index.js +111 -1
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +235 -1
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +31 -1
- package/dist/esm/node_modules/prismjs/components/prism-css.js +64 -1
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +172 -1
- package/dist/esm/node_modules/prismjs/components/prism-json.js +27 -1
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +143 -1
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +186 -1
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +81 -1
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +15 -1
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +60 -1
- package/dist/index.cjs +55414 -1
- package/dist/index.css +1 -1
- package/dist/index.esm.js +38284 -1
- package/dist/react/chunks/lottie-72a4c6d4.js +17032 -0
- package/dist/react/index.cjs +56503 -1
- package/dist/react/index.esm.js +39373 -1
- package/package.json +1 -1
- package/dist/chunks/lottie-2637aa0f.js +0 -1
- package/dist/react/chunks/lottie-14e7addb.js +0 -1
|
@@ -1 +1,420 @@
|
|
|
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};
|
|
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 };
|