@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,523 @@
|
|
|
1
|
-
import{createDbIcon as t,getDbComponentIconSize as e}from"./db-icons.js";import"./db-button.js";const i="designbase-wc-time-picker",s=["s","m","l"],n=["12h","24h","12h-with-seconds","24h-with-seconds"];class DbTimePicker extends HTMLElement{constructor(){super(...arguments),this.built=!1,this.isOpen=!1,this.hours=12,this.minutes=0,this.seconds=0,this.period="PM",this.inputText="",this.tempHours=12,this.tempMinutes=0,this.tempSeconds=0,this.tempPeriod="PM",this.boundDocumentMouseDown=t=>this.handleDocumentMouseDown(t)}static get observedAttributes(){return["value","default-value","type","format","minute-step","size","disabled","readonly","label","full-width","error","dropdown-position","open"]}connectedCallback(){this.built||this.build(),this.parseTimeString(this.getAttribute("value")??this.getAttribute("default-value")??"12:00"),this.syncInputText(),this.render(),document.addEventListener("mousedown",this.boundDocumentMouseDown)}disconnectedCallback(){document.removeEventListener("mousedown",this.boundDocumentMouseDown)}attributeChangedCallback(t){if(this.built){if("value"===t){const t=this.getAttribute("value");t&&(this.parseTimeString(t),this.syncInputText())}if("open"===t)return this.isOpen=this.hasAttribute("open"),void this.render();this.render()}}get value(){return this.getAttribute("value")||""}set value(t){t?this.setAttribute("value",t):this.removeAttribute("value")}get format(){const t=this.getAttribute("format")||"24h";return n.includes(t)?t:"24h"}set format(t){this.setAttribute("format",t)}get type(){return"modal"===this.getAttribute("type")?"modal":"dropdown"}get is12h(){return"12h"===this.format||"12h-with-seconds"===this.format}get showSeconds(){return"12h-with-seconds"===this.format||"24h-with-seconds"===this.format}get minuteStep(){const t=Number(this.getAttribute("minute-step")||"1");return Number.isFinite(t)&&t>0?t:1}get disabled(){return this.hasAttribute("disabled")}set disabled(t){this.toggleAttribute("disabled",Boolean(t))}get readonly(){return this.hasAttribute("readonly")}set readonly(t){this.toggleAttribute("readonly",Boolean(t))}build(){this.built=!0,this.labelEl=document.createElement("label"),this.labelEl.className=`${i}__label`,this.triggerEl=document.createElement("div"),this.triggerEl.className=`${i}__trigger`;const t=document.createElement("button");t.type="button",t.className=`${i}__icon-display`,t.setAttribute("aria-label","시간 선택 열기"),t.addEventListener("click",()=>this.toggleOpen()),this.inputEl=document.createElement("input"),this.inputEl.type="text",this.inputEl.className=`${i}__input`,this.inputEl.setAttribute("aria-label","시간 입력"),this.inputEl.addEventListener("click",()=>this.openPicker()),this.inputEl.addEventListener("blur",()=>this.handleInputBlur()),this.inputEl.addEventListener("input",()=>{this.inputText=this.inputEl?.value||""});const e=document.createElement("button");e.type="button",e.className=`${i}__toggle`,e.setAttribute("aria-label","시간 선택 열기"),e.addEventListener("click",()=>this.toggleOpen()),this.triggerEl.append(t,this.inputEl,e),this.dropdownEl=document.createElement("div"),this.dropdownEl.className=`${i}__dropdown`,this.dropdownEl.setAttribute("role","dialog"),this.dropdownEl.setAttribute("aria-modal","false")}pad2(t){return String(t).padStart(2,"0")}to24Hour(t,e){return"AM"===e?12===t?0:t:12===t?12:t+12}formatTimeString(t,e,i,s){const n="AM"===(s||this.period)?"오전":"오후";return this.is12h?`${n} ${this.pad2(t)}:${this.pad2(e)}${this.showSeconds?`:${this.pad2(i)}`:""}`:`${this.pad2(t)}:${this.pad2(e)}${this.showSeconds?`:${this.pad2(i)}`:""}`}toValue24(t,e,i,s){const n=this.is12h?this.to24Hour(t,s||this.period):t;return`${this.pad2(n)}:${this.pad2(e)}${this.showSeconds?`:${this.pad2(i)}`:""}`}parseTimeString(t){const e=t.trim();if(this.is12h){const t=this.showSeconds?/^(오전|오후|AM|PM)?\s*(0?[1-9]|1[0-2]):([0-5]\d):([0-5]\d)\s*(AM|PM|오전|오후)?$/i:/^(오전|오후|AM|PM)?\s*(0?[1-9]|1[0-2]):([0-5]\d)\s*(AM|PM|오전|오후)?$/i,i=e.match(t);if(i){const t=i[1],e=this.showSeconds?i[5]:i[4],s=(t||e||"AM").toUpperCase();return this.hours=parseInt(i[2],10),this.minutes=parseInt(i[3],10),this.seconds=this.showSeconds?parseInt(i[4],10):0,void(this.period="오후"===s||"PM"===s?"PM":"AM")}}else{const t=this.showSeconds?/^([01]?\d|2[0-3]):([0-5]\d):([0-5]\d)$/:/^([01]?\d|2[0-3]):([0-5]\d)$/,i=e.match(t);i&&(this.hours=parseInt(i[1],10),this.minutes=parseInt(i[2],10),this.seconds=this.showSeconds?parseInt(i[3],10):0)}}syncInputText(){this.inputText=this.formatTimeString(this.hours,this.minutes,this.seconds),this.inputEl&&(this.inputEl.value=this.inputText)}emitChange(t){this.setAttribute("value",t),this.dispatchEvent(new CustomEvent("db-change",{detail:{value:t},bubbles:!0,composed:!0}))}handleTimeChange(t,e,i=this.seconds,s){this.hours=t,this.minutes=e,this.seconds=i,s&&(this.period=s);const n=this.formatTimeString(t,e,i,s);this.inputText=n,this.inputEl&&(this.inputEl.value=n),this.emitChange(this.toValue24(t,e,i,s))}handleInputBlur(){if(!this.inputEl)return;const t=this.inputText;this.parseTimeString(this.inputEl.value);this.formatTimeString(this.hours,this.minutes,this.seconds)!==t||this.inputEl.value.trim()?this.handleTimeChange(this.hours,this.minutes,this.seconds,this.period):this.syncInputText()}openPicker(){this.disabled||this.readonly||(this.isOpen=!0,"modal"===this.type&&(this.tempHours=this.hours,this.tempMinutes=this.minutes,this.tempSeconds=this.seconds,this.tempPeriod=this.period),this.render())}closePicker(){this.isOpen=!1,this.render()}toggleOpen(){this.isOpen?this.closePicker():this.openPicker()}handleDocumentMouseDown(t){this.isOpen&&(this.contains(t.target)||this.closePicker())}createWheel(t){const{label:e,items:s,value:n,onChange:r,formatter:o}=t,h=document.createElement("div");h.className=`${i}__wheel-container`;const d=document.createElement("div");d.className=`${i}__wheel-label`,d.textContent=e,h.appendChild(d);const l=document.createElement("div");l.className=`${i}__wheel-viewport`;const a=document.createElement("div");a.className=`${i}__wheel`,a.setAttribute("role","listbox"),a.setAttribute("aria-label",e);let c=null,u=!1,p=!1,m=0,b=0;const indexOfValue=t=>s.findIndex(e=>e===t),scrollToIndex=(t,e=!0)=>{const i=40*t;u=!0,a.scrollTo({top:i,behavior:e?"smooth":"auto"}),window.setTimeout(()=>{u=!1},150)},fmt=t=>o?o(t):"number"==typeof t?this.pad2(t):String(t);s.forEach(t=>{const e=document.createElement("div");e.className=[`${i}__wheel-item`,t===n&&`${i}__wheel-item--selected`].filter(Boolean).join(" "),e.setAttribute("role","option"),e.setAttribute("aria-selected",String(t===n)),e.textContent=fmt(t),e.addEventListener("click",()=>{const e=indexOfValue(t);scrollToIndex(e,!0),t!==n&&r(t)}),a.appendChild(e)});const handleScroll=()=>{u||(c&&window.clearTimeout(c),c=window.setTimeout(()=>{const t=a.scrollTop,e=Math.round(t/40),i=Math.max(0,Math.min(s.length-1,e)),o=s[i];scrollToIndex(i,!0),o!==n&&r(o)},120))};a.addEventListener("scroll",handleScroll),a.addEventListener("pointerdown",t=>{p=!0,m=t.clientY,b=a.scrollTop,a.setPointerCapture(t.pointerId),a.style.cursor="grabbing"}),a.addEventListener("pointermove",t=>{p&&(a.scrollTop=b-(t.clientY-m))});const endDrag=t=>{p&&(p=!1,a.releasePointerCapture(t.pointerId),a.style.cursor="grab",handleScroll())};a.addEventListener("pointerup",endDrag),a.addEventListener("pointercancel",endDrag);const E=indexOfValue(n);E>=0&&requestAnimationFrame(()=>scrollToIndex(E,!1));const g=document.createElement("div");g.className=`${i}__wheel-center-indicator`,g.setAttribute("aria-hidden","true");const v=document.createElement("div");v.className=`${i}__wheel-fade wheel-fade--top`,v.setAttribute("aria-hidden","true");const w=document.createElement("div");return w.className=`${i}__wheel-fade wheel-fade--bottom`,w.setAttribute("aria-hidden","true"),l.append(a,g,v,w),h.appendChild(l),h}renderSelector(e=!1){const s=document.createElement("div");s.className=`${i}__selector`;const n=document.createElement("div");n.className=`${i}__picker-wheels`;const r=this.is12h?Array.from({length:12},(t,e)=>e+1):Array.from({length:24},(t,e)=>e),o=Array.from({length:Math.floor(60/this.minuteStep)},(t,e)=>e*this.minuteStep),h=Array.from({length:60},(t,e)=>e),d=e?this.tempHours:this.hours,l=e?this.tempMinutes:this.minutes,a=e?this.tempSeconds:this.seconds,c=e?this.tempPeriod:this.period,onChange=(t,i,s,n)=>{if(e)return this.tempHours=t,this.tempMinutes=i,this.tempSeconds=s,void(this.tempPeriod=n);this.handleTimeChange(t,i,s,n)};if(n.appendChild(this.createWheel({label:"시간",items:r,value:d,onChange:t=>onChange(t,l,a,c)})),n.appendChild(this.createWheel({label:"분",items:o,value:o.includes(l)?l:o[0],onChange:t=>onChange(d,t,a,c)})),this.showSeconds&&n.appendChild(this.createWheel({label:"초",items:h,value:a,onChange:t=>onChange(d,l,t,c)})),this.is12h&&n.appendChild(this.createWheel({label:"오전/오후",items:["AM","PM"],value:c,onChange:t=>onChange(d,l,a,t),formatter:t=>"AM"===t?"오전":"오후"})),s.appendChild(n),e)return s;const u=document.createElement("div");u.className=`${i}__dropdown-actions`;const p=document.createElement("div");p.className=`${i}__preview`,p.setAttribute("aria-live","polite"),p.appendChild(t("clock",16));const m=document.createElement("div");m.className=`${i}__preview-time`,m.textContent=this.formatTimeString(d,l,a,c),p.appendChild(m);const b=document.createElement("db-button");return b.setAttribute("variant","primary"),b.setAttribute("size","m"),b.textContent="선택",b.addEventListener("click",()=>{this.handleTimeChange(d,l,a,c),this.closePicker()}),u.append(p,b),s.appendChild(u),s}render(){const n=s.includes(this.getAttribute("size")||"m")&&this.getAttribute("size")||"m",r=this.getAttribute("dropdown-position")||"bottom-start",o=e(n);if(this.className=[i,`${i}--${n}`,this.hasAttribute("full-width")&&`${i}--full-width`,this.disabled&&`${i}--disabled`,this.readonly&&`${i}--readonly`,this.isOpen&&`${i}--open`,this.hasAttribute("error")&&`${i}--error`].filter(Boolean).join(" "),this.replaceChildren(),!(this.labelEl&&this.triggerEl&&this.inputEl&&this.dropdownEl))return;const h=this.getAttribute("label")||"";this.labelEl.textContent=h,this.labelEl.hidden=!h,this.inputEl.value=this.inputText,this.inputEl.placeholder=this.is12h?this.showSeconds?"12:00:00 PM":"12:00 PM":this.showSeconds?"12:00:00":"12:00",this.inputEl.disabled=this.disabled,this.inputEl.readOnly=this.readonly;const d=this.triggerEl.querySelector(`.${i}__icon-display`);d&&(d.innerHTML="",d.appendChild(t("clock",o)),d.disabled=this.disabled);const l=this.triggerEl.querySelector(`.${i}__toggle`);if(l&&(l.innerHTML="",l.appendChild(t("chevron-down",o)),l.disabled=this.disabled),this.dropdownEl.className=[`${i}__dropdown`,`${i}__dropdown--${r}`].filter(Boolean).join(" "),this.dropdownEl.hidden=!this.isOpen,this.isOpen&&"dropdown"===this.type&&this.dropdownEl.replaceChildren(this.renderSelector(!1)),this.append(this.labelEl,this.triggerEl),this.isOpen&&"dropdown"===this.type&&this.appendChild(this.dropdownEl),this.isOpen&&"modal"===this.type){const t=document.createElement("db-modal");t.setAttribute("open","true"),t.setAttribute("title","시간 선택"),t.setAttribute("size","s"),t.addEventListener("db-close",()=>this.closePicker());const e=this.renderSelector(!0),s=document.createElement("div");s.className=`${i}__modal-footer`;const n=document.createElement("db-button");n.setAttribute("variant","secondary"),n.setAttribute("size","m"),n.textContent="취소",n.addEventListener("click",()=>this.closePicker());const r=document.createElement("db-button");r.setAttribute("variant","primary"),r.setAttribute("size","m"),r.textContent="적용",r.addEventListener("click",()=>{this.handleTimeChange(this.tempHours,this.tempMinutes,this.tempSeconds,this.tempPeriod),this.closePicker()}),s.append(n,r),t.append(e,s),this.appendChild(t)}}}customElements.get("db-time-picker")||customElements.define("db-time-picker",DbTimePicker);export{DbTimePicker};
|
|
1
|
+
import { createDbIcon, getDbComponentIconSize } from './db-icons.js';
|
|
2
|
+
import './db-button.js';
|
|
3
|
+
|
|
4
|
+
const CLASS = 'designbase-wc-time-picker';
|
|
5
|
+
const SIZES = ['s', 'm', 'l'];
|
|
6
|
+
const FORMATS = ['12h', '24h', '12h-with-seconds', '24h-with-seconds'];
|
|
7
|
+
const ITEM_HEIGHT = 40;
|
|
8
|
+
class DbTimePicker extends HTMLElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.built = false;
|
|
12
|
+
this.isOpen = false;
|
|
13
|
+
this.hours = 12;
|
|
14
|
+
this.minutes = 0;
|
|
15
|
+
this.seconds = 0;
|
|
16
|
+
this.period = 'PM';
|
|
17
|
+
this.inputText = '';
|
|
18
|
+
this.tempHours = 12;
|
|
19
|
+
this.tempMinutes = 0;
|
|
20
|
+
this.tempSeconds = 0;
|
|
21
|
+
this.tempPeriod = 'PM';
|
|
22
|
+
this.boundDocumentMouseDown = (event) => this.handleDocumentMouseDown(event);
|
|
23
|
+
}
|
|
24
|
+
static get observedAttributes() {
|
|
25
|
+
return [
|
|
26
|
+
'value',
|
|
27
|
+
'default-value',
|
|
28
|
+
'type',
|
|
29
|
+
'format',
|
|
30
|
+
'minute-step',
|
|
31
|
+
'size',
|
|
32
|
+
'disabled',
|
|
33
|
+
'readonly',
|
|
34
|
+
'label',
|
|
35
|
+
'full-width',
|
|
36
|
+
'error',
|
|
37
|
+
'dropdown-position',
|
|
38
|
+
'open',
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
connectedCallback() {
|
|
42
|
+
if (!this.built)
|
|
43
|
+
this.build();
|
|
44
|
+
this.parseTimeString(this.getAttribute('value') ?? this.getAttribute('default-value') ?? '12:00');
|
|
45
|
+
this.syncInputText();
|
|
46
|
+
this.render();
|
|
47
|
+
document.addEventListener('mousedown', this.boundDocumentMouseDown);
|
|
48
|
+
}
|
|
49
|
+
disconnectedCallback() {
|
|
50
|
+
document.removeEventListener('mousedown', this.boundDocumentMouseDown);
|
|
51
|
+
}
|
|
52
|
+
attributeChangedCallback(name) {
|
|
53
|
+
if (!this.built)
|
|
54
|
+
return;
|
|
55
|
+
if (name === 'value') {
|
|
56
|
+
const raw = this.getAttribute('value');
|
|
57
|
+
if (raw) {
|
|
58
|
+
this.parseTimeString(raw);
|
|
59
|
+
this.syncInputText();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (name === 'open') {
|
|
63
|
+
this.isOpen = this.hasAttribute('open');
|
|
64
|
+
this.render();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.render();
|
|
68
|
+
}
|
|
69
|
+
get value() {
|
|
70
|
+
return this.getAttribute('value') || '';
|
|
71
|
+
}
|
|
72
|
+
set value(value) {
|
|
73
|
+
if (value)
|
|
74
|
+
this.setAttribute('value', value);
|
|
75
|
+
else
|
|
76
|
+
this.removeAttribute('value');
|
|
77
|
+
}
|
|
78
|
+
get format() {
|
|
79
|
+
const raw = this.getAttribute('format') || '24h';
|
|
80
|
+
return FORMATS.includes(raw) ? raw : '24h';
|
|
81
|
+
}
|
|
82
|
+
set format(value) {
|
|
83
|
+
this.setAttribute('format', value);
|
|
84
|
+
}
|
|
85
|
+
get type() {
|
|
86
|
+
return this.getAttribute('type') === 'modal' ? 'modal' : 'dropdown';
|
|
87
|
+
}
|
|
88
|
+
get is12h() {
|
|
89
|
+
return this.format === '12h' || this.format === '12h-with-seconds';
|
|
90
|
+
}
|
|
91
|
+
get showSeconds() {
|
|
92
|
+
return this.format === '12h-with-seconds' || this.format === '24h-with-seconds';
|
|
93
|
+
}
|
|
94
|
+
get minuteStep() {
|
|
95
|
+
const step = Number(this.getAttribute('minute-step') || '1');
|
|
96
|
+
return Number.isFinite(step) && step > 0 ? step : 1;
|
|
97
|
+
}
|
|
98
|
+
get disabled() {
|
|
99
|
+
return this.hasAttribute('disabled');
|
|
100
|
+
}
|
|
101
|
+
set disabled(value) {
|
|
102
|
+
this.toggleAttribute('disabled', Boolean(value));
|
|
103
|
+
}
|
|
104
|
+
get readonly() {
|
|
105
|
+
return this.hasAttribute('readonly');
|
|
106
|
+
}
|
|
107
|
+
set readonly(value) {
|
|
108
|
+
this.toggleAttribute('readonly', Boolean(value));
|
|
109
|
+
}
|
|
110
|
+
build() {
|
|
111
|
+
this.built = true;
|
|
112
|
+
this.labelEl = document.createElement('label');
|
|
113
|
+
this.labelEl.className = `${CLASS}__label`;
|
|
114
|
+
this.triggerEl = document.createElement('div');
|
|
115
|
+
this.triggerEl.className = `${CLASS}__trigger`;
|
|
116
|
+
const iconBtn = document.createElement('button');
|
|
117
|
+
iconBtn.type = 'button';
|
|
118
|
+
iconBtn.className = `${CLASS}__icon-display`;
|
|
119
|
+
iconBtn.setAttribute('aria-label', '시간 선택 열기');
|
|
120
|
+
iconBtn.addEventListener('click', () => this.toggleOpen());
|
|
121
|
+
this.inputEl = document.createElement('input');
|
|
122
|
+
this.inputEl.type = 'text';
|
|
123
|
+
this.inputEl.className = `${CLASS}__input`;
|
|
124
|
+
this.inputEl.setAttribute('aria-label', '시간 입력');
|
|
125
|
+
this.inputEl.addEventListener('click', () => this.openPicker());
|
|
126
|
+
this.inputEl.addEventListener('blur', () => this.handleInputBlur());
|
|
127
|
+
this.inputEl.addEventListener('input', () => {
|
|
128
|
+
this.inputText = this.inputEl?.value || '';
|
|
129
|
+
});
|
|
130
|
+
const toggleBtn = document.createElement('button');
|
|
131
|
+
toggleBtn.type = 'button';
|
|
132
|
+
toggleBtn.className = `${CLASS}__toggle`;
|
|
133
|
+
toggleBtn.setAttribute('aria-label', '시간 선택 열기');
|
|
134
|
+
toggleBtn.addEventListener('click', () => this.toggleOpen());
|
|
135
|
+
this.triggerEl.append(iconBtn, this.inputEl, toggleBtn);
|
|
136
|
+
this.dropdownEl = document.createElement('div');
|
|
137
|
+
this.dropdownEl.className = `${CLASS}__dropdown`;
|
|
138
|
+
this.dropdownEl.setAttribute('role', 'dialog');
|
|
139
|
+
this.dropdownEl.setAttribute('aria-modal', 'false');
|
|
140
|
+
}
|
|
141
|
+
pad2(n) {
|
|
142
|
+
return String(n).padStart(2, '0');
|
|
143
|
+
}
|
|
144
|
+
to24Hour(h12, p) {
|
|
145
|
+
return p === 'AM' ? (h12 === 12 ? 0 : h12) : h12 === 12 ? 12 : h12 + 12;
|
|
146
|
+
}
|
|
147
|
+
formatTimeString(h, m, s, p) {
|
|
148
|
+
const currentPeriod = p || this.period;
|
|
149
|
+
const periodDisplay = currentPeriod === 'AM' ? '오전' : '오후';
|
|
150
|
+
if (this.is12h) {
|
|
151
|
+
return `${periodDisplay} ${this.pad2(h)}:${this.pad2(m)}${this.showSeconds ? `:${this.pad2(s)}` : ''}`;
|
|
152
|
+
}
|
|
153
|
+
return `${this.pad2(h)}:${this.pad2(m)}${this.showSeconds ? `:${this.pad2(s)}` : ''}`;
|
|
154
|
+
}
|
|
155
|
+
toValue24(h, m, s, p) {
|
|
156
|
+
const h24 = this.is12h ? this.to24Hour(h, p || this.period) : h;
|
|
157
|
+
return `${this.pad2(h24)}:${this.pad2(m)}${this.showSeconds ? `:${this.pad2(s)}` : ''}`;
|
|
158
|
+
}
|
|
159
|
+
parseTimeString(timeStr) {
|
|
160
|
+
const s = timeStr.trim();
|
|
161
|
+
if (this.is12h) {
|
|
162
|
+
const re = this.showSeconds
|
|
163
|
+
? /^(오전|오후|AM|PM)?\s*(0?[1-9]|1[0-2]):([0-5]\d):([0-5]\d)\s*(AM|PM|오전|오후)?$/i
|
|
164
|
+
: /^(오전|오후|AM|PM)?\s*(0?[1-9]|1[0-2]):([0-5]\d)\s*(AM|PM|오전|오후)?$/i;
|
|
165
|
+
const match = s.match(re);
|
|
166
|
+
if (match) {
|
|
167
|
+
const prefix = match[1];
|
|
168
|
+
const suffix = this.showSeconds ? match[5] : match[4];
|
|
169
|
+
const periodStr = (prefix || suffix || 'AM').toUpperCase();
|
|
170
|
+
this.hours = parseInt(match[2], 10);
|
|
171
|
+
this.minutes = parseInt(match[3], 10);
|
|
172
|
+
this.seconds = this.showSeconds ? parseInt(match[4], 10) : 0;
|
|
173
|
+
this.period = periodStr === '오후' || periodStr === 'PM' ? 'PM' : 'AM';
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const re = this.showSeconds
|
|
179
|
+
? /^([01]?\d|2[0-3]):([0-5]\d):([0-5]\d)$/
|
|
180
|
+
: /^([01]?\d|2[0-3]):([0-5]\d)$/;
|
|
181
|
+
const match = s.match(re);
|
|
182
|
+
if (match) {
|
|
183
|
+
this.hours = parseInt(match[1], 10);
|
|
184
|
+
this.minutes = parseInt(match[2], 10);
|
|
185
|
+
this.seconds = this.showSeconds ? parseInt(match[3], 10) : 0;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
syncInputText() {
|
|
190
|
+
this.inputText = this.formatTimeString(this.hours, this.minutes, this.seconds);
|
|
191
|
+
if (this.inputEl)
|
|
192
|
+
this.inputEl.value = this.inputText;
|
|
193
|
+
}
|
|
194
|
+
emitChange(value24) {
|
|
195
|
+
this.setAttribute('value', value24);
|
|
196
|
+
this.dispatchEvent(new CustomEvent('db-change', {
|
|
197
|
+
detail: { value: value24 },
|
|
198
|
+
bubbles: true,
|
|
199
|
+
composed: true,
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
handleTimeChange(h, m, s = this.seconds, p) {
|
|
203
|
+
this.hours = h;
|
|
204
|
+
this.minutes = m;
|
|
205
|
+
this.seconds = s;
|
|
206
|
+
if (p)
|
|
207
|
+
this.period = p;
|
|
208
|
+
const display = this.formatTimeString(h, m, s, p);
|
|
209
|
+
this.inputText = display;
|
|
210
|
+
if (this.inputEl)
|
|
211
|
+
this.inputEl.value = display;
|
|
212
|
+
this.emitChange(this.toValue24(h, m, s, p));
|
|
213
|
+
}
|
|
214
|
+
handleInputBlur() {
|
|
215
|
+
if (!this.inputEl)
|
|
216
|
+
return;
|
|
217
|
+
const before = this.inputText;
|
|
218
|
+
this.parseTimeString(this.inputEl.value);
|
|
219
|
+
const parsed = this.formatTimeString(this.hours, this.minutes, this.seconds);
|
|
220
|
+
if (parsed !== before || this.inputEl.value.trim()) {
|
|
221
|
+
this.handleTimeChange(this.hours, this.minutes, this.seconds, this.period);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
this.syncInputText();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
openPicker() {
|
|
228
|
+
if (this.disabled || this.readonly)
|
|
229
|
+
return;
|
|
230
|
+
this.isOpen = true;
|
|
231
|
+
if (this.type === 'modal') {
|
|
232
|
+
this.tempHours = this.hours;
|
|
233
|
+
this.tempMinutes = this.minutes;
|
|
234
|
+
this.tempSeconds = this.seconds;
|
|
235
|
+
this.tempPeriod = this.period;
|
|
236
|
+
}
|
|
237
|
+
this.render();
|
|
238
|
+
}
|
|
239
|
+
closePicker() {
|
|
240
|
+
this.isOpen = false;
|
|
241
|
+
this.render();
|
|
242
|
+
}
|
|
243
|
+
toggleOpen() {
|
|
244
|
+
if (this.isOpen)
|
|
245
|
+
this.closePicker();
|
|
246
|
+
else
|
|
247
|
+
this.openPicker();
|
|
248
|
+
}
|
|
249
|
+
handleDocumentMouseDown(event) {
|
|
250
|
+
if (!this.isOpen)
|
|
251
|
+
return;
|
|
252
|
+
if (!this.contains(event.target))
|
|
253
|
+
this.closePicker();
|
|
254
|
+
}
|
|
255
|
+
createWheel(options) {
|
|
256
|
+
const { label, items, value, onChange, formatter } = options;
|
|
257
|
+
const container = document.createElement('div');
|
|
258
|
+
container.className = `${CLASS}__wheel-container`;
|
|
259
|
+
const labelEl = document.createElement('div');
|
|
260
|
+
labelEl.className = `${CLASS}__wheel-label`;
|
|
261
|
+
labelEl.textContent = label;
|
|
262
|
+
container.appendChild(labelEl);
|
|
263
|
+
const viewport = document.createElement('div');
|
|
264
|
+
viewport.className = `${CLASS}__wheel-viewport`;
|
|
265
|
+
const wheel = document.createElement('div');
|
|
266
|
+
wheel.className = `${CLASS}__wheel`;
|
|
267
|
+
wheel.setAttribute('role', 'listbox');
|
|
268
|
+
wheel.setAttribute('aria-label', label);
|
|
269
|
+
let scrollTimeout = null;
|
|
270
|
+
let isProgrammatic = false;
|
|
271
|
+
let isDragging = false;
|
|
272
|
+
let startY = 0;
|
|
273
|
+
let startScrollTop = 0;
|
|
274
|
+
const indexOfValue = (v) => items.findIndex((item) => item === v);
|
|
275
|
+
const scrollToIndex = (idx, smooth = true) => {
|
|
276
|
+
const top = idx * ITEM_HEIGHT;
|
|
277
|
+
isProgrammatic = true;
|
|
278
|
+
wheel.scrollTo({ top, behavior: smooth ? 'smooth' : 'auto' });
|
|
279
|
+
window.setTimeout(() => {
|
|
280
|
+
isProgrammatic = false;
|
|
281
|
+
}, 150);
|
|
282
|
+
};
|
|
283
|
+
const fmt = (v) => (formatter ? formatter(v) : typeof v === 'number' ? this.pad2(v) : String(v));
|
|
284
|
+
items.forEach((item) => {
|
|
285
|
+
const itemEl = document.createElement('div');
|
|
286
|
+
itemEl.className = [
|
|
287
|
+
`${CLASS}__wheel-item`,
|
|
288
|
+
item === value && `${CLASS}__wheel-item--selected`,
|
|
289
|
+
]
|
|
290
|
+
.filter(Boolean)
|
|
291
|
+
.join(' ');
|
|
292
|
+
itemEl.setAttribute('role', 'option');
|
|
293
|
+
itemEl.setAttribute('aria-selected', String(item === value));
|
|
294
|
+
itemEl.textContent = fmt(item);
|
|
295
|
+
itemEl.addEventListener('click', () => {
|
|
296
|
+
const idx = indexOfValue(item);
|
|
297
|
+
scrollToIndex(idx, true);
|
|
298
|
+
if (item !== value)
|
|
299
|
+
onChange(item);
|
|
300
|
+
});
|
|
301
|
+
wheel.appendChild(itemEl);
|
|
302
|
+
});
|
|
303
|
+
const handleScroll = () => {
|
|
304
|
+
if (isProgrammatic)
|
|
305
|
+
return;
|
|
306
|
+
if (scrollTimeout)
|
|
307
|
+
window.clearTimeout(scrollTimeout);
|
|
308
|
+
scrollTimeout = window.setTimeout(() => {
|
|
309
|
+
const top = wheel.scrollTop;
|
|
310
|
+
const idx = Math.round(top / ITEM_HEIGHT);
|
|
311
|
+
const clamped = Math.max(0, Math.min(items.length - 1, idx));
|
|
312
|
+
const next = items[clamped];
|
|
313
|
+
scrollToIndex(clamped, true);
|
|
314
|
+
if (next !== value)
|
|
315
|
+
onChange(next);
|
|
316
|
+
}, 120);
|
|
317
|
+
};
|
|
318
|
+
wheel.addEventListener('scroll', handleScroll);
|
|
319
|
+
wheel.addEventListener('pointerdown', (e) => {
|
|
320
|
+
isDragging = true;
|
|
321
|
+
startY = e.clientY;
|
|
322
|
+
startScrollTop = wheel.scrollTop;
|
|
323
|
+
wheel.setPointerCapture(e.pointerId);
|
|
324
|
+
wheel.style.cursor = 'grabbing';
|
|
325
|
+
});
|
|
326
|
+
wheel.addEventListener('pointermove', (e) => {
|
|
327
|
+
if (!isDragging)
|
|
328
|
+
return;
|
|
329
|
+
wheel.scrollTop = startScrollTop - (e.clientY - startY);
|
|
330
|
+
});
|
|
331
|
+
const endDrag = (e) => {
|
|
332
|
+
if (!isDragging)
|
|
333
|
+
return;
|
|
334
|
+
isDragging = false;
|
|
335
|
+
wheel.releasePointerCapture(e.pointerId);
|
|
336
|
+
wheel.style.cursor = 'grab';
|
|
337
|
+
handleScroll();
|
|
338
|
+
};
|
|
339
|
+
wheel.addEventListener('pointerup', endDrag);
|
|
340
|
+
wheel.addEventListener('pointercancel', endDrag);
|
|
341
|
+
const initialIndex = indexOfValue(value);
|
|
342
|
+
if (initialIndex >= 0) {
|
|
343
|
+
requestAnimationFrame(() => scrollToIndex(initialIndex, false));
|
|
344
|
+
}
|
|
345
|
+
const center = document.createElement('div');
|
|
346
|
+
center.className = `${CLASS}__wheel-center-indicator`;
|
|
347
|
+
center.setAttribute('aria-hidden', 'true');
|
|
348
|
+
const fadeTop = document.createElement('div');
|
|
349
|
+
fadeTop.className = `${CLASS}__wheel-fade wheel-fade--top`;
|
|
350
|
+
fadeTop.setAttribute('aria-hidden', 'true');
|
|
351
|
+
const fadeBottom = document.createElement('div');
|
|
352
|
+
fadeBottom.className = `${CLASS}__wheel-fade wheel-fade--bottom`;
|
|
353
|
+
fadeBottom.setAttribute('aria-hidden', 'true');
|
|
354
|
+
viewport.append(wheel, center, fadeTop, fadeBottom);
|
|
355
|
+
container.appendChild(viewport);
|
|
356
|
+
return container;
|
|
357
|
+
}
|
|
358
|
+
renderSelector(isModal = false) {
|
|
359
|
+
const selector = document.createElement('div');
|
|
360
|
+
selector.className = `${CLASS}__selector`;
|
|
361
|
+
const wheels = document.createElement('div');
|
|
362
|
+
wheels.className = `${CLASS}__picker-wheels`;
|
|
363
|
+
const hourItems = this.is12h
|
|
364
|
+
? Array.from({ length: 12 }, (_, i) => i + 1)
|
|
365
|
+
: Array.from({ length: 24 }, (_, i) => i);
|
|
366
|
+
const minuteItems = Array.from({ length: Math.floor(60 / this.minuteStep) }, (_, i) => i * this.minuteStep);
|
|
367
|
+
const secondItems = Array.from({ length: 60 }, (_, i) => i);
|
|
368
|
+
const currentHours = isModal ? this.tempHours : this.hours;
|
|
369
|
+
const currentMinutes = isModal ? this.tempMinutes : this.minutes;
|
|
370
|
+
const currentSeconds = isModal ? this.tempSeconds : this.seconds;
|
|
371
|
+
const currentPeriod = isModal ? this.tempPeriod : this.period;
|
|
372
|
+
const onChange = (h, m, s, p) => {
|
|
373
|
+
if (isModal) {
|
|
374
|
+
this.tempHours = h;
|
|
375
|
+
this.tempMinutes = m;
|
|
376
|
+
this.tempSeconds = s;
|
|
377
|
+
this.tempPeriod = p;
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
this.handleTimeChange(h, m, s, p);
|
|
381
|
+
};
|
|
382
|
+
wheels.appendChild(this.createWheel({
|
|
383
|
+
label: '시간',
|
|
384
|
+
items: hourItems,
|
|
385
|
+
value: currentHours,
|
|
386
|
+
onChange: (v) => onChange(v, currentMinutes, currentSeconds, currentPeriod),
|
|
387
|
+
}));
|
|
388
|
+
wheels.appendChild(this.createWheel({
|
|
389
|
+
label: '분',
|
|
390
|
+
items: minuteItems,
|
|
391
|
+
value: minuteItems.includes(currentMinutes) ? currentMinutes : minuteItems[0],
|
|
392
|
+
onChange: (v) => onChange(currentHours, v, currentSeconds, currentPeriod),
|
|
393
|
+
}));
|
|
394
|
+
if (this.showSeconds) {
|
|
395
|
+
wheels.appendChild(this.createWheel({
|
|
396
|
+
label: '초',
|
|
397
|
+
items: secondItems,
|
|
398
|
+
value: currentSeconds,
|
|
399
|
+
onChange: (v) => onChange(currentHours, currentMinutes, v, currentPeriod),
|
|
400
|
+
}));
|
|
401
|
+
}
|
|
402
|
+
if (this.is12h) {
|
|
403
|
+
wheels.appendChild(this.createWheel({
|
|
404
|
+
label: '오전/오후',
|
|
405
|
+
items: ['AM', 'PM'],
|
|
406
|
+
value: currentPeriod,
|
|
407
|
+
onChange: (v) => onChange(currentHours, currentMinutes, currentSeconds, v),
|
|
408
|
+
formatter: (v) => (v === 'AM' ? '오전' : '오후'),
|
|
409
|
+
}));
|
|
410
|
+
}
|
|
411
|
+
selector.appendChild(wheels);
|
|
412
|
+
if (isModal)
|
|
413
|
+
return selector;
|
|
414
|
+
const actions = document.createElement('div');
|
|
415
|
+
actions.className = `${CLASS}__dropdown-actions`;
|
|
416
|
+
const preview = document.createElement('div');
|
|
417
|
+
preview.className = `${CLASS}__preview`;
|
|
418
|
+
preview.setAttribute('aria-live', 'polite');
|
|
419
|
+
preview.appendChild(createDbIcon('clock', 16));
|
|
420
|
+
const previewTime = document.createElement('div');
|
|
421
|
+
previewTime.className = `${CLASS}__preview-time`;
|
|
422
|
+
previewTime.textContent = this.formatTimeString(currentHours, currentMinutes, currentSeconds, currentPeriod);
|
|
423
|
+
preview.appendChild(previewTime);
|
|
424
|
+
const selectBtn = document.createElement('db-button');
|
|
425
|
+
selectBtn.setAttribute('variant', 'primary');
|
|
426
|
+
selectBtn.setAttribute('size', 'm');
|
|
427
|
+
selectBtn.textContent = '선택';
|
|
428
|
+
selectBtn.addEventListener('click', () => {
|
|
429
|
+
this.handleTimeChange(currentHours, currentMinutes, currentSeconds, currentPeriod);
|
|
430
|
+
this.closePicker();
|
|
431
|
+
});
|
|
432
|
+
actions.append(preview, selectBtn);
|
|
433
|
+
selector.appendChild(actions);
|
|
434
|
+
return selector;
|
|
435
|
+
}
|
|
436
|
+
render() {
|
|
437
|
+
const size = SIZES.includes((this.getAttribute('size') || 'm'))
|
|
438
|
+
? this.getAttribute('size') || 'm'
|
|
439
|
+
: 'm';
|
|
440
|
+
const dropdownPosition = this.getAttribute('dropdown-position') || 'bottom-start';
|
|
441
|
+
const iconSize = getDbComponentIconSize(size);
|
|
442
|
+
this.className = [
|
|
443
|
+
CLASS,
|
|
444
|
+
`${CLASS}--${size}`,
|
|
445
|
+
this.hasAttribute('full-width') && `${CLASS}--full-width`,
|
|
446
|
+
this.disabled && `${CLASS}--disabled`,
|
|
447
|
+
this.readonly && `${CLASS}--readonly`,
|
|
448
|
+
this.isOpen && `${CLASS}--open`,
|
|
449
|
+
this.hasAttribute('error') && `${CLASS}--error`,
|
|
450
|
+
]
|
|
451
|
+
.filter(Boolean)
|
|
452
|
+
.join(' ');
|
|
453
|
+
this.replaceChildren();
|
|
454
|
+
if (!this.labelEl || !this.triggerEl || !this.inputEl || !this.dropdownEl)
|
|
455
|
+
return;
|
|
456
|
+
const label = this.getAttribute('label') || '';
|
|
457
|
+
this.labelEl.textContent = label;
|
|
458
|
+
this.labelEl.hidden = !label;
|
|
459
|
+
this.inputEl.value = this.inputText;
|
|
460
|
+
this.inputEl.placeholder = this.is12h
|
|
461
|
+
? this.showSeconds
|
|
462
|
+
? '12:00:00 PM'
|
|
463
|
+
: '12:00 PM'
|
|
464
|
+
: this.showSeconds
|
|
465
|
+
? '12:00:00'
|
|
466
|
+
: '12:00';
|
|
467
|
+
this.inputEl.disabled = this.disabled;
|
|
468
|
+
this.inputEl.readOnly = this.readonly;
|
|
469
|
+
const iconBtn = this.triggerEl.querySelector(`.${CLASS}__icon-display`);
|
|
470
|
+
if (iconBtn) {
|
|
471
|
+
iconBtn.innerHTML = '';
|
|
472
|
+
iconBtn.appendChild(createDbIcon('clock', iconSize));
|
|
473
|
+
iconBtn.disabled = this.disabled;
|
|
474
|
+
}
|
|
475
|
+
const toggleBtn = this.triggerEl.querySelector(`.${CLASS}__toggle`);
|
|
476
|
+
if (toggleBtn) {
|
|
477
|
+
toggleBtn.innerHTML = '';
|
|
478
|
+
toggleBtn.appendChild(createDbIcon('chevron-down', iconSize));
|
|
479
|
+
toggleBtn.disabled = this.disabled;
|
|
480
|
+
}
|
|
481
|
+
this.dropdownEl.className = [`${CLASS}__dropdown`, `${CLASS}__dropdown--${dropdownPosition}`]
|
|
482
|
+
.filter(Boolean)
|
|
483
|
+
.join(' ');
|
|
484
|
+
this.dropdownEl.hidden = !this.isOpen;
|
|
485
|
+
if (this.isOpen && this.type === 'dropdown') {
|
|
486
|
+
this.dropdownEl.replaceChildren(this.renderSelector(false));
|
|
487
|
+
}
|
|
488
|
+
this.append(this.labelEl, this.triggerEl);
|
|
489
|
+
if (this.isOpen && this.type === 'dropdown')
|
|
490
|
+
this.appendChild(this.dropdownEl);
|
|
491
|
+
if (this.isOpen && this.type === 'modal') {
|
|
492
|
+
const modal = document.createElement('db-modal');
|
|
493
|
+
modal.setAttribute('open', 'true');
|
|
494
|
+
modal.setAttribute('title', '시간 선택');
|
|
495
|
+
modal.setAttribute('size', 's');
|
|
496
|
+
modal.addEventListener('db-close', () => this.closePicker());
|
|
497
|
+
const selector = this.renderSelector(true);
|
|
498
|
+
const footer = document.createElement('div');
|
|
499
|
+
footer.className = `${CLASS}__modal-footer`;
|
|
500
|
+
const cancelBtn = document.createElement('db-button');
|
|
501
|
+
cancelBtn.setAttribute('variant', 'secondary');
|
|
502
|
+
cancelBtn.setAttribute('size', 'm');
|
|
503
|
+
cancelBtn.textContent = '취소';
|
|
504
|
+
cancelBtn.addEventListener('click', () => this.closePicker());
|
|
505
|
+
const applyBtn = document.createElement('db-button');
|
|
506
|
+
applyBtn.setAttribute('variant', 'primary');
|
|
507
|
+
applyBtn.setAttribute('size', 'm');
|
|
508
|
+
applyBtn.textContent = '적용';
|
|
509
|
+
applyBtn.addEventListener('click', () => {
|
|
510
|
+
this.handleTimeChange(this.tempHours, this.tempMinutes, this.tempSeconds, this.tempPeriod);
|
|
511
|
+
this.closePicker();
|
|
512
|
+
});
|
|
513
|
+
footer.append(cancelBtn, applyBtn);
|
|
514
|
+
modal.append(selector, footer);
|
|
515
|
+
this.appendChild(modal);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
if (!customElements.get('db-time-picker')) {
|
|
520
|
+
customElements.define('db-time-picker', DbTimePicker);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
export { DbTimePicker };
|