@haiyue/ui 0.2.1 → 0.3.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/CHANGELOG.md +46 -0
- package/LICENSE +27 -0
- package/README.md +707 -5
- package/dist/adapters/web/controls.js +28 -5
- package/dist/adapters/web/renderer.js +11 -10
- package/dist/adapters/web/styles.d.ts +2 -3
- package/dist/adapters/web/styles.js +42 -18
- package/dist/alert.d.ts +39 -0
- package/dist/alert.js +144 -0
- package/dist/anchor.d.ts +60 -0
- package/dist/anchor.js +274 -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 +1 -1
- 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.d.ts +92 -0
- package/dist/carousel.js +509 -0
- package/dist/cascader.js +12 -12
- package/dist/checkbox.d.ts +12 -0
- package/dist/checkbox.js +22 -6
- package/dist/collapse.d.ts +13 -0
- package/dist/collapse.js +100 -13
- package/dist/context-menu.js +3 -3
- package/dist/core/types.d.ts +22 -3
- package/dist/core/validation.js +9 -4
- package/dist/date-picker.js +13 -13
- package/dist/descriptions.d.ts +44 -0
- package/dist/descriptions.js +169 -0
- package/dist/dialog.js +11 -11
- package/dist/divider.js +2 -2
- package/dist/draggable.js +1 -1
- package/dist/drawer.js +12 -12
- package/dist/dropdown.js +3 -3
- 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 +56 -0
- package/dist/index.js +84 -0
- package/dist/input.d.ts +11 -0
- package/dist/input.js +29 -15
- package/dist/internal/anchored-popup.d.ts +19 -0
- package/dist/internal/anchored-popup.js +89 -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/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/internal/qrcodegen.d.ts +94 -0
- package/dist/internal/qrcodegen.js +856 -0
- package/dist/masonry.d.ts +36 -0
- package/dist/masonry.js +171 -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.d.ts +73 -0
- package/dist/modal.js +361 -0
- package/dist/notification.js +9 -9
- 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/icons.d.ts +5 -0
- package/dist/portable/icons.js +24 -0
- package/dist/portable/index.d.ts +3 -0
- package/dist/portable/index.js +2 -0
- package/dist/portable/responsive.d.ts +20 -0
- package/dist/portable/responsive.js +15 -0
- package/dist/portable/theme.d.ts +6 -1
- package/dist/portable/theme.js +23 -3
- package/dist/progress.d.ts +30 -0
- package/dist/progress.js +102 -0
- package/dist/qr-code.d.ts +62 -0
- package/dist/qr-code.js +224 -0
- 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 +4 -4
- 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 +0 -2
- package/dist/table.js +46 -87
- package/dist/tabs.js +7 -7
- package/dist/tag.js +8 -8
- package/dist/time-picker.js +10 -10
- package/dist/timeline.js +12 -12
- package/dist/toast.js +9 -9
- package/dist/tooltip.js +4 -4
- package/dist/tour.js +11 -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.js +6 -5
- package/dist/upload.d.ts +107 -0
- package/dist/upload.js +353 -0
- package/dist/virtual-keyboard.js +5 -5
- package/dist/virtual-list.js +4 -4
- package/dist/virtual-mouse.js +5 -5
- package/package.json +99 -1
- package/themes/haiyue-dark.css +51 -0
- package/themes/haiyue-light.css +51 -0
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
|
package/dist/steps.js
CHANGED
|
@@ -37,24 +37,24 @@ export class HYSteps extends HTMLElement {
|
|
|
37
37
|
const root = this.attachShadow({ mode: 'open' });
|
|
38
38
|
const style = document.createElement('style');
|
|
39
39
|
style.textContent = `
|
|
40
|
-
:host { display: block; min-width: 0; color: var(--hy-text-color, #eef3ff); font: 12px/1.
|
|
40
|
+
:host { display: block; min-width: 0; color: var(--hy-text-color, #eef3ff); font: var(--hy-font-size-sm, 12px)/calc(var(--hy-line-height-snug, 1.4) + 0.05) var(--hy-font-family, system-ui, sans-serif); }
|
|
41
41
|
.steps { display: flex; width: 100%; margin: 0; padding: 0; list-style: none; }
|
|
42
42
|
.item { position: relative; flex: 1 1 0; min-width: 0; text-align: center; }
|
|
43
|
-
.step { display: flex; width: 100%; min-width: 0; flex-direction: column; align-items: center; padding: 0 10px; border: 0; color: inherit; background: transparent; font: inherit; text-align: center; }
|
|
43
|
+
.step { display: flex; width: 100%; min-width: 0; flex-direction: column; align-items: center; padding: 0 var(--hy-space-5, 10px); border: 0; color: inherit; background: transparent; font: inherit; text-align: center; }
|
|
44
44
|
button.step { cursor: pointer; }
|
|
45
45
|
button.step:hover .icon { transform: scale(1.08); }
|
|
46
46
|
button.step:focus-visible { outline: none; }
|
|
47
47
|
button.step:focus-visible .icon { box-shadow: 0 0 0 3px var(--hy-focus-ring-color, rgba(121, 168, 255, .22)); }
|
|
48
48
|
button.step:disabled { cursor: not-allowed; opacity: .45; }
|
|
49
49
|
.head { position: relative; z-index: 1; display: grid; place-items: center; }
|
|
50
|
-
.icon { display: grid; width: var(--hy-steps-icon-size, 30px); height: var(--hy-steps-icon-size, 30px); box-sizing: border-box; place-items: center; border: 1px solid var(--_step-color, var(--hy-muted-color, #788697)); border-radius: 50%; color: var(--_step-color, var(--hy-muted-color, #788697)); background: var(--hy-surface-color, #111722); font-weight:
|
|
50
|
+
.icon { display: grid; width: var(--hy-steps-icon-size, 30px); height: var(--hy-steps-icon-size, 30px); box-sizing: border-box; place-items: center; border: 1px solid var(--_step-color, var(--hy-muted-color, #788697)); border-radius: 50%; color: var(--_step-color, var(--hy-muted-color, #788697)); background: var(--hy-surface-color, #111722); font-weight: calc(var(--hy-font-weight-semibold, 600) + 50); transition: transform 120ms ease, box-shadow 120ms ease; }
|
|
51
51
|
.tail { position: absolute; z-index: 0; top: calc(var(--hy-steps-icon-size, 30px) / 2); right: calc(-50% + var(--hy-steps-icon-size, 30px) / 2 + 10px); left: calc(50% + var(--hy-steps-icon-size, 30px) / 2 + 10px); height: var(--hy-steps-line-width, 1px); background: var(--hy-steps-line-color, var(--hy-border-color, #3d4654)); }
|
|
52
52
|
.item:last-child .tail { display: none; }
|
|
53
|
-
.body { min-width: 0; margin-top:
|
|
54
|
-
.title-row { display: flex; min-width: 0; justify-content: center; gap: 6px; }
|
|
55
|
-
.title { overflow: hidden; color: var(--hy-secondary-text-color, #aebbd0); font-weight:
|
|
56
|
-
.subtitle { flex: 0 0 auto; color: var(--hy-muted-color, #788697); font-size: 10px; }
|
|
57
|
-
.description { max-width: 30ch; margin: 4px auto 0; color: var(--hy-muted-color, #788697); font-size:
|
|
53
|
+
.body { min-width: 0; margin-top: calc(var(--hy-space-4, 8px) + 1px); }
|
|
54
|
+
.title-row { display: flex; min-width: 0; justify-content: center; gap: var(--hy-space-3, 6px); }
|
|
55
|
+
.title { overflow: hidden; color: var(--hy-secondary-text-color, #aebbd0); font-weight: calc(var(--hy-font-weight-semibold, 600) + 50); text-overflow: ellipsis; white-space: nowrap; }
|
|
56
|
+
.subtitle { flex: 0 0 auto; color: var(--hy-muted-color, #788697); font-size: var(--hy-font-size-xs, 10px); }
|
|
57
|
+
.description { max-width: 30ch; margin: var(--hy-space-2, 4px) auto 0; color: var(--hy-muted-color, #788697); font-size: calc(var(--hy-font-size-xs, 10px) + 1px); }
|
|
58
58
|
.status-finish { --_step-color: var(--hy-success-color, #4ade80); }
|
|
59
59
|
.status-process { --_step-color: var(--hy-accent-color, #79a8ff); }
|
|
60
60
|
.status-error { --_step-color: var(--hy-error-color, #fb7185); }
|
|
@@ -63,15 +63,15 @@ export class HYSteps extends HTMLElement {
|
|
|
63
63
|
.status-error .icon { color: var(--hy-selected-text-color, #fff); background: var(--_step-color); }
|
|
64
64
|
.status-process .title, .status-finish .title, .status-error .title { color: var(--hy-text-color, #eef3ff); }
|
|
65
65
|
:host([size="small"]) { --hy-steps-icon-size: 22px; }
|
|
66
|
-
:host([size="small"]) .step { padding-inline:
|
|
67
|
-
:host([size="small"]) .body { margin-top: 6px; }
|
|
66
|
+
:host([size="small"]) .step { padding-inline: calc(var(--hy-space-3, 6px) + 1px); }
|
|
67
|
+
:host([size="small"]) .body { margin-top: var(--hy-space-3, 6px); }
|
|
68
68
|
:host([direction="vertical"]) .steps { flex-direction: column; }
|
|
69
69
|
:host([direction="vertical"]) .item { flex: none; min-height: var(--hy-steps-vertical-item-height, 78px); text-align: left; }
|
|
70
|
-
:host([direction="vertical"]) .step { display: grid; grid-template-columns: var(--hy-steps-icon-size, 30px) minmax(0, 1fr); align-items: start; gap: 12px; padding: 0 0 20px; text-align: left; }
|
|
70
|
+
:host([direction="vertical"]) .step { display: grid; grid-template-columns: var(--hy-steps-icon-size, 30px) minmax(0, 1fr); align-items: start; gap: var(--hy-space-6, 12px); padding: 0 0 var(--hy-space-10, 20px); text-align: left; }
|
|
71
71
|
:host([direction="vertical"]) .head { grid-column: 1; grid-row: 1; }
|
|
72
|
-
:host([direction="vertical"]) .body { grid-column: 2; grid-row: 1; margin-top: 4px; }
|
|
72
|
+
:host([direction="vertical"]) .body { grid-column: 2; grid-row: 1; margin-top: var(--hy-space-2, 4px); }
|
|
73
73
|
:host([direction="vertical"]) .title-row { justify-content: flex-start; }
|
|
74
|
-
:host([direction="vertical"]) .description { margin: 4px 0 0; }
|
|
74
|
+
:host([direction="vertical"]) .description { margin: var(--hy-space-2, 4px) 0 0; }
|
|
75
75
|
:host([direction="vertical"]) .tail { top: calc(var(--hy-steps-icon-size, 30px) + 5px); bottom: 5px; left: calc(var(--hy-steps-icon-size, 30px) / 2); width: var(--hy-steps-line-width, 1px); height: auto; }
|
|
76
76
|
@media (prefers-reduced-motion: reduce) { .icon { transition: none; } }
|
|
77
77
|
`;
|
package/dist/switch.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface HYSwitchChangeDetail {
|
|
2
|
+
checked: boolean;
|
|
3
|
+
value: string;
|
|
4
|
+
}
|
|
5
|
+
export type HYSwitchSize = 'small' | 'default';
|
|
6
|
+
export declare class HYSwitch extends HTMLElement {
|
|
7
|
+
static readonly formAssociated = true;
|
|
8
|
+
private readonly _input;
|
|
9
|
+
private readonly _text;
|
|
10
|
+
private readonly _labelSlot;
|
|
11
|
+
private readonly _formControl;
|
|
12
|
+
static get observedAttributes(): string[];
|
|
13
|
+
constructor();
|
|
14
|
+
connectedCallback(): void;
|
|
15
|
+
disconnectedCallback(): void;
|
|
16
|
+
attributeChangedCallback(): void;
|
|
17
|
+
get checked(): boolean;
|
|
18
|
+
set checked(value: boolean);
|
|
19
|
+
get disabled(): boolean;
|
|
20
|
+
set disabled(value: boolean);
|
|
21
|
+
get loading(): boolean;
|
|
22
|
+
set loading(value: boolean);
|
|
23
|
+
get value(): string;
|
|
24
|
+
set value(value: string);
|
|
25
|
+
get name(): string;
|
|
26
|
+
set name(value: string);
|
|
27
|
+
get label(): string;
|
|
28
|
+
set label(value: string);
|
|
29
|
+
get size(): HYSwitchSize;
|
|
30
|
+
set size(value: HYSwitchSize);
|
|
31
|
+
get form(): HTMLFormElement | null;
|
|
32
|
+
checkValidity(): boolean;
|
|
33
|
+
reportValidity(): boolean;
|
|
34
|
+
setCustomValidity(message: string): void;
|
|
35
|
+
formDisabledCallback(disabled: boolean): void;
|
|
36
|
+
formResetCallback(): void;
|
|
37
|
+
formStateRestoreCallback(state: string | File | FormData | null): void;
|
|
38
|
+
focus(options?: FocusOptions): void;
|
|
39
|
+
click(): void;
|
|
40
|
+
private _sync;
|
|
41
|
+
private _onChange;
|
|
42
|
+
private _onKeydown;
|
|
43
|
+
}
|
|
44
|
+
export declare function defineSwitchComponents(): void;
|
package/dist/switch.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { HYFormControl } from './internal/form-control.js';
|
|
2
|
+
export class HYSwitch extends HTMLElement {
|
|
3
|
+
static formAssociated = true;
|
|
4
|
+
_input = document.createElement('input');
|
|
5
|
+
_text = document.createElement('span');
|
|
6
|
+
_labelSlot = document.createElement('slot');
|
|
7
|
+
_formControl = new HYFormControl(this, this._input);
|
|
8
|
+
static get observedAttributes() { return ['checked', 'disabled', 'loading', 'required', 'name', 'value', 'label', 'aria-label', 'checked-text', 'unchecked-text', 'size']; }
|
|
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; color: var(--hy-text-color, #d8e2f2); font: var(--hy-font-size-sm, 12px)/1.5 var(--hy-font-family, system-ui, sans-serif); }
|
|
15
|
+
label { display: inline-flex; align-items: center; gap: var(--hy-space-4, 8px); cursor: pointer; }
|
|
16
|
+
input { position: absolute; width: 1px; height: 1px; opacity: 0; clip-path: inset(50%); }
|
|
17
|
+
.track { position: relative; display: inline-flex; align-items: center; box-sizing: border-box; min-width: 38px; height: 22px; padding: 0 7px 0 24px; border-radius: 999px; background: var(--hy-switch-off-bg, var(--hy-disabled-text-color, #65738a)); color: var(--hy-selected-text-color, #fff); transition: background 120ms; }
|
|
18
|
+
.thumb { position: absolute; inset-inline-start: 3px; top: 3px; width: 16px; height: 16px; box-sizing: border-box; border-radius: 50%; background: var(--hy-switch-thumb-color, var(--hy-selected-text-color, #fff)); transition: inset-inline-start 120ms; }
|
|
19
|
+
.state { font-size: 11px; white-space: nowrap; }
|
|
20
|
+
input:checked + .track { padding-inline: 7px 24px; background: var(--hy-switch-on-bg, var(--hy-accent-strong-color, #554cc6)); }
|
|
21
|
+
input:checked + .track .thumb { inset-inline-start: calc(100% - 19px); }
|
|
22
|
+
input:focus-visible + .track { outline: 2px solid var(--hy-focus-border-color, #79a8ff); outline-offset: 2px; }
|
|
23
|
+
input:disabled ~ * { opacity: .55; cursor: not-allowed; }
|
|
24
|
+
:host([size="small"]) .track { min-width: 30px; height: 18px; padding-inline: 20px 5px; }
|
|
25
|
+
:host([size="small"]) .thumb { width: 12px; height: 12px; }
|
|
26
|
+
:host([size="small"]) input:checked + .track { padding-inline: 5px 20px; }
|
|
27
|
+
:host([size="small"]) input:checked + .track .thumb { inset-inline-start: calc(100% - 15px); }
|
|
28
|
+
:host([loading]) .thumb::after { content: ''; position: absolute; inset: 3px; border: 2px solid var(--hy-border-color, #65738a); border-top-color: transparent; border-radius: 50%; animation: hy-switch-spin .8s linear infinite; }
|
|
29
|
+
@keyframes hy-switch-spin { to { transform: rotate(360deg); } }
|
|
30
|
+
@media (prefers-reduced-motion: reduce) { .track, .thumb { transition: none; } :host([loading]) .thumb::after { animation: none; } }
|
|
31
|
+
`;
|
|
32
|
+
const label = document.createElement('label');
|
|
33
|
+
label.part.add('label');
|
|
34
|
+
const track = document.createElement('span');
|
|
35
|
+
track.className = 'track';
|
|
36
|
+
track.part.add('track');
|
|
37
|
+
track.setAttribute('aria-hidden', 'true');
|
|
38
|
+
const thumb = document.createElement('span');
|
|
39
|
+
thumb.className = 'thumb';
|
|
40
|
+
thumb.part.add('thumb');
|
|
41
|
+
this._text.className = 'state';
|
|
42
|
+
this._text.part.add('state');
|
|
43
|
+
this._input.type = 'checkbox';
|
|
44
|
+
this._input.setAttribute('role', 'switch');
|
|
45
|
+
this._input.part.add('input');
|
|
46
|
+
track.append(thumb, this._text);
|
|
47
|
+
label.append(this._input, track, this._labelSlot);
|
|
48
|
+
root.append(style, label);
|
|
49
|
+
}
|
|
50
|
+
connectedCallback() { this._input.addEventListener('change', this._onChange); this._input.addEventListener('keydown', this._onKeydown); this._sync(); this._formControl.connect(); }
|
|
51
|
+
disconnectedCallback() { this._input.removeEventListener('change', this._onChange); this._input.removeEventListener('keydown', this._onKeydown); }
|
|
52
|
+
attributeChangedCallback() { this._sync(); }
|
|
53
|
+
get checked() { return this.hasAttribute('checked'); }
|
|
54
|
+
set checked(value) { this.toggleAttribute('checked', Boolean(value)); }
|
|
55
|
+
get disabled() { return this.hasAttribute('disabled'); }
|
|
56
|
+
set disabled(value) { this.toggleAttribute('disabled', Boolean(value)); }
|
|
57
|
+
get loading() { return this.hasAttribute('loading'); }
|
|
58
|
+
set loading(value) { this.toggleAttribute('loading', Boolean(value)); }
|
|
59
|
+
get value() { return this.getAttribute('value') ?? 'on'; }
|
|
60
|
+
set value(value) { this.setAttribute('value', String(value)); }
|
|
61
|
+
get name() { return this.getAttribute('name') ?? ''; }
|
|
62
|
+
set name(value) { this.setAttribute('name', value); }
|
|
63
|
+
get label() { return this.getAttribute('label') ?? ''; }
|
|
64
|
+
set label(value) { this.setAttribute('label', value); }
|
|
65
|
+
get size() { return this.getAttribute('size') === 'small' ? 'small' : 'default'; }
|
|
66
|
+
set size(value) { this.setAttribute('size', value); }
|
|
67
|
+
get form() { return this._formControl.internals.form; }
|
|
68
|
+
checkValidity() { return this._formControl.internals.checkValidity(); }
|
|
69
|
+
reportValidity() { return this._formControl.internals.reportValidity(); }
|
|
70
|
+
setCustomValidity(message) { this._formControl.setCustomValidity(message); }
|
|
71
|
+
formDisabledCallback(disabled) { this._formControl.disabled = disabled; this._sync(); }
|
|
72
|
+
formResetCallback() { this._formControl.reset(); }
|
|
73
|
+
formStateRestoreCallback(state) { this._formControl.restore(state); }
|
|
74
|
+
focus(options) { this._input.focus(options); }
|
|
75
|
+
click() { this._input.click(); }
|
|
76
|
+
_sync() {
|
|
77
|
+
this._input.checked = this.checked;
|
|
78
|
+
this._input.disabled = this.disabled || this.loading || this._formControl.disabled;
|
|
79
|
+
this._input.required = this.hasAttribute('required');
|
|
80
|
+
this._input.value = this.value;
|
|
81
|
+
this._input.setAttribute('aria-checked', String(this.checked));
|
|
82
|
+
this._input.setAttribute('aria-busy', String(this.loading));
|
|
83
|
+
const name = this.getAttribute('aria-label') ?? this.label;
|
|
84
|
+
if (name)
|
|
85
|
+
this._input.setAttribute('aria-label', name);
|
|
86
|
+
else
|
|
87
|
+
this._input.removeAttribute('aria-label');
|
|
88
|
+
this._labelSlot.textContent = this.label;
|
|
89
|
+
this._text.textContent = this.getAttribute(this.checked ? 'checked-text' : 'unchecked-text') ?? '';
|
|
90
|
+
this._formControl.sync();
|
|
91
|
+
}
|
|
92
|
+
_onChange = () => {
|
|
93
|
+
this.checked = this._input.checked;
|
|
94
|
+
this.dispatchEvent(new CustomEvent('checked-change', { detail: { checked: this.checked, value: this.value }, bubbles: true, composed: true }));
|
|
95
|
+
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
96
|
+
};
|
|
97
|
+
_onKeydown = (event) => { if (event.key === 'Enter' && !event.isComposing) {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
this._input.click();
|
|
100
|
+
} };
|
|
101
|
+
}
|
|
102
|
+
export function defineSwitchComponents() { if (!customElements.get('hy-switch'))
|
|
103
|
+
customElements.define('hy-switch', HYSwitch); }
|
|
104
|
+
//# sourceMappingURL=switch.js.map
|
package/dist/table.d.ts
CHANGED
|
@@ -94,8 +94,6 @@ export declare class HYTable<T extends object = Record<string, unknown>> extends
|
|
|
94
94
|
private _renderBodyAndPagination;
|
|
95
95
|
private _createRow;
|
|
96
96
|
private _renderPagination;
|
|
97
|
-
private _pageButton;
|
|
98
|
-
private _pageNumbers;
|
|
99
97
|
private _processedRecords;
|
|
100
98
|
private _visibleRecords;
|
|
101
99
|
private _clampPage;
|
package/dist/table.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HYPaginationControls, HY_PAGINATION_STYLES } from './internal/pagination.js';
|
|
1
2
|
const DEFAULT_PAGE_SIZE = 10;
|
|
2
3
|
const DEFAULT_PAGE_SIZE_OPTIONS = [5, 10, 20, 50];
|
|
3
4
|
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
|
|
@@ -47,7 +48,12 @@ export class HYTable extends HTMLElement {
|
|
|
47
48
|
_table = document.createElement('table');
|
|
48
49
|
_head = document.createElement('thead');
|
|
49
50
|
_body = document.createElement('tbody');
|
|
50
|
-
_pagination =
|
|
51
|
+
_pagination = new HYPaginationControls((page, pageSize, source) => {
|
|
52
|
+
if (source === 'size')
|
|
53
|
+
this.pageSize = pageSize;
|
|
54
|
+
else
|
|
55
|
+
this.goToPage(page);
|
|
56
|
+
}, 'table');
|
|
51
57
|
_columns = [];
|
|
52
58
|
_dataSource = [];
|
|
53
59
|
_filters = {};
|
|
@@ -68,12 +74,12 @@ export class HYTable extends HTMLElement {
|
|
|
68
74
|
display: block;
|
|
69
75
|
min-width: 0;
|
|
70
76
|
color: var(--hy-text-color, #eef3ff);
|
|
71
|
-
font:
|
|
77
|
+
font: calc(var(--hy-font-size-sm, 12px) + 1px)/var(--hy-line-height-snug, 1.4) var(--hy-font-family, system-ui, sans-serif);
|
|
72
78
|
}
|
|
73
79
|
.scroller {
|
|
74
80
|
overflow: auto;
|
|
75
81
|
border: 1px solid var(--hy-border-color, #3d4654);
|
|
76
|
-
border-radius: var(--hy-table-radius,
|
|
82
|
+
border-radius: var(--hy-table-radius, calc(var(--hy-radius-md, 6px) + 1px));
|
|
77
83
|
background: var(--hy-surface-color, #171d27);
|
|
78
84
|
scrollbar-color: var(--hy-border-strong-color, #596779) var(--hy-input-bg-color, #111722);
|
|
79
85
|
scrollbar-width: thin;
|
|
@@ -82,7 +88,7 @@ export class HYTable extends HTMLElement {
|
|
|
82
88
|
th, td {
|
|
83
89
|
box-sizing: border-box;
|
|
84
90
|
min-width: 0;
|
|
85
|
-
padding: var(--hy-table-cell-padding,
|
|
91
|
+
padding: var(--hy-table-cell-padding, calc(var(--hy-space-5, 10px) + 1px) calc(var(--hy-space-6, 12px) + 1px));
|
|
86
92
|
border-bottom: 1px solid var(--hy-border-subtle-color, var(--hy-border-color, #3d4654));
|
|
87
93
|
overflow-wrap: anywhere;
|
|
88
94
|
}
|
|
@@ -90,8 +96,8 @@ export class HYTable extends HTMLElement {
|
|
|
90
96
|
position: relative;
|
|
91
97
|
color: var(--hy-secondary-text-color, #aebbd0);
|
|
92
98
|
background: var(--hy-table-header-background, var(--hy-input-bg-color, #111722));
|
|
93
|
-
font-size:
|
|
94
|
-
font-weight:
|
|
99
|
+
font-size: calc(var(--hy-font-size-xs, 10px) + 1px);
|
|
100
|
+
font-weight: calc(var(--hy-font-weight-semibold, 600) + 50);
|
|
95
101
|
text-align: left;
|
|
96
102
|
}
|
|
97
103
|
tbody tr { background: var(--hy-table-row-background, var(--hy-surface-color, #171d27)); }
|
|
@@ -99,12 +105,12 @@ export class HYTable extends HTMLElement {
|
|
|
99
105
|
tbody tr:last-child td { border-bottom: 0; }
|
|
100
106
|
thead { position: relative; z-index: 2; }
|
|
101
107
|
tbody { position: relative; z-index: 1; }
|
|
102
|
-
.header-content { display: flex; align-items: center; gap:
|
|
108
|
+
.header-content { display: flex; align-items: center; gap: calc(var(--hy-space-3, 6px) + 1px); min-width: 0; }
|
|
103
109
|
.header-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
104
110
|
.sort-button {
|
|
105
111
|
display: inline-flex;
|
|
106
112
|
align-items: center;
|
|
107
|
-
gap:
|
|
113
|
+
gap: calc(var(--hy-space-3, 6px) + 1px);
|
|
108
114
|
max-width: 100%;
|
|
109
115
|
padding: 0;
|
|
110
116
|
border: 0;
|
|
@@ -115,7 +121,7 @@ export class HYTable extends HTMLElement {
|
|
|
115
121
|
text-align: inherit;
|
|
116
122
|
}
|
|
117
123
|
.sort-button:hover, .sort-button:focus-visible { color: var(--hy-accent-color, #79a8ff); }
|
|
118
|
-
.sort-indicator { color: var(--hy-muted-text-color, #667587); font-size:
|
|
124
|
+
.sort-indicator { color: var(--hy-muted-text-color, var(--hy-muted-color, #667587)); font-size: calc(var(--hy-font-size-xs, 10px) - 1px); }
|
|
119
125
|
th[aria-sort="ascending"] .sort-indicator,
|
|
120
126
|
th[aria-sort="descending"] .sort-indicator { color: var(--hy-accent-color, #79a8ff); }
|
|
121
127
|
.filter-menu { position: relative; flex: 0 0 auto; }
|
|
@@ -127,8 +133,8 @@ export class HYTable extends HTMLElement {
|
|
|
127
133
|
place-items: center;
|
|
128
134
|
padding: 0;
|
|
129
135
|
border: 1px solid transparent;
|
|
130
|
-
border-radius: var(--hy-table-filter-radius,
|
|
131
|
-
color: var(--hy-muted-text-color, #667587);
|
|
136
|
+
border-radius: var(--hy-table-filter-radius, calc(var(--hy-radius-sm, 4px) + 1px));
|
|
137
|
+
color: var(--hy-muted-text-color, var(--hy-muted-color, #667587));
|
|
132
138
|
background: transparent;
|
|
133
139
|
cursor: pointer;
|
|
134
140
|
list-style: none;
|
|
@@ -151,11 +157,11 @@ export class HYTable extends HTMLElement {
|
|
|
151
157
|
width: max-content;
|
|
152
158
|
min-width: 184px;
|
|
153
159
|
max-width: min(280px, 70vw);
|
|
154
|
-
gap:
|
|
160
|
+
gap: calc(var(--hy-space-3, 6px) + 1px);
|
|
155
161
|
box-sizing: border-box;
|
|
156
|
-
padding:
|
|
162
|
+
padding: calc(var(--hy-space-4, 8px) + 1px);
|
|
157
163
|
border: 1px solid var(--hy-border-color, #3d4654);
|
|
158
|
-
border-radius: var(--hy-table-filter-panel-radius,
|
|
164
|
+
border-radius: var(--hy-table-filter-panel-radius, calc(var(--hy-radius-md, 6px) + 1px));
|
|
159
165
|
background: var(--hy-surface-elevated-color, var(--hy-surface-color, #171d27));
|
|
160
166
|
box-shadow: 0 10px 28px var(--hy-menu-shadow-color, rgba(0, 0, 0, 0.28));
|
|
161
167
|
}
|
|
@@ -167,63 +173,60 @@ export class HYTable extends HTMLElement {
|
|
|
167
173
|
min-width: 74px;
|
|
168
174
|
height: 30px;
|
|
169
175
|
box-sizing: border-box;
|
|
170
|
-
padding: 0
|
|
176
|
+
padding: 0 calc(var(--hy-space-4, 8px) + 1px);
|
|
171
177
|
border: 1px solid var(--hy-border-color, #3d4654);
|
|
172
|
-
border-radius: var(--hy-table-filter-radius,
|
|
178
|
+
border-radius: var(--hy-table-filter-radius, calc(var(--hy-radius-sm, 4px) + 1px));
|
|
173
179
|
outline: none;
|
|
174
180
|
color: var(--hy-text-color, #eef3ff);
|
|
175
181
|
background: var(--hy-input-bg-color, #111722);
|
|
176
|
-
font:
|
|
182
|
+
font: calc(var(--hy-font-size-xs, 10px) + 1px) var(--hy-font-family, system-ui, sans-serif);
|
|
177
183
|
}
|
|
178
184
|
.filter:focus { border-color: var(--hy-focus-border-color, #79a8ff); box-shadow: 0 0 0 2px var(--hy-focus-ring-color, rgba(121, 168, 255, 0.22)); }
|
|
179
185
|
.filter-clear {
|
|
180
186
|
flex: 0 0 auto;
|
|
181
187
|
height: 30px;
|
|
182
|
-
padding: 0
|
|
188
|
+
padding: 0 calc(var(--hy-space-4, 8px) + 1px);
|
|
183
189
|
border: 1px solid var(--hy-border-color, #3d4654);
|
|
184
|
-
border-radius: var(--hy-table-filter-radius,
|
|
190
|
+
border-radius: var(--hy-table-filter-radius, calc(var(--hy-radius-sm, 4px) + 1px));
|
|
185
191
|
color: var(--hy-secondary-text-color, #aebbd0);
|
|
186
192
|
background: var(--hy-surface-color, #171d27);
|
|
187
193
|
cursor: pointer;
|
|
188
|
-
font:
|
|
194
|
+
font: calc(var(--hy-font-size-xs, 10px) + 1px) var(--hy-font-family, system-ui, sans-serif);
|
|
189
195
|
}
|
|
190
196
|
.filter-clear:hover:not(:disabled) { border-color: var(--hy-accent-color, #79a8ff); color: var(--hy-accent-color, #79a8ff); }
|
|
191
197
|
.filter-clear:disabled { cursor: default; opacity: 0.45; }
|
|
192
|
-
.empty { height: 112px; color: var(--hy-muted-text-color, #788697); text-align: center; }
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
align-items: center;
|
|
198
|
+
.empty { height: 112px; color: var(--hy-muted-text-color, var(--hy-muted-color, #788697)); text-align: center; }
|
|
199
|
+
${HY_PAGINATION_STYLES}
|
|
200
|
+
.pagination-controls.pagination {
|
|
196
201
|
justify-content: flex-end;
|
|
197
|
-
gap: 6px;
|
|
198
|
-
padding:
|
|
202
|
+
gap: var(--hy-space-3, 6px);
|
|
203
|
+
padding: calc(var(--hy-space-5, 10px) + 1px) 0 0;
|
|
204
|
+
font: calc(var(--hy-font-size-xs, 10px) + 1px) var(--hy-font-family, system-ui, sans-serif);
|
|
199
205
|
}
|
|
200
|
-
.pagination
|
|
206
|
+
.pagination .pages { display: contents; }
|
|
201
207
|
.pagination button, .pagination select {
|
|
202
208
|
height: 30px;
|
|
203
|
-
|
|
204
|
-
border:
|
|
205
|
-
border-radius:
|
|
209
|
+
min-height: 0;
|
|
210
|
+
border-color: var(--hy-border-color, #3d4654);
|
|
211
|
+
border-radius: calc(var(--hy-radius-sm, 4px) + 1px);
|
|
206
212
|
color: var(--hy-secondary-text-color, #aebbd0);
|
|
207
213
|
background: var(--hy-surface-color, #171d27);
|
|
208
|
-
font: 11px system-ui, sans-serif;
|
|
209
214
|
}
|
|
210
|
-
.pagination button { min-width: 30px; padding: 0 8px;
|
|
215
|
+
.pagination button { min-width: 30px; padding: 0 var(--hy-space-4, 8px); }
|
|
211
216
|
.pagination button:hover:not(:disabled), .pagination button[aria-current="page"] { border-color: var(--hy-accent-color, #79a8ff); color: var(--hy-accent-color, #79a8ff); }
|
|
212
217
|
.pagination button:disabled { cursor: not-allowed; opacity: 0.45; }
|
|
213
|
-
.pagination select { margin-left: 6px; padding: 0
|
|
214
|
-
.summary { margin-
|
|
218
|
+
.pagination select { margin-left: var(--hy-space-3, 6px); padding: 0 calc(var(--hy-space-3, 6px) + 1px); }
|
|
219
|
+
.pagination .summary { margin-inline-end: auto; color: var(--hy-muted-text-color, var(--hy-muted-color, #788697)); font-size: var(--hy-font-size-xs, 10px); }
|
|
215
220
|
`;
|
|
216
221
|
this._scroller.className = 'scroller';
|
|
217
222
|
this._scroller.part.add('scroller');
|
|
218
223
|
this._table.part.add('table');
|
|
219
224
|
this._head.part.add('header');
|
|
220
225
|
this._body.part.add('body');
|
|
221
|
-
this._pagination.
|
|
222
|
-
this._pagination.part.add('pagination');
|
|
223
|
-
this._pagination.setAttribute('aria-label', 'Table pagination');
|
|
226
|
+
this._pagination.element.classList.add('pagination');
|
|
224
227
|
this._table.append(this._head, this._body);
|
|
225
228
|
this._scroller.append(this._table);
|
|
226
|
-
root.append(style, this._scroller, this._pagination);
|
|
229
|
+
root.append(style, this._scroller, this._pagination.element);
|
|
227
230
|
}
|
|
228
231
|
connectedCallback() {
|
|
229
232
|
this._syncAttributes();
|
|
@@ -553,55 +556,11 @@ export class HYTable extends HTMLElement {
|
|
|
553
556
|
return row;
|
|
554
557
|
}
|
|
555
558
|
_renderPagination() {
|
|
556
|
-
|
|
557
|
-
this.
|
|
558
|
-
this.
|
|
559
|
-
|
|
560
|
-
}
|
|
561
|
-
this._pagination.hidden = false;
|
|
562
|
-
const processed = this._processedRecords();
|
|
563
|
-
const pageCount = Math.max(1, Math.ceil(processed.length / this._pageSize));
|
|
564
|
-
const summary = document.createElement('span');
|
|
565
|
-
summary.className = 'summary';
|
|
566
|
-
summary.part.add('summary');
|
|
567
|
-
const start = processed.length ? (this._page - 1) * this._pageSize + 1 : 0;
|
|
568
|
-
const end = Math.min(processed.length, this._page * this._pageSize);
|
|
569
|
-
summary.textContent = `${start}–${end} of ${processed.length}`;
|
|
570
|
-
const previous = this._pageButton('‹', 'Previous page', this._page - 1, this._page <= 1);
|
|
571
|
-
const pages = this._pageNumbers(pageCount).map(page => this._pageButton(String(page), `Page ${page}`, page, false, page === this._page));
|
|
572
|
-
const next = this._pageButton('›', 'Next page', this._page + 1, this._page >= pageCount);
|
|
573
|
-
const pageSize = document.createElement('select');
|
|
574
|
-
pageSize.part.add('page-size');
|
|
575
|
-
pageSize.setAttribute('aria-label', 'Rows per page');
|
|
576
|
-
const options = this._pageSizeOptions.includes(this._pageSize)
|
|
577
|
-
? this._pageSizeOptions
|
|
578
|
-
: [...this._pageSizeOptions, this._pageSize].sort((a, b) => a - b);
|
|
579
|
-
pageSize.append(...options.map(value => {
|
|
580
|
-
const option = document.createElement('option');
|
|
581
|
-
option.value = String(value);
|
|
582
|
-
option.textContent = `${value} / page`;
|
|
583
|
-
option.selected = value === this._pageSize;
|
|
584
|
-
return option;
|
|
585
|
-
}));
|
|
586
|
-
pageSize.addEventListener('change', () => { this.pageSize = Number(pageSize.value); });
|
|
587
|
-
this._pagination.replaceChildren(summary, previous, ...pages, next, pageSize);
|
|
588
|
-
}
|
|
589
|
-
_pageButton(text, label, page, disabled, current = false) {
|
|
590
|
-
const button = document.createElement('button');
|
|
591
|
-
button.type = 'button';
|
|
592
|
-
button.textContent = text;
|
|
593
|
-
button.disabled = disabled;
|
|
594
|
-
button.setAttribute('aria-label', label);
|
|
595
|
-
if (current)
|
|
596
|
-
button.setAttribute('aria-current', 'page');
|
|
597
|
-
button.addEventListener('click', () => this.goToPage(page));
|
|
598
|
-
return button;
|
|
599
|
-
}
|
|
600
|
-
_pageNumbers(pageCount) {
|
|
601
|
-
if (pageCount <= 7)
|
|
602
|
-
return Array.from({ length: pageCount }, (_, index) => index + 1);
|
|
603
|
-
const start = Math.max(1, Math.min(pageCount - 4, this._page - 2));
|
|
604
|
-
return Array.from({ length: 5 }, (_, index) => start + index);
|
|
559
|
+
this._pagination.update({
|
|
560
|
+
page: this._page, pageSize: this._pageSize, total: this._processedRecords().length,
|
|
561
|
+
pageSizeOptions: this._pageSizeOptions, label: 'Table pagination',
|
|
562
|
+
hidden: !this.pagination, showSizeChanger: true,
|
|
563
|
+
});
|
|
605
564
|
}
|
|
606
565
|
_processedRecords() {
|
|
607
566
|
let records = this._dataSource.map((record, index) => ({ record, index }));
|