@haiyue/ui 0.2.2 → 0.3.1
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/CHANGELOG.md +42 -0
- package/README.md +523 -4
- package/dist/adapters/web/controls.js +48 -8
- package/dist/adapters/web/renderer.js +9 -11
- package/dist/adapters/web/styles.d.ts +2 -3
- package/dist/adapters/web/styles.js +26 -23
- package/dist/alert.d.ts +39 -0
- package/dist/alert.js +144 -0
- package/dist/anchor.d.ts +62 -0
- package/dist/anchor.js +293 -0
- package/dist/auto-complete.d.ts +83 -0
- package/dist/auto-complete.js +267 -0
- package/dist/avatar.d.ts +45 -0
- package/dist/avatar.js +135 -0
- package/dist/badge.js +5 -5
- package/dist/border-beam.js +3 -2
- package/dist/breadcrumb.js +5 -5
- package/dist/button-group.js +8 -8
- package/dist/button.js +10 -10
- package/dist/card.d.ts +29 -0
- package/dist/card.js +101 -0
- package/dist/carousel.js +6 -6
- package/dist/cascader.js +19 -13
- package/dist/checkbox.d.ts +12 -0
- package/dist/checkbox.js +22 -6
- package/dist/collapse.js +6 -6
- package/dist/context-menu.js +3 -4
- package/dist/core/actions.js +7 -8
- package/dist/core/data.d.ts +1 -1
- package/dist/core/data.js +44 -10
- package/dist/core/platform-view.js +8 -2
- package/dist/core/selection.js +4 -4
- package/dist/core/semantics.d.ts +26 -0
- package/dist/core/semantics.js +8 -0
- package/dist/core/text.js +3 -3
- package/dist/core/validation.d.ts +3 -1
- package/dist/core/validation.js +23 -5
- package/dist/date-picker.js +19 -13
- package/dist/descriptions.d.ts +44 -0
- package/dist/descriptions.js +169 -0
- package/dist/dialog.d.ts +4 -0
- package/dist/dialog.js +48 -27
- package/dist/divider.js +2 -2
- package/dist/draggable.js +5 -3
- package/dist/drawer.js +16 -24
- package/dist/dropdown.js +3 -4
- package/dist/empty.d.ts +20 -0
- package/dist/empty.js +58 -0
- package/dist/expandable.js +4 -4
- package/dist/form-item.d.ts +60 -0
- package/dist/form-item.js +212 -0
- package/dist/form.d.ts +41 -0
- package/dist/form.js +154 -0
- package/dist/history-controls.js +5 -5
- package/dist/image-preview.d.ts +22 -0
- package/dist/image-preview.js +38 -0
- package/dist/image.d.ts +52 -0
- package/dist/image.js +152 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +72 -0
- package/dist/input.d.ts +11 -0
- package/dist/input.js +32 -18
- package/dist/internal/anchored-popup.d.ts +19 -0
- package/dist/internal/anchored-popup.js +89 -0
- package/dist/internal/focus.d.ts +2 -0
- package/dist/internal/focus.js +31 -0
- package/dist/internal/form-control.d.ts +22 -0
- package/dist/internal/form-control.js +52 -0
- package/dist/internal/image-viewer.d.ts +51 -0
- package/dist/internal/image-viewer.js +210 -0
- package/dist/internal/keyboard.d.ts +2 -0
- package/dist/internal/keyboard.js +12 -0
- package/dist/internal/numbers.d.ts +2 -0
- package/dist/internal/numbers.js +8 -0
- package/dist/internal/pagination.d.ts +35 -0
- package/dist/internal/pagination.js +169 -0
- package/dist/internal/popover-base.d.ts +87 -0
- package/dist/internal/popover-base.js +365 -0
- package/dist/internal/presentation.d.ts +2 -0
- package/dist/internal/presentation.js +28 -0
- package/dist/mentions.d.ts +115 -0
- package/dist/mentions.js +485 -0
- package/dist/menu-shared.d.ts +1 -1
- package/dist/menu-shared.js +3 -3
- package/dist/menu.d.ts +63 -0
- package/dist/menu.js +339 -0
- package/dist/modal.js +11 -40
- package/dist/notification.js +11 -10
- package/dist/pagination.d.ts +34 -0
- package/dist/pagination.js +73 -0
- package/dist/popconfirm.d.ts +6 -0
- package/dist/popconfirm.js +7 -0
- package/dist/popover.d.ts +6 -0
- package/dist/popover.js +7 -0
- package/dist/portable/page.js +25 -14
- package/dist/progress.d.ts +30 -0
- package/dist/progress.js +102 -0
- package/dist/qr-code.js +3 -3
- package/dist/radio.d.ts +10 -0
- package/dist/radio.js +18 -5
- package/dist/range.js +7 -7
- package/dist/rate.js +3 -3
- package/dist/resizable.js +8 -5
- package/dist/result.d.ts +22 -0
- package/dist/result.js +88 -0
- package/dist/ribbon.d.ts +19 -0
- package/dist/ribbon.js +106 -0
- package/dist/segmented.d.ts +39 -0
- package/dist/segmented.js +192 -0
- package/dist/select.d.ts +12 -0
- package/dist/select.js +31 -13
- package/dist/skeleton.js +10 -10
- package/dist/spin.d.ts +26 -0
- package/dist/spin.js +80 -0
- package/dist/steps.js +13 -13
- package/dist/switch.d.ts +44 -0
- package/dist/switch.js +104 -0
- package/dist/table.d.ts +3 -3
- package/dist/table.js +110 -128
- package/dist/tabs.js +7 -7
- package/dist/tag.js +8 -8
- package/dist/time-picker.js +16 -10
- package/dist/timeline.js +12 -12
- package/dist/toast.js +12 -11
- package/dist/tooltip.d.ts +6 -0
- package/dist/tooltip.js +107 -6
- package/dist/tour.js +26 -17
- package/dist/tree-model.d.ts +2 -0
- package/dist/tree-model.js +32 -11
- package/dist/tree-node.js +2 -2
- package/dist/tree-select.d.ts +94 -0
- package/dist/tree-select.js +398 -0
- package/dist/tree.d.ts +0 -2
- package/dist/tree.js +14 -29
- package/dist/upload.d.ts +108 -0
- package/dist/upload.js +358 -0
- package/dist/virtual-keyboard.d.ts +1 -0
- package/dist/virtual-keyboard.js +72 -41
- package/dist/virtual-list.d.ts +1 -0
- package/dist/virtual-list.js +25 -8
- package/dist/virtual-mouse.js +7 -6
- package/dist/watermark.js +2 -1
- package/package.json +82 -1
- package/themes/haiyue-dark.css +51 -0
- package/themes/haiyue-light.css +51 -0
package/dist/ribbon.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { hasSlotContent } from './internal/presentation.js';
|
|
2
|
+
/** Folded ribbon decorating content in the default slot. */
|
|
3
|
+
export class HYRibbon extends HTMLElement {
|
|
4
|
+
_ribbon = document.createElement('div');
|
|
5
|
+
_text = document.createElement('slot');
|
|
6
|
+
_fallback = document.createTextNode('');
|
|
7
|
+
static get observedAttributes() {
|
|
8
|
+
return ['text', 'color', 'placement'];
|
|
9
|
+
}
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
13
|
+
const style = document.createElement('style');
|
|
14
|
+
style.textContent = `
|
|
15
|
+
:host {
|
|
16
|
+
display: block;
|
|
17
|
+
min-width: 0;
|
|
18
|
+
color: var(--hy-text-color, #eef0ff);
|
|
19
|
+
font: var(--hy-font-size-sm, 12px)/var(--hy-line-height-relaxed, 1.5) var(--hy-font-family, system-ui, sans-serif);
|
|
20
|
+
}
|
|
21
|
+
:host([hidden]), [hidden] { display: none !important; }
|
|
22
|
+
.wrapper { position: relative; display: flow-root; min-width: 0; }
|
|
23
|
+
.ribbon {
|
|
24
|
+
position: absolute;
|
|
25
|
+
z-index: 1;
|
|
26
|
+
inset-block-start: var(--hy-ribbon-offset, var(--hy-space-6, 12px));
|
|
27
|
+
inset-inline-end: calc(-1 * var(--hy-ribbon-fold-size, var(--hy-space-4, 8px)));
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
box-sizing: border-box;
|
|
31
|
+
max-inline-size: calc(100% + 2 * var(--hy-ribbon-fold-size, var(--hy-space-4, 8px)));
|
|
32
|
+
min-block-size: var(--hy-ribbon-height, var(--hy-control-height-xs, 24px));
|
|
33
|
+
padding: var(--hy-ribbon-padding, var(--hy-space-2, 4px) var(--hy-space-6, 12px));
|
|
34
|
+
border-radius: var(--hy-ribbon-radius, var(--hy-radius-sm, 4px));
|
|
35
|
+
color: var(--hy-ribbon-text-color, var(--hy-on-accent-color, #fff));
|
|
36
|
+
background: var(--_hy-ribbon-color, var(--hy-ribbon-bg-color, var(--hy-accent-color, #8177f2)));
|
|
37
|
+
font-size: var(--hy-ribbon-font-size, var(--hy-font-size-sm, 12px));
|
|
38
|
+
}
|
|
39
|
+
.text { display: block; min-width: 0; overflow-wrap: anywhere; }
|
|
40
|
+
.fold {
|
|
41
|
+
position: absolute;
|
|
42
|
+
inset-block-start: 100%;
|
|
43
|
+
inset-inline-end: 0;
|
|
44
|
+
inline-size: var(--hy-ribbon-fold-size, var(--hy-space-4, 8px));
|
|
45
|
+
block-size: var(--hy-ribbon-fold-size, var(--hy-space-4, 8px));
|
|
46
|
+
background: color-mix(in srgb, var(--_hy-ribbon-color, var(--hy-ribbon-bg-color, var(--hy-accent-color, #8177f2))) 70%, #000);
|
|
47
|
+
clip-path: polygon(0 0, 100% 0, 0 100%);
|
|
48
|
+
pointer-events: none;
|
|
49
|
+
}
|
|
50
|
+
:host([placement="start"]) .ribbon {
|
|
51
|
+
inset-inline-start: calc(-1 * var(--hy-ribbon-fold-size, var(--hy-space-4, 8px)));
|
|
52
|
+
inset-inline-end: auto;
|
|
53
|
+
}
|
|
54
|
+
:host([placement="start"]) .fold { inset-inline-start: 0; inset-inline-end: auto; transform: scaleX(-1); }
|
|
55
|
+
:host(:dir(rtl)) .fold { transform: scaleX(-1); }
|
|
56
|
+
:host([placement="start"]:dir(rtl)) .fold { transform: none; }
|
|
57
|
+
`;
|
|
58
|
+
const wrapper = document.createElement('div');
|
|
59
|
+
wrapper.className = 'wrapper';
|
|
60
|
+
wrapper.part.add('wrapper');
|
|
61
|
+
const content = document.createElement('div');
|
|
62
|
+
content.part.add('content');
|
|
63
|
+
content.append(document.createElement('slot'));
|
|
64
|
+
this._ribbon.className = 'ribbon';
|
|
65
|
+
this._ribbon.part.add('ribbon');
|
|
66
|
+
this._text.name = 'text';
|
|
67
|
+
this._text.className = 'text';
|
|
68
|
+
this._text.part.add('text');
|
|
69
|
+
this._text.append(this._fallback);
|
|
70
|
+
const fold = document.createElement('span');
|
|
71
|
+
fold.className = 'fold';
|
|
72
|
+
fold.part.add('fold');
|
|
73
|
+
fold.setAttribute('aria-hidden', 'true');
|
|
74
|
+
this._ribbon.append(this._text, fold);
|
|
75
|
+
wrapper.append(content, this._ribbon);
|
|
76
|
+
root.append(style, wrapper);
|
|
77
|
+
this._text.addEventListener('slotchange', this._render);
|
|
78
|
+
}
|
|
79
|
+
connectedCallback() { this._render(); }
|
|
80
|
+
attributeChangedCallback() { this._render(); }
|
|
81
|
+
get text() { return this.getAttribute('text') ?? ''; }
|
|
82
|
+
set text(value) { this.setAttribute('text', value); }
|
|
83
|
+
get color() { return this.getAttribute('color')?.trim() ?? ''; }
|
|
84
|
+
set color(value) {
|
|
85
|
+
if (value.trim())
|
|
86
|
+
this.setAttribute('color', value.trim());
|
|
87
|
+
else
|
|
88
|
+
this.removeAttribute('color');
|
|
89
|
+
}
|
|
90
|
+
get placement() { return this.getAttribute('placement') === 'start' ? 'start' : 'end'; }
|
|
91
|
+
set placement(value) { this.setAttribute('placement', value === 'start' ? 'start' : 'end'); }
|
|
92
|
+
_render = () => {
|
|
93
|
+
if (this._fallback.textContent !== this.text)
|
|
94
|
+
this._fallback.textContent = this.text;
|
|
95
|
+
this._ribbon.hidden = !this.text.trim() && !hasSlotContent(this._text);
|
|
96
|
+
if (this.color && CSS.supports('color', this.color))
|
|
97
|
+
this._ribbon.style.setProperty('--_hy-ribbon-color', this.color);
|
|
98
|
+
else
|
|
99
|
+
this._ribbon.style.removeProperty('--_hy-ribbon-color');
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export function defineRibbonComponents() {
|
|
103
|
+
if (!customElements.get('hy-ribbon'))
|
|
104
|
+
customElements.define('hy-ribbon', HYRibbon);
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=ribbon.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type HYSegmentedSize = 'small' | 'medium' | 'large';
|
|
2
|
+
export interface HYSegmentedOption {
|
|
3
|
+
readonly label: string;
|
|
4
|
+
readonly value: string;
|
|
5
|
+
readonly icon?: string;
|
|
6
|
+
readonly disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type HYSegmentedOptionInput = HYSegmentedOption | string | number;
|
|
9
|
+
export interface HYSegmentedChangeDetail {
|
|
10
|
+
readonly value: string;
|
|
11
|
+
readonly option: HYSegmentedOption | null;
|
|
12
|
+
}
|
|
13
|
+
/** A compact single-choice control with roving keyboard focus. */
|
|
14
|
+
export declare class HYSegmented extends HTMLElement {
|
|
15
|
+
private readonly _group;
|
|
16
|
+
private _options;
|
|
17
|
+
private _pendingFocus;
|
|
18
|
+
static get observedAttributes(): string[];
|
|
19
|
+
constructor();
|
|
20
|
+
connectedCallback(): void;
|
|
21
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
22
|
+
get options(): HYSegmentedOption[];
|
|
23
|
+
set options(value: readonly HYSegmentedOptionInput[]);
|
|
24
|
+
get value(): string;
|
|
25
|
+
set value(value: string);
|
|
26
|
+
get size(): HYSegmentedSize;
|
|
27
|
+
set size(value: HYSegmentedSize);
|
|
28
|
+
get block(): boolean;
|
|
29
|
+
set block(value: boolean);
|
|
30
|
+
get disabled(): boolean;
|
|
31
|
+
set disabled(value: boolean);
|
|
32
|
+
select(value: string): boolean;
|
|
33
|
+
private _readOptionsAttribute;
|
|
34
|
+
private _normalizeValue;
|
|
35
|
+
private _render;
|
|
36
|
+
private _onKeyDown;
|
|
37
|
+
private _focus;
|
|
38
|
+
}
|
|
39
|
+
export declare function defineSegmentedComponents(): void;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/** A compact single-choice control with roving keyboard focus. */
|
|
2
|
+
export class HYSegmented extends HTMLElement {
|
|
3
|
+
_group = document.createElement('div');
|
|
4
|
+
_options = [];
|
|
5
|
+
_pendingFocus = null;
|
|
6
|
+
static get observedAttributes() {
|
|
7
|
+
return ['options', 'value', 'size', 'block', 'disabled', 'aria-label'];
|
|
8
|
+
}
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
12
|
+
const style = document.createElement('style');
|
|
13
|
+
style.textContent = `
|
|
14
|
+
:host { display: inline-block; max-width: 100%; color: var(--hy-text-color, #d8e2f2); font: var(--hy-font-size-sm, 12px) var(--hy-font-family, system-ui, sans-serif); }
|
|
15
|
+
:host([block]) { display: block; width: 100%; }
|
|
16
|
+
.group { display: inline-flex; box-sizing: border-box; max-width: 100%; gap: var(--hy-space-1, 2px); padding: calc(var(--hy-space-1, 2px) + 1px); border: 1px solid var(--hy-segmented-border-color, transparent); border-radius: var(--hy-segmented-radius, calc(var(--hy-radius-md, 6px) + 1px)); background: var(--hy-segmented-bg-color, var(--hy-input-bg-color, #121822)); }
|
|
17
|
+
:host([block]) .group { display: flex; width: 100%; }
|
|
18
|
+
button { display: inline-flex; min-width: 0; height: var(--hy-control-height-sm, 28px); align-items: center; justify-content: center; gap: var(--hy-space-3, 6px); padding: 0 var(--hy-space-6, 12px); border: 0; border-radius: calc(var(--hy-segmented-radius, calc(var(--hy-radius-md, 6px) + 1px)) - 2px); color: var(--hy-segmented-text-color, var(--hy-secondary-text-color, #8fa7c8)); background: transparent; font: inherit; white-space: nowrap; cursor: pointer; transition: color 120ms ease, background 120ms ease, box-shadow 120ms ease; }
|
|
19
|
+
:host([block]) button { flex: 1 1 0; }
|
|
20
|
+
:host([size="small"]) button { height: calc(var(--hy-control-height-xs, 24px) - 2px); padding-inline: var(--hy-space-4, 8px); font-size: calc(var(--hy-font-size-xs, 10px) + 1px); }
|
|
21
|
+
:host([size="large"]) button { height: var(--hy-control-height-md, 34px); padding-inline: var(--hy-space-8, 16px); font-size: calc(var(--hy-font-size-sm, 12px) + 1px); }
|
|
22
|
+
button:hover:not(:disabled):not(.selected) { color: var(--hy-text-color, #d8e2f2); background: var(--hy-hover-bg-color, #222b3a); }
|
|
23
|
+
button.selected { color: var(--hy-segmented-selected-text-color, var(--hy-active-text-color, #eef3ff)); background: var(--hy-segmented-selected-bg-color, var(--hy-surface-elevated-color, #1b2230)); box-shadow: var(--hy-segmented-selected-shadow, 0 1px 3px var(--hy-shadow-color, rgba(0, 0, 0, 0.24))); }
|
|
24
|
+
button:focus-visible { outline: 2px solid var(--hy-focus-border-color, #3d6fa8); outline-offset: 1px; }
|
|
25
|
+
button:disabled { opacity: 0.42; cursor: default; }
|
|
26
|
+
.icon { flex: none; line-height: var(--hy-line-height-tight, 1); }
|
|
27
|
+
.label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
28
|
+
@media (prefers-reduced-motion: reduce) { button { transition: none; } }
|
|
29
|
+
`;
|
|
30
|
+
this._group.className = 'group';
|
|
31
|
+
this._group.part.add('group');
|
|
32
|
+
this._group.setAttribute('role', 'radiogroup');
|
|
33
|
+
root.append(style, this._group);
|
|
34
|
+
}
|
|
35
|
+
connectedCallback() {
|
|
36
|
+
if (this.hasAttribute('options'))
|
|
37
|
+
this._readOptionsAttribute();
|
|
38
|
+
this._normalizeValue();
|
|
39
|
+
this._render();
|
|
40
|
+
}
|
|
41
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
42
|
+
if (oldValue === newValue)
|
|
43
|
+
return;
|
|
44
|
+
if (name === 'options')
|
|
45
|
+
this._readOptionsAttribute();
|
|
46
|
+
if ((name === 'options' || name === 'value') && this.isConnected)
|
|
47
|
+
this._normalizeValue();
|
|
48
|
+
this._render();
|
|
49
|
+
}
|
|
50
|
+
get options() { return this._options; }
|
|
51
|
+
set options(value) {
|
|
52
|
+
this._options = Array.isArray(value) ? value.map(item => {
|
|
53
|
+
if (typeof item === 'string' || typeof item === 'number')
|
|
54
|
+
return { label: String(item), value: String(item) };
|
|
55
|
+
const normalized = {
|
|
56
|
+
label: String(item.label ?? item.value ?? ''),
|
|
57
|
+
value: String(item.value ?? item.label ?? ''),
|
|
58
|
+
disabled: Boolean(item.disabled),
|
|
59
|
+
};
|
|
60
|
+
return item.icon == null ? normalized : { ...normalized, icon: String(item.icon) };
|
|
61
|
+
}) : [];
|
|
62
|
+
this._normalizeValue();
|
|
63
|
+
this._render();
|
|
64
|
+
}
|
|
65
|
+
get value() { return this.getAttribute('value') ?? ''; }
|
|
66
|
+
set value(value) { if (value)
|
|
67
|
+
this.setAttribute('value', value);
|
|
68
|
+
else
|
|
69
|
+
this.removeAttribute('value'); }
|
|
70
|
+
get size() {
|
|
71
|
+
const value = this.getAttribute('size');
|
|
72
|
+
return value === 'small' || value === 'large' ? value : 'medium';
|
|
73
|
+
}
|
|
74
|
+
set size(value) { this.setAttribute('size', value); }
|
|
75
|
+
get block() { return this.hasAttribute('block'); }
|
|
76
|
+
set block(value) { this.toggleAttribute('block', Boolean(value)); }
|
|
77
|
+
get disabled() { return this.hasAttribute('disabled'); }
|
|
78
|
+
set disabled(value) { this.toggleAttribute('disabled', Boolean(value)); }
|
|
79
|
+
select(value) {
|
|
80
|
+
const option = this._options.find(item => item.value === value && !item.disabled) ?? null;
|
|
81
|
+
if (!option || this.disabled || value === this.value)
|
|
82
|
+
return false;
|
|
83
|
+
this.value = value;
|
|
84
|
+
this.dispatchEvent(new CustomEvent('value-change', {
|
|
85
|
+
detail: { value, option }, bubbles: true, composed: true,
|
|
86
|
+
}));
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
_readOptionsAttribute() {
|
|
90
|
+
const raw = this.getAttribute('options');
|
|
91
|
+
if (!raw) {
|
|
92
|
+
this._options = [];
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const parsed = JSON.parse(raw);
|
|
97
|
+
this._options = Array.isArray(parsed) ? parsed.map(item => {
|
|
98
|
+
if (typeof item === 'string' || typeof item === 'number')
|
|
99
|
+
return { label: String(item), value: String(item) };
|
|
100
|
+
const record = item && typeof item === 'object' ? item : {};
|
|
101
|
+
const normalized = {
|
|
102
|
+
label: String(record.label ?? record.value ?? ''), value: String(record.value ?? record.label ?? ''),
|
|
103
|
+
disabled: Boolean(record.disabled),
|
|
104
|
+
};
|
|
105
|
+
return record.icon == null ? normalized : { ...normalized, icon: String(record.icon) };
|
|
106
|
+
}) : [];
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.warn('Invalid hy-segmented options attribute.', error);
|
|
110
|
+
this._options = [];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
_normalizeValue() {
|
|
114
|
+
if (this._options.some(item => item.value === this.value && !item.disabled))
|
|
115
|
+
return;
|
|
116
|
+
const value = this._options.find(item => !item.disabled)?.value ?? '';
|
|
117
|
+
if (value === this.value)
|
|
118
|
+
return;
|
|
119
|
+
if (value)
|
|
120
|
+
this.setAttribute('value', value);
|
|
121
|
+
else
|
|
122
|
+
this.removeAttribute('value');
|
|
123
|
+
}
|
|
124
|
+
_render() {
|
|
125
|
+
if (!this._group)
|
|
126
|
+
return;
|
|
127
|
+
const focused = this._pendingFocus ?? [...this._group.querySelectorAll('button')]
|
|
128
|
+
.find(button => button === this.shadowRoot?.activeElement)?.dataset.value ?? null;
|
|
129
|
+
this._pendingFocus = null;
|
|
130
|
+
this._group.replaceChildren();
|
|
131
|
+
this._group.setAttribute('aria-label', this.getAttribute('aria-label') ?? 'Segmented control');
|
|
132
|
+
this._group.setAttribute('aria-disabled', String(this.disabled));
|
|
133
|
+
const enabled = this._options.filter(item => !item.disabled);
|
|
134
|
+
const tabValue = enabled.some(item => item.value === this.value) ? this.value : enabled[0]?.value;
|
|
135
|
+
for (const option of this._options) {
|
|
136
|
+
const button = document.createElement('button');
|
|
137
|
+
button.type = 'button';
|
|
138
|
+
button.part.add('item');
|
|
139
|
+
button.dataset.value = option.value;
|
|
140
|
+
button.setAttribute('role', 'radio');
|
|
141
|
+
button.setAttribute('aria-checked', String(option.value === this.value));
|
|
142
|
+
button.classList.toggle('selected', option.value === this.value);
|
|
143
|
+
button.disabled = this.disabled || Boolean(option.disabled);
|
|
144
|
+
button.tabIndex = !button.disabled && option.value === tabValue ? 0 : -1;
|
|
145
|
+
if (option.icon) {
|
|
146
|
+
const icon = document.createElement('span');
|
|
147
|
+
icon.className = 'icon';
|
|
148
|
+
icon.part.add('icon');
|
|
149
|
+
icon.textContent = option.icon;
|
|
150
|
+
button.append(icon);
|
|
151
|
+
}
|
|
152
|
+
const label = document.createElement('span');
|
|
153
|
+
label.className = 'label';
|
|
154
|
+
label.part.add('label');
|
|
155
|
+
label.textContent = option.label;
|
|
156
|
+
button.append(label);
|
|
157
|
+
button.addEventListener('click', () => this.select(option.value));
|
|
158
|
+
button.addEventListener('keydown', event => this._onKeyDown(event, option, enabled));
|
|
159
|
+
this._group.append(button);
|
|
160
|
+
}
|
|
161
|
+
if (focused)
|
|
162
|
+
queueMicrotask(() => this._focus(enabled.some(item => item.value === focused) ? focused : tabValue ?? ''));
|
|
163
|
+
}
|
|
164
|
+
_onKeyDown(event, option, enabled) {
|
|
165
|
+
if (!enabled.length || !['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End'].includes(event.key))
|
|
166
|
+
return;
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
const position = Math.max(0, enabled.findIndex(item => item.value === option.value));
|
|
169
|
+
const direction = getComputedStyle(this).direction === 'rtl' ? -1 : 1;
|
|
170
|
+
let next = position;
|
|
171
|
+
if (event.key === 'Home')
|
|
172
|
+
next = 0;
|
|
173
|
+
else if (event.key === 'End')
|
|
174
|
+
next = enabled.length - 1;
|
|
175
|
+
else {
|
|
176
|
+
const forward = event.key === 'ArrowRight' || event.key === 'ArrowDown';
|
|
177
|
+
const delta = (forward ? 1 : -1) * (event.key === 'ArrowLeft' || event.key === 'ArrowRight' ? direction : 1);
|
|
178
|
+
next = (position + delta + enabled.length) % enabled.length;
|
|
179
|
+
}
|
|
180
|
+
this._pendingFocus = enabled[next].value;
|
|
181
|
+
if (!this.select(enabled[next].value))
|
|
182
|
+
this._render();
|
|
183
|
+
}
|
|
184
|
+
_focus(value) {
|
|
185
|
+
[...this._group.querySelectorAll('button')].find(button => button.dataset.value === value)?.focus();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export function defineSegmentedComponents() {
|
|
189
|
+
if (!customElements.get('hy-segmented'))
|
|
190
|
+
customElements.define('hy-segmented', HYSegmented);
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=segmented.js.map
|
package/dist/select.d.ts
CHANGED
|
@@ -8,11 +8,13 @@ export interface HYSelectChangeDetail {
|
|
|
8
8
|
option: HYSelectOption | null;
|
|
9
9
|
}
|
|
10
10
|
export declare class HYSelect extends HTMLElement {
|
|
11
|
+
static readonly formAssociated = true;
|
|
11
12
|
private readonly _wrap;
|
|
12
13
|
private readonly _search;
|
|
13
14
|
private readonly _select;
|
|
14
15
|
private _options;
|
|
15
16
|
private _filterText;
|
|
17
|
+
private readonly _formControl;
|
|
16
18
|
static get observedAttributes(): string[];
|
|
17
19
|
constructor();
|
|
18
20
|
connectedCallback(): void;
|
|
@@ -32,6 +34,16 @@ export declare class HYSelect extends HTMLElement {
|
|
|
32
34
|
private _readOptionsAttribute;
|
|
33
35
|
private _render;
|
|
34
36
|
private _syncDisabled;
|
|
37
|
+
get form(): HTMLFormElement | null;
|
|
38
|
+
get validity(): ValidityState;
|
|
39
|
+
get validationMessage(): string;
|
|
40
|
+
checkValidity(): boolean;
|
|
41
|
+
reportValidity(): boolean;
|
|
42
|
+
setCustomValidity(message: string): void;
|
|
43
|
+
formDisabledCallback(disabled: boolean): void;
|
|
44
|
+
formResetCallback(): void;
|
|
45
|
+
formStateRestoreCallback(state: string | File | FormData | null): void;
|
|
46
|
+
focus(options?: FocusOptions): void;
|
|
35
47
|
private _syncAriaLabel;
|
|
36
48
|
private _matchesFilter;
|
|
37
49
|
private _onChange;
|
package/dist/select.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { HYFormControl } from './internal/form-control.js';
|
|
1
2
|
export class HYSelect extends HTMLElement {
|
|
3
|
+
static formAssociated = true;
|
|
2
4
|
_wrap = document.createElement('div');
|
|
3
5
|
_search = document.createElement('input');
|
|
4
6
|
_select = document.createElement('select');
|
|
5
7
|
_options = [];
|
|
6
8
|
_filterText = '';
|
|
9
|
+
_formControl = new HYFormControl(this, this._select);
|
|
7
10
|
static get observedAttributes() {
|
|
8
|
-
return ['options', 'value', 'disabled', 'searchable', 'aria-label', 'label'];
|
|
11
|
+
return ['options', 'value', 'disabled', 'searchable', 'aria-label', 'label', 'name', 'required'];
|
|
9
12
|
}
|
|
10
13
|
constructor() {
|
|
11
14
|
super();
|
|
@@ -19,7 +22,7 @@ export class HYSelect extends HTMLElement {
|
|
|
19
22
|
}
|
|
20
23
|
.wrap {
|
|
21
24
|
display: grid;
|
|
22
|
-
gap: 4px;
|
|
25
|
+
gap: var(--hy-space-2, 4px);
|
|
23
26
|
width: 100%;
|
|
24
27
|
min-width: 0;
|
|
25
28
|
}
|
|
@@ -27,14 +30,14 @@ export class HYSelect extends HTMLElement {
|
|
|
27
30
|
select {
|
|
28
31
|
box-sizing: border-box;
|
|
29
32
|
width: 100%;
|
|
30
|
-
height: 28px;
|
|
33
|
+
height: var(--hy-control-height-sm, 28px);
|
|
31
34
|
min-width: 0;
|
|
32
|
-
padding: 0
|
|
35
|
+
padding: 0 calc(var(--hy-space-12, 24px) + 4px) 0 var(--hy-space-4, 8px);
|
|
33
36
|
border: 1px solid var(--hy-border-color, #303746);
|
|
34
|
-
border-radius: 4px;
|
|
37
|
+
border-radius: var(--hy-radius-sm, 4px);
|
|
35
38
|
color: var(--hy-text-color, #d8e2f2);
|
|
36
39
|
background-color: var(--hy-input-bg-color, var(--hy-surface-color, #121822));
|
|
37
|
-
font: 12px system-ui, sans-serif;
|
|
40
|
+
font: var(--hy-font-size-sm, 12px) var(--hy-font-family, system-ui, sans-serif);
|
|
38
41
|
outline: none;
|
|
39
42
|
color-scheme: inherit;
|
|
40
43
|
}
|
|
@@ -45,8 +48,8 @@ export class HYSelect extends HTMLElement {
|
|
|
45
48
|
linear-gradient(45deg, transparent 50%, var(--hy-select-arrow-color, var(--hy-secondary-text-color, #8fa7c8)) 50%),
|
|
46
49
|
linear-gradient(135deg, var(--hy-select-arrow-color, var(--hy-secondary-text-color, #8fa7c8)) 50%, transparent 50%);
|
|
47
50
|
background-position:
|
|
48
|
-
calc(100% -
|
|
49
|
-
calc(100% - 10px)
|
|
51
|
+
calc(100% - var(--hy-space-5, 10px) - 5px) center,
|
|
52
|
+
calc(100% - var(--hy-space-5, 10px)) center;
|
|
50
53
|
background-size: 5px 5px, 5px 5px;
|
|
51
54
|
background-repeat: no-repeat;
|
|
52
55
|
}
|
|
@@ -55,11 +58,11 @@ export class HYSelect extends HTMLElement {
|
|
|
55
58
|
background-color: var(--hy-select-hover-bg-color, var(--hy-input-bg-color, #151d2a));
|
|
56
59
|
}
|
|
57
60
|
option {
|
|
58
|
-
min-height: 28px;
|
|
59
|
-
padding: 6px 8px;
|
|
61
|
+
min-height: var(--hy-control-height-sm, 28px);
|
|
62
|
+
padding: var(--hy-space-3, 6px) var(--hy-space-4, 8px);
|
|
60
63
|
color: var(--hy-select-option-text-color, var(--hy-text-color, #d8e2f2));
|
|
61
64
|
background: var(--hy-select-option-bg-color, var(--hy-menu-bg-color, #1b2230));
|
|
62
|
-
font: 12px system-ui, sans-serif;
|
|
65
|
+
font: var(--hy-font-size-sm, 12px) var(--hy-font-family, system-ui, sans-serif);
|
|
63
66
|
}
|
|
64
67
|
option:checked {
|
|
65
68
|
color: var(--hy-select-option-selected-text-color, var(--hy-selected-text-color, #ffffff));
|
|
@@ -98,6 +101,7 @@ export class HYSelect extends HTMLElement {
|
|
|
98
101
|
this._search.addEventListener('input', this._onSearchInput);
|
|
99
102
|
this._syncFromAttributes();
|
|
100
103
|
this._render();
|
|
104
|
+
this._formControl.connect();
|
|
101
105
|
}
|
|
102
106
|
disconnectedCallback() {
|
|
103
107
|
this._select.removeEventListener('change', this._onChange);
|
|
@@ -116,6 +120,8 @@ export class HYSelect extends HTMLElement {
|
|
|
116
120
|
this._syncAriaLabel();
|
|
117
121
|
if (name === 'options' || name === 'searchable')
|
|
118
122
|
this._render();
|
|
123
|
+
this._select.required = this.hasAttribute('required');
|
|
124
|
+
this._formControl.sync();
|
|
119
125
|
}
|
|
120
126
|
get options() {
|
|
121
127
|
return this._options;
|
|
@@ -203,9 +209,21 @@ export class HYSelect extends HTMLElement {
|
|
|
203
209
|
this._syncDisabled();
|
|
204
210
|
}
|
|
205
211
|
_syncDisabled() {
|
|
206
|
-
this._select.disabled = this.disabled;
|
|
207
|
-
this._search.disabled = this.disabled;
|
|
212
|
+
this._select.disabled = this.disabled || this._formControl.disabled;
|
|
213
|
+
this._search.disabled = this.disabled || this._formControl.disabled;
|
|
214
|
+
this._select.required = this.hasAttribute('required');
|
|
215
|
+
this._formControl.sync();
|
|
208
216
|
}
|
|
217
|
+
get form() { return this._formControl.internals.form; }
|
|
218
|
+
get validity() { return this._formControl.internals.validity; }
|
|
219
|
+
get validationMessage() { return this._formControl.internals.validationMessage; }
|
|
220
|
+
checkValidity() { return this._formControl.internals.checkValidity(); }
|
|
221
|
+
reportValidity() { return this._formControl.internals.reportValidity(); }
|
|
222
|
+
setCustomValidity(message) { this._formControl.setCustomValidity(message); }
|
|
223
|
+
formDisabledCallback(disabled) { this._formControl.disabled = disabled; this._syncDisabled(); }
|
|
224
|
+
formResetCallback() { this._formControl.reset(); }
|
|
225
|
+
formStateRestoreCallback(state) { this._formControl.restore(state); }
|
|
226
|
+
focus(options) { (this.searchable ? this._search : this._select).focus(options); }
|
|
209
227
|
_syncAriaLabel() {
|
|
210
228
|
const label = this.getAttribute('aria-label') ?? this.getAttribute('label') ?? '';
|
|
211
229
|
if (label) {
|
package/dist/skeleton.js
CHANGED
|
@@ -20,19 +20,19 @@ export class HYSkeleton extends HTMLElement {
|
|
|
20
20
|
const root = this.attachShadow({ mode: 'open' });
|
|
21
21
|
const style = document.createElement('style');
|
|
22
22
|
style.textContent = `
|
|
23
|
-
:host { display: block; min-width: 0; font: 12px/1.4 system-ui, sans-serif; }
|
|
24
|
-
.placeholder { display: flex; min-width: 0; align-items: flex-start; gap: var(--hy-skeleton-gap, 14px); }
|
|
23
|
+
:host { display: block; min-width: 0; font: var(--hy-font-size-sm, 12px)/var(--hy-line-height-snug, 1.4) var(--hy-font-family, system-ui, sans-serif); }
|
|
24
|
+
.placeholder { display: flex; min-width: 0; align-items: flex-start; gap: var(--hy-skeleton-gap, var(--hy-space-7, 14px)); }
|
|
25
25
|
.placeholder[hidden], .content[hidden] { display: none; }
|
|
26
|
-
.body { flex: 1; min-width: 0; padding-top: var(--hy-skeleton-body-offset, 2px); }
|
|
26
|
+
.body { flex: 1; min-width: 0; padding-top: var(--hy-skeleton-body-offset, var(--hy-space-1, 2px)); }
|
|
27
27
|
.block { position: relative; overflow: hidden; background: var(--hy-skeleton-color, color-mix(in srgb, var(--hy-text-color, #eef3ff) 11%, transparent)); }
|
|
28
28
|
.avatar { flex: 0 0 auto; width: var(--_avatar-size); height: var(--_avatar-size); border-radius: 50%; }
|
|
29
|
-
:host([avatar-shape="square"]) .avatar { border-radius: var(--hy-skeleton-avatar-radius,
|
|
30
|
-
.title { height: var(--hy-skeleton-title-height, 15px); margin-bottom: var(--hy-skeleton-title-gap,
|
|
31
|
-
.paragraph { display: grid; gap: var(--hy-skeleton-row-gap,
|
|
32
|
-
.row { height: var(--hy-skeleton-row-height, 11px); border-radius: var(--hy-skeleton-radius,
|
|
33
|
-
:host([round]) .title, :host([round]) .row { border-radius: 999px; }
|
|
34
|
-
:host([size="small"]) { --hy-skeleton-title-height: 12px; --hy-skeleton-row-height: 8px; --hy-skeleton-row-gap:
|
|
35
|
-
:host([size="large"]) { --hy-skeleton-title-height: 18px; --hy-skeleton-row-height: 14px; --hy-skeleton-row-gap:
|
|
29
|
+
:host([avatar-shape="square"]) .avatar { border-radius: var(--hy-skeleton-avatar-radius, calc(var(--hy-radius-md, 6px) + 1px)); }
|
|
30
|
+
.title { height: var(--hy-skeleton-title-height, 15px); margin-bottom: var(--hy-skeleton-title-gap, calc(var(--hy-space-8, 16px) + 1px)); border-radius: var(--hy-skeleton-radius, calc(var(--hy-radius-sm, 4px) + 1px)); }
|
|
31
|
+
.paragraph { display: grid; gap: var(--hy-skeleton-row-gap, calc(var(--hy-space-5, 10px) + 1px)); }
|
|
32
|
+
.row { height: var(--hy-skeleton-row-height, 11px); border-radius: var(--hy-skeleton-radius, calc(var(--hy-radius-sm, 4px) + 1px)); }
|
|
33
|
+
:host([round]) .title, :host([round]) .row { border-radius: var(--hy-radius-full, 999px); }
|
|
34
|
+
:host([size="small"]) { --hy-skeleton-title-height: 12px; --hy-skeleton-row-height: 8px; --hy-skeleton-row-gap: calc(var(--hy-space-4, 8px) + 1px); --hy-skeleton-gap: calc(var(--hy-space-5, 10px) + 1px); }
|
|
35
|
+
:host([size="large"]) { --hy-skeleton-title-height: 18px; --hy-skeleton-row-height: 14px; --hy-skeleton-row-gap: calc(var(--hy-space-6, 12px) + 1px); --hy-skeleton-gap: calc(var(--hy-space-8, 16px) + 1px); }
|
|
36
36
|
:host([active]) .block::after { position: absolute; inset: 0; background: linear-gradient(90deg, transparent 0%, var(--hy-skeleton-highlight-color, color-mix(in srgb, var(--hy-text-color, #eef3ff) 12%, transparent)) 45%, transparent 85%); content: ''; transform: translateX(-100%); animation: hy-skeleton-wave var(--hy-skeleton-duration, 1.5s) ease-in-out infinite; }
|
|
37
37
|
@keyframes hy-skeleton-wave { to { transform: translateX(100%); } }
|
|
38
38
|
@media (prefers-reduced-motion: reduce) { :host([active]) .block::after { animation: none; } }
|
package/dist/spin.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type HYSpinSize = 'small' | 'default' | 'large';
|
|
2
|
+
export declare class HYSpin extends HTMLElement {
|
|
3
|
+
private readonly _content;
|
|
4
|
+
private readonly _slot;
|
|
5
|
+
private readonly _indicator;
|
|
6
|
+
private readonly _tip;
|
|
7
|
+
private _timer;
|
|
8
|
+
private _visible;
|
|
9
|
+
static get observedAttributes(): string[];
|
|
10
|
+
constructor();
|
|
11
|
+
connectedCallback(): void;
|
|
12
|
+
disconnectedCallback(): void;
|
|
13
|
+
attributeChangedCallback(name: string, previous: string | null, next: string | null): void;
|
|
14
|
+
get spinning(): boolean;
|
|
15
|
+
set spinning(value: boolean);
|
|
16
|
+
get delay(): number;
|
|
17
|
+
set delay(value: number);
|
|
18
|
+
get tip(): string;
|
|
19
|
+
set tip(value: string);
|
|
20
|
+
get size(): HYSpinSize;
|
|
21
|
+
set size(value: HYSpinSize);
|
|
22
|
+
private _schedule;
|
|
23
|
+
private _clearTimer;
|
|
24
|
+
private _render;
|
|
25
|
+
}
|
|
26
|
+
export declare function defineSpinComponents(): void;
|
package/dist/spin.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export class HYSpin extends HTMLElement {
|
|
2
|
+
_content = document.createElement('div');
|
|
3
|
+
_slot = document.createElement('slot');
|
|
4
|
+
_indicator = document.createElement('div');
|
|
5
|
+
_tip = document.createElement('span');
|
|
6
|
+
_timer = null;
|
|
7
|
+
_visible = false;
|
|
8
|
+
static get observedAttributes() { return ['spinning', 'delay', 'tip', 'size', 'aria-label']; }
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
12
|
+
const style = document.createElement('style');
|
|
13
|
+
style.textContent = `
|
|
14
|
+
:host { position: relative; display: inline-block; min-width: 0; color: var(--hy-text-color, #d8e2f2); font: var(--hy-font-size-sm, 12px)/1.5 var(--hy-font-family, system-ui, sans-serif); }
|
|
15
|
+
:host(.has-content) { display: block; } .content.busy { opacity: .45; }
|
|
16
|
+
.indicator { display: inline-flex; flex-direction: column; justify-content: center; align-items: center; gap: var(--hy-space-4, 8px); color: var(--hy-accent-color, #8177f2); }
|
|
17
|
+
:host(.has-content) .indicator { position: absolute; inset: 0; z-index: 1; background: var(--hy-spin-mask-color, transparent); }
|
|
18
|
+
.spinner { width: var(--hy-spin-size, 24px); height: var(--hy-spin-size, 24px); box-sizing: border-box; border: 3px solid color-mix(in srgb, currentColor 22%, transparent); border-top-color: currentColor; border-radius: 50%; animation: hy-spin 0.8s linear infinite; }
|
|
19
|
+
:host([size="small"]) .spinner { width: 16px; height: 16px; border-width: 2px; } :host([size="large"]) .spinner { width: 36px; height: 36px; border-width: 4px; }
|
|
20
|
+
[hidden] { display: none !important; } @keyframes hy-spin { to { transform: rotate(360deg); } }
|
|
21
|
+
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
|
|
22
|
+
`;
|
|
23
|
+
this._content.className = 'content';
|
|
24
|
+
this._content.part.add('content');
|
|
25
|
+
this._content.append(this._slot);
|
|
26
|
+
this._indicator.className = 'indicator';
|
|
27
|
+
this._indicator.part.add('indicator');
|
|
28
|
+
this._indicator.setAttribute('role', 'status');
|
|
29
|
+
const spinner = document.createElement('span');
|
|
30
|
+
spinner.className = 'spinner';
|
|
31
|
+
spinner.part.add('spinner');
|
|
32
|
+
spinner.setAttribute('aria-hidden', 'true');
|
|
33
|
+
this._tip.part.add('tip');
|
|
34
|
+
this._indicator.append(spinner, this._tip);
|
|
35
|
+
this._indicator.hidden = true;
|
|
36
|
+
root.append(style, this._content, this._indicator);
|
|
37
|
+
}
|
|
38
|
+
connectedCallback() { this._slot.addEventListener('slotchange', this._render); this._schedule(); }
|
|
39
|
+
disconnectedCallback() { this._clearTimer(); this._slot.removeEventListener('slotchange', this._render); this._visible = false; this._content.inert = false; }
|
|
40
|
+
attributeChangedCallback(name, previous, next) { if (previous !== next) {
|
|
41
|
+
if (name === 'spinning' || name === 'delay')
|
|
42
|
+
this._schedule();
|
|
43
|
+
else
|
|
44
|
+
this._render();
|
|
45
|
+
} }
|
|
46
|
+
get spinning() { return this.getAttribute('spinning') !== 'false'; }
|
|
47
|
+
set spinning(value) { this.setAttribute('spinning', String(value)); }
|
|
48
|
+
get delay() { const value = Number(this.getAttribute('delay')); return Number.isFinite(value) ? Math.max(0, Math.min(value, 60000)) : 0; }
|
|
49
|
+
set delay(value) { this.setAttribute('delay', String(value)); }
|
|
50
|
+
get tip() { return this.getAttribute('tip') ?? ''; }
|
|
51
|
+
set tip(value) { this.setAttribute('tip', value); }
|
|
52
|
+
get size() { const value = this.getAttribute('size'); return value === 'small' || value === 'large' ? value : 'default'; }
|
|
53
|
+
set size(value) { this.setAttribute('size', value); }
|
|
54
|
+
_schedule() {
|
|
55
|
+
this._clearTimer();
|
|
56
|
+
if (!this.isConnected)
|
|
57
|
+
return;
|
|
58
|
+
this._visible = this.spinning && this.delay === 0;
|
|
59
|
+
if (this.spinning && this.delay > 0)
|
|
60
|
+
this._timer = setTimeout(() => { this._timer = null; this._visible = this.spinning; this._render(); }, this.delay);
|
|
61
|
+
this._render();
|
|
62
|
+
}
|
|
63
|
+
_clearTimer() { if (this._timer !== null)
|
|
64
|
+
clearTimeout(this._timer); this._timer = null; }
|
|
65
|
+
_render = () => {
|
|
66
|
+
const hasContent = this._slot.assignedNodes().some(node => node.nodeType === Node.ELEMENT_NODE || Boolean(node.textContent?.trim()));
|
|
67
|
+
if (this.isConnected)
|
|
68
|
+
this.classList.toggle('has-content', hasContent);
|
|
69
|
+
this._content.inert = this.spinning;
|
|
70
|
+
this._content.setAttribute('aria-busy', String(this.spinning));
|
|
71
|
+
this._content.classList.toggle('busy', this._visible);
|
|
72
|
+
this._indicator.hidden = !this._visible;
|
|
73
|
+
this._indicator.setAttribute('aria-label', this.getAttribute('aria-label') || this.tip || 'Loading');
|
|
74
|
+
this._tip.textContent = this.tip;
|
|
75
|
+
this._tip.hidden = !this.tip;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export function defineSpinComponents() { if (!customElements.get('hy-spin'))
|
|
79
|
+
customElements.define('hy-spin', HYSpin); }
|
|
80
|
+
//# sourceMappingURL=spin.js.map
|