@designbasekorea/ui-wc 0.5.6 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/lottie-0e23d630.js +1 -0
- package/dist/esm/components/animation-background/canvas-controller.js +1 -121
- package/dist/esm/components/animation-background/controls.js +1 -180
- package/dist/esm/components/animation-background/graphite-controller.js +1 -196
- package/dist/esm/components/animation-background/graphite-presets.js +1 -42
- package/dist/esm/components/animation-background/graphite-shader.js +1 -111
- package/dist/esm/components/animation-background/layers.js +1 -369
- package/dist/esm/components/animation-background/lumina-presets.js +1 -53
- package/dist/esm/components/animation-background/lumina-shaders.js +1 -181
- package/dist/esm/components/animation-background/lumina-utils.js +1 -60
- package/dist/esm/components/animation-background/particle-defaults.js +1 -36
- package/dist/esm/components/animation-background/renderers.js +1 -167
- package/dist/esm/components/animation-background/shader-controller.js +1 -154
- package/dist/esm/components/color-picker-utils.js +1 -134
- package/dist/esm/components/date-picker-utils.js +1 -140
- package/dist/esm/components/db-accordion.js +1 -304
- package/dist/esm/components/db-ad-banner.js +1 -455
- package/dist/esm/components/db-ai-chat-list.d.ts +43 -0
- package/dist/esm/components/db-ai-chat-list.js +1 -0
- package/dist/esm/components/db-ai-chat.d.ts +159 -0
- package/dist/esm/components/db-ai-chat.js +1 -0
- package/dist/esm/components/db-alert.js +1 -149
- package/dist/esm/components/db-animation-background.js +1 -486
- package/dist/esm/components/db-animation-text.js +1 -601
- package/dist/esm/components/db-app-badge.js +1 -88
- package/dist/esm/components/db-audio-player.js +1 -752
- package/dist/esm/components/db-avatar.js +1 -188
- package/dist/esm/components/db-backdrop.js +1 -139
- package/dist/esm/components/db-badge.js +1 -91
- package/dist/esm/components/db-banner.js +1 -188
- package/dist/esm/components/db-bottom-navigation.js +1 -146
- package/dist/esm/components/db-bottom-sheet.js +1 -481
- package/dist/esm/components/db-breadcrumbs.js +1 -329
- package/dist/esm/components/db-button.js +1 -316
- package/dist/esm/components/db-calendar.js +1 -675
- package/dist/esm/components/db-card.js +1 -265
- package/dist/esm/components/db-carousel.js +1 -264
- package/dist/esm/components/db-chat-composer.d.ts +134 -0
- package/dist/esm/components/db-chat-composer.js +1 -0
- package/dist/esm/components/db-chat-list.d.ts +47 -0
- package/dist/esm/components/db-chat-list.js +1 -0
- package/dist/esm/components/db-chat-message.d.ts +39 -0
- package/dist/esm/components/db-chat-message.js +1 -0
- package/dist/esm/components/db-chat-orb.d.ts +99 -0
- package/dist/esm/components/db-chat-orb.js +1 -0
- package/dist/esm/components/db-chat-room.d.ts +71 -0
- package/dist/esm/components/db-chat-room.js +1 -0
- package/dist/esm/components/db-chat-suggestions.d.ts +44 -0
- package/dist/esm/components/db-chat-suggestions.js +1 -0
- package/dist/esm/components/db-chat-typing.d.ts +22 -0
- package/dist/esm/components/db-chat-typing.js +1 -0
- package/dist/esm/components/db-chat-welcome.d.ts +32 -0
- package/dist/esm/components/db-chat-welcome.js +1 -0
- package/dist/esm/components/db-chat-widget.d.ts +146 -0
- package/dist/esm/components/db-chat-widget.js +1 -0
- package/dist/esm/components/db-checkbox.js +1 -202
- package/dist/esm/components/db-chip.js +1 -104
- package/dist/esm/components/db-code-block.js +1 -304
- package/dist/esm/components/db-color-picker.js +1 -746
- package/dist/esm/components/db-confirm.js +1 -191
- package/dist/esm/components/db-container.js +1 -39
- package/dist/esm/components/db-context-menu.js +1 -265
- package/dist/esm/components/db-countdown.js +1 -146
- package/dist/esm/components/db-cursor-follower.js +1 -173
- package/dist/esm/components/db-date-picker.js +1 -837
- package/dist/esm/components/db-divider.js +1 -66
- package/dist/esm/components/db-download-progress.d.ts +89 -0
- package/dist/esm/components/db-download-progress.js +1 -0
- package/dist/esm/components/db-drawer.js +1 -245
- package/dist/esm/components/db-dropdown.js +1 -493
- package/dist/esm/components/db-dropzone.js +1 -266
- package/dist/esm/components/db-email-verify.d.ts +62 -0
- package/dist/esm/components/db-email-verify.js +1 -0
- package/dist/esm/components/db-empty-state.js +1 -97
- package/dist/esm/components/db-file-uploader.js +1 -256
- package/dist/esm/components/db-floating-action-button.js +1 -139
- package/dist/esm/components/db-footer.js +1 -385
- package/dist/esm/components/db-form.js +1 -566
- package/dist/esm/components/db-gantt.js +1 -882
- package/dist/esm/components/db-gradient.js +1 -133
- package/dist/esm/components/db-grid-background.js +1 -909
- package/dist/esm/components/db-grid.js +1 -73
- package/dist/esm/components/db-icons.d.ts +3 -0
- package/dist/esm/components/db-icons.js +1 -82
- package/dist/esm/components/db-image-list.js +1 -214
- package/dist/esm/components/db-image-placeholder.js +1 -96
- package/dist/esm/components/db-image.js +1 -289
- package/dist/esm/components/db-indicator.js +1 -517
- package/dist/esm/components/db-input.js +1 -420
- package/dist/esm/components/db-kanban.js +1 -538
- package/dist/esm/components/db-label.js +1 -66
- package/dist/esm/components/db-lightbox.js +1 -372
- package/dist/esm/components/db-list.js +1 -340
- package/dist/esm/components/db-logo-svg.js +1 -72
- package/dist/esm/components/db-logo.js +1 -106
- package/dist/esm/components/db-lottie.js +1 -109
- package/dist/esm/components/db-markdown-editor.js +1 -458
- package/dist/esm/components/db-marquee.js +1 -402
- package/dist/esm/components/db-masonry.js +1 -94
- package/dist/esm/components/db-menu-item.js +1 -211
- package/dist/esm/components/db-modal.js +1 -522
- package/dist/esm/components/db-navbar.js +1 -680
- package/dist/esm/components/db-onboarding-modal.js +1 -322
- package/dist/esm/components/db-otp-input.d.ts +53 -0
- package/dist/esm/components/db-otp-input.js +1 -0
- package/dist/esm/components/db-page-header.js +1 -312
- package/dist/esm/components/db-pagination.js +1 -271
- package/dist/esm/components/db-phone-verify.d.ts +61 -0
- package/dist/esm/components/db-phone-verify.js +1 -0
- package/dist/esm/components/db-popover.js +1 -580
- package/dist/esm/components/db-progress-step.js +1 -166
- package/dist/esm/components/db-progress.js +1 -171
- package/dist/esm/components/db-progressbar.js +1 -72
- package/dist/esm/components/db-radio.js +1 -172
- package/dist/esm/components/db-random-gradient.js +1 -121
- package/dist/esm/components/db-range-slider.js +1 -811
- package/dist/esm/components/db-rating.js +1 -325
- package/dist/esm/components/db-reorder.js +1 -286
- package/dist/esm/components/db-resizable-panels.js +1 -282
- package/dist/esm/components/db-scroll-area.js +1 -126
- package/dist/esm/components/db-search-bar.js +1 -668
- package/dist/esm/components/db-section-app-download.js +1 -101
- package/dist/esm/components/db-section-contact.js +1 -102
- package/dist/esm/components/db-section-cta.js +1 -150
- package/dist/esm/components/db-section-faq.js +1 -120
- package/dist/esm/components/db-section-feature-grid.js +1 -137
- package/dist/esm/components/db-section-feature.js +1 -179
- package/dist/esm/components/db-section-hero.js +1 -243
- package/dist/esm/components/db-section-logo-cloud.js +1 -138
- package/dist/esm/components/db-section-pricing.js +1 -166
- package/dist/esm/components/db-section-stats.js +1 -129
- package/dist/esm/components/db-section-testimonials.js +1 -252
- package/dist/esm/components/db-section.js +1 -385
- package/dist/esm/components/db-segment-control.js +1 -231
- package/dist/esm/components/db-select.js +1 -571
- package/dist/esm/components/db-share-icons.js +1 -40
- package/dist/esm/components/db-share.js +1 -489
- package/dist/esm/components/db-sidebar.js +1 -1068
- package/dist/esm/components/db-skeleton.js +1 -94
- package/dist/esm/components/db-spinner.js +1 -102
- package/dist/esm/components/db-split-view.js +1 -297
- package/dist/esm/components/db-stack.js +1 -46
- package/dist/esm/components/db-stat.js +1 -218
- package/dist/esm/components/db-stepper.js +1 -398
- package/dist/esm/components/db-table.js +1 -412
- package/dist/esm/components/db-tabs.js +1 -335
- package/dist/esm/components/db-testimonial.d.ts +2 -0
- package/dist/esm/components/db-testimonial.js +1 -162
- package/dist/esm/components/db-textarea.js +1 -233
- package/dist/esm/components/db-time-picker.js +1 -523
- package/dist/esm/components/db-timeline.js +1 -174
- package/dist/esm/components/db-toast.js +1 -158
- package/dist/esm/components/db-toggle.js +1 -162
- package/dist/esm/components/db-toolbar.js +1 -94
- package/dist/esm/components/db-tooltip.js +1 -440
- package/dist/esm/components/db-top-banner.js +1 -121
- package/dist/esm/components/db-tutorial.js +1 -324
- package/dist/esm/components/db-two-factor.d.ts +60 -0
- package/dist/esm/components/db-two-factor.js +1 -0
- package/dist/esm/components/db-video-player.js +1 -503
- package/dist/esm/components/db-youtube-player.js +1 -194
- package/dist/esm/components/highlight-code.js +1 -65
- package/dist/esm/components/input-validation.js +1 -50
- package/dist/esm/components/marketing-block-host-utils.js +1 -9
- package/dist/esm/components/number-scrub.js +1 -117
- package/dist/esm/components/random-gradient-palettes.js +1 -67
- package/dist/esm/components/section-block-header-utils.js +1 -48
- package/dist/esm/helpers/confirm.js +1 -52
- package/dist/esm/helpers/toast.js +1 -73
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +1 -111
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-bash.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-clike.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-css.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-javascript.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-json.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-jsx.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-markup.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-scss.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-tsx.js +1 -0
- package/dist/esm/node_modules/.pnpm/prismjs@1.30.0/node_modules/prismjs/components/prism-typescript.js +1 -0
- package/dist/index.cjs +1 -55414
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1091 -2
- package/dist/index.esm.js +1 -38284
- package/dist/react/chunks/lottie-14e7addb.js +1 -0
- package/dist/react/index.cjs +1 -56503
- package/dist/react/index.d.ts +1620 -54
- package/dist/react/index.esm.js +1 -39373
- package/package.json +1 -1
- package/dist/chunks/lottie-e273b936.js +0 -17032
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +0 -235
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -31
- package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -64
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -172
- package/dist/esm/node_modules/prismjs/components/prism-json.js +0 -27
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +0 -143
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -186
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +0 -81
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +0 -15
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -60
- package/dist/react/chunks/lottie-72a4c6d4.js +0 -17032
|
@@ -1,188 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const SIZES = ['xs', 's', 'm', 'l', 'xl', '2xl'];
|
|
4
|
-
const VARIANTS = ['default', 'primary', 'success', 'warning', 'danger', 'info'];
|
|
5
|
-
const STATUSES = ['online', 'offline', 'away', 'busy'];
|
|
6
|
-
const LIGHT_COLORS = ['#E3F2FD', '#F3E5F5', '#E8F5E8', '#FFF3E0', '#FCE4EC', '#E0F2F1', '#FFF8E1', '#F1F8E9', '#E8EAF6', '#FFEBEE'];
|
|
7
|
-
const DARK_COLORS = ['#1976D2', '#7B1FA2', '#388E3C', '#F57C00', '#C2185B', '#00796B', '#F9A825', '#689F38', '#3F51B5', '#D32F2F'];
|
|
8
|
-
function initialsColor(text) {
|
|
9
|
-
let hash = 0;
|
|
10
|
-
for (let i = 0; i < text.length; i++) {
|
|
11
|
-
hash = text.charCodeAt(i) + ((hash << 5) - hash);
|
|
12
|
-
}
|
|
13
|
-
const index = Math.abs(hash) % LIGHT_COLORS.length;
|
|
14
|
-
return { backgroundColor: LIGHT_COLORS[index], color: DARK_COLORS[index] };
|
|
15
|
-
}
|
|
16
|
-
function iconSize(size) {
|
|
17
|
-
if (size === 'xs')
|
|
18
|
-
return 12;
|
|
19
|
-
if (size === 's')
|
|
20
|
-
return 16;
|
|
21
|
-
if (size === 'm')
|
|
22
|
-
return 20;
|
|
23
|
-
if (size === 'l')
|
|
24
|
-
return 24;
|
|
25
|
-
if (size === 'xl')
|
|
26
|
-
return 32;
|
|
27
|
-
return 40;
|
|
28
|
-
}
|
|
29
|
-
class DbAvatar extends HTMLElement {
|
|
30
|
-
constructor() {
|
|
31
|
-
super(...arguments);
|
|
32
|
-
this.imageFailed = false;
|
|
33
|
-
this.imageLoaded = false;
|
|
34
|
-
this.handleClick = () => {
|
|
35
|
-
if (this.hasAttribute('disabled') || !this.hasAttribute('clickable'))
|
|
36
|
-
return;
|
|
37
|
-
this.dispatchEvent(new CustomEvent('db-click', { bubbles: true, composed: true }));
|
|
38
|
-
};
|
|
39
|
-
this.handleKeyDown = (event) => {
|
|
40
|
-
if (!this.hasAttribute('clickable') || this.hasAttribute('disabled'))
|
|
41
|
-
return;
|
|
42
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
43
|
-
event.preventDefault();
|
|
44
|
-
this.handleClick();
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
static get observedAttributes() {
|
|
49
|
-
return [
|
|
50
|
-
'src',
|
|
51
|
-
'alt',
|
|
52
|
-
'initials',
|
|
53
|
-
'size',
|
|
54
|
-
'variant',
|
|
55
|
-
'status',
|
|
56
|
-
'disabled',
|
|
57
|
-
'clickable',
|
|
58
|
-
'badge',
|
|
59
|
-
'badge-max-count',
|
|
60
|
-
'badge-variant',
|
|
61
|
-
'badge-style',
|
|
62
|
-
'badge-text',
|
|
63
|
-
];
|
|
64
|
-
}
|
|
65
|
-
connectedCallback() {
|
|
66
|
-
this.render();
|
|
67
|
-
this.addEventListener('click', this.handleClick);
|
|
68
|
-
this.addEventListener('keydown', this.handleKeyDown);
|
|
69
|
-
}
|
|
70
|
-
disconnectedCallback() {
|
|
71
|
-
this.removeEventListener('click', this.handleClick);
|
|
72
|
-
this.removeEventListener('keydown', this.handleKeyDown);
|
|
73
|
-
}
|
|
74
|
-
attributeChangedCallback(name) {
|
|
75
|
-
if (name === 'src') {
|
|
76
|
-
this.imageFailed = false;
|
|
77
|
-
this.imageLoaded = false;
|
|
78
|
-
}
|
|
79
|
-
this.render();
|
|
80
|
-
}
|
|
81
|
-
render() {
|
|
82
|
-
const size = SIZES.includes((this.getAttribute('size') || 'm'))
|
|
83
|
-
? this.getAttribute('size') || 'm'
|
|
84
|
-
: 'm';
|
|
85
|
-
const variant = VARIANTS.includes((this.getAttribute('variant') || 'default'))
|
|
86
|
-
? this.getAttribute('variant') || 'default'
|
|
87
|
-
: 'default';
|
|
88
|
-
const disabled = this.hasAttribute('disabled');
|
|
89
|
-
const clickable = this.hasAttribute('clickable');
|
|
90
|
-
const src = this.getAttribute('src');
|
|
91
|
-
const initials = this.getAttribute('initials') || '';
|
|
92
|
-
const showImage = Boolean(src && !this.imageFailed);
|
|
93
|
-
const showLoading = showImage && !this.imageLoaded;
|
|
94
|
-
this.className = [
|
|
95
|
-
'designbase-wc-avatar',
|
|
96
|
-
`designbase-wc-avatar--${size}`,
|
|
97
|
-
`designbase-wc-avatar--${variant}`,
|
|
98
|
-
clickable && 'designbase-wc-avatar--clickable',
|
|
99
|
-
disabled && 'designbase-wc-avatar--disabled',
|
|
100
|
-
showLoading && 'designbase-wc-avatar--loading',
|
|
101
|
-
]
|
|
102
|
-
.filter(Boolean)
|
|
103
|
-
.join(' ');
|
|
104
|
-
if (clickable && !disabled) {
|
|
105
|
-
this.setAttribute('role', 'button');
|
|
106
|
-
this.tabIndex = 0;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
this.removeAttribute('role');
|
|
110
|
-
this.removeAttribute('tabindex');
|
|
111
|
-
}
|
|
112
|
-
this.toggleAttribute('aria-disabled', disabled);
|
|
113
|
-
this.replaceChildren();
|
|
114
|
-
if (showLoading) {
|
|
115
|
-
const loading = document.createElement('div');
|
|
116
|
-
loading.className = 'designbase-wc-avatar__loading';
|
|
117
|
-
const skeleton = document.createElement('div');
|
|
118
|
-
skeleton.className = 'designbase-wc-avatar__skeleton';
|
|
119
|
-
loading.append(skeleton);
|
|
120
|
-
this.append(loading);
|
|
121
|
-
}
|
|
122
|
-
if (showImage) {
|
|
123
|
-
const image = document.createElement('img');
|
|
124
|
-
image.className = 'designbase-wc-avatar__image';
|
|
125
|
-
image.src = src;
|
|
126
|
-
image.alt = this.getAttribute('alt') || '아바타 이미지';
|
|
127
|
-
image.loading = 'lazy';
|
|
128
|
-
image.addEventListener('load', () => {
|
|
129
|
-
this.imageLoaded = true;
|
|
130
|
-
this.classList.remove('designbase-wc-avatar--loading');
|
|
131
|
-
this.querySelector('.designbase-wc-avatar__loading')?.remove();
|
|
132
|
-
});
|
|
133
|
-
image.addEventListener('error', () => {
|
|
134
|
-
this.imageFailed = true;
|
|
135
|
-
this.imageLoaded = false;
|
|
136
|
-
this.render();
|
|
137
|
-
});
|
|
138
|
-
this.append(image);
|
|
139
|
-
}
|
|
140
|
-
else if (initials) {
|
|
141
|
-
const initialsEl = document.createElement('div');
|
|
142
|
-
initialsEl.className = 'designbase-wc-avatar__initials';
|
|
143
|
-
if (variant === 'default') {
|
|
144
|
-
const colors = initialsColor(initials);
|
|
145
|
-
initialsEl.style.backgroundColor = colors.backgroundColor;
|
|
146
|
-
initialsEl.style.color = colors.color;
|
|
147
|
-
}
|
|
148
|
-
initialsEl.textContent = initials.charAt(0).toUpperCase();
|
|
149
|
-
this.append(initialsEl);
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
const iconWrap = document.createElement('div');
|
|
153
|
-
iconWrap.className = 'designbase-wc-avatar__icon';
|
|
154
|
-
iconWrap.append(createDbIcon('user', iconSize(size)));
|
|
155
|
-
this.append(iconWrap);
|
|
156
|
-
}
|
|
157
|
-
const status = this.getAttribute('status') || '';
|
|
158
|
-
if (STATUSES.includes(status)) {
|
|
159
|
-
const statusElement = document.createElement('span');
|
|
160
|
-
statusElement.className = `designbase-wc-avatar__status designbase-wc-avatar__status--${status}`;
|
|
161
|
-
this.append(statusElement);
|
|
162
|
-
}
|
|
163
|
-
if (this.hasAttribute('badge')) {
|
|
164
|
-
const badgeWrap = document.createElement('div');
|
|
165
|
-
badgeWrap.className = 'designbase-wc-avatar__badge';
|
|
166
|
-
const badge = document.createElement('db-badge');
|
|
167
|
-
badge.setAttribute('count', this.getAttribute('badge') || '0');
|
|
168
|
-
const badgeStyle = this.getAttribute('badge-style') || 'number';
|
|
169
|
-
badge.setAttribute('badge-style', badgeStyle);
|
|
170
|
-
if (this.hasAttribute('badge-max-count')) {
|
|
171
|
-
badge.setAttribute('max-count', this.getAttribute('badge-max-count'));
|
|
172
|
-
}
|
|
173
|
-
badge.setAttribute('variant', this.getAttribute('badge-variant') || 'danger');
|
|
174
|
-
if (this.hasAttribute('badge-text')) {
|
|
175
|
-
badge.textContent = this.getAttribute('badge-text');
|
|
176
|
-
}
|
|
177
|
-
const badgeSize = size === 'xl' || size === '2xl' ? 'm' : 's';
|
|
178
|
-
badge.setAttribute('size', badgeSize);
|
|
179
|
-
badgeWrap.append(badge);
|
|
180
|
-
this.append(badgeWrap);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (!customElements.get('db-avatar')) {
|
|
185
|
-
customElements.define('db-avatar', DbAvatar);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export { DbAvatar };
|
|
1
|
+
import{createDbIcon as t}from"./db-icons.js";const e=["xs","s","m","l","xl","2xl"],a=["default","primary","success","warning","danger","info"],s=["online","offline","away","busy"],i=["#E3F2FD","#F3E5F5","#E8F5E8","#FFF3E0","#FCE4EC","#E0F2F1","#FFF8E1","#F1F8E9","#E8EAF6","#FFEBEE"],n=["#1976D2","#7B1FA2","#388E3C","#F57C00","#C2185B","#00796B","#F9A825","#689F38","#3F51B5","#D32F2F"];class DbAvatar extends HTMLElement{constructor(){super(...arguments),this.imageFailed=!1,this.imageLoaded=!1,this.handleClick=()=>{!this.hasAttribute("disabled")&&this.hasAttribute("clickable")&&this.dispatchEvent(new CustomEvent("db-click",{bubbles:!0,composed:!0}))},this.handleKeyDown=t=>{this.hasAttribute("clickable")&&!this.hasAttribute("disabled")&&("Enter"!==t.key&&" "!==t.key||(t.preventDefault(),this.handleClick()))}}static get observedAttributes(){return["src","alt","initials","size","variant","status","disabled","clickable","badge","badge-max-count","badge-variant","badge-style","badge-text"]}connectedCallback(){this.render(),this.addEventListener("click",this.handleClick),this.addEventListener("keydown",this.handleKeyDown)}disconnectedCallback(){this.removeEventListener("click",this.handleClick),this.removeEventListener("keydown",this.handleKeyDown)}attributeChangedCallback(t){"src"===t&&(this.imageFailed=!1,this.imageLoaded=!1),this.render()}render(){const r=e.includes(this.getAttribute("size")||"m")&&this.getAttribute("size")||"m",d=a.includes(this.getAttribute("variant")||"default")&&this.getAttribute("variant")||"default",l=this.hasAttribute("disabled"),c=this.hasAttribute("clickable"),o=this.getAttribute("src"),b=this.getAttribute("initials")||"",h=Boolean(o&&!this.imageFailed),u=h&&!this.imageLoaded;if(this.className=["designbase-wc-avatar",`designbase-wc-avatar--${r}`,`designbase-wc-avatar--${d}`,c&&"designbase-wc-avatar--clickable",l&&"designbase-wc-avatar--disabled",u&&"designbase-wc-avatar--loading"].filter(Boolean).join(" "),c&&!l?(this.setAttribute("role","button"),this.tabIndex=0):(this.removeAttribute("role"),this.removeAttribute("tabindex")),this.toggleAttribute("aria-disabled",l),this.replaceChildren(),u){const t=document.createElement("div");t.className="designbase-wc-avatar__loading";const e=document.createElement("div");e.className="designbase-wc-avatar__skeleton",t.append(e),this.append(t)}if(h){const t=document.createElement("img");t.className="designbase-wc-avatar__image",t.src=o,t.alt=this.getAttribute("alt")||"아바타 이미지",t.loading="lazy",t.addEventListener("load",()=>{this.imageLoaded=!0,this.classList.remove("designbase-wc-avatar--loading"),this.querySelector(".designbase-wc-avatar__loading")?.remove()}),t.addEventListener("error",()=>{this.imageFailed=!0,this.imageLoaded=!1,this.render()}),this.append(t)}else if(b){const t=document.createElement("div");if(t.className="designbase-wc-avatar__initials","default"===d){const e=function initialsColor(t){let e=0;for(let a=0;a<t.length;a++)e=t.charCodeAt(a)+((e<<5)-e);const a=Math.abs(e)%i.length;return{backgroundColor:i[a],color:n[a]}}(b);t.style.backgroundColor=e.backgroundColor,t.style.color=e.color}t.textContent=b.charAt(0).toUpperCase(),this.append(t)}else{const e=document.createElement("div");e.className="designbase-wc-avatar__icon",e.append(t("user",function iconSize(t){return"xs"===t?12:"s"===t?16:"m"===t?20:"l"===t?24:"xl"===t?32:40}(r))),this.append(e)}const g=this.getAttribute("status")||"";if(s.includes(g)){const t=document.createElement("span");t.className=`designbase-wc-avatar__status designbase-wc-avatar__status--${g}`,this.append(t)}if(this.hasAttribute("badge")){const t=document.createElement("div");t.className="designbase-wc-avatar__badge";const e=document.createElement("db-badge");e.setAttribute("count",this.getAttribute("badge")||"0");const a=this.getAttribute("badge-style")||"number";e.setAttribute("badge-style",a),this.hasAttribute("badge-max-count")&&e.setAttribute("max-count",this.getAttribute("badge-max-count")),e.setAttribute("variant",this.getAttribute("badge-variant")||"danger"),this.hasAttribute("badge-text")&&(e.textContent=this.getAttribute("badge-text"));const s="xl"===r||"2xl"===r?"m":"s";e.setAttribute("size",s),t.append(e),this.append(t)}}}customElements.get("db-avatar")||customElements.define("db-avatar",DbAvatar);export{DbAvatar};
|
|
@@ -1,139 +1 @@
|
|
|
1
|
-
const
|
|
2
|
-
class DbBackdrop extends HTMLElement {
|
|
3
|
-
constructor() {
|
|
4
|
-
super(...arguments);
|
|
5
|
-
this.keyHandler = null;
|
|
6
|
-
this.handlePortalClick = (event) => {
|
|
7
|
-
if (event.target !== this.portal)
|
|
8
|
-
return;
|
|
9
|
-
if (this.getAttribute('disable-backdrop-click') === 'true')
|
|
10
|
-
return;
|
|
11
|
-
this.dispatchEvent(new CustomEvent('db-click', { bubbles: true, composed: true }));
|
|
12
|
-
this.dispatchEvent(new CustomEvent('db-close', { bubbles: true, composed: true }));
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
static get observedAttributes() {
|
|
16
|
-
return [
|
|
17
|
-
'open',
|
|
18
|
-
'blur',
|
|
19
|
-
'opacity',
|
|
20
|
-
'blur-amount',
|
|
21
|
-
'animation',
|
|
22
|
-
'animation-duration',
|
|
23
|
-
'z-index',
|
|
24
|
-
'background-color',
|
|
25
|
-
'disable-backdrop-click',
|
|
26
|
-
'disable-escape-key-down',
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
get open() {
|
|
30
|
-
return this.hasAttribute('open') && this.getAttribute('open') !== 'false';
|
|
31
|
-
}
|
|
32
|
-
set open(value) {
|
|
33
|
-
if (value)
|
|
34
|
-
this.setAttribute('open', '');
|
|
35
|
-
else
|
|
36
|
-
this.removeAttribute('open');
|
|
37
|
-
}
|
|
38
|
-
connectedCallback() {
|
|
39
|
-
this.style.display = 'contents';
|
|
40
|
-
this.syncOpenState();
|
|
41
|
-
}
|
|
42
|
-
disconnectedCallback() {
|
|
43
|
-
this.detachListeners();
|
|
44
|
-
this.portal?.remove();
|
|
45
|
-
this.portal = undefined;
|
|
46
|
-
document.body.style.overflow = '';
|
|
47
|
-
}
|
|
48
|
-
attributeChangedCallback() {
|
|
49
|
-
if (!this.isConnected)
|
|
50
|
-
return;
|
|
51
|
-
this.syncOpenState();
|
|
52
|
-
}
|
|
53
|
-
isOpen() {
|
|
54
|
-
return this.open;
|
|
55
|
-
}
|
|
56
|
-
syncOpenState() {
|
|
57
|
-
if (this.isOpen()) {
|
|
58
|
-
this.render();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
document.body.style.overflow = '';
|
|
62
|
-
this.detachListeners();
|
|
63
|
-
this.portal?.remove();
|
|
64
|
-
}
|
|
65
|
-
collectChildren() {
|
|
66
|
-
return Array.from(this.children).filter((child) => !child.hasAttribute('data-wc-internal'));
|
|
67
|
-
}
|
|
68
|
-
attachListeners() {
|
|
69
|
-
if (this.keyHandler)
|
|
70
|
-
return;
|
|
71
|
-
this.keyHandler = (event) => {
|
|
72
|
-
if (event.key !== 'Escape')
|
|
73
|
-
return;
|
|
74
|
-
if (this.getAttribute('disable-escape-key-down') === 'true')
|
|
75
|
-
return;
|
|
76
|
-
this.dispatchEvent(new CustomEvent('db-click', { bubbles: true, composed: true }));
|
|
77
|
-
this.dispatchEvent(new CustomEvent('db-close', { bubbles: true, composed: true }));
|
|
78
|
-
};
|
|
79
|
-
document.addEventListener('keydown', this.keyHandler);
|
|
80
|
-
}
|
|
81
|
-
detachListeners() {
|
|
82
|
-
if (!this.keyHandler)
|
|
83
|
-
return;
|
|
84
|
-
document.removeEventListener('keydown', this.keyHandler);
|
|
85
|
-
this.keyHandler = null;
|
|
86
|
-
}
|
|
87
|
-
render() {
|
|
88
|
-
if (!this.isOpen()) {
|
|
89
|
-
this.syncOpenState();
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const blur = this.hasAttribute('blur');
|
|
93
|
-
const opacity = this.getAttribute('opacity') || '0.5';
|
|
94
|
-
const blurAmount = this.getAttribute('blur-amount') || '4';
|
|
95
|
-
const animation = ANIMATIONS.includes((this.getAttribute('animation') || 'fade'))
|
|
96
|
-
? this.getAttribute('animation') || 'fade'
|
|
97
|
-
: 'fade';
|
|
98
|
-
const animationDuration = this.getAttribute('animation-duration') || '300';
|
|
99
|
-
const zIndex = this.getAttribute('z-index') || '1000';
|
|
100
|
-
const backgroundColor = this.getAttribute('background-color');
|
|
101
|
-
const userChildren = this.collectChildren();
|
|
102
|
-
document.body.style.overflow = 'hidden';
|
|
103
|
-
this.attachListeners();
|
|
104
|
-
if (!this.portal) {
|
|
105
|
-
this.portal = document.createElement('div');
|
|
106
|
-
this.portal.setAttribute('data-wc-internal', '');
|
|
107
|
-
this.portal.addEventListener('click', this.handlePortalClick);
|
|
108
|
-
}
|
|
109
|
-
this.portal.className = [
|
|
110
|
-
'designbase-wc-backdrop',
|
|
111
|
-
`designbase-wc-backdrop--${animation}`,
|
|
112
|
-
'designbase-wc-backdrop--open',
|
|
113
|
-
blur ? 'designbase-wc-backdrop--blur' : '',
|
|
114
|
-
]
|
|
115
|
-
.filter(Boolean)
|
|
116
|
-
.join(' ');
|
|
117
|
-
this.portal.setAttribute('role', 'presentation');
|
|
118
|
-
this.portal.setAttribute('aria-hidden', 'false');
|
|
119
|
-
this.portal.style.setProperty('--backdrop-opacity', opacity);
|
|
120
|
-
this.portal.style.setProperty('--backdrop-blur-amount', `${blurAmount}px`);
|
|
121
|
-
this.portal.style.setProperty('--backdrop-animation-duration', `${animationDuration}ms`);
|
|
122
|
-
this.portal.style.setProperty('--backdrop-z-index', zIndex);
|
|
123
|
-
if (backgroundColor) {
|
|
124
|
-
this.portal.style.backgroundColor = backgroundColor;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
this.portal.style.removeProperty('background-color');
|
|
128
|
-
}
|
|
129
|
-
this.portal.replaceChildren(...userChildren);
|
|
130
|
-
if (!this.portal.isConnected) {
|
|
131
|
-
document.body.append(this.portal);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (!customElements.get('db-backdrop')) {
|
|
136
|
-
customElements.define('db-backdrop', DbBackdrop);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export { DbBackdrop };
|
|
1
|
+
const t=["fade","slide","zoom","none"];class DbBackdrop extends HTMLElement{constructor(){super(...arguments),this.keyHandler=null,this.handlePortalClick=t=>{t.target===this.portal&&"true"!==this.getAttribute("disable-backdrop-click")&&(this.dispatchEvent(new CustomEvent("db-click",{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("db-close",{bubbles:!0,composed:!0})))}}static get observedAttributes(){return["open","blur","opacity","blur-amount","animation","animation-duration","z-index","background-color","disable-backdrop-click","disable-escape-key-down"]}get open(){return this.hasAttribute("open")&&"false"!==this.getAttribute("open")}set open(t){t?this.setAttribute("open",""):this.removeAttribute("open")}connectedCallback(){this.style.display="contents",this.syncOpenState()}disconnectedCallback(){this.detachListeners(),this.portal?.remove(),this.portal=void 0,document.body.style.overflow=""}attributeChangedCallback(){this.isConnected&&this.syncOpenState()}isOpen(){return this.open}syncOpenState(){this.isOpen()?this.render():(document.body.style.overflow="",this.detachListeners(),this.portal?.remove())}collectChildren(){return Array.from(this.children).filter(t=>!t.hasAttribute("data-wc-internal"))}attachListeners(){this.keyHandler||(this.keyHandler=t=>{"Escape"===t.key&&"true"!==this.getAttribute("disable-escape-key-down")&&(this.dispatchEvent(new CustomEvent("db-click",{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("db-close",{bubbles:!0,composed:!0})))},document.addEventListener("keydown",this.keyHandler))}detachListeners(){this.keyHandler&&(document.removeEventListener("keydown",this.keyHandler),this.keyHandler=null)}render(){if(!this.isOpen())return void this.syncOpenState();const e=this.hasAttribute("blur"),s=this.getAttribute("opacity")||"0.5",i=this.getAttribute("blur-amount")||"4",r=t.includes(this.getAttribute("animation")||"fade")&&this.getAttribute("animation")||"fade",o=this.getAttribute("animation-duration")||"300",n=this.getAttribute("z-index")||"1000",a=this.getAttribute("background-color"),d=this.collectChildren();document.body.style.overflow="hidden",this.attachListeners(),this.portal||(this.portal=document.createElement("div"),this.portal.setAttribute("data-wc-internal",""),this.portal.addEventListener("click",this.handlePortalClick)),this.portal.className=["designbase-wc-backdrop",`designbase-wc-backdrop--${r}`,"designbase-wc-backdrop--open",e?"designbase-wc-backdrop--blur":""].filter(Boolean).join(" "),this.portal.setAttribute("role","presentation"),this.portal.setAttribute("aria-hidden","false"),this.portal.style.setProperty("--backdrop-opacity",s),this.portal.style.setProperty("--backdrop-blur-amount",`${i}px`),this.portal.style.setProperty("--backdrop-animation-duration",`${o}ms`),this.portal.style.setProperty("--backdrop-z-index",n),a?this.portal.style.backgroundColor=a:this.portal.style.removeProperty("background-color"),this.portal.replaceChildren(...d),this.portal.isConnected||document.body.append(this.portal)}}customElements.get("db-backdrop")||customElements.define("db-backdrop",DbBackdrop);export{DbBackdrop};
|
|
@@ -1,91 +1 @@
|
|
|
1
|
-
const
|
|
2
|
-
const VARIANTS = ['primary', 'secondary', 'info', 'success', 'warning', 'danger'];
|
|
3
|
-
const SIZES = ['s', 'm', 'l'];
|
|
4
|
-
const STYLES = ['dot', 'number', 'text', 'outlined'];
|
|
5
|
-
class DbBadge extends HTMLElement {
|
|
6
|
-
static get observedAttributes() {
|
|
7
|
-
return ['variant', 'size', 'badge-style', 'count', 'max-count', 'disabled'];
|
|
8
|
-
}
|
|
9
|
-
get variant() {
|
|
10
|
-
return this.getAttribute('variant') || 'primary';
|
|
11
|
-
}
|
|
12
|
-
set variant(value) {
|
|
13
|
-
this.setAttribute('variant', value);
|
|
14
|
-
}
|
|
15
|
-
get size() {
|
|
16
|
-
return this.getAttribute('size') || 'm';
|
|
17
|
-
}
|
|
18
|
-
set size(value) {
|
|
19
|
-
this.setAttribute('size', value);
|
|
20
|
-
}
|
|
21
|
-
get badgeStyle() {
|
|
22
|
-
return this.getAttribute('badge-style') || 'text';
|
|
23
|
-
}
|
|
24
|
-
set badgeStyle(value) {
|
|
25
|
-
this.setAttribute('badge-style', value);
|
|
26
|
-
}
|
|
27
|
-
get count() {
|
|
28
|
-
const value = this.getAttribute('count');
|
|
29
|
-
return value === null ? undefined : Number(value);
|
|
30
|
-
}
|
|
31
|
-
set count(value) {
|
|
32
|
-
if (value === undefined)
|
|
33
|
-
this.removeAttribute('count');
|
|
34
|
-
else
|
|
35
|
-
this.setAttribute('count', String(value));
|
|
36
|
-
}
|
|
37
|
-
get maxCount() {
|
|
38
|
-
return Number(this.getAttribute('max-count') || 99);
|
|
39
|
-
}
|
|
40
|
-
set maxCount(value) {
|
|
41
|
-
this.setAttribute('max-count', String(value));
|
|
42
|
-
}
|
|
43
|
-
get disabled() {
|
|
44
|
-
return this.hasAttribute('disabled');
|
|
45
|
-
}
|
|
46
|
-
set disabled(value) {
|
|
47
|
-
this.toggleAttribute('disabled', value);
|
|
48
|
-
}
|
|
49
|
-
connectedCallback() {
|
|
50
|
-
this.syncAttributes();
|
|
51
|
-
}
|
|
52
|
-
attributeChangedCallback(name, _oldValue, _newValue) {
|
|
53
|
-
if (name === 'count' || name === 'max-count' || name === 'badge-style') {
|
|
54
|
-
this.syncContent();
|
|
55
|
-
}
|
|
56
|
-
this.syncAttributes();
|
|
57
|
-
}
|
|
58
|
-
syncAttributes() {
|
|
59
|
-
this.classList.add(CLASS);
|
|
60
|
-
this.setAttribute('aria-disabled', String(this.disabled));
|
|
61
|
-
this.syncEnum('variant', this.variant, VARIANTS);
|
|
62
|
-
this.syncEnum('size', this.size, SIZES);
|
|
63
|
-
this.syncEnum('style', this.badgeStyle, STYLES);
|
|
64
|
-
this.classList.toggle(`${CLASS}--disabled`, this.disabled);
|
|
65
|
-
this.syncContent();
|
|
66
|
-
}
|
|
67
|
-
syncContent() {
|
|
68
|
-
if (this.badgeStyle === 'number' && this.count !== undefined) {
|
|
69
|
-
this.textContent =
|
|
70
|
-
this.count > this.maxCount ? `${this.maxCount}+` : String(this.count);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (this.badgeStyle === 'dot') {
|
|
74
|
-
this.textContent = '';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
syncEnum(name, value, values) {
|
|
78
|
-
values.forEach((item) => this.classList.remove(`${CLASS}--${item}`));
|
|
79
|
-
if (values.includes(value)) {
|
|
80
|
-
this.classList.add(`${CLASS}--${value}`);
|
|
81
|
-
}
|
|
82
|
-
else if (name === 'style') {
|
|
83
|
-
this.classList.add(`${CLASS}--text`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (!customElements.get('db-badge')) {
|
|
88
|
-
customElements.define('db-badge', DbBadge);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export { DbBadge };
|
|
1
|
+
const t="designbase-wc-badge",e=["primary","secondary","info","success","warning","danger"],s=["s","m","l"],i=["dot","number","text","outlined"];class DbBadge extends HTMLElement{static get observedAttributes(){return["variant","size","badge-style","count","max-count","disabled"]}get variant(){return this.getAttribute("variant")||"primary"}set variant(t){this.setAttribute("variant",t)}get size(){return this.getAttribute("size")||"m"}set size(t){this.setAttribute("size",t)}get badgeStyle(){return this.getAttribute("badge-style")||"text"}set badgeStyle(t){this.setAttribute("badge-style",t)}get count(){const t=this.getAttribute("count");return null===t?void 0:Number(t)}set count(t){void 0===t?this.removeAttribute("count"):this.setAttribute("count",String(t))}get maxCount(){return Number(this.getAttribute("max-count")||99)}set maxCount(t){this.setAttribute("max-count",String(t))}get disabled(){return this.hasAttribute("disabled")}set disabled(t){this.toggleAttribute("disabled",t)}connectedCallback(){this.syncAttributes()}attributeChangedCallback(t,e,s){"count"!==t&&"max-count"!==t&&"badge-style"!==t||this.syncContent(),this.syncAttributes()}syncAttributes(){this.classList.add(t),this.setAttribute("aria-disabled",String(this.disabled)),this.syncEnum("variant",this.variant,e),this.syncEnum("size",this.size,s),this.syncEnum("style",this.badgeStyle,i),this.classList.toggle(`${t}--disabled`,this.disabled),this.syncContent()}syncContent(){"number"!==this.badgeStyle||void 0===this.count?"dot"===this.badgeStyle&&(this.textContent=""):this.textContent=this.count>this.maxCount?`${this.maxCount}+`:String(this.count)}syncEnum(e,s,i){i.forEach(e=>this.classList.remove(`${t}--${e}`)),i.includes(s)?this.classList.add(`${t}--${s}`):"style"===e&&this.classList.add(`${t}--text`)}}customElements.get("db-badge")||customElements.define("db-badge",DbBadge);export{DbBadge};
|
|
@@ -1,188 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const BUTTON_VARIANT_MAP = {
|
|
4
|
-
primary: 'primary',
|
|
5
|
-
secondary: 'secondary',
|
|
6
|
-
outline: 'tertiary',
|
|
7
|
-
ghost: 'ghost',
|
|
8
|
-
};
|
|
9
|
-
const BUTTON_SIZE_MAP = {
|
|
10
|
-
s: 's',
|
|
11
|
-
sm: 's',
|
|
12
|
-
m: 'm',
|
|
13
|
-
md: 'm',
|
|
14
|
-
l: 'l',
|
|
15
|
-
lg: 'l',
|
|
16
|
-
};
|
|
17
|
-
class DbBanner extends HTMLElement {
|
|
18
|
-
static get observedAttributes() {
|
|
19
|
-
return [
|
|
20
|
-
'title',
|
|
21
|
-
'description',
|
|
22
|
-
'icon',
|
|
23
|
-
'image',
|
|
24
|
-
'image-alt',
|
|
25
|
-
'actions',
|
|
26
|
-
'size',
|
|
27
|
-
'variant',
|
|
28
|
-
'background-image',
|
|
29
|
-
];
|
|
30
|
-
}
|
|
31
|
-
connectedCallback() {
|
|
32
|
-
this.render();
|
|
33
|
-
}
|
|
34
|
-
attributeChangedCallback() {
|
|
35
|
-
this.render();
|
|
36
|
-
}
|
|
37
|
-
parseActions() {
|
|
38
|
-
const raw = this.getAttribute('actions');
|
|
39
|
-
if (!raw)
|
|
40
|
-
return [];
|
|
41
|
-
try {
|
|
42
|
-
const parsed = JSON.parse(raw);
|
|
43
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
getIconSize(size) {
|
|
50
|
-
if (size === 's')
|
|
51
|
-
return 16;
|
|
52
|
-
if (size === 'l')
|
|
53
|
-
return 24;
|
|
54
|
-
return 20;
|
|
55
|
-
}
|
|
56
|
-
getActionIconSize(size) {
|
|
57
|
-
if (size === 's')
|
|
58
|
-
return 16;
|
|
59
|
-
if (size === 'l')
|
|
60
|
-
return 20;
|
|
61
|
-
return 18;
|
|
62
|
-
}
|
|
63
|
-
resolveIconName(icon) {
|
|
64
|
-
if (!icon)
|
|
65
|
-
return undefined;
|
|
66
|
-
if (icon in { close: 1, 'info-filled': 1 })
|
|
67
|
-
return icon;
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
createActionControl(action, index, actionVariant, actionSize) {
|
|
71
|
-
const iconName = this.resolveIconName(action.icon);
|
|
72
|
-
const iconOnly = Boolean(action.iconOnly && iconName);
|
|
73
|
-
const bindClick = (element) => {
|
|
74
|
-
element.addEventListener('db-click', () => {
|
|
75
|
-
this.dispatchEvent(new CustomEvent('db-action', {
|
|
76
|
-
bubbles: true,
|
|
77
|
-
composed: true,
|
|
78
|
-
detail: { index, action },
|
|
79
|
-
}));
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
if (action.href) {
|
|
83
|
-
const link = document.createElement('a');
|
|
84
|
-
link.className = `designbase-wc-button designbase-wc-button--${actionVariant} designbase-wc-button--${actionSize}`;
|
|
85
|
-
if (iconOnly)
|
|
86
|
-
link.classList.add('designbase-wc-button--icon-only');
|
|
87
|
-
link.href = action.href;
|
|
88
|
-
link.setAttribute('aria-label', action.text);
|
|
89
|
-
if (iconOnly && iconName) {
|
|
90
|
-
link.append(createDbIcon(iconName, this.getActionIconSize(actionSize)));
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
link.textContent = action.text;
|
|
94
|
-
}
|
|
95
|
-
if (action.external) {
|
|
96
|
-
link.target = '_blank';
|
|
97
|
-
link.rel = 'noopener noreferrer';
|
|
98
|
-
}
|
|
99
|
-
return link;
|
|
100
|
-
}
|
|
101
|
-
const button = document.createElement('db-button');
|
|
102
|
-
button.setAttribute('variant', actionVariant);
|
|
103
|
-
button.setAttribute('size', actionSize);
|
|
104
|
-
if (iconOnly) {
|
|
105
|
-
button.setAttribute('icon-only', '');
|
|
106
|
-
button.setAttribute('aria-label', action.text);
|
|
107
|
-
if (iconName)
|
|
108
|
-
button.append(createDbIcon(iconName, this.getActionIconSize(actionSize)));
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
button.textContent = action.text;
|
|
112
|
-
}
|
|
113
|
-
bindClick(button);
|
|
114
|
-
return button;
|
|
115
|
-
}
|
|
116
|
-
render() {
|
|
117
|
-
const title = this.getAttribute('title') || '';
|
|
118
|
-
const description = this.getAttribute('description') || '';
|
|
119
|
-
const iconName = this.getAttribute('icon');
|
|
120
|
-
const image = this.getAttribute('image');
|
|
121
|
-
const imageAlt = this.getAttribute('image-alt') || title || 'Banner image';
|
|
122
|
-
const size = this.getAttribute('size') || 'm';
|
|
123
|
-
const variant = this.getAttribute('variant') || 'primary';
|
|
124
|
-
const backgroundImage = this.getAttribute('background-image');
|
|
125
|
-
const actions = this.parseActions();
|
|
126
|
-
this.className = `designbase-wc-banner designbase-wc-banner--${size} designbase-wc-banner--${variant}`;
|
|
127
|
-
this.replaceChildren();
|
|
128
|
-
if (variant === 'image' && backgroundImage) {
|
|
129
|
-
const background = document.createElement('div');
|
|
130
|
-
background.className = 'designbase-wc-banner__background';
|
|
131
|
-
background.style.backgroundImage = `url(${backgroundImage})`;
|
|
132
|
-
background.style.backgroundSize = 'cover';
|
|
133
|
-
background.style.backgroundPosition = 'center';
|
|
134
|
-
background.style.backgroundRepeat = 'no-repeat';
|
|
135
|
-
this.append(background);
|
|
136
|
-
const overlay = document.createElement('div');
|
|
137
|
-
overlay.className = 'designbase-wc-banner__overlay';
|
|
138
|
-
this.append(overlay);
|
|
139
|
-
}
|
|
140
|
-
const container = document.createElement('div');
|
|
141
|
-
container.className = 'designbase-wc-banner__container';
|
|
142
|
-
if (iconName) {
|
|
143
|
-
const iconWrap = document.createElement('div');
|
|
144
|
-
iconWrap.className = 'designbase-wc-banner__icon';
|
|
145
|
-
iconWrap.append(createDbIcon(iconName, this.getIconSize(size)));
|
|
146
|
-
container.append(iconWrap);
|
|
147
|
-
}
|
|
148
|
-
if (image) {
|
|
149
|
-
const imageWrap = document.createElement('div');
|
|
150
|
-
imageWrap.className = 'designbase-wc-banner__image';
|
|
151
|
-
const imageElement = document.createElement('img');
|
|
152
|
-
imageElement.src = image;
|
|
153
|
-
imageElement.alt = imageAlt;
|
|
154
|
-
imageWrap.append(imageElement);
|
|
155
|
-
container.append(imageWrap);
|
|
156
|
-
}
|
|
157
|
-
const content = document.createElement('div');
|
|
158
|
-
content.className = 'designbase-wc-banner__content';
|
|
159
|
-
if (title) {
|
|
160
|
-
const heading = document.createElement('h3');
|
|
161
|
-
heading.className = 'designbase-wc-banner__title';
|
|
162
|
-
heading.textContent = title;
|
|
163
|
-
content.append(heading);
|
|
164
|
-
}
|
|
165
|
-
if (description) {
|
|
166
|
-
const body = document.createElement('p');
|
|
167
|
-
body.className = 'designbase-wc-banner__description';
|
|
168
|
-
body.textContent = description;
|
|
169
|
-
content.append(body);
|
|
170
|
-
}
|
|
171
|
-
container.append(content);
|
|
172
|
-
if (actions.length > 0) {
|
|
173
|
-
const actionsWrap = document.createElement('div');
|
|
174
|
-
actionsWrap.className = 'designbase-wc-banner__actions';
|
|
175
|
-
actions.forEach((action, index) => {
|
|
176
|
-
const actionVariant = BUTTON_VARIANT_MAP[action.variant || 'primary'] || 'primary';
|
|
177
|
-
const actionSize = BUTTON_SIZE_MAP[action.size || 'sm'] || 's';
|
|
178
|
-
actionsWrap.append(this.createActionControl(action, index, actionVariant, actionSize));
|
|
179
|
-
});
|
|
180
|
-
container.append(actionsWrap);
|
|
181
|
-
}
|
|
182
|
-
this.append(container);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (!customElements.get('db-banner'))
|
|
186
|
-
customElements.define('db-banner', DbBanner);
|
|
187
|
-
|
|
188
|
-
export { DbBanner };
|
|
1
|
+
import{createDbIcon as e}from"./db-icons.js";const t={primary:"primary",secondary:"secondary",outline:"tertiary",ghost:"ghost"},n={s:"s",sm:"s",m:"m",md:"m",l:"l",lg:"l"};class DbBanner extends HTMLElement{static get observedAttributes(){return["title","description","icon","image","image-alt","actions","size","variant","background-image"]}connectedCallback(){this.render()}attributeChangedCallback(){this.render()}parseActions(){const e=this.getAttribute("actions");if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}getIconSize(e){return"s"===e?16:"l"===e?24:20}getActionIconSize(e){return"s"===e?16:"l"===e?20:18}resolveIconName(e){if(e)return e in{close:1,"info-filled":1}?e:void 0}createActionControl(t,n,a,s){const i=this.resolveIconName(t.icon),r=Boolean(t.iconOnly&&i);if(t.href){const n=document.createElement("a");return n.className=`designbase-wc-button designbase-wc-button--${a} designbase-wc-button--${s}`,r&&n.classList.add("designbase-wc-button--icon-only"),n.href=t.href,n.setAttribute("aria-label",t.text),r&&i?n.append(e(i,this.getActionIconSize(s))):n.textContent=t.text,t.external&&(n.target="_blank",n.rel="noopener noreferrer"),n}const c=document.createElement("db-button");return c.setAttribute("variant",a),c.setAttribute("size",s),r?(c.setAttribute("icon-only",""),c.setAttribute("aria-label",t.text),i&&c.append(e(i,this.getActionIconSize(s)))):c.textContent=t.text,(e=>{e.addEventListener("db-click",()=>{this.dispatchEvent(new CustomEvent("db-action",{bubbles:!0,composed:!0,detail:{index:n,action:t}}))})})(c),c}render(){const a=this.getAttribute("title")||"",s=this.getAttribute("description")||"",i=this.getAttribute("icon"),r=this.getAttribute("image"),c=this.getAttribute("image-alt")||a||"Banner image",o=this.getAttribute("size")||"m",d=this.getAttribute("variant")||"primary",b=this.getAttribute("background-image"),l=this.parseActions();if(this.className=`designbase-wc-banner designbase-wc-banner--${o} designbase-wc-banner--${d}`,this.replaceChildren(),"image"===d&&b){const e=document.createElement("div");e.className="designbase-wc-banner__background",e.style.backgroundImage=`url(${b})`,e.style.backgroundSize="cover",e.style.backgroundPosition="center",e.style.backgroundRepeat="no-repeat",this.append(e);const t=document.createElement("div");t.className="designbase-wc-banner__overlay",this.append(t)}const m=document.createElement("div");if(m.className="designbase-wc-banner__container",i){const t=document.createElement("div");t.className="designbase-wc-banner__icon",t.append(e(i,this.getIconSize(o))),m.append(t)}if(r){const e=document.createElement("div");e.className="designbase-wc-banner__image";const t=document.createElement("img");t.src=r,t.alt=c,e.append(t),m.append(e)}const g=document.createElement("div");if(g.className="designbase-wc-banner__content",a){const e=document.createElement("h3");e.className="designbase-wc-banner__title",e.textContent=a,g.append(e)}if(s){const e=document.createElement("p");e.className="designbase-wc-banner__description",e.textContent=s,g.append(e)}if(m.append(g),l.length>0){const e=document.createElement("div");e.className="designbase-wc-banner__actions",l.forEach((a,s)=>{const i=t[a.variant||"primary"]||"primary",r=n[a.size||"sm"]||"s";e.append(this.createActionControl(a,s,i,r))}),m.append(e)}this.append(m)}}customElements.get("db-banner")||customElements.define("db-banner",DbBanner);export{DbBanner};
|