@designbasekorea/ui-wc 0.5.3 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/dist/chunks/lottie-e273b936.js +17032 -0
  2. package/dist/esm/components/animation-background/canvas-controller.js +121 -1
  3. package/dist/esm/components/animation-background/controls.js +180 -1
  4. package/dist/esm/components/animation-background/graphite-controller.js +196 -1
  5. package/dist/esm/components/animation-background/graphite-presets.js +42 -1
  6. package/dist/esm/components/animation-background/graphite-shader.js +111 -1
  7. package/dist/esm/components/animation-background/layers.js +369 -1
  8. package/dist/esm/components/animation-background/lumina-presets.js +53 -1
  9. package/dist/esm/components/animation-background/lumina-shaders.js +181 -1
  10. package/dist/esm/components/animation-background/lumina-utils.js +60 -1
  11. package/dist/esm/components/animation-background/particle-defaults.js +36 -1
  12. package/dist/esm/components/animation-background/renderers.js +167 -1
  13. package/dist/esm/components/animation-background/shader-controller.js +154 -1
  14. package/dist/esm/components/color-picker-utils.js +134 -1
  15. package/dist/esm/components/date-picker-utils.js +140 -1
  16. package/dist/esm/components/db-accordion.js +304 -1
  17. package/dist/esm/components/db-ad-banner.js +455 -1
  18. package/dist/esm/components/db-alert.js +149 -1
  19. package/dist/esm/components/db-animation-background.js +486 -1
  20. package/dist/esm/components/db-animation-text.js +601 -1
  21. package/dist/esm/components/db-app-badge.js +88 -1
  22. package/dist/esm/components/db-audio-player.js +752 -1
  23. package/dist/esm/components/db-avatar.js +188 -1
  24. package/dist/esm/components/db-backdrop.js +139 -1
  25. package/dist/esm/components/db-badge.js +91 -1
  26. package/dist/esm/components/db-banner.js +188 -1
  27. package/dist/esm/components/db-bottom-navigation.js +146 -1
  28. package/dist/esm/components/db-bottom-sheet.js +481 -1
  29. package/dist/esm/components/db-breadcrumbs.js +329 -1
  30. package/dist/esm/components/db-button.js +316 -1
  31. package/dist/esm/components/db-calendar.js +675 -1
  32. package/dist/esm/components/db-card.js +265 -1
  33. package/dist/esm/components/db-carousel.js +264 -1
  34. package/dist/esm/components/db-checkbox.js +202 -1
  35. package/dist/esm/components/db-chip.js +104 -1
  36. package/dist/esm/components/db-code-block.js +304 -1
  37. package/dist/esm/components/db-color-picker.js +746 -1
  38. package/dist/esm/components/db-confirm.js +191 -1
  39. package/dist/esm/components/db-container.js +39 -1
  40. package/dist/esm/components/db-context-menu.js +265 -1
  41. package/dist/esm/components/db-countdown.js +146 -1
  42. package/dist/esm/components/db-cursor-follower.js +173 -1
  43. package/dist/esm/components/db-date-picker.js +837 -1
  44. package/dist/esm/components/db-divider.js +66 -1
  45. package/dist/esm/components/db-drawer.js +245 -1
  46. package/dist/esm/components/db-dropdown.js +493 -1
  47. package/dist/esm/components/db-dropzone.js +266 -1
  48. package/dist/esm/components/db-empty-state.js +97 -1
  49. package/dist/esm/components/db-file-uploader.js +256 -1
  50. package/dist/esm/components/db-floating-action-button.js +139 -1
  51. package/dist/esm/components/db-footer.js +385 -1
  52. package/dist/esm/components/db-form.js +566 -1
  53. package/dist/esm/components/db-gantt.js +882 -1
  54. package/dist/esm/components/db-gradient.js +133 -1
  55. package/dist/esm/components/db-grid-background.js +909 -1
  56. package/dist/esm/components/db-grid.js +73 -1
  57. package/dist/esm/components/db-icons.js +82 -1
  58. package/dist/esm/components/db-image-list.js +214 -1
  59. package/dist/esm/components/db-image-placeholder.js +96 -1
  60. package/dist/esm/components/db-image.js +289 -1
  61. package/dist/esm/components/db-indicator.js +517 -1
  62. package/dist/esm/components/db-input.js +420 -1
  63. package/dist/esm/components/db-kanban.js +538 -1
  64. package/dist/esm/components/db-label.js +66 -1
  65. package/dist/esm/components/db-lightbox.js +372 -1
  66. package/dist/esm/components/db-list.js +340 -1
  67. package/dist/esm/components/db-logo-svg.js +72 -1
  68. package/dist/esm/components/db-logo.js +106 -1
  69. package/dist/esm/components/db-lottie.js +109 -1
  70. package/dist/esm/components/db-markdown-editor.js +458 -1
  71. package/dist/esm/components/db-marquee.js +402 -1
  72. package/dist/esm/components/db-masonry.js +94 -1
  73. package/dist/esm/components/db-menu-item.js +211 -1
  74. package/dist/esm/components/db-modal.js +522 -1
  75. package/dist/esm/components/db-navbar.js +680 -1
  76. package/dist/esm/components/db-onboarding-modal.js +322 -1
  77. package/dist/esm/components/db-page-header.js +312 -1
  78. package/dist/esm/components/db-pagination.js +271 -1
  79. package/dist/esm/components/db-popover.js +580 -1
  80. package/dist/esm/components/db-progress-step.js +166 -1
  81. package/dist/esm/components/db-progress.js +171 -1
  82. package/dist/esm/components/db-progressbar.js +72 -1
  83. package/dist/esm/components/db-radio.js +172 -1
  84. package/dist/esm/components/db-random-gradient.js +121 -1
  85. package/dist/esm/components/db-range-slider.js +811 -1
  86. package/dist/esm/components/db-rating.js +325 -1
  87. package/dist/esm/components/db-reorder.js +286 -1
  88. package/dist/esm/components/db-resizable-panels.js +282 -1
  89. package/dist/esm/components/db-scroll-area.js +126 -1
  90. package/dist/esm/components/db-search-bar.js +668 -1
  91. package/dist/esm/components/db-section-app-download.js +101 -1
  92. package/dist/esm/components/db-section-contact.js +102 -1
  93. package/dist/esm/components/db-section-cta.js +150 -1
  94. package/dist/esm/components/db-section-faq.js +120 -1
  95. package/dist/esm/components/db-section-feature-grid.js +137 -1
  96. package/dist/esm/components/db-section-feature.js +179 -1
  97. package/dist/esm/components/db-section-hero.js +243 -1
  98. package/dist/esm/components/db-section-logo-cloud.js +138 -1
  99. package/dist/esm/components/db-section-pricing.js +166 -1
  100. package/dist/esm/components/db-section-stats.js +129 -1
  101. package/dist/esm/components/db-section-testimonials.js +252 -1
  102. package/dist/esm/components/db-section.js +385 -1
  103. package/dist/esm/components/db-segment-control.js +231 -1
  104. package/dist/esm/components/db-select.js +571 -1
  105. package/dist/esm/components/db-share-icons.js +40 -1
  106. package/dist/esm/components/db-share.js +489 -1
  107. package/dist/esm/components/db-sidebar.js +1068 -1
  108. package/dist/esm/components/db-skeleton.js +94 -1
  109. package/dist/esm/components/db-spinner.js +102 -1
  110. package/dist/esm/components/db-split-view.js +297 -1
  111. package/dist/esm/components/db-stack.js +46 -1
  112. package/dist/esm/components/db-stat.js +218 -1
  113. package/dist/esm/components/db-stepper.js +398 -1
  114. package/dist/esm/components/db-table.js +412 -1
  115. package/dist/esm/components/db-tabs.js +335 -1
  116. package/dist/esm/components/db-testimonial.js +162 -1
  117. package/dist/esm/components/db-textarea.js +233 -1
  118. package/dist/esm/components/db-time-picker.js +523 -1
  119. package/dist/esm/components/db-timeline.js +174 -1
  120. package/dist/esm/components/db-toast.js +158 -1
  121. package/dist/esm/components/db-toggle.js +162 -1
  122. package/dist/esm/components/db-toolbar.js +94 -1
  123. package/dist/esm/components/db-tooltip.js +440 -1
  124. package/dist/esm/components/db-top-banner.js +121 -1
  125. package/dist/esm/components/db-tutorial.js +324 -1
  126. package/dist/esm/components/db-video-player.js +503 -1
  127. package/dist/esm/components/db-youtube-player.js +194 -1
  128. package/dist/esm/components/highlight-code.js +65 -1
  129. package/dist/esm/components/input-validation.js +50 -1
  130. package/dist/esm/components/marketing-block-host-utils.js +9 -1
  131. package/dist/esm/components/number-scrub.js +117 -1
  132. package/dist/esm/components/random-gradient-palettes.js +67 -1
  133. package/dist/esm/components/section-block-header-utils.js +48 -1
  134. package/dist/esm/helpers/confirm.js +52 -1
  135. package/dist/esm/helpers/toast.js +73 -1
  136. package/dist/esm/index.js +111 -1
  137. package/dist/esm/node_modules/prismjs/components/prism-bash.js +235 -1
  138. package/dist/esm/node_modules/prismjs/components/prism-clike.js +31 -1
  139. package/dist/esm/node_modules/prismjs/components/prism-css.js +64 -1
  140. package/dist/esm/node_modules/prismjs/components/prism-javascript.js +172 -1
  141. package/dist/esm/node_modules/prismjs/components/prism-json.js +27 -1
  142. package/dist/esm/node_modules/prismjs/components/prism-jsx.js +143 -1
  143. package/dist/esm/node_modules/prismjs/components/prism-markup.js +186 -1
  144. package/dist/esm/node_modules/prismjs/components/prism-scss.js +81 -1
  145. package/dist/esm/node_modules/prismjs/components/prism-tsx.js +15 -1
  146. package/dist/esm/node_modules/prismjs/components/prism-typescript.js +60 -1
  147. package/dist/index.cjs +55414 -1
  148. package/dist/index.css +1 -1
  149. package/dist/index.esm.js +38284 -1
  150. package/dist/react/chunks/lottie-72a4c6d4.js +17032 -0
  151. package/dist/react/index.cjs +56503 -1
  152. package/dist/react/index.d.ts +1 -1
  153. package/dist/react/index.esm.js +39373 -1
  154. package/package.json +1 -1
  155. package/dist/chunks/lottie-2d1f6278.js +0 -1
  156. package/dist/react/chunks/lottie-14e7addb.js +0 -1
@@ -1 +1,385 @@
1
- import{createDbIcon as e}from"./db-icons.js";const t=["s","m","l","xl"];class DbSection extends HTMLElement{constructor(){super(...arguments),this.contentId=`db-section-${Math.random().toString(36).slice(2,9)}`,this.internalExpanded=!0,this.internalTabId="",this.handleToggle=()=>{if(!this.isCollapsible())return;const e=!this.isExpanded();this.hasAttribute("expanded")||(this.internalExpanded=e),this.dispatchEvent(new CustomEvent("db-expanded-change",{bubbles:!0,composed:!0,detail:{expanded:e}})),this.hasAttribute("expanded")||(this.syncHostClasses(),this.syncCollapsibleState())},this.handleTabChange=e=>{const t=e.detail,s=t?.id??this.parseTabs()[t?.index??0]?.id??String(t?.index??0);this.internalTabId=s,this.tabsEl?.setAttribute("selected-id",s),this.dispatchEvent(new CustomEvent("db-tab-change",{bubbles:!0,composed:!0,detail:{tabId:s}}))}}static get observedAttributes(){return["title","subtitle","description","size","collapsible","default-expanded","expanded","no-padding","full-width","full-height","overflow-visible","tabs","selected-tab-id","default-selected-tab-id"]}connectedCallback(){this.internalExpanded="false"!==this.getAttribute("default-expanded"),this.syncDefaultTab(),this.ensureStructure(),this.sync(),this.observer=new MutationObserver(()=>this.sync()),this.observer.observe(this,{childList:!0})}disconnectedCallback(){this.observer?.disconnect()}attributeChangedCallback(e){if(this.isConnected){if("default-expanded"!==e||this.hasAttribute("expanded")||(this.internalExpanded="false"!==this.getAttribute("default-expanded")),"default-selected-tab-id"!==e&&"tabs"!==e||this.syncDefaultTab(),"selected-tab-id"===e){const e=this.getAttribute("selected-tab-id");e&&(this.internalTabId=e)}this.sync()}}syncDefaultTab(){if(this.internalTabId)return;const e=this.parseTabs(),t=this.getAttribute("default-selected-tab-id")||"";this.internalTabId=t||e[0]?.id||""}parseTabs(){try{const e=JSON.parse(this.getAttribute("tabs")||"[]");return Array.isArray(e)?e:[]}catch{return[]}}getActiveTabId(){const e=this.getAttribute("selected-tab-id");return e&&this.internalTabId&&e!==this.internalTabId?this.internalTabId:e||this.internalTabId||this.tabsEl?.getAttribute("selected-id")||""}hasHeaderTabs(){return this.parseTabs().length>0&&!this.isCollapsible()}isCollapsible(){return this.hasAttribute("collapsible")}isExpanded(){return!this.isCollapsible()||(this.hasAttribute("expanded")?"false"!==this.getAttribute("expanded"):this.internalExpanded)}isUserNode(e){return!e.hasAttribute("data-wc-internal")}collectSlotted(e){const t=Array.from(this.querySelectorAll(`:scope > [slot="${e}"]`)).filter(this.isUserNode);if(t.length)return t;if("actions"===e&&this.actionsHostEl)return Array.from(this.actionsHostEl.children);if("footer"===e&&this.footerEl)return Array.from(this.footerEl.children);if("header"===e){const e=this.headerEl?.querySelector(".designbase-wc-section__header-main");return e?Array.from(e.children):[]}if("description"===e){const e=this.headerEl?.querySelector(".designbase-wc-section__description"),t=e?.firstElementChild;return t?[t]:[]}return[]}collectContentNodes(){const e=Array.from(this.children).filter(e=>{if(!this.isUserNode(e))return!1;const t=e.getAttribute("slot");return!t||"default"===t});return e.length?e:this.contentEl?Array.from(this.contentEl.children):[]}ensureStructure(){this.headerEl||(this.headerEl=document.createElement("div"),this.headerEl.className="designbase-wc-section__header",this.headerEl.setAttribute("data-wc-internal","")),this.bodyEl||(this.bodyEl=document.createElement("div"),this.bodyEl.className="designbase-wc-section__body",this.bodyEl.id=this.contentId,this.bodyEl.setAttribute("data-wc-internal",""),this.bodyInnerEl=document.createElement("div"),this.bodyInnerEl.className="designbase-wc-section__body-inner",this.bodyInnerEl.setAttribute("data-wc-internal",""),this.bodyEl.append(this.bodyInnerEl)),this.contentEl||(this.contentEl=document.createElement("div"),this.contentEl.className="designbase-wc-section__content",this.contentEl.setAttribute("data-wc-internal","")),this.footerEl||(this.footerEl=document.createElement("div"),this.footerEl.className="designbase-wc-section__footer",this.footerEl.setAttribute("data-wc-internal","")),this.headerEl.isConnected||this.append(this.headerEl)}mountBody(){const e=this.collectContentNodes(),t=this.collectSlotted("footer");if(this.contentEl.replaceChildren(...e),this.footerEl.replaceChildren(...t),this.footerEl.hidden=0===t.length,this.isCollapsible())return this.bodyInnerEl.replaceChildren(this.contentEl,this.footerEl),void(this.bodyEl.isConnected||this.append(this.bodyEl));this.bodyEl?.remove(),this.contentEl.isConnected||this.append(this.contentEl),t.length?this.footerEl.isConnected||this.append(this.footerEl):this.footerEl.remove()}getChevronSize(){const e=this.getAttribute("size")||"m";return"s"===e?16:"l"===e||"xl"===e?24:20}createTitleArea(){const e=this.getAttribute("title"),t=this.getAttribute("subtitle"),s=this.getAttribute("description"),i=this.collectSlotted("description")[0];if(!(e||t||s||i))return null;const n=document.createElement("div");if(n.className="designbase-wc-section__title-area",e){const t=document.createElement("h2");t.className="designbase-wc-section__title",t.textContent=e,n.append(t)}if(t){const e=document.createElement("h3");e.className="designbase-wc-section__subtitle",e.textContent=t,n.append(e)}if(i){const e=document.createElement("p");e.className="designbase-wc-section__description",e.append(i),n.append(e)}else if(s){const e=document.createElement("p");e.className="designbase-wc-section__description",e.textContent=s,n.append(e)}return n}createChevron(){const t=document.createElement("span");return t.className="designbase-wc-section__chevron",t.setAttribute("aria-hidden","true"),t.append(e("chevron-down",this.getChevronSize())),t}renderHeader(){if(!this.headerEl)return;const e=this.collectSlotted("header")[0],t=this.collectSlotted("actions"),s=this.createTitleArea(),i=this.hasHeaderTabs(),n=Boolean(e||s||t.length);if(this.headerEl.replaceChildren(),this.headerEl.hidden=!n&&!i,this.headerEl.classList.toggle("designbase-wc-section__header--with-tabs",i),!n&&!i)return;if(this.isCollapsible()){if(e){const t=document.createElement("button");t.type="button",t.className="designbase-wc-section__header-trigger",t.setAttribute("aria-expanded",String(this.isExpanded())),t.setAttribute("aria-controls",this.contentId),t.addEventListener("click",this.handleToggle);const s=document.createElement("div");s.className="designbase-wc-section__header-main",s.append(e),t.append(s,this.createChevron()),this.headerEl.append(t)}else{const e=document.createElement("button");e.type="button",e.className="designbase-wc-section__header-trigger",e.setAttribute("aria-expanded",String(this.isExpanded())),e.setAttribute("aria-controls",this.contentId),e.addEventListener("click",this.handleToggle),s&&e.append(s),e.append(this.createChevron()),this.headerEl.append(e),t.length&&(this.actionsHostEl=document.createElement("div"),this.actionsHostEl.className="designbase-wc-section__actions",this.actionsHostEl.addEventListener("click",e=>e.stopPropagation()),t.forEach(e=>this.actionsHostEl.append(e)),this.headerEl.append(this.actionsHostEl))}return}const appendHeaderMain=i=>{e?i.append(e):(s&&i.append(s),t.length&&(this.actionsHostEl=document.createElement("div"),this.actionsHostEl.className="designbase-wc-section__actions",t.forEach(e=>this.actionsHostEl.append(e)),i.append(this.actionsHostEl)))};if(i){const e=document.createElement("div");e.className="designbase-wc-section__header-row",appendHeaderMain(e),this.headerEl.append(e);const t=document.createElement("div");return t.className="designbase-wc-section__header-tabs",this.tabsEl||(this.tabsEl=document.createElement("db-tabs"),this.tabsEl.setAttribute("size","m"),this.tabsEl.addEventListener("db-change",this.handleTabChange)),this.tabsEl.setAttribute("items",JSON.stringify(this.parseTabs())),this.tabsEl.setAttribute("selected-id",this.getActiveTabId()),t.append(this.tabsEl),void this.headerEl.append(t)}appendHeaderMain(this.headerEl)}syncHostClasses(){const e=this.getAttribute("size")||"m",s=t.includes(e)?e:"m",i=this.isExpanded();this.className=["designbase-wc-section",`designbase-wc-section--size-${s}`,this.hasAttribute("no-padding")&&"designbase-wc-section--no-padding",this.hasHeaderTabs()&&"designbase-wc-section--has-header-tabs",this.hasAttribute("full-width")&&"designbase-wc-section--full-width",this.hasAttribute("full-height")&&"designbase-wc-section--full-height",this.hasAttribute("overflow-visible")&&"designbase-wc-section--overflow-visible",this.isCollapsible()&&"designbase-wc-section--collapsible",this.isCollapsible()&&i&&"designbase-wc-section--expanded",this.isCollapsible()&&!i&&"designbase-wc-section--collapsed"].filter(Boolean).join(" ")}syncCollapsibleState(){if(!this.isCollapsible()||!this.bodyEl)return;const e=this.isExpanded();this.bodyEl.setAttribute("aria-hidden",String(!e));const t=this.headerEl?.querySelector(".designbase-wc-section__header-trigger");t?.setAttribute("aria-expanded",String(e))}sync(){this.ensureStructure(),this.syncHostClasses(),this.renderHeader(),this.mountBody(),this.syncCollapsibleState()}}customElements.get("db-section")||customElements.define("db-section",DbSection);export{DbSection};
1
+ import { createDbIcon } from './db-icons.js';
2
+
3
+ const SIZES = ['s', 'm', 'l'];
4
+ class DbSection extends HTMLElement {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.contentId = `db-section-${Math.random().toString(36).slice(2, 9)}`;
8
+ this.internalExpanded = true;
9
+ this.internalTabId = '';
10
+ this.handleToggle = () => {
11
+ if (!this.isCollapsible())
12
+ return;
13
+ const next = !this.isExpanded();
14
+ if (!this.hasAttribute('expanded')) {
15
+ this.internalExpanded = next;
16
+ }
17
+ this.dispatchEvent(new CustomEvent('db-expanded-change', {
18
+ bubbles: true,
19
+ composed: true,
20
+ detail: { expanded: next },
21
+ }));
22
+ if (!this.hasAttribute('expanded')) {
23
+ this.syncHostClasses();
24
+ this.syncCollapsibleState();
25
+ }
26
+ };
27
+ this.handleTabChange = (event) => {
28
+ const detail = event.detail;
29
+ const tabId = detail?.id ??
30
+ this.parseTabs()[detail?.index ?? 0]?.id ??
31
+ String(detail?.index ?? 0);
32
+ this.internalTabId = tabId;
33
+ this.tabsEl?.setAttribute('selected-id', tabId);
34
+ this.dispatchEvent(new CustomEvent('db-tab-change', {
35
+ bubbles: true,
36
+ composed: true,
37
+ detail: { tabId },
38
+ }));
39
+ };
40
+ }
41
+ static get observedAttributes() {
42
+ return [
43
+ 'title',
44
+ 'subtitle',
45
+ 'description',
46
+ 'size',
47
+ 'collapsible',
48
+ 'default-expanded',
49
+ 'expanded',
50
+ 'no-padding',
51
+ 'full-width',
52
+ 'full-height',
53
+ 'overflow-visible',
54
+ 'tabs',
55
+ 'selected-tab-id',
56
+ 'default-selected-tab-id',
57
+ ];
58
+ }
59
+ connectedCallback() {
60
+ this.internalExpanded = this.getAttribute('default-expanded') !== 'false';
61
+ this.syncDefaultTab();
62
+ this.ensureStructure();
63
+ this.sync();
64
+ this.observer = new MutationObserver(() => this.sync());
65
+ this.observer.observe(this, { childList: true });
66
+ }
67
+ disconnectedCallback() {
68
+ this.observer?.disconnect();
69
+ }
70
+ attributeChangedCallback(name) {
71
+ if (!this.isConnected)
72
+ return;
73
+ if (name === 'default-expanded' && !this.hasAttribute('expanded')) {
74
+ this.internalExpanded = this.getAttribute('default-expanded') !== 'false';
75
+ }
76
+ if (name === 'default-selected-tab-id' || name === 'tabs') {
77
+ this.syncDefaultTab();
78
+ }
79
+ if (name === 'selected-tab-id') {
80
+ const next = this.getAttribute('selected-tab-id');
81
+ if (next)
82
+ this.internalTabId = next;
83
+ }
84
+ this.sync();
85
+ }
86
+ syncDefaultTab() {
87
+ if (this.internalTabId)
88
+ return;
89
+ const tabs = this.parseTabs();
90
+ const defaultId = this.getAttribute('default-selected-tab-id') || '';
91
+ this.internalTabId = defaultId || tabs[0]?.id || '';
92
+ }
93
+ parseTabs() {
94
+ try {
95
+ const parsed = JSON.parse(this.getAttribute('tabs') || '[]');
96
+ return Array.isArray(parsed) ? parsed : [];
97
+ }
98
+ catch {
99
+ return [];
100
+ }
101
+ }
102
+ getActiveTabId() {
103
+ const attr = this.getAttribute('selected-tab-id');
104
+ if (attr && this.internalTabId && attr !== this.internalTabId) {
105
+ return this.internalTabId;
106
+ }
107
+ return attr || this.internalTabId || this.tabsEl?.getAttribute('selected-id') || '';
108
+ }
109
+ hasHeaderTabs() {
110
+ return this.parseTabs().length > 0 && !this.isCollapsible();
111
+ }
112
+ isCollapsible() {
113
+ return this.hasAttribute('collapsible');
114
+ }
115
+ isExpanded() {
116
+ if (!this.isCollapsible())
117
+ return true;
118
+ if (this.hasAttribute('expanded')) {
119
+ return this.getAttribute('expanded') !== 'false';
120
+ }
121
+ return this.internalExpanded;
122
+ }
123
+ isUserNode(node) {
124
+ return !node.hasAttribute('data-wc-internal');
125
+ }
126
+ collectSlotted(name) {
127
+ const direct = Array.from(this.querySelectorAll(`:scope > [slot="${name}"]`)).filter(this.isUserNode);
128
+ if (direct.length)
129
+ return direct;
130
+ if (name === 'actions' && this.actionsHostEl) {
131
+ return Array.from(this.actionsHostEl.children);
132
+ }
133
+ if (name === 'footer' && this.footerEl) {
134
+ return Array.from(this.footerEl.children);
135
+ }
136
+ if (name === 'header') {
137
+ const main = this.headerEl?.querySelector('.designbase-wc-section__header-main');
138
+ return main ? Array.from(main.children) : [];
139
+ }
140
+ if (name === 'description') {
141
+ const description = this.headerEl?.querySelector('.designbase-wc-section__description');
142
+ const child = description?.firstElementChild;
143
+ return child ? [child] : [];
144
+ }
145
+ return [];
146
+ }
147
+ collectContentNodes() {
148
+ const direct = Array.from(this.children).filter((child) => {
149
+ if (!this.isUserNode(child))
150
+ return false;
151
+ const slot = child.getAttribute('slot');
152
+ return !slot || slot === 'default';
153
+ });
154
+ if (direct.length)
155
+ return direct;
156
+ return this.contentEl ? Array.from(this.contentEl.children) : [];
157
+ }
158
+ ensureStructure() {
159
+ if (!this.headerEl) {
160
+ this.headerEl = document.createElement('div');
161
+ this.headerEl.className = 'designbase-wc-section__header';
162
+ this.headerEl.setAttribute('data-wc-internal', '');
163
+ }
164
+ if (!this.bodyEl) {
165
+ this.bodyEl = document.createElement('div');
166
+ this.bodyEl.className = 'designbase-wc-section__body';
167
+ this.bodyEl.id = this.contentId;
168
+ this.bodyEl.setAttribute('data-wc-internal', '');
169
+ this.bodyInnerEl = document.createElement('div');
170
+ this.bodyInnerEl.className = 'designbase-wc-section__body-inner';
171
+ this.bodyInnerEl.setAttribute('data-wc-internal', '');
172
+ this.bodyEl.append(this.bodyInnerEl);
173
+ }
174
+ if (!this.contentEl) {
175
+ this.contentEl = document.createElement('div');
176
+ this.contentEl.className = 'designbase-wc-section__content';
177
+ this.contentEl.setAttribute('data-wc-internal', '');
178
+ }
179
+ if (!this.footerEl) {
180
+ this.footerEl = document.createElement('div');
181
+ this.footerEl.className = 'designbase-wc-section__footer';
182
+ this.footerEl.setAttribute('data-wc-internal', '');
183
+ }
184
+ if (!this.headerEl.isConnected) {
185
+ this.append(this.headerEl);
186
+ }
187
+ }
188
+ mountBody() {
189
+ const contentNodes = this.collectContentNodes();
190
+ const footerNodes = this.collectSlotted('footer');
191
+ this.contentEl.replaceChildren(...contentNodes);
192
+ this.footerEl.replaceChildren(...footerNodes);
193
+ this.footerEl.hidden = footerNodes.length === 0;
194
+ if (this.isCollapsible()) {
195
+ this.bodyInnerEl.replaceChildren(this.contentEl, this.footerEl);
196
+ if (!this.bodyEl.isConnected) {
197
+ this.append(this.bodyEl);
198
+ }
199
+ return;
200
+ }
201
+ this.bodyEl?.remove();
202
+ if (!this.contentEl.isConnected) {
203
+ this.append(this.contentEl);
204
+ }
205
+ if (footerNodes.length) {
206
+ if (!this.footerEl.isConnected) {
207
+ this.append(this.footerEl);
208
+ }
209
+ }
210
+ else {
211
+ this.footerEl.remove();
212
+ }
213
+ }
214
+ getChevronSize() {
215
+ const size = this.getAttribute('size') || 'm';
216
+ if (size === 's')
217
+ return 16;
218
+ if (size === 'l')
219
+ return 24;
220
+ return 20;
221
+ }
222
+ createTitleArea() {
223
+ const title = this.getAttribute('title');
224
+ const subtitle = this.getAttribute('subtitle');
225
+ const description = this.getAttribute('description');
226
+ const descriptionSlot = this.collectSlotted('description')[0];
227
+ if (!title && !subtitle && !description && !descriptionSlot)
228
+ return null;
229
+ const area = document.createElement('div');
230
+ area.className = 'designbase-wc-section__title-area';
231
+ if (title) {
232
+ const heading = document.createElement('h2');
233
+ heading.className = 'designbase-wc-section__title';
234
+ heading.textContent = title;
235
+ area.append(heading);
236
+ }
237
+ if (subtitle) {
238
+ const sub = document.createElement('h3');
239
+ sub.className = 'designbase-wc-section__subtitle';
240
+ sub.textContent = subtitle;
241
+ area.append(sub);
242
+ }
243
+ if (descriptionSlot) {
244
+ const body = document.createElement('p');
245
+ body.className = 'designbase-wc-section__description';
246
+ body.append(descriptionSlot);
247
+ area.append(body);
248
+ }
249
+ else if (description) {
250
+ const body = document.createElement('p');
251
+ body.className = 'designbase-wc-section__description';
252
+ body.textContent = description;
253
+ area.append(body);
254
+ }
255
+ return area;
256
+ }
257
+ createChevron() {
258
+ const chevron = document.createElement('span');
259
+ chevron.className = 'designbase-wc-section__chevron';
260
+ chevron.setAttribute('aria-hidden', 'true');
261
+ chevron.append(createDbIcon('chevron-down', this.getChevronSize()));
262
+ return chevron;
263
+ }
264
+ renderHeader() {
265
+ if (!this.headerEl)
266
+ return;
267
+ const headerSlot = this.collectSlotted('header')[0];
268
+ const actionNodes = this.collectSlotted('actions');
269
+ const titleArea = this.createTitleArea();
270
+ const hasTabs = this.hasHeaderTabs();
271
+ const hasHeader = Boolean(headerSlot || titleArea || actionNodes.length);
272
+ this.headerEl.replaceChildren();
273
+ this.headerEl.hidden = !hasHeader && !hasTabs;
274
+ this.headerEl.classList.toggle('designbase-wc-section__header--with-tabs', hasTabs);
275
+ if (!hasHeader && !hasTabs)
276
+ return;
277
+ if (this.isCollapsible()) {
278
+ if (headerSlot) {
279
+ const trigger = document.createElement('button');
280
+ trigger.type = 'button';
281
+ trigger.className = 'designbase-wc-section__header-trigger';
282
+ trigger.setAttribute('aria-expanded', String(this.isExpanded()));
283
+ trigger.setAttribute('aria-controls', this.contentId);
284
+ trigger.addEventListener('click', this.handleToggle);
285
+ const main = document.createElement('div');
286
+ main.className = 'designbase-wc-section__header-main';
287
+ main.append(headerSlot);
288
+ trigger.append(main, this.createChevron());
289
+ this.headerEl.append(trigger);
290
+ }
291
+ else {
292
+ const trigger = document.createElement('button');
293
+ trigger.type = 'button';
294
+ trigger.className = 'designbase-wc-section__header-trigger';
295
+ trigger.setAttribute('aria-expanded', String(this.isExpanded()));
296
+ trigger.setAttribute('aria-controls', this.contentId);
297
+ trigger.addEventListener('click', this.handleToggle);
298
+ if (titleArea)
299
+ trigger.append(titleArea);
300
+ trigger.append(this.createChevron());
301
+ this.headerEl.append(trigger);
302
+ if (actionNodes.length) {
303
+ this.actionsHostEl = document.createElement('div');
304
+ this.actionsHostEl.className = 'designbase-wc-section__actions';
305
+ this.actionsHostEl.addEventListener('click', (event) => event.stopPropagation());
306
+ actionNodes.forEach((node) => this.actionsHostEl.append(node));
307
+ this.headerEl.append(this.actionsHostEl);
308
+ }
309
+ }
310
+ return;
311
+ }
312
+ const appendHeaderMain = (container) => {
313
+ if (headerSlot) {
314
+ container.append(headerSlot);
315
+ return;
316
+ }
317
+ if (titleArea)
318
+ container.append(titleArea);
319
+ if (actionNodes.length) {
320
+ this.actionsHostEl = document.createElement('div');
321
+ this.actionsHostEl.className = 'designbase-wc-section__actions';
322
+ actionNodes.forEach((node) => this.actionsHostEl.append(node));
323
+ container.append(this.actionsHostEl);
324
+ }
325
+ };
326
+ if (hasTabs) {
327
+ const row = document.createElement('div');
328
+ row.className = 'designbase-wc-section__header-row';
329
+ appendHeaderMain(row);
330
+ this.headerEl.append(row);
331
+ const tabsWrap = document.createElement('div');
332
+ tabsWrap.className = 'designbase-wc-section__header-tabs';
333
+ if (!this.tabsEl) {
334
+ this.tabsEl = document.createElement('db-tabs');
335
+ this.tabsEl.setAttribute('size', 'm');
336
+ this.tabsEl.addEventListener('db-change', this.handleTabChange);
337
+ }
338
+ this.tabsEl.setAttribute('items', JSON.stringify(this.parseTabs()));
339
+ this.tabsEl.setAttribute('selected-id', this.getActiveTabId());
340
+ tabsWrap.append(this.tabsEl);
341
+ this.headerEl.append(tabsWrap);
342
+ return;
343
+ }
344
+ appendHeaderMain(this.headerEl);
345
+ }
346
+ syncHostClasses() {
347
+ const size = this.getAttribute('size') || 'm';
348
+ const safeSize = SIZES.includes(size) ? size : 'm';
349
+ const expanded = this.isExpanded();
350
+ this.className = [
351
+ 'designbase-wc-section',
352
+ `designbase-wc-section--size-${safeSize}`,
353
+ this.hasAttribute('no-padding') && 'designbase-wc-section--no-padding',
354
+ this.hasHeaderTabs() && 'designbase-wc-section--has-header-tabs',
355
+ this.hasAttribute('full-width') && 'designbase-wc-section--full-width',
356
+ this.hasAttribute('full-height') && 'designbase-wc-section--full-height',
357
+ this.hasAttribute('overflow-visible') && 'designbase-wc-section--overflow-visible',
358
+ this.isCollapsible() && 'designbase-wc-section--collapsible',
359
+ this.isCollapsible() && expanded && 'designbase-wc-section--expanded',
360
+ this.isCollapsible() && !expanded && 'designbase-wc-section--collapsed',
361
+ ]
362
+ .filter(Boolean)
363
+ .join(' ');
364
+ }
365
+ syncCollapsibleState() {
366
+ if (!this.isCollapsible() || !this.bodyEl)
367
+ return;
368
+ const expanded = this.isExpanded();
369
+ this.bodyEl.setAttribute('aria-hidden', String(!expanded));
370
+ const trigger = this.headerEl?.querySelector('.designbase-wc-section__header-trigger');
371
+ trigger?.setAttribute('aria-expanded', String(expanded));
372
+ }
373
+ sync() {
374
+ this.ensureStructure();
375
+ this.syncHostClasses();
376
+ this.renderHeader();
377
+ this.mountBody();
378
+ this.syncCollapsibleState();
379
+ }
380
+ }
381
+ if (!customElements.get('db-section')) {
382
+ customElements.define('db-section', DbSection);
383
+ }
384
+
385
+ export { DbSection };
@@ -1 +1,231 @@
1
- const e="designbase-wc-segment-control",t={bar:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="12" width="4" height="8"/><rect x="10" y="8" width="4" height="12"/><rect x="17" y="4" width="4" height="16"/></svg>',line:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="4 16 9 10 14 13 20 6"/></svg>',pie:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2v10l8.66 5"/><circle cx="12" cy="12" r="10"/></svg>',donut:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="8"/><circle cx="12" cy="12" r="3"/></svg>',radar:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="12 2 20 8 17 20 7 20 4 8"/></svg>'};class DbSegmentControl extends HTMLElement{constructor(){super(...arguments),this.built=!1,this.indicatorEl=null,this.segmentButtons=[],this.focusedIndex=-1,this.boundKeyDown=e=>this.handleKeyDown(e),this.boundResize=()=>this.updateIndicator(),this.resizeObserver=null}static get observedAttributes(){return["options","value","default-value","size","variant","appearance","full-width","disabled"]}connectedCallback(){this.built||(this.built=!0),this.render(),this.addEventListener("keydown",this.boundKeyDown),window.addEventListener("resize",this.boundResize),this.resizeObserver=new ResizeObserver(()=>this.updateIndicator()),this.resizeObserver.observe(this)}disconnectedCallback(){this.removeEventListener("keydown",this.boundKeyDown),window.removeEventListener("resize",this.boundResize),this.resizeObserver?.disconnect(),this.resizeObserver=null}attributeChangedCallback(e){this.built&&("value"!==e?this.render():this.updateSelection())}get options(){return this.parseOptions(this.getAttribute("options"))}set options(e){this.setAttribute("options","string"==typeof e?e:JSON.stringify(e))}get value(){return this.getAttribute("value")||this.getAttribute("default-value")||this.options[0]?.value||""}set value(e){this.setAttribute("value",e)}parseOptions(e){if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}render(){const i=this.getAttribute("size")||"m",s=this.getAttribute("variant")||"default",n=this.getAttribute("appearance")||"pill",r=this.hasAttribute("disabled"),o=this.options,a=this.value;this.className=[e,`${e}--${i}`,`${e}--${s}`,"rounded"===n&&`${e}--appearance-rounded`,this.hasAttribute("full-width")&&`${e}--full-width`,r&&`${e}--disabled`].filter(Boolean).join(" "),this.setAttribute("role","tablist"),this.setAttribute("aria-label","세그먼트 컨트롤"),this.replaceChildren(),this.segmentButtons=[],o.forEach((i,n)=>{const o=i.value===a,l=Boolean(r||i.disabled),d=document.createElement("button");if(d.type="button",d.className=[`${e}__segment`,o&&`${e}__segment--selected`,l&&`${e}__segment--disabled`].filter(Boolean).join(" "),d.setAttribute("role","tab"),d.setAttribute("aria-selected",String(o)),d.setAttribute("aria-disabled",String(l)),d.setAttribute("tabindex",o?"0":"-1"),d.disabled=l,i.icon&&t[i.icon]){const s=document.createElement("span");s.className=`${e}__segment-icon`,s.innerHTML=t[i.icon],d.appendChild(s)}const h=document.createElement("span");h.className=`${e}__segment-label`,h.textContent=i.label,"icon-only"===s&&h.setAttribute("aria-label",i.label),d.appendChild(h),d.addEventListener("click",()=>this.select(i.value)),d.addEventListener("focus",()=>{this.focusedIndex=n,d.classList.add(`${e}__segment--focused`)}),d.addEventListener("blur",()=>{this.focusedIndex=-1,d.classList.remove(`${e}__segment--focused`)}),this.appendChild(d),this.segmentButtons.push(d)}),this.indicatorEl=document.createElement("div"),this.indicatorEl.className=`${e}__indicator`,this.appendChild(this.indicatorEl),this.updateSelection()}updateSelection(){const t=this.options,i=this.value,s=t.findIndex(e=>e.value===i);this.segmentButtons.forEach((s,n)=>{const r=t[n],o=r?.value===i;s.classList.toggle(`${e}__segment--selected`,o),s.setAttribute("aria-selected",String(o)),s.setAttribute("tabindex",o?"0":"-1")}),this.indicatorEl&&t.length>0&&s>=0&&requestAnimationFrame(()=>this.updateIndicator())}updateIndicator(){const e=this.options.findIndex(e=>e.value===this.value),t=this.segmentButtons[e];this.indicatorEl&&t&&(this.indicatorEl.style.width=`${t.offsetWidth}px`,this.indicatorEl.style.transform=`translateX(${t.offsetLeft}px)`)}select(e){if(this.hasAttribute("disabled"))return;const t=this.options.find(t=>t.value===e);t&&!t.disabled&&(this.setAttribute("value",e),this.dispatchEvent(new CustomEvent("db-change",{detail:{value:e},bubbles:!0,composed:!0})))}handleKeyDown(e){if(this.hasAttribute("disabled"))return;const t=this.options,i=t.findIndex(e=>e.value===this.value);if(-1===i)return;let s=i;switch(e.key){case"ArrowLeft":e.preventDefault(),s=i>0?i-1:t.length-1;break;case"ArrowRight":e.preventDefault(),s=i<t.length-1?i+1:0;break;case"Home":e.preventDefault(),s=0;break;case"End":e.preventDefault(),s=t.length-1;break;case"Enter":case" ":return e.preventDefault(),void this.select(t[s]?.value??this.value);default:return}for(;s!==i;){const i=t[s];if(i&&!i.disabled){this.segmentButtons[s]?.focus();break}s="ArrowLeft"===e.key||"Home"===e.key?s>0?s-1:t.length-1:s<t.length-1?s+1:0}}}customElements.get("db-segment-control")||customElements.define("db-segment-control",DbSegmentControl);export{DbSegmentControl};
1
+ /**
2
+ * SegmentControl Web Component
3
+ * packages/ui SegmentControl.tsx와 DOM·동작·스타일 1:1 동기화
4
+ */
5
+ const CLASS = 'designbase-wc-segment-control';
6
+ const ICON_SVGS = {
7
+ bar: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="12" width="4" height="8"/><rect x="10" y="8" width="4" height="12"/><rect x="17" y="4" width="4" height="16"/></svg>',
8
+ line: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="4 16 9 10 14 13 20 6"/></svg>',
9
+ pie: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2v10l8.66 5"/><circle cx="12" cy="12" r="10"/></svg>',
10
+ donut: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="8"/><circle cx="12" cy="12" r="3"/></svg>',
11
+ radar: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="12 2 20 8 17 20 7 20 4 8"/></svg>',
12
+ };
13
+ class DbSegmentControl extends HTMLElement {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.built = false;
17
+ this.indicatorEl = null;
18
+ this.segmentButtons = [];
19
+ this.focusedIndex = -1;
20
+ this.boundKeyDown = (e) => this.handleKeyDown(e);
21
+ this.boundResize = () => this.updateIndicator();
22
+ this.resizeObserver = null;
23
+ }
24
+ static get observedAttributes() {
25
+ return ['options', 'value', 'default-value', 'size', 'variant', 'appearance', 'full-width', 'disabled'];
26
+ }
27
+ connectedCallback() {
28
+ if (!this.built) {
29
+ this.built = true;
30
+ }
31
+ this.render();
32
+ this.addEventListener('keydown', this.boundKeyDown);
33
+ window.addEventListener('resize', this.boundResize);
34
+ this.resizeObserver = new ResizeObserver(() => this.updateIndicator());
35
+ this.resizeObserver.observe(this);
36
+ }
37
+ disconnectedCallback() {
38
+ this.removeEventListener('keydown', this.boundKeyDown);
39
+ window.removeEventListener('resize', this.boundResize);
40
+ this.resizeObserver?.disconnect();
41
+ this.resizeObserver = null;
42
+ }
43
+ attributeChangedCallback(name) {
44
+ if (!this.built)
45
+ return;
46
+ if (name === 'value') {
47
+ this.updateSelection();
48
+ return;
49
+ }
50
+ this.render();
51
+ }
52
+ get options() {
53
+ return this.parseOptions(this.getAttribute('options'));
54
+ }
55
+ set options(value) {
56
+ this.setAttribute('options', typeof value === 'string' ? value : JSON.stringify(value));
57
+ }
58
+ get value() {
59
+ return this.getAttribute('value') || this.getAttribute('default-value') || this.options[0]?.value || '';
60
+ }
61
+ set value(value) {
62
+ this.setAttribute('value', value);
63
+ }
64
+ parseOptions(raw) {
65
+ if (!raw)
66
+ return [];
67
+ try {
68
+ const parsed = JSON.parse(raw);
69
+ return Array.isArray(parsed) ? parsed : [];
70
+ }
71
+ catch {
72
+ return [];
73
+ }
74
+ }
75
+ render() {
76
+ const size = this.getAttribute('size') || 'm';
77
+ const variant = this.getAttribute('variant') || 'default';
78
+ const appearance = this.getAttribute('appearance') || 'pill';
79
+ const disabled = this.hasAttribute('disabled');
80
+ const options = this.options;
81
+ const selected = this.value;
82
+ this.className = [
83
+ CLASS,
84
+ `${CLASS}--${size}`,
85
+ `${CLASS}--${variant}`,
86
+ appearance === 'rounded' && `${CLASS}--appearance-rounded`,
87
+ this.hasAttribute('full-width') && `${CLASS}--full-width`,
88
+ disabled && `${CLASS}--disabled`,
89
+ ]
90
+ .filter(Boolean)
91
+ .join(' ');
92
+ this.setAttribute('role', 'tablist');
93
+ this.setAttribute('aria-label', '세그먼트 컨트롤');
94
+ this.replaceChildren();
95
+ this.segmentButtons = [];
96
+ options.forEach((option, index) => {
97
+ const isSelected = option.value === selected;
98
+ const isDisabled = Boolean(disabled || option.disabled);
99
+ const button = document.createElement('button');
100
+ button.type = 'button';
101
+ button.className = [
102
+ `${CLASS}__segment`,
103
+ isSelected && `${CLASS}__segment--selected`,
104
+ isDisabled && `${CLASS}__segment--disabled`,
105
+ ]
106
+ .filter(Boolean)
107
+ .join(' ');
108
+ button.setAttribute('role', 'tab');
109
+ button.setAttribute('aria-selected', String(isSelected));
110
+ button.setAttribute('aria-disabled', String(isDisabled));
111
+ button.setAttribute('tabindex', isSelected ? '0' : '-1');
112
+ button.disabled = isDisabled;
113
+ if (option.icon && ICON_SVGS[option.icon]) {
114
+ const iconWrap = document.createElement('span');
115
+ iconWrap.className = `${CLASS}__segment-icon`;
116
+ iconWrap.innerHTML = ICON_SVGS[option.icon];
117
+ button.appendChild(iconWrap);
118
+ }
119
+ const label = document.createElement('span');
120
+ label.className = `${CLASS}__segment-label`;
121
+ label.textContent = option.label;
122
+ if (variant === 'icon-only') {
123
+ label.setAttribute('aria-label', option.label);
124
+ }
125
+ button.appendChild(label);
126
+ button.addEventListener('click', () => this.select(option.value));
127
+ button.addEventListener('focus', () => {
128
+ this.focusedIndex = index;
129
+ button.classList.add(`${CLASS}__segment--focused`);
130
+ });
131
+ button.addEventListener('blur', () => {
132
+ this.focusedIndex = -1;
133
+ button.classList.remove(`${CLASS}__segment--focused`);
134
+ });
135
+ this.appendChild(button);
136
+ this.segmentButtons.push(button);
137
+ });
138
+ this.indicatorEl = document.createElement('div');
139
+ this.indicatorEl.className = `${CLASS}__indicator`;
140
+ this.appendChild(this.indicatorEl);
141
+ this.updateSelection();
142
+ }
143
+ updateSelection() {
144
+ const options = this.options;
145
+ const selected = this.value;
146
+ const selectedIndex = options.findIndex((option) => option.value === selected);
147
+ this.segmentButtons.forEach((button, index) => {
148
+ const option = options[index];
149
+ const isSelected = option?.value === selected;
150
+ button.classList.toggle(`${CLASS}__segment--selected`, isSelected);
151
+ button.setAttribute('aria-selected', String(isSelected));
152
+ button.setAttribute('tabindex', isSelected ? '0' : '-1');
153
+ });
154
+ if (this.indicatorEl && options.length > 0 && selectedIndex >= 0) {
155
+ requestAnimationFrame(() => this.updateIndicator());
156
+ }
157
+ }
158
+ updateIndicator() {
159
+ const selectedIndex = this.options.findIndex((option) => option.value === this.value);
160
+ const activeButton = this.segmentButtons[selectedIndex];
161
+ if (!this.indicatorEl || !activeButton)
162
+ return;
163
+ this.indicatorEl.style.width = `${activeButton.offsetWidth}px`;
164
+ this.indicatorEl.style.transform = `translateX(${activeButton.offsetLeft}px)`;
165
+ }
166
+ select(value) {
167
+ if (this.hasAttribute('disabled'))
168
+ return;
169
+ const option = this.options.find((item) => item.value === value);
170
+ if (!option || option.disabled)
171
+ return;
172
+ this.setAttribute('value', value);
173
+ this.dispatchEvent(new CustomEvent('db-change', {
174
+ detail: { value },
175
+ bubbles: true,
176
+ composed: true,
177
+ }));
178
+ }
179
+ handleKeyDown(event) {
180
+ if (this.hasAttribute('disabled'))
181
+ return;
182
+ const options = this.options;
183
+ const currentIndex = options.findIndex((option) => option.value === this.value);
184
+ if (currentIndex === -1)
185
+ return;
186
+ let nextIndex = currentIndex;
187
+ switch (event.key) {
188
+ case 'ArrowLeft':
189
+ event.preventDefault();
190
+ nextIndex = currentIndex > 0 ? currentIndex - 1 : options.length - 1;
191
+ break;
192
+ case 'ArrowRight':
193
+ event.preventDefault();
194
+ nextIndex = currentIndex < options.length - 1 ? currentIndex + 1 : 0;
195
+ break;
196
+ case 'Home':
197
+ event.preventDefault();
198
+ nextIndex = 0;
199
+ break;
200
+ case 'End':
201
+ event.preventDefault();
202
+ nextIndex = options.length - 1;
203
+ break;
204
+ case 'Enter':
205
+ case ' ':
206
+ event.preventDefault();
207
+ this.select(options[nextIndex]?.value ?? this.value);
208
+ return;
209
+ default:
210
+ return;
211
+ }
212
+ while (nextIndex !== currentIndex) {
213
+ const nextOption = options[nextIndex];
214
+ if (nextOption && !nextOption.disabled) {
215
+ this.segmentButtons[nextIndex]?.focus();
216
+ break;
217
+ }
218
+ if (event.key === 'ArrowLeft' || event.key === 'Home') {
219
+ nextIndex = nextIndex > 0 ? nextIndex - 1 : options.length - 1;
220
+ }
221
+ else {
222
+ nextIndex = nextIndex < options.length - 1 ? nextIndex + 1 : 0;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ if (!customElements.get('db-segment-control')) {
228
+ customElements.define('db-segment-control', DbSegmentControl);
229
+ }
230
+
231
+ export { DbSegmentControl };