@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.
- 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.d.ts +1 -1
- package/dist/react/index.esm.js +39373 -1
- package/package.json +1 -1
- package/dist/chunks/lottie-2d1f6278.js +0 -1
- package/dist/react/chunks/lottie-14e7addb.js +0 -1
|
@@ -1 +1,440 @@
|
|
|
1
|
-
const
|
|
1
|
+
const POSITIONS = [
|
|
2
|
+
'top',
|
|
3
|
+
'bottom',
|
|
4
|
+
'left',
|
|
5
|
+
'right',
|
|
6
|
+
'top-start',
|
|
7
|
+
'top-end',
|
|
8
|
+
'bottom-start',
|
|
9
|
+
'bottom-end',
|
|
10
|
+
'left-start',
|
|
11
|
+
'left-end',
|
|
12
|
+
'right-start',
|
|
13
|
+
'right-end',
|
|
14
|
+
];
|
|
15
|
+
const SIZES = ['s', 'm', 'l'];
|
|
16
|
+
const VARIANTS = ['default', 'primary', 'success', 'warning', 'danger', 'info'];
|
|
17
|
+
const GAP = 8;
|
|
18
|
+
const ARW = 6;
|
|
19
|
+
const PAD = 8;
|
|
20
|
+
const OUT = -10;
|
|
21
|
+
const INSET = 2;
|
|
22
|
+
class DbTooltip extends HTMLElement {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.tooltipId = `db-tooltip-${Math.random().toString(36).slice(2, 9)}`;
|
|
26
|
+
this.visible = false;
|
|
27
|
+
this.handleShow = () => {
|
|
28
|
+
if (this.disabled || this.alwaysShow)
|
|
29
|
+
return;
|
|
30
|
+
this.clearTimers();
|
|
31
|
+
this.showTimer = setTimeout(() => this.setVisible(true), Math.max(0, this.delay));
|
|
32
|
+
};
|
|
33
|
+
this.handleHide = () => {
|
|
34
|
+
if (this.alwaysShow)
|
|
35
|
+
return;
|
|
36
|
+
this.clearTimers();
|
|
37
|
+
this.hideTimer = setTimeout(() => this.setVisible(false), Math.max(0, this.hideDelay));
|
|
38
|
+
};
|
|
39
|
+
this.handleKeyDown = (event) => {
|
|
40
|
+
if (event.key === 'Escape') {
|
|
41
|
+
this.clearTimers();
|
|
42
|
+
this.setVisible(false);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
this.handleReposition = () => {
|
|
46
|
+
if (!this.visible && !this.alwaysShow)
|
|
47
|
+
return;
|
|
48
|
+
if (this.repositionRaf)
|
|
49
|
+
cancelAnimationFrame(this.repositionRaf);
|
|
50
|
+
this.repositionRaf = requestAnimationFrame(() => this.calculatePosition());
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
static get observedAttributes() {
|
|
54
|
+
return [
|
|
55
|
+
'content',
|
|
56
|
+
'position',
|
|
57
|
+
'size',
|
|
58
|
+
'variant',
|
|
59
|
+
'disabled',
|
|
60
|
+
'always-show',
|
|
61
|
+
'delay',
|
|
62
|
+
'hide-delay',
|
|
63
|
+
'max-width',
|
|
64
|
+
'show-arrow',
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
get content() {
|
|
68
|
+
return this.getAttribute('content') || '';
|
|
69
|
+
}
|
|
70
|
+
set content(value) {
|
|
71
|
+
this.setAttribute('content', value);
|
|
72
|
+
}
|
|
73
|
+
get position() {
|
|
74
|
+
return this.getAttribute('position') || 'top';
|
|
75
|
+
}
|
|
76
|
+
set position(value) {
|
|
77
|
+
this.setAttribute('position', value);
|
|
78
|
+
}
|
|
79
|
+
get size() {
|
|
80
|
+
return this.getAttribute('size') || 'm';
|
|
81
|
+
}
|
|
82
|
+
set size(value) {
|
|
83
|
+
this.setAttribute('size', value);
|
|
84
|
+
}
|
|
85
|
+
get variant() {
|
|
86
|
+
return this.getAttribute('variant') || 'default';
|
|
87
|
+
}
|
|
88
|
+
set variant(value) {
|
|
89
|
+
this.setAttribute('variant', value);
|
|
90
|
+
}
|
|
91
|
+
get disabled() {
|
|
92
|
+
return this.hasAttribute('disabled');
|
|
93
|
+
}
|
|
94
|
+
set disabled(value) {
|
|
95
|
+
this.toggleAttribute('disabled', value);
|
|
96
|
+
}
|
|
97
|
+
get alwaysShow() {
|
|
98
|
+
return this.hasAttribute('always-show');
|
|
99
|
+
}
|
|
100
|
+
set alwaysShow(value) {
|
|
101
|
+
this.toggleAttribute('always-show', value);
|
|
102
|
+
}
|
|
103
|
+
get delay() {
|
|
104
|
+
return Number(this.getAttribute('delay') ?? '200');
|
|
105
|
+
}
|
|
106
|
+
get hideDelay() {
|
|
107
|
+
return Number(this.getAttribute('hide-delay') ?? '80');
|
|
108
|
+
}
|
|
109
|
+
get maxWidth() {
|
|
110
|
+
return Number(this.getAttribute('max-width') ?? '240');
|
|
111
|
+
}
|
|
112
|
+
get showArrow() {
|
|
113
|
+
return this.getAttribute('show-arrow') !== 'false';
|
|
114
|
+
}
|
|
115
|
+
connectedCallback() {
|
|
116
|
+
this.render();
|
|
117
|
+
this.childObserver = new MutationObserver(() => this.render());
|
|
118
|
+
this.childObserver.observe(this, { childList: true });
|
|
119
|
+
window.addEventListener('scroll', this.handleReposition, true);
|
|
120
|
+
window.addEventListener('resize', this.handleReposition);
|
|
121
|
+
}
|
|
122
|
+
disconnectedCallback() {
|
|
123
|
+
this.childObserver?.disconnect();
|
|
124
|
+
this.clearTimers();
|
|
125
|
+
if (this.repositionRaf)
|
|
126
|
+
cancelAnimationFrame(this.repositionRaf);
|
|
127
|
+
if (this.enterRaf)
|
|
128
|
+
cancelAnimationFrame(this.enterRaf);
|
|
129
|
+
if (this.removalTimer)
|
|
130
|
+
clearTimeout(this.removalTimer);
|
|
131
|
+
window.removeEventListener('scroll', this.handleReposition, true);
|
|
132
|
+
window.removeEventListener('resize', this.handleReposition);
|
|
133
|
+
this.tooltip?.remove();
|
|
134
|
+
this.tooltip = undefined;
|
|
135
|
+
}
|
|
136
|
+
attributeChangedCallback() {
|
|
137
|
+
if (!this.isConnected)
|
|
138
|
+
return;
|
|
139
|
+
this.render();
|
|
140
|
+
if (this.alwaysShow) {
|
|
141
|
+
this.setVisible(true);
|
|
142
|
+
}
|
|
143
|
+
else if (!this.visible) {
|
|
144
|
+
this.removeTooltip();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
clearTimers() {
|
|
148
|
+
if (this.showTimer)
|
|
149
|
+
clearTimeout(this.showTimer);
|
|
150
|
+
if (this.hideTimer)
|
|
151
|
+
clearTimeout(this.hideTimer);
|
|
152
|
+
this.showTimer = undefined;
|
|
153
|
+
this.hideTimer = undefined;
|
|
154
|
+
}
|
|
155
|
+
groupOf(position) {
|
|
156
|
+
if (position.startsWith('top'))
|
|
157
|
+
return 'top';
|
|
158
|
+
if (position.startsWith('bottom'))
|
|
159
|
+
return 'bottom';
|
|
160
|
+
if (position.startsWith('left'))
|
|
161
|
+
return 'left';
|
|
162
|
+
return 'right';
|
|
163
|
+
}
|
|
164
|
+
resolvedPosition() {
|
|
165
|
+
return POSITIONS.includes(this.position) ? this.position : 'top';
|
|
166
|
+
}
|
|
167
|
+
collectTriggerChildren() {
|
|
168
|
+
const isInternalNode = (child) => child.hasAttribute('data-wc-internal') || child === this.trigger;
|
|
169
|
+
const fromHost = Array.from(this.children).filter((child) => !isInternalNode(child));
|
|
170
|
+
if (fromHost.length > 0)
|
|
171
|
+
return fromHost;
|
|
172
|
+
return Array.from(this.trigger?.children || []);
|
|
173
|
+
}
|
|
174
|
+
ensureTrigger() {
|
|
175
|
+
if (!this.trigger) {
|
|
176
|
+
this.trigger = document.createElement('span');
|
|
177
|
+
this.trigger.className = 'designbase-wc-tooltip__trigger';
|
|
178
|
+
this.trigger.setAttribute('data-wc-internal', '');
|
|
179
|
+
this.trigger.tabIndex = 0;
|
|
180
|
+
this.trigger.addEventListener('mouseenter', this.handleShow);
|
|
181
|
+
this.trigger.addEventListener('mouseleave', this.handleHide);
|
|
182
|
+
this.trigger.addEventListener('focus', this.handleShow);
|
|
183
|
+
this.trigger.addEventListener('blur', this.handleHide);
|
|
184
|
+
this.trigger.addEventListener('keydown', this.handleKeyDown);
|
|
185
|
+
}
|
|
186
|
+
if (this.trigger.parentElement !== this) {
|
|
187
|
+
this.append(this.trigger);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
mountTriggerChildren(children) {
|
|
191
|
+
if (!this.trigger)
|
|
192
|
+
return;
|
|
193
|
+
children.forEach((child) => {
|
|
194
|
+
if (child.parentElement !== this.trigger) {
|
|
195
|
+
this.trigger.append(child);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
render() {
|
|
200
|
+
this.ensureTrigger();
|
|
201
|
+
this.mountTriggerChildren(this.collectTriggerChildren());
|
|
202
|
+
if (this.alwaysShow) {
|
|
203
|
+
this.setVisible(true);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
ensureTooltip() {
|
|
207
|
+
if (this.tooltip)
|
|
208
|
+
return;
|
|
209
|
+
this.tooltip = document.createElement('div');
|
|
210
|
+
this.tooltip.className = 'designbase-wc-tooltip';
|
|
211
|
+
this.tooltip.setAttribute('data-wc-internal', '');
|
|
212
|
+
this.tooltip.setAttribute('role', 'tooltip');
|
|
213
|
+
this.tooltip.id = this.tooltipId;
|
|
214
|
+
this.contentEl = document.createElement('div');
|
|
215
|
+
this.contentEl.className = 'designbase-wc-tooltip__content';
|
|
216
|
+
this.arrow = document.createElement('div');
|
|
217
|
+
this.arrow.className = 'designbase-wc-tooltip__arrow';
|
|
218
|
+
this.tooltip.append(this.contentEl, this.arrow);
|
|
219
|
+
document.body.append(this.tooltip);
|
|
220
|
+
}
|
|
221
|
+
syncTooltipClasses(showVisible = this.visible || this.alwaysShow) {
|
|
222
|
+
if (!this.tooltip || !this.arrow)
|
|
223
|
+
return;
|
|
224
|
+
const position = this.resolvedPosition();
|
|
225
|
+
const size = SIZES.includes(this.size) ? this.size : 'm';
|
|
226
|
+
const variant = VARIANTS.includes(this.variant) ? this.variant : 'default';
|
|
227
|
+
this.tooltip.className = [
|
|
228
|
+
'designbase-wc-tooltip',
|
|
229
|
+
`designbase-wc-tooltip--${size}`,
|
|
230
|
+
`designbase-wc-tooltip--${variant}`,
|
|
231
|
+
`designbase-wc-tooltip--${position}`,
|
|
232
|
+
showVisible && 'designbase-wc-tooltip--visible',
|
|
233
|
+
this.disabled && 'designbase-wc-tooltip--disabled',
|
|
234
|
+
]
|
|
235
|
+
.filter(Boolean)
|
|
236
|
+
.join(' ');
|
|
237
|
+
this.arrow.className = `designbase-wc-tooltip__arrow designbase-wc-tooltip__arrow--${position}`;
|
|
238
|
+
this.arrow.hidden = !this.showArrow;
|
|
239
|
+
this.tooltip.setAttribute('data-placement-group', this.groupOf(position));
|
|
240
|
+
this.tooltip.setAttribute('aria-hidden', String(!showVisible));
|
|
241
|
+
this.tooltip.style.maxWidth = `${this.maxWidth}px`;
|
|
242
|
+
this.tooltip.style.zIndex = '9999';
|
|
243
|
+
this.tooltip.style.pointerEvents = 'none';
|
|
244
|
+
if (this.contentEl) {
|
|
245
|
+
this.contentEl.textContent = this.content;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
calculatePosition() {
|
|
249
|
+
if (!this.trigger || !this.tooltip || !this.arrow)
|
|
250
|
+
return;
|
|
251
|
+
const position = this.resolvedPosition();
|
|
252
|
+
const tRect = this.trigger.getBoundingClientRect();
|
|
253
|
+
// offsetWidth/Height 는 transform(스케일/이동) 영향을 받지 않으므로
|
|
254
|
+
// 등장 트랜지션 중에도 정확한 크기로 위치를 계산할 수 있다.
|
|
255
|
+
const pRect = { width: this.tooltip.offsetWidth, height: this.tooltip.offsetHeight };
|
|
256
|
+
let top = 0;
|
|
257
|
+
let left = 0;
|
|
258
|
+
let aTop = 0;
|
|
259
|
+
let aLeft = 0;
|
|
260
|
+
switch (position) {
|
|
261
|
+
case 'top':
|
|
262
|
+
top = tRect.top - pRect.height - GAP;
|
|
263
|
+
left = tRect.left + tRect.width / 2 - pRect.width / 2;
|
|
264
|
+
aTop = pRect.height - INSET;
|
|
265
|
+
aLeft = pRect.width / 2 - ARW;
|
|
266
|
+
break;
|
|
267
|
+
case 'top-start':
|
|
268
|
+
top = tRect.top - pRect.height - GAP;
|
|
269
|
+
left = tRect.left;
|
|
270
|
+
aTop = pRect.height - INSET;
|
|
271
|
+
aLeft = PAD;
|
|
272
|
+
break;
|
|
273
|
+
case 'top-end':
|
|
274
|
+
top = tRect.top - pRect.height - GAP;
|
|
275
|
+
left = tRect.right - pRect.width;
|
|
276
|
+
aTop = pRect.height - INSET;
|
|
277
|
+
aLeft = pRect.width - PAD - ARW;
|
|
278
|
+
break;
|
|
279
|
+
case 'bottom':
|
|
280
|
+
top = tRect.bottom + GAP;
|
|
281
|
+
left = tRect.left + tRect.width / 2 - pRect.width / 2;
|
|
282
|
+
aTop = OUT;
|
|
283
|
+
aLeft = pRect.width / 2 - ARW;
|
|
284
|
+
break;
|
|
285
|
+
case 'bottom-start':
|
|
286
|
+
top = tRect.bottom + GAP;
|
|
287
|
+
left = tRect.left;
|
|
288
|
+
aTop = OUT;
|
|
289
|
+
aLeft = PAD;
|
|
290
|
+
break;
|
|
291
|
+
case 'bottom-end':
|
|
292
|
+
top = tRect.bottom + GAP;
|
|
293
|
+
left = tRect.right - pRect.width;
|
|
294
|
+
aTop = OUT;
|
|
295
|
+
aLeft = pRect.width - PAD - ARW;
|
|
296
|
+
break;
|
|
297
|
+
case 'left':
|
|
298
|
+
top = tRect.top + tRect.height / 2 - pRect.height / 2;
|
|
299
|
+
left = tRect.left - pRect.width - GAP;
|
|
300
|
+
aTop = pRect.height / 2 - ARW;
|
|
301
|
+
aLeft = pRect.width - INSET;
|
|
302
|
+
break;
|
|
303
|
+
case 'left-start':
|
|
304
|
+
top = tRect.top;
|
|
305
|
+
left = tRect.left - pRect.width - GAP;
|
|
306
|
+
aTop = PAD;
|
|
307
|
+
aLeft = pRect.width - INSET;
|
|
308
|
+
break;
|
|
309
|
+
case 'left-end':
|
|
310
|
+
top = tRect.bottom - pRect.height;
|
|
311
|
+
left = tRect.left - pRect.width - GAP;
|
|
312
|
+
aTop = pRect.height - PAD - ARW;
|
|
313
|
+
aLeft = pRect.width - INSET;
|
|
314
|
+
break;
|
|
315
|
+
case 'right':
|
|
316
|
+
top = tRect.top + tRect.height / 2 - pRect.height / 2;
|
|
317
|
+
left = tRect.right + GAP;
|
|
318
|
+
aTop = pRect.height / 2 - ARW;
|
|
319
|
+
aLeft = OUT;
|
|
320
|
+
break;
|
|
321
|
+
case 'right-start':
|
|
322
|
+
top = tRect.top;
|
|
323
|
+
left = tRect.right + GAP;
|
|
324
|
+
aTop = PAD;
|
|
325
|
+
aLeft = OUT;
|
|
326
|
+
break;
|
|
327
|
+
case 'right-end':
|
|
328
|
+
top = tRect.bottom - pRect.height;
|
|
329
|
+
left = tRect.right + GAP;
|
|
330
|
+
aTop = pRect.height - PAD - ARW;
|
|
331
|
+
aLeft = OUT;
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
const EDGE = 8;
|
|
335
|
+
const vw = window.innerWidth;
|
|
336
|
+
const vh = window.innerHeight;
|
|
337
|
+
if (left < EDGE)
|
|
338
|
+
left = EDGE;
|
|
339
|
+
if (left + pRect.width > vw - EDGE)
|
|
340
|
+
left = vw - pRect.width - EDGE;
|
|
341
|
+
if (top < EDGE)
|
|
342
|
+
top = EDGE;
|
|
343
|
+
if (top + pRect.height > vh - EDGE)
|
|
344
|
+
top = vh - pRect.height - EDGE;
|
|
345
|
+
const group = this.groupOf(position);
|
|
346
|
+
if (group === 'top' || group === 'bottom') {
|
|
347
|
+
const triggerCenterX = tRect.left + tRect.width / 2;
|
|
348
|
+
const localX = triggerCenterX - left - ARW;
|
|
349
|
+
aLeft = Math.min(pRect.width - PAD - ARW, Math.max(PAD, localX));
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
const triggerCenterY = tRect.top + tRect.height / 2;
|
|
353
|
+
const localY = triggerCenterY - top - ARW;
|
|
354
|
+
aTop = Math.min(pRect.height - PAD - ARW, Math.max(PAD, localY));
|
|
355
|
+
}
|
|
356
|
+
this.tooltip.style.position = 'fixed';
|
|
357
|
+
this.tooltip.style.top = `${top}px`;
|
|
358
|
+
this.tooltip.style.left = `${left}px`;
|
|
359
|
+
this.arrow.style.position = 'absolute';
|
|
360
|
+
this.arrow.style.top = `${aTop}px`;
|
|
361
|
+
this.arrow.style.left = `${aLeft}px`;
|
|
362
|
+
}
|
|
363
|
+
setVisible(next) {
|
|
364
|
+
if (this.disabled && next)
|
|
365
|
+
return;
|
|
366
|
+
this.visible = next;
|
|
367
|
+
if (!next && !this.alwaysShow) {
|
|
368
|
+
this.hideTooltip();
|
|
369
|
+
this.trigger?.removeAttribute('aria-describedby');
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
// 퇴장 애니메이션 중 다시 나타나는 경우 예약된 제거를 취소
|
|
373
|
+
if (this.removalTimer) {
|
|
374
|
+
clearTimeout(this.removalTimer);
|
|
375
|
+
this.removalTimer = undefined;
|
|
376
|
+
}
|
|
377
|
+
if (this.enterRaf) {
|
|
378
|
+
cancelAnimationFrame(this.enterRaf);
|
|
379
|
+
this.enterRaf = undefined;
|
|
380
|
+
}
|
|
381
|
+
this.ensureTooltip();
|
|
382
|
+
// 1) 먼저 "숨김" 상태로 마운트하고 위치를 잡는다.
|
|
383
|
+
this.syncTooltipClasses(false);
|
|
384
|
+
this.calculatePosition();
|
|
385
|
+
this.trigger?.setAttribute('aria-describedby', this.tooltipId);
|
|
386
|
+
// 2) 다음 프레임에 visible 로 전환해야 등장 트랜지션이 실제로 재생된다.
|
|
387
|
+
this.enterRaf = requestAnimationFrame(() => {
|
|
388
|
+
this.enterRaf = requestAnimationFrame(() => {
|
|
389
|
+
this.enterRaf = undefined;
|
|
390
|
+
this.syncTooltipClasses(true);
|
|
391
|
+
this.calculatePosition();
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
hideTooltip() {
|
|
396
|
+
if (this.enterRaf) {
|
|
397
|
+
cancelAnimationFrame(this.enterRaf);
|
|
398
|
+
this.enterRaf = undefined;
|
|
399
|
+
}
|
|
400
|
+
if (!this.tooltip)
|
|
401
|
+
return;
|
|
402
|
+
const el = this.tooltip;
|
|
403
|
+
el.classList.remove('designbase-wc-tooltip--visible');
|
|
404
|
+
el.setAttribute('aria-hidden', 'true');
|
|
405
|
+
const finish = () => {
|
|
406
|
+
el.removeEventListener('transitionend', onEnd);
|
|
407
|
+
if (this.removalTimer) {
|
|
408
|
+
clearTimeout(this.removalTimer);
|
|
409
|
+
this.removalTimer = undefined;
|
|
410
|
+
}
|
|
411
|
+
// 퇴장이 끝나기 전에 다시 보이게 되었다면 제거하지 않는다.
|
|
412
|
+
if (!this.visible && this.tooltip === el) {
|
|
413
|
+
this.removeTooltip();
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
const onEnd = (event) => {
|
|
417
|
+
if (event.target !== el || event.propertyName !== 'opacity')
|
|
418
|
+
return;
|
|
419
|
+
finish();
|
|
420
|
+
};
|
|
421
|
+
el.addEventListener('transitionend', onEnd);
|
|
422
|
+
// transitionend 가 발생하지 않는 경우를 대비한 안전장치
|
|
423
|
+
this.removalTimer = setTimeout(finish, 400);
|
|
424
|
+
}
|
|
425
|
+
removeTooltip() {
|
|
426
|
+
if (this.removalTimer) {
|
|
427
|
+
clearTimeout(this.removalTimer);
|
|
428
|
+
this.removalTimer = undefined;
|
|
429
|
+
}
|
|
430
|
+
this.tooltip?.remove();
|
|
431
|
+
this.tooltip = undefined;
|
|
432
|
+
this.contentEl = undefined;
|
|
433
|
+
this.arrow = undefined;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (!customElements.get('db-tooltip')) {
|
|
437
|
+
customElements.define('db-tooltip', DbTooltip);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export { DbTooltip };
|
|
@@ -1 +1,121 @@
|
|
|
1
|
-
import{createDbIcon
|
|
1
|
+
import { createDbIcon } from './db-icons.js';
|
|
2
|
+
|
|
3
|
+
const VARIANTS = ['primary', 'white', 'dark'];
|
|
4
|
+
class DbTopBanner extends HTMLElement {
|
|
5
|
+
static get observedAttributes() {
|
|
6
|
+
return ['badge-text', 'content', 'image', 'link-text', 'variant', 'fixed', 'dismissed'];
|
|
7
|
+
}
|
|
8
|
+
connectedCallback() {
|
|
9
|
+
this.render();
|
|
10
|
+
}
|
|
11
|
+
attributeChangedCallback() {
|
|
12
|
+
this.render();
|
|
13
|
+
}
|
|
14
|
+
isDarkBg(variant) {
|
|
15
|
+
return variant === 'primary' || variant === 'dark';
|
|
16
|
+
}
|
|
17
|
+
createLinkButton(variant, linkText) {
|
|
18
|
+
const isDarkBg = this.isDarkBg(variant);
|
|
19
|
+
const button = document.createElement('db-button');
|
|
20
|
+
button.setAttribute('variant', isDarkBg ? 'secondary' : 'ghost');
|
|
21
|
+
button.setAttribute('size', 's');
|
|
22
|
+
button.classList.add('designbase-wc-top-banner__link');
|
|
23
|
+
const label = document.createElement('span');
|
|
24
|
+
label.textContent = linkText;
|
|
25
|
+
const endIcon = document.createElement('span');
|
|
26
|
+
endIcon.className = 'designbase-wc-button__end-icon';
|
|
27
|
+
endIcon.append(createDbIcon('chevron-right', 16));
|
|
28
|
+
button.append(label, endIcon);
|
|
29
|
+
button.addEventListener('db-click', () => {
|
|
30
|
+
this.dispatchEvent(new CustomEvent('db-link', { bubbles: true, composed: true }));
|
|
31
|
+
});
|
|
32
|
+
return button;
|
|
33
|
+
}
|
|
34
|
+
createCloseButton() {
|
|
35
|
+
const button = document.createElement('db-button');
|
|
36
|
+
button.setAttribute('variant', 'ghost');
|
|
37
|
+
button.setAttribute('size', 'm');
|
|
38
|
+
button.setAttribute('icon-only', '');
|
|
39
|
+
button.setAttribute('aria-label', '닫기');
|
|
40
|
+
button.classList.add('designbase-wc-top-banner__close');
|
|
41
|
+
button.append(createDbIcon('close', 20));
|
|
42
|
+
button.addEventListener('db-click', () => {
|
|
43
|
+
this.setAttribute('dismissed', '');
|
|
44
|
+
this.dispatchEvent(new CustomEvent('db-close', { bubbles: true, composed: true }));
|
|
45
|
+
this.render();
|
|
46
|
+
});
|
|
47
|
+
return button;
|
|
48
|
+
}
|
|
49
|
+
createBadge(badgeText, isDarkBg) {
|
|
50
|
+
const badge = document.createElement('db-badge');
|
|
51
|
+
badge.setAttribute('size', 's');
|
|
52
|
+
badge.setAttribute('variant', isDarkBg ? 'secondary' : 'primary');
|
|
53
|
+
badge.setAttribute('badge-style', 'text');
|
|
54
|
+
badge.textContent = badgeText;
|
|
55
|
+
badge.classList.add('designbase-wc-top-banner__badge');
|
|
56
|
+
return badge;
|
|
57
|
+
}
|
|
58
|
+
render() {
|
|
59
|
+
if (this.hasAttribute('dismissed')) {
|
|
60
|
+
this.replaceChildren();
|
|
61
|
+
this.className = 'designbase-wc-top-banner designbase-wc-top-banner--dismissed';
|
|
62
|
+
this.style.display = 'none';
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.style.display = '';
|
|
66
|
+
const badgeText = this.getAttribute('badge-text') || '';
|
|
67
|
+
const content = this.getAttribute('content') || '';
|
|
68
|
+
const image = this.getAttribute('image') || '';
|
|
69
|
+
const linkText = this.getAttribute('link-text') || '';
|
|
70
|
+
const rawVariant = this.getAttribute('variant') || 'primary';
|
|
71
|
+
const variant = VARIANTS.includes(rawVariant) ? rawVariant : 'primary';
|
|
72
|
+
const fixed = this.hasAttribute('fixed');
|
|
73
|
+
const isDarkBg = this.isDarkBg(variant);
|
|
74
|
+
this.className = [
|
|
75
|
+
'designbase-wc-top-banner',
|
|
76
|
+
`designbase-wc-top-banner--${variant}`,
|
|
77
|
+
fixed && 'designbase-wc-top-banner--fixed',
|
|
78
|
+
image && 'designbase-wc-top-banner--has-image',
|
|
79
|
+
]
|
|
80
|
+
.filter(Boolean)
|
|
81
|
+
.join(' ');
|
|
82
|
+
this.setAttribute('role', 'alert');
|
|
83
|
+
if (image) {
|
|
84
|
+
this.style.setProperty('--db-top-banner-bg-image', `url("${image}")`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.style.removeProperty('--db-top-banner-bg-image');
|
|
88
|
+
}
|
|
89
|
+
this.replaceChildren();
|
|
90
|
+
if (image) {
|
|
91
|
+
const background = document.createElement('div');
|
|
92
|
+
background.className = 'designbase-wc-top-banner__background';
|
|
93
|
+
background.setAttribute('aria-hidden', 'true');
|
|
94
|
+
const overlay = document.createElement('div');
|
|
95
|
+
overlay.className = 'designbase-wc-top-banner__overlay';
|
|
96
|
+
overlay.setAttribute('aria-hidden', 'true');
|
|
97
|
+
this.append(background, overlay);
|
|
98
|
+
}
|
|
99
|
+
const container = document.createElement('div');
|
|
100
|
+
container.className = 'designbase-wc-top-banner__container';
|
|
101
|
+
const contentWrap = document.createElement('div');
|
|
102
|
+
contentWrap.className = 'designbase-wc-top-banner__content';
|
|
103
|
+
if (badgeText) {
|
|
104
|
+
contentWrap.append(this.createBadge(badgeText, isDarkBg));
|
|
105
|
+
}
|
|
106
|
+
const text = document.createElement('span');
|
|
107
|
+
text.className = 'designbase-wc-top-banner__text';
|
|
108
|
+
text.textContent = content;
|
|
109
|
+
contentWrap.append(text);
|
|
110
|
+
if (linkText) {
|
|
111
|
+
contentWrap.append(this.createLinkButton(variant, linkText));
|
|
112
|
+
}
|
|
113
|
+
container.append(contentWrap);
|
|
114
|
+
container.append(this.createCloseButton());
|
|
115
|
+
this.append(container);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!customElements.get('db-top-banner'))
|
|
119
|
+
customElements.define('db-top-banner', DbTopBanner);
|
|
120
|
+
|
|
121
|
+
export { DbTopBanner };
|