@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,166 @@
|
|
|
1
|
-
import{createDbIcon
|
|
1
|
+
import { createDbIcon } from './db-icons.js';
|
|
2
|
+
|
|
3
|
+
class DbProgressStep extends HTMLElement {
|
|
4
|
+
static get observedAttributes() {
|
|
5
|
+
return ['items', 'size', 'layout', 'current-step', 'clickable', 'full-width', 'disabled'];
|
|
6
|
+
}
|
|
7
|
+
get items() {
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(this.getAttribute('items') || '[]');
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
set items(value) {
|
|
16
|
+
this.setAttribute('items', typeof value === 'string' ? value : JSON.stringify(value));
|
|
17
|
+
}
|
|
18
|
+
connectedCallback() {
|
|
19
|
+
this.render();
|
|
20
|
+
}
|
|
21
|
+
attributeChangedCallback() {
|
|
22
|
+
this.render();
|
|
23
|
+
}
|
|
24
|
+
resolveStatus(index, item) {
|
|
25
|
+
const itemStatus = item.status ?? 'pending';
|
|
26
|
+
if (itemStatus !== 'pending')
|
|
27
|
+
return itemStatus;
|
|
28
|
+
const current = Number(this.getAttribute('current-step') || 0);
|
|
29
|
+
if (index < current)
|
|
30
|
+
return 'completed';
|
|
31
|
+
if (index === current)
|
|
32
|
+
return 'active';
|
|
33
|
+
return 'pending';
|
|
34
|
+
}
|
|
35
|
+
iconSize(size) {
|
|
36
|
+
if (size === 's')
|
|
37
|
+
return 12;
|
|
38
|
+
if (size === 'l')
|
|
39
|
+
return 20;
|
|
40
|
+
return 16;
|
|
41
|
+
}
|
|
42
|
+
renderIndicatorContent(status, index, size) {
|
|
43
|
+
const iconWrap = document.createElement('div');
|
|
44
|
+
iconWrap.className = 'designbase-wc-progress-step__icon';
|
|
45
|
+
if (status === 'completed') {
|
|
46
|
+
iconWrap.append(createDbIcon('done', this.iconSize(size)));
|
|
47
|
+
}
|
|
48
|
+
else if (status === 'error') {
|
|
49
|
+
iconWrap.append(createDbIcon('warning-filled', this.iconSize(size)));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const number = document.createElement('span');
|
|
53
|
+
number.className = 'designbase-wc-progress-step__number';
|
|
54
|
+
number.textContent = String(index + 1);
|
|
55
|
+
iconWrap.append(number);
|
|
56
|
+
}
|
|
57
|
+
return iconWrap;
|
|
58
|
+
}
|
|
59
|
+
handleStepClick(item, index) {
|
|
60
|
+
const disabled = this.hasAttribute('disabled');
|
|
61
|
+
const clickable = this.hasAttribute('clickable');
|
|
62
|
+
if (disabled || item.disabled || !clickable)
|
|
63
|
+
return;
|
|
64
|
+
this.dispatchEvent(new CustomEvent('db-step-click', {
|
|
65
|
+
detail: { item, index },
|
|
66
|
+
bubbles: true,
|
|
67
|
+
composed: true,
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
render() {
|
|
71
|
+
const size = this.getAttribute('size') || 'm';
|
|
72
|
+
const layout = this.getAttribute('layout') || 'horizontal';
|
|
73
|
+
const clickable = this.hasAttribute('clickable');
|
|
74
|
+
const disabled = this.hasAttribute('disabled');
|
|
75
|
+
const items = this.items;
|
|
76
|
+
this.className = [
|
|
77
|
+
'designbase-wc-progress-step',
|
|
78
|
+
`designbase-wc-progress-step--${size}`,
|
|
79
|
+
`designbase-wc-progress-step--${layout}`,
|
|
80
|
+
clickable && 'designbase-wc-progress-step--clickable',
|
|
81
|
+
this.hasAttribute('full-width') && 'designbase-wc-progress-step--full-width',
|
|
82
|
+
disabled && 'designbase-wc-progress-step--disabled',
|
|
83
|
+
]
|
|
84
|
+
.filter(Boolean)
|
|
85
|
+
.join(' ');
|
|
86
|
+
this.replaceChildren();
|
|
87
|
+
items.forEach((item, index) => {
|
|
88
|
+
const status = this.resolveStatus(index, item);
|
|
89
|
+
const isLast = index === items.length - 1;
|
|
90
|
+
const isClickable = clickable && !disabled && !item.disabled;
|
|
91
|
+
const prevStatus = index > 0 ? this.resolveStatus(index - 1, items[index - 1]) : 'pending';
|
|
92
|
+
const connectorStatus = prevStatus === 'completed' ? 'completed' : status;
|
|
93
|
+
const row = document.createElement('div');
|
|
94
|
+
row.className = [
|
|
95
|
+
'designbase-wc-progress-step__item',
|
|
96
|
+
`designbase-wc-progress-step__item--${status}`,
|
|
97
|
+
isClickable && 'designbase-wc-progress-step__item--clickable',
|
|
98
|
+
item.disabled && 'designbase-wc-progress-step__item--disabled',
|
|
99
|
+
]
|
|
100
|
+
.filter(Boolean)
|
|
101
|
+
.join(' ');
|
|
102
|
+
const indicatorContainer = document.createElement('div');
|
|
103
|
+
indicatorContainer.className = 'designbase-wc-progress-step__indicator-container';
|
|
104
|
+
const indicator = document.createElement('div');
|
|
105
|
+
indicator.className = 'designbase-wc-progress-step__indicator';
|
|
106
|
+
if (isClickable) {
|
|
107
|
+
indicator.tabIndex = 0;
|
|
108
|
+
indicator.setAttribute('role', 'button');
|
|
109
|
+
indicator.setAttribute('aria-label', `${item.title} 단계로 이동`);
|
|
110
|
+
indicator.addEventListener('click', () => this.handleStepClick(item, index));
|
|
111
|
+
indicator.addEventListener('keydown', (event) => {
|
|
112
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
this.handleStepClick(item, index);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
indicator.tabIndex = -1;
|
|
120
|
+
}
|
|
121
|
+
if (status === 'active') {
|
|
122
|
+
const pulse = document.createElement('div');
|
|
123
|
+
pulse.className = 'designbase-wc-progress-step__pulse';
|
|
124
|
+
indicator.append(pulse);
|
|
125
|
+
}
|
|
126
|
+
indicator.append(this.renderIndicatorContent(status, index, size));
|
|
127
|
+
indicatorContainer.append(indicator);
|
|
128
|
+
if (!isLast) {
|
|
129
|
+
const connector = document.createElement('div');
|
|
130
|
+
connector.className = [
|
|
131
|
+
'designbase-wc-progress-step__connector',
|
|
132
|
+
`designbase-wc-progress-step__connector--${connectorStatus}`,
|
|
133
|
+
].join(' ');
|
|
134
|
+
indicatorContainer.append(connector);
|
|
135
|
+
}
|
|
136
|
+
row.append(indicatorContainer);
|
|
137
|
+
const content = document.createElement('div');
|
|
138
|
+
content.className = 'designbase-wc-progress-step__content';
|
|
139
|
+
const header = document.createElement('div');
|
|
140
|
+
header.className = 'designbase-wc-progress-step__header';
|
|
141
|
+
const title = document.createElement('h3');
|
|
142
|
+
title.className = 'designbase-wc-progress-step__title';
|
|
143
|
+
title.textContent = item.title;
|
|
144
|
+
header.append(title);
|
|
145
|
+
content.append(header);
|
|
146
|
+
if (item.description) {
|
|
147
|
+
const description = document.createElement('p');
|
|
148
|
+
description.className = 'designbase-wc-progress-step__description';
|
|
149
|
+
description.textContent = item.description;
|
|
150
|
+
content.append(description);
|
|
151
|
+
}
|
|
152
|
+
if (item.timestamp) {
|
|
153
|
+
const timestamp = document.createElement('span');
|
|
154
|
+
timestamp.className = 'designbase-wc-progress-step__timestamp';
|
|
155
|
+
timestamp.textContent = item.timestamp;
|
|
156
|
+
content.append(timestamp);
|
|
157
|
+
}
|
|
158
|
+
row.append(content);
|
|
159
|
+
this.append(row);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!customElements.get('db-progress-step'))
|
|
164
|
+
customElements.define('db-progress-step', DbProgressStep);
|
|
165
|
+
|
|
166
|
+
export { DbProgressStep };
|
|
@@ -1 +1,171 @@
|
|
|
1
|
-
const
|
|
1
|
+
const SIZES = ['s', 'm', 'l'];
|
|
2
|
+
const VARIANTS = ['default', 'success', 'warning', 'danger'];
|
|
3
|
+
const CIRCULAR_STYLES = ['default', 'minimal'];
|
|
4
|
+
function getCircularMetrics(circularStyle, size) {
|
|
5
|
+
if (circularStyle === 'minimal') {
|
|
6
|
+
return { svgSize: 20, radius: 8, strokeWidth: 2, center: 10 };
|
|
7
|
+
}
|
|
8
|
+
switch (size) {
|
|
9
|
+
case 's':
|
|
10
|
+
return { svgSize: 64, radius: 26, strokeWidth: 4, center: 32 };
|
|
11
|
+
case 'l':
|
|
12
|
+
return { svgSize: 160, radius: 62, strokeWidth: 10, center: 80 };
|
|
13
|
+
default:
|
|
14
|
+
return { svgSize: 120, radius: 45, strokeWidth: 8, center: 60 };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function createSvgCircle(className, cx, cy, radius, strokeWidth, extras) {
|
|
18
|
+
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
19
|
+
circle.setAttribute('class', className);
|
|
20
|
+
circle.setAttribute('cx', String(cx));
|
|
21
|
+
circle.setAttribute('cy', String(cy));
|
|
22
|
+
circle.setAttribute('r', String(radius));
|
|
23
|
+
circle.setAttribute('stroke-width', String(strokeWidth));
|
|
24
|
+
if (extras) {
|
|
25
|
+
Object.entries(extras).forEach(([key, value]) => circle.setAttribute(key, value));
|
|
26
|
+
}
|
|
27
|
+
return circle;
|
|
28
|
+
}
|
|
29
|
+
class DbProgress extends HTMLElement {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
// 재사용을 위한 DOM 참조 — 매 렌더마다 새로 만들지 않아야 width/offset 트랜지션이 부드럽다.
|
|
33
|
+
this.structureSignature = '';
|
|
34
|
+
this.circumference = 0;
|
|
35
|
+
}
|
|
36
|
+
static get observedAttributes() {
|
|
37
|
+
return ['value', 'max', 'size', 'variant', 'type', 'circular-style', 'show-value', 'animated', 'striped', 'glow', 'gradient'];
|
|
38
|
+
}
|
|
39
|
+
get value() {
|
|
40
|
+
return Number(this.getAttribute('value') || 0);
|
|
41
|
+
}
|
|
42
|
+
set value(value) {
|
|
43
|
+
this.setAttribute('value', String(value));
|
|
44
|
+
}
|
|
45
|
+
connectedCallback() {
|
|
46
|
+
this.render();
|
|
47
|
+
}
|
|
48
|
+
attributeChangedCallback() {
|
|
49
|
+
this.render();
|
|
50
|
+
}
|
|
51
|
+
render() {
|
|
52
|
+
const max = Number(this.getAttribute('max') || 100);
|
|
53
|
+
const percentage = Math.min(Math.max((this.value / max) * 100, 0), 100);
|
|
54
|
+
const size = this.getAttribute('size') || 'm';
|
|
55
|
+
const variant = this.getAttribute('variant') || 'default';
|
|
56
|
+
const type = this.getAttribute('type') || 'linear';
|
|
57
|
+
const circularStyle = this.getAttribute('circular-style') || 'default';
|
|
58
|
+
const resolvedSize = SIZES.includes(size) ? size : 'm';
|
|
59
|
+
const resolvedVariant = VARIANTS.includes(variant) ? variant : 'default';
|
|
60
|
+
const resolvedCircularStyle = CIRCULAR_STYLES.includes(circularStyle)
|
|
61
|
+
? circularStyle
|
|
62
|
+
: 'default';
|
|
63
|
+
const showValue = this.hasAttribute('show-value');
|
|
64
|
+
this.className = [
|
|
65
|
+
'designbase-wc-progress',
|
|
66
|
+
`designbase-wc-progress--size-${resolvedSize}`,
|
|
67
|
+
`designbase-wc-progress--variant-${resolvedVariant}`,
|
|
68
|
+
`designbase-wc-progress--type-${type}`,
|
|
69
|
+
type === 'circular' && resolvedCircularStyle === 'minimal' ? 'designbase-wc-progress--circular-minimal' : '',
|
|
70
|
+
this.hasAttribute('animated') ? 'designbase-wc-progress--animated' : '',
|
|
71
|
+
this.hasAttribute('striped') ? 'designbase-wc-progress--striped' : '',
|
|
72
|
+
this.hasAttribute('gradient') ? 'designbase-wc-progress--gradient' : '',
|
|
73
|
+
this.hasAttribute('glow') ? 'designbase-wc-progress--glow' : '',
|
|
74
|
+
].filter(Boolean).join(' ');
|
|
75
|
+
this.setAttribute('role', 'progressbar');
|
|
76
|
+
this.setAttribute('aria-valuemin', '0');
|
|
77
|
+
this.setAttribute('aria-valuemax', String(max));
|
|
78
|
+
this.setAttribute('aria-valuenow', String(this.value));
|
|
79
|
+
// 구조가 바뀔 때만 다시 만든다. 값만 바뀔 땐 in-place 업데이트로 트랜지션 유지.
|
|
80
|
+
const signature = [type, resolvedCircularStyle, resolvedSize, showValue ? '1' : '0'].join('|');
|
|
81
|
+
if (signature !== this.structureSignature) {
|
|
82
|
+
this.structureSignature = signature;
|
|
83
|
+
if (type === 'circular') {
|
|
84
|
+
this.buildCircular(resolvedCircularStyle, resolvedSize, showValue);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.buildLinear(showValue);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (type === 'circular') {
|
|
91
|
+
this.updateCircular(percentage);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
this.updateLinear(percentage);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
buildLinear(showValue) {
|
|
98
|
+
this.circularBarEl = undefined;
|
|
99
|
+
this.circularValueEl = undefined;
|
|
100
|
+
const linear = document.createElement('div');
|
|
101
|
+
linear.className = 'designbase-wc-progress__linear';
|
|
102
|
+
const track = document.createElement('div');
|
|
103
|
+
track.className = 'designbase-wc-progress__track';
|
|
104
|
+
const bar = document.createElement('div');
|
|
105
|
+
bar.className = 'designbase-wc-progress__bar';
|
|
106
|
+
track.append(bar);
|
|
107
|
+
linear.append(track);
|
|
108
|
+
this.barEl = bar;
|
|
109
|
+
if (showValue) {
|
|
110
|
+
const value = document.createElement('span');
|
|
111
|
+
value.className = 'designbase-wc-progress__value';
|
|
112
|
+
linear.append(value);
|
|
113
|
+
this.linearValueEl = value;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.linearValueEl = undefined;
|
|
117
|
+
}
|
|
118
|
+
this.replaceChildren(linear);
|
|
119
|
+
}
|
|
120
|
+
updateLinear(percentage) {
|
|
121
|
+
if (this.barEl)
|
|
122
|
+
this.barEl.style.width = `${percentage}%`;
|
|
123
|
+
if (this.linearValueEl)
|
|
124
|
+
this.linearValueEl.textContent = `${Math.round(percentage)}%`;
|
|
125
|
+
}
|
|
126
|
+
buildCircular(circularStyle, size, showValue) {
|
|
127
|
+
this.barEl = undefined;
|
|
128
|
+
this.linearValueEl = undefined;
|
|
129
|
+
const { svgSize, radius, strokeWidth, center } = getCircularMetrics(circularStyle, size);
|
|
130
|
+
this.circumference = 2 * Math.PI * radius;
|
|
131
|
+
const wrapper = document.createElement('div');
|
|
132
|
+
wrapper.className = 'designbase-wc-progress__circular';
|
|
133
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
134
|
+
svg.setAttribute('class', 'designbase-wc-progress__circular-svg');
|
|
135
|
+
svg.setAttribute('width', String(svgSize));
|
|
136
|
+
svg.setAttribute('height', String(svgSize));
|
|
137
|
+
svg.setAttribute('viewBox', `0 0 ${svgSize} ${svgSize}`);
|
|
138
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
139
|
+
const barCircle = createSvgCircle('designbase-wc-progress__circular-bar', center, center, radius, strokeWidth, {
|
|
140
|
+
'stroke-dasharray': String(this.circumference),
|
|
141
|
+
'stroke-dashoffset': String(this.circumference),
|
|
142
|
+
transform: `rotate(-90 ${center} ${center})`,
|
|
143
|
+
});
|
|
144
|
+
this.circularBarEl = barCircle;
|
|
145
|
+
svg.append(createSvgCircle('designbase-wc-progress__circular-track', center, center, radius, strokeWidth), barCircle);
|
|
146
|
+
wrapper.append(svg);
|
|
147
|
+
if (showValue && circularStyle !== 'minimal') {
|
|
148
|
+
const value = document.createElement('span');
|
|
149
|
+
value.className = 'designbase-wc-progress__circular-value';
|
|
150
|
+
wrapper.append(value);
|
|
151
|
+
this.circularValueEl = value;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
this.circularValueEl = undefined;
|
|
155
|
+
}
|
|
156
|
+
this.replaceChildren(wrapper);
|
|
157
|
+
}
|
|
158
|
+
updateCircular(percentage) {
|
|
159
|
+
if (this.circularBarEl) {
|
|
160
|
+
const offset = this.circumference - (percentage / 100) * this.circumference;
|
|
161
|
+
this.circularBarEl.setAttribute('stroke-dashoffset', String(offset));
|
|
162
|
+
}
|
|
163
|
+
if (this.circularValueEl)
|
|
164
|
+
this.circularValueEl.textContent = `${Math.round(percentage)}%`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (!customElements.get('db-progress')) {
|
|
168
|
+
customElements.define('db-progress', DbProgress);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export { DbProgress };
|
|
@@ -1 +1,72 @@
|
|
|
1
|
-
const
|
|
1
|
+
const SIZES = ['s', 'm', 'l'];
|
|
2
|
+
const VARIANTS = ['default', 'primary', 'success', 'warning', 'danger'];
|
|
3
|
+
const STYLES = ['solid', 'striped', 'animated'];
|
|
4
|
+
class DbProgressbar extends HTMLElement {
|
|
5
|
+
static get observedAttributes() {
|
|
6
|
+
return ['value', 'min', 'max', 'size', 'variant', 'bar-style', 'show-label', 'label', 'label-position', 'full-width', 'disabled'];
|
|
7
|
+
}
|
|
8
|
+
connectedCallback() {
|
|
9
|
+
this.render();
|
|
10
|
+
}
|
|
11
|
+
attributeChangedCallback() {
|
|
12
|
+
this.render();
|
|
13
|
+
}
|
|
14
|
+
render() {
|
|
15
|
+
const min = Number(this.getAttribute('min') || 0);
|
|
16
|
+
const max = Number(this.getAttribute('max') || 100);
|
|
17
|
+
const rawValue = Number(this.getAttribute('value') || 0);
|
|
18
|
+
const value = Math.max(min, Math.min(max, rawValue));
|
|
19
|
+
const percentage = max === min ? 0 : ((value - min) / (max - min)) * 100;
|
|
20
|
+
const size = this.getAttribute('size') || 'm';
|
|
21
|
+
const variant = this.getAttribute('variant') || 'default';
|
|
22
|
+
const barStyle = this.getAttribute('bar-style') || 'solid';
|
|
23
|
+
const labelPosition = this.getAttribute('label-position') || 'top';
|
|
24
|
+
const showLabel = this.hasAttribute('show-label');
|
|
25
|
+
const label = this.getAttribute('label') || (showLabel ? `${Math.round(percentage)}%` : '');
|
|
26
|
+
const disabled = this.hasAttribute('disabled');
|
|
27
|
+
this.className = [
|
|
28
|
+
'designbase-wc-progressbar',
|
|
29
|
+
`designbase-wc-progressbar--${SIZES.includes(size) ? size : 'm'}`,
|
|
30
|
+
`designbase-wc-progressbar--${VARIANTS.includes(variant) ? variant : 'default'}`,
|
|
31
|
+
`designbase-wc-progressbar--${STYLES.includes(barStyle) ? barStyle : 'solid'}`,
|
|
32
|
+
this.hasAttribute('full-width') && 'designbase-wc-progressbar--full-width',
|
|
33
|
+
disabled && 'designbase-wc-progressbar--disabled',
|
|
34
|
+
percentage === 100 && 'designbase-wc-progressbar--completed',
|
|
35
|
+
]
|
|
36
|
+
.filter(Boolean)
|
|
37
|
+
.join(' ');
|
|
38
|
+
this.setAttribute('role', 'progressbar');
|
|
39
|
+
this.setAttribute('aria-valuemin', String(min));
|
|
40
|
+
this.setAttribute('aria-valuemax', String(max));
|
|
41
|
+
this.setAttribute('aria-valuenow', String(value));
|
|
42
|
+
if (label)
|
|
43
|
+
this.setAttribute('aria-label', label);
|
|
44
|
+
this.replaceChildren();
|
|
45
|
+
const container = document.createElement('div');
|
|
46
|
+
container.className = `designbase-wc-progressbar__container designbase-wc-progressbar__container--${labelPosition}`;
|
|
47
|
+
if (label && labelPosition !== 'inside') {
|
|
48
|
+
const labelEl = document.createElement('span');
|
|
49
|
+
labelEl.className = `designbase-wc-progressbar__label designbase-wc-progressbar__label--${labelPosition}`;
|
|
50
|
+
labelEl.textContent = label;
|
|
51
|
+
container.append(labelEl);
|
|
52
|
+
}
|
|
53
|
+
const track = document.createElement('div');
|
|
54
|
+
track.className = 'designbase-wc-progressbar__track';
|
|
55
|
+
const fill = document.createElement('div');
|
|
56
|
+
fill.className = 'designbase-wc-progressbar__fill';
|
|
57
|
+
fill.style.width = `${percentage}%`;
|
|
58
|
+
if (label && labelPosition === 'inside') {
|
|
59
|
+
const inside = document.createElement('span');
|
|
60
|
+
inside.className = 'designbase-wc-progressbar__fill-label';
|
|
61
|
+
inside.textContent = label;
|
|
62
|
+
fill.append(inside);
|
|
63
|
+
}
|
|
64
|
+
track.append(fill);
|
|
65
|
+
container.append(track);
|
|
66
|
+
this.append(container);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!customElements.get('db-progressbar'))
|
|
70
|
+
customElements.define('db-progressbar', DbProgressbar);
|
|
71
|
+
|
|
72
|
+
export { DbProgressbar };
|
|
@@ -1 +1,172 @@
|
|
|
1
|
-
const
|
|
1
|
+
const SIZES = ['s', 'm', 'l'];
|
|
2
|
+
class DbRadio extends HTMLElement {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.built = false;
|
|
6
|
+
this.handleChange = () => {
|
|
7
|
+
if (!this.input || this.disabled || this.readOnly)
|
|
8
|
+
return;
|
|
9
|
+
const checked = this.input.checked;
|
|
10
|
+
this.toggleAttribute('checked', checked);
|
|
11
|
+
this.syncVisual();
|
|
12
|
+
this.syncClasses();
|
|
13
|
+
this.dispatchEvent(new CustomEvent('db-change', {
|
|
14
|
+
detail: {
|
|
15
|
+
checked,
|
|
16
|
+
selected: checked,
|
|
17
|
+
value: this.getAttribute('value') || '',
|
|
18
|
+
},
|
|
19
|
+
bubbles: true,
|
|
20
|
+
composed: true,
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
static get observedAttributes() {
|
|
25
|
+
return [
|
|
26
|
+
'checked',
|
|
27
|
+
'selected',
|
|
28
|
+
'default-checked',
|
|
29
|
+
'default-selected',
|
|
30
|
+
'size',
|
|
31
|
+
'disabled',
|
|
32
|
+
'readonly',
|
|
33
|
+
'required',
|
|
34
|
+
'name',
|
|
35
|
+
'value',
|
|
36
|
+
'has-label',
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
get checked() {
|
|
40
|
+
return this.input?.checked ?? (this.hasAttribute('checked') || this.hasAttribute('selected'));
|
|
41
|
+
}
|
|
42
|
+
set checked(value) {
|
|
43
|
+
this.toggleAttribute('checked', value);
|
|
44
|
+
if (this.input) {
|
|
45
|
+
this.input.checked = value;
|
|
46
|
+
this.syncVisual();
|
|
47
|
+
this.syncClasses();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
get disabled() {
|
|
51
|
+
return this.hasAttribute('disabled');
|
|
52
|
+
}
|
|
53
|
+
set disabled(value) {
|
|
54
|
+
this.toggleAttribute('disabled', value);
|
|
55
|
+
if (this.input)
|
|
56
|
+
this.input.disabled = value;
|
|
57
|
+
this.syncClasses();
|
|
58
|
+
}
|
|
59
|
+
get readOnly() {
|
|
60
|
+
return this.hasAttribute('readonly');
|
|
61
|
+
}
|
|
62
|
+
set readOnly(value) {
|
|
63
|
+
this.toggleAttribute('readonly', value);
|
|
64
|
+
if (this.input)
|
|
65
|
+
this.input.readOnly = value;
|
|
66
|
+
this.syncClasses();
|
|
67
|
+
}
|
|
68
|
+
get required() {
|
|
69
|
+
return this.hasAttribute('required');
|
|
70
|
+
}
|
|
71
|
+
set required(value) {
|
|
72
|
+
this.toggleAttribute('required', value);
|
|
73
|
+
if (this.input)
|
|
74
|
+
this.input.required = value;
|
|
75
|
+
}
|
|
76
|
+
get size() {
|
|
77
|
+
return this.getAttribute('size') || 'm';
|
|
78
|
+
}
|
|
79
|
+
set size(value) {
|
|
80
|
+
this.setAttribute('size', value);
|
|
81
|
+
}
|
|
82
|
+
connectedCallback() {
|
|
83
|
+
this.style.display = 'contents';
|
|
84
|
+
if (!this.built) {
|
|
85
|
+
this.build();
|
|
86
|
+
}
|
|
87
|
+
this.syncState();
|
|
88
|
+
}
|
|
89
|
+
attributeChangedCallback(name) {
|
|
90
|
+
if (!this.built)
|
|
91
|
+
return;
|
|
92
|
+
if (name === 'checked' || name === 'selected') {
|
|
93
|
+
if (this.input) {
|
|
94
|
+
this.input.checked = this.hasAttribute('checked') || this.hasAttribute('selected');
|
|
95
|
+
}
|
|
96
|
+
this.syncVisual();
|
|
97
|
+
this.syncClasses();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.syncState();
|
|
101
|
+
}
|
|
102
|
+
get hasLabel() {
|
|
103
|
+
return !this.hasAttribute('has-label') || this.getAttribute('has-label') !== 'false';
|
|
104
|
+
}
|
|
105
|
+
build() {
|
|
106
|
+
this.root = document.createElement('label');
|
|
107
|
+
this.root.className = 'designbase-wc-radio';
|
|
108
|
+
this.input = document.createElement('input');
|
|
109
|
+
this.input.type = 'radio';
|
|
110
|
+
this.input.className = 'designbase-wc-radio__input';
|
|
111
|
+
this.visual = document.createElement('span');
|
|
112
|
+
this.visual.className = 'designbase-wc-radio__visual';
|
|
113
|
+
this.visual.setAttribute('aria-hidden', 'true');
|
|
114
|
+
this.dot = document.createElement('span');
|
|
115
|
+
this.dot.className = 'designbase-wc-radio__dot';
|
|
116
|
+
this.visual.appendChild(this.dot);
|
|
117
|
+
this.labelEl = document.createElement('span');
|
|
118
|
+
this.labelEl.className = 'designbase-wc-radio__label';
|
|
119
|
+
while (this.firstChild) {
|
|
120
|
+
this.labelEl.appendChild(this.firstChild);
|
|
121
|
+
}
|
|
122
|
+
this.root.append(this.input, this.visual, this.labelEl);
|
|
123
|
+
this.appendChild(this.root);
|
|
124
|
+
this.input.addEventListener('change', this.handleChange);
|
|
125
|
+
this.built = true;
|
|
126
|
+
}
|
|
127
|
+
syncState() {
|
|
128
|
+
if (!this.root || !this.input || !this.visual)
|
|
129
|
+
return;
|
|
130
|
+
const checked = this.hasAttribute('checked')
|
|
131
|
+
|| this.hasAttribute('selected')
|
|
132
|
+
|| (!this.hasAttribute('checked')
|
|
133
|
+
&& !this.hasAttribute('selected')
|
|
134
|
+
&& (this.hasAttribute('default-checked') || this.hasAttribute('default-selected')));
|
|
135
|
+
this.input.checked = checked;
|
|
136
|
+
this.input.disabled = this.disabled;
|
|
137
|
+
this.input.readOnly = this.readOnly;
|
|
138
|
+
this.input.required = this.required;
|
|
139
|
+
this.input.name = this.getAttribute('name') || '';
|
|
140
|
+
this.input.value = this.getAttribute('value') || '';
|
|
141
|
+
if (this.hasLabel) {
|
|
142
|
+
this.labelEl?.removeAttribute('hidden');
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.labelEl?.setAttribute('hidden', '');
|
|
146
|
+
}
|
|
147
|
+
this.syncVisual();
|
|
148
|
+
this.syncClasses();
|
|
149
|
+
}
|
|
150
|
+
syncVisual() {
|
|
151
|
+
// Dot stays in DOM; visibility is controlled via --selected CSS.
|
|
152
|
+
}
|
|
153
|
+
syncClasses() {
|
|
154
|
+
if (!this.root || !this.input)
|
|
155
|
+
return;
|
|
156
|
+
const size = SIZES.includes(this.size) ? this.size : 'm';
|
|
157
|
+
const hasLabelText = this.hasLabel && Boolean(this.labelEl?.textContent?.trim());
|
|
158
|
+
this.root.className = [
|
|
159
|
+
'designbase-wc-radio',
|
|
160
|
+
`designbase-wc-radio--${size}`,
|
|
161
|
+
this.input.checked && 'designbase-wc-radio--selected',
|
|
162
|
+
this.disabled && 'designbase-wc-radio--disabled',
|
|
163
|
+
this.readOnly && 'designbase-wc-radio--readonly',
|
|
164
|
+
!hasLabelText && 'designbase-wc-radio--no-label',
|
|
165
|
+
].filter(Boolean).join(' ');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (!customElements.get('db-radio')) {
|
|
169
|
+
customElements.define('db-radio', DbRadio);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { DbRadio };
|