@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.
Files changed (139) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +27 -0
  3. package/README.md +707 -5
  4. package/dist/adapters/web/controls.js +28 -5
  5. package/dist/adapters/web/renderer.js +11 -10
  6. package/dist/adapters/web/styles.d.ts +2 -3
  7. package/dist/adapters/web/styles.js +42 -18
  8. package/dist/alert.d.ts +39 -0
  9. package/dist/alert.js +144 -0
  10. package/dist/anchor.d.ts +60 -0
  11. package/dist/anchor.js +274 -0
  12. package/dist/auto-complete.d.ts +83 -0
  13. package/dist/auto-complete.js +267 -0
  14. package/dist/avatar.d.ts +45 -0
  15. package/dist/avatar.js +135 -0
  16. package/dist/badge.js +5 -5
  17. package/dist/border-beam.js +1 -1
  18. package/dist/breadcrumb.js +5 -5
  19. package/dist/button-group.js +8 -8
  20. package/dist/button.js +10 -10
  21. package/dist/card.d.ts +29 -0
  22. package/dist/card.js +101 -0
  23. package/dist/carousel.d.ts +92 -0
  24. package/dist/carousel.js +509 -0
  25. package/dist/cascader.js +12 -12
  26. package/dist/checkbox.d.ts +12 -0
  27. package/dist/checkbox.js +22 -6
  28. package/dist/collapse.d.ts +13 -0
  29. package/dist/collapse.js +100 -13
  30. package/dist/context-menu.js +3 -3
  31. package/dist/core/types.d.ts +22 -3
  32. package/dist/core/validation.js +9 -4
  33. package/dist/date-picker.js +13 -13
  34. package/dist/descriptions.d.ts +44 -0
  35. package/dist/descriptions.js +169 -0
  36. package/dist/dialog.js +11 -11
  37. package/dist/divider.js +2 -2
  38. package/dist/draggable.js +1 -1
  39. package/dist/drawer.js +12 -12
  40. package/dist/dropdown.js +3 -3
  41. package/dist/empty.d.ts +20 -0
  42. package/dist/empty.js +58 -0
  43. package/dist/expandable.js +4 -4
  44. package/dist/form-item.d.ts +60 -0
  45. package/dist/form-item.js +212 -0
  46. package/dist/form.d.ts +41 -0
  47. package/dist/form.js +154 -0
  48. package/dist/history-controls.js +5 -5
  49. package/dist/image-preview.d.ts +22 -0
  50. package/dist/image-preview.js +38 -0
  51. package/dist/image.d.ts +52 -0
  52. package/dist/image.js +152 -0
  53. package/dist/index.d.ts +56 -0
  54. package/dist/index.js +84 -0
  55. package/dist/input.d.ts +11 -0
  56. package/dist/input.js +29 -15
  57. package/dist/internal/anchored-popup.d.ts +19 -0
  58. package/dist/internal/anchored-popup.js +89 -0
  59. package/dist/internal/form-control.d.ts +22 -0
  60. package/dist/internal/form-control.js +52 -0
  61. package/dist/internal/image-viewer.d.ts +51 -0
  62. package/dist/internal/image-viewer.js +210 -0
  63. package/dist/internal/pagination.d.ts +35 -0
  64. package/dist/internal/pagination.js +169 -0
  65. package/dist/internal/popover-base.d.ts +87 -0
  66. package/dist/internal/popover-base.js +365 -0
  67. package/dist/internal/presentation.d.ts +2 -0
  68. package/dist/internal/presentation.js +28 -0
  69. package/dist/internal/qrcodegen.d.ts +94 -0
  70. package/dist/internal/qrcodegen.js +856 -0
  71. package/dist/masonry.d.ts +36 -0
  72. package/dist/masonry.js +171 -0
  73. package/dist/mentions.d.ts +115 -0
  74. package/dist/mentions.js +485 -0
  75. package/dist/menu-shared.d.ts +1 -1
  76. package/dist/menu-shared.js +3 -3
  77. package/dist/menu.d.ts +63 -0
  78. package/dist/menu.js +339 -0
  79. package/dist/modal.d.ts +73 -0
  80. package/dist/modal.js +361 -0
  81. package/dist/notification.js +9 -9
  82. package/dist/pagination.d.ts +34 -0
  83. package/dist/pagination.js +73 -0
  84. package/dist/popconfirm.d.ts +6 -0
  85. package/dist/popconfirm.js +7 -0
  86. package/dist/popover.d.ts +6 -0
  87. package/dist/popover.js +7 -0
  88. package/dist/portable/icons.d.ts +5 -0
  89. package/dist/portable/icons.js +24 -0
  90. package/dist/portable/index.d.ts +3 -0
  91. package/dist/portable/index.js +2 -0
  92. package/dist/portable/responsive.d.ts +20 -0
  93. package/dist/portable/responsive.js +15 -0
  94. package/dist/portable/theme.d.ts +6 -1
  95. package/dist/portable/theme.js +23 -3
  96. package/dist/progress.d.ts +30 -0
  97. package/dist/progress.js +102 -0
  98. package/dist/qr-code.d.ts +62 -0
  99. package/dist/qr-code.js +224 -0
  100. package/dist/radio.d.ts +10 -0
  101. package/dist/radio.js +18 -5
  102. package/dist/range.js +7 -7
  103. package/dist/rate.js +3 -3
  104. package/dist/resizable.js +4 -4
  105. package/dist/result.d.ts +22 -0
  106. package/dist/result.js +88 -0
  107. package/dist/ribbon.d.ts +19 -0
  108. package/dist/ribbon.js +106 -0
  109. package/dist/segmented.d.ts +39 -0
  110. package/dist/segmented.js +192 -0
  111. package/dist/select.d.ts +12 -0
  112. package/dist/select.js +31 -13
  113. package/dist/skeleton.js +10 -10
  114. package/dist/spin.d.ts +26 -0
  115. package/dist/spin.js +80 -0
  116. package/dist/steps.js +13 -13
  117. package/dist/switch.d.ts +44 -0
  118. package/dist/switch.js +104 -0
  119. package/dist/table.d.ts +0 -2
  120. package/dist/table.js +46 -87
  121. package/dist/tabs.js +7 -7
  122. package/dist/tag.js +8 -8
  123. package/dist/time-picker.js +10 -10
  124. package/dist/timeline.js +12 -12
  125. package/dist/toast.js +9 -9
  126. package/dist/tooltip.js +4 -4
  127. package/dist/tour.js +11 -11
  128. package/dist/tree-node.js +2 -2
  129. package/dist/tree-select.d.ts +94 -0
  130. package/dist/tree-select.js +398 -0
  131. package/dist/tree.js +6 -5
  132. package/dist/upload.d.ts +107 -0
  133. package/dist/upload.js +353 -0
  134. package/dist/virtual-keyboard.js +5 -5
  135. package/dist/virtual-list.js +4 -4
  136. package/dist/virtual-mouse.js +5 -5
  137. package/package.json +99 -1
  138. package/themes/haiyue-dark.css +51 -0
  139. package/themes/haiyue-light.css +51 -0
package/dist/rate.js CHANGED
@@ -19,10 +19,10 @@ export class HYRate extends HTMLElement {
19
19
  const root = this.attachShadow({ mode: 'open' });
20
20
  const style = document.createElement('style');
21
21
  style.textContent = `
22
- :host { display: inline-block; color: var(--hy-text-color, #eef3ff); font: 12px/1 system-ui, sans-serif; }
23
- .group { display: inline-flex; align-items: center; gap: var(--hy-rate-gap, 5px); border-radius: var(--hy-rate-focus-radius, 5px); }
22
+ :host { display: inline-block; color: var(--hy-text-color, #eef3ff); font: var(--hy-font-size-sm, 12px)/var(--hy-line-height-tight, 1) var(--hy-font-family, system-ui, sans-serif); }
23
+ .group { display: inline-flex; align-items: center; gap: var(--hy-rate-gap, calc(var(--hy-space-2, 4px) + 1px)); border-radius: var(--hy-rate-focus-radius, calc(var(--hy-radius-sm, 4px) + 1px)); }
24
24
  .group:focus-visible { outline: 2px solid var(--hy-focus-border-color, #79a8ff); outline-offset: 3px; }
25
- .star { position: relative; width: 1em; height: 1em; padding: 0; overflow: hidden; border: 0; color: inherit; background: transparent; cursor: pointer; font: var(--hy-rate-font-size, 25px)/1 system-ui, sans-serif; transition: transform 120ms ease; }
25
+ .star { position: relative; width: 1em; height: 1em; padding: 0; overflow: hidden; border: 0; color: inherit; background: transparent; cursor: pointer; font: var(--hy-rate-font-size, calc(var(--hy-font-size-2xl, 24px) + 1px))/var(--hy-line-height-tight, 1) var(--hy-font-family, system-ui, sans-serif); transition: transform 120ms ease; }
26
26
  .star:hover { transform: scale(1.12); }
27
27
  .empty, .fill-inner { display: block; width: 1em; height: 1em; }
28
28
  .empty { color: var(--hy-rate-empty-color, color-mix(in srgb, var(--hy-text-color, #eef3ff) 16%, transparent)); }
package/dist/resizable.js CHANGED
@@ -65,12 +65,12 @@ export class HYResizable extends HTMLElement {
65
65
  z-index: 2;
66
66
  inset: 0;
67
67
  border: var(--hy-resizable-border-width, 1px) var(--hy-resizable-border-style, solid) var(--hy-resizable-border-color, var(--hy-accent-color, #79a8ff));
68
- border-radius: var(--hy-resizable-radius, 5px);
68
+ border-radius: var(--hy-resizable-radius, calc(var(--hy-radius-sm, 4px) + 1px));
69
69
  pointer-events: none;
70
70
  content: '';
71
71
  }
72
72
  .frame:focus-visible { outline: 2px solid var(--hy-focus-border-color, #79a8ff); outline-offset: 3px; }
73
- .content { width: 100%; height: 100%; overflow: var(--hy-resizable-content-overflow, hidden); border-radius: var(--hy-resizable-radius, 5px); }
73
+ .content { width: 100%; height: 100%; overflow: var(--hy-resizable-content-overflow, hidden); border-radius: var(--hy-resizable-radius, calc(var(--hy-radius-sm, 4px) + 1px)); }
74
74
  :host(:not([disabled])) .content { cursor: var(--hy-resizable-move-cursor, move); }
75
75
  :host([movable="false"]) .content, :host([disabled]) .content { cursor: default; }
76
76
  .handle { position: absolute; z-index: 3; box-sizing: border-box; touch-action: none; outline: none; }
@@ -97,9 +97,9 @@ export class HYResizable extends HTMLElement {
97
97
  height: var(--hy-resizable-corner-size, 10px);
98
98
  box-sizing: border-box;
99
99
  border: 1px solid var(--hy-resizable-handle-border-color, #dbeeff);
100
- border-radius: var(--hy-resizable-handle-radius, 2px);
100
+ border-radius: var(--hy-resizable-handle-radius, var(--hy-radius-xs, 2px));
101
101
  background: var(--hy-resizable-handle-color, var(--hy-accent-color, #79a8ff));
102
- box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
102
+ box-shadow: 0 1px 4px var(--hy-shadow-color, rgba(0, 0, 0, 0.28));
103
103
  content: '';
104
104
  }
105
105
  .handle.n::after, .handle.s::after { left: 50%; top: 50%; translate: -50% -50%; }
@@ -0,0 +1,22 @@
1
+ export type HYResultStatus = 'success' | 'info' | 'warning' | 'error' | '403' | '404' | '500';
2
+ /** Outcome page with semantic status, details and custom actions. */
3
+ export declare class HYResult extends HTMLElement {
4
+ private readonly _surface;
5
+ private readonly _icon;
6
+ private readonly _heading;
7
+ private readonly _description;
8
+ private readonly _content;
9
+ private readonly _extra;
10
+ static get observedAttributes(): string[];
11
+ constructor();
12
+ connectedCallback(): void;
13
+ attributeChangedCallback(): void;
14
+ get status(): HYResultStatus;
15
+ set status(value: HYResultStatus);
16
+ get heading(): string;
17
+ set heading(value: string);
18
+ get description(): string;
19
+ set description(value: string);
20
+ private _render;
21
+ }
22
+ export declare function defineResultComponents(): void;
package/dist/result.js ADDED
@@ -0,0 +1,88 @@
1
+ import { hasSlotContent, presentationIcon } from './internal/presentation.js';
2
+ const headings = { success: 'Completed', info: 'Information', warning: 'Please check', error: 'Something went wrong', '403': '403', '404': '404', '500': '500' };
3
+ /** Outcome page with semantic status, details and custom actions. */
4
+ export class HYResult extends HTMLElement {
5
+ _surface = document.createElement('section');
6
+ _icon = document.createElement('slot');
7
+ _heading = document.createElement('slot');
8
+ _description = document.createElement('slot');
9
+ _content = document.createElement('slot');
10
+ _extra = document.createElement('slot');
11
+ static get observedAttributes() { return ['status', 'heading', 'description', 'aria-label']; }
12
+ constructor() {
13
+ super();
14
+ const root = this.attachShadow({ mode: 'open' });
15
+ const style = document.createElement('style');
16
+ style.textContent = `
17
+ :host { display: block; min-width: 0; color: var(--hy-text-color, #eef0ff); font: var(--hy-font-size-sm, 12px)/var(--hy-line-height-relaxed, 1.5) var(--hy-font-family, system-ui, sans-serif); }
18
+ .result { display: flex; align-items: center; flex-direction: column; gap: var(--hy-space-6, 12px); padding: var(--hy-result-padding, var(--hy-space-16, 32px) var(--hy-space-10, 20px)); text-align: center; overflow-wrap: anywhere; }
19
+ .icon { display: block; width: var(--hy-result-icon-size, 64px); max-width: 100%; color: var(--hy-result-status-color, var(--hy-info-color, #55b4da)); }
20
+ .icon svg, .icon::slotted(*) { display: block; width: 100%; height: auto; }
21
+ .icon.code { width: auto; font-size: var(--hy-result-code-size, 64px); font-weight: var(--hy-font-weight-bold, 700); line-height: var(--hy-line-height-compact, 1.2); }
22
+ .success { --hy-result-status-color: var(--hy-success-color, #51b88b); } .warning { --hy-result-status-color: var(--hy-warning-color, #e1b952); } .error { --hy-result-status-color: var(--hy-error-color, #e47689); }
23
+ h2 { max-width: 100%; margin: 0; font-size: var(--hy-font-size-2xl, 24px); font-weight: var(--hy-font-weight-semibold, 600); }
24
+ .description { display: block; max-width: 64ch; color: var(--hy-secondary-text-color, #a9add4); }
25
+ .content { display: block; width: 100%; box-sizing: border-box; padding: var(--hy-space-8, 16px); border-radius: var(--hy-radius-md, 6px); color: var(--hy-secondary-text-color, #a9add4); background: var(--hy-surface-color, #10132f); text-align: start; }
26
+ .extra { display: flex; justify-content: center; flex-wrap: wrap; gap: var(--hy-space-4, 8px); max-width: 100%; }
27
+ [hidden] { display: none !important; }
28
+ `;
29
+ this._surface.className = 'result';
30
+ this._surface.part.add('result');
31
+ this._surface.setAttribute('aria-labelledby', 'result-heading');
32
+ this._icon.name = 'icon';
33
+ this._icon.className = 'icon';
34
+ this._icon.part.add('icon');
35
+ this._icon.setAttribute('aria-hidden', 'true');
36
+ const heading = document.createElement('h2');
37
+ heading.id = 'result-heading';
38
+ heading.part.add('heading');
39
+ this._heading.name = 'heading';
40
+ heading.append(this._heading);
41
+ this._description.name = 'description';
42
+ this._description.className = 'description';
43
+ this._description.part.add('description');
44
+ this._content.className = 'content';
45
+ this._content.part.add('content');
46
+ this._extra.name = 'extra';
47
+ this._extra.className = 'extra';
48
+ this._extra.part.add('extra');
49
+ this._surface.append(this._icon, heading, this._description, this._content, this._extra);
50
+ root.append(style, this._surface);
51
+ for (const slot of [this._description, this._content, this._extra])
52
+ slot.addEventListener('slotchange', this._render);
53
+ }
54
+ connectedCallback() { this._render(); }
55
+ attributeChangedCallback() { this._render(); }
56
+ get status() { const value = this.getAttribute('status'); return Object.hasOwn(headings, value) ? value : 'info'; }
57
+ set status(value) { this.setAttribute('status', value); }
58
+ get heading() { return this.getAttribute('heading') ?? headings[this.status]; }
59
+ set heading(value) { this.setAttribute('heading', value); }
60
+ get description() { return this.getAttribute('description') ?? ''; }
61
+ set description(value) { this.setAttribute('description', value); }
62
+ _render = () => {
63
+ const status = this.status;
64
+ const code = /^\d/.test(status);
65
+ this._surface.className = `result ${code ? 'info' : status}`;
66
+ this._icon.className = code ? 'icon code' : 'icon';
67
+ this._icon.replaceChildren(code ? document.createTextNode(status) : presentationIcon(status));
68
+ if (this._heading.textContent !== this.heading)
69
+ this._heading.textContent = this.heading;
70
+ if (this._description.textContent !== this.description)
71
+ this._description.textContent = this.description;
72
+ this._description.hidden = !this.description && !hasSlotContent(this._description);
73
+ this._content.hidden = !hasSlotContent(this._content);
74
+ this._extra.hidden = !hasSlotContent(this._extra);
75
+ const label = this.getAttribute('aria-label');
76
+ if (label) {
77
+ this._surface.setAttribute('aria-label', label);
78
+ this._surface.removeAttribute('aria-labelledby');
79
+ }
80
+ else {
81
+ this._surface.removeAttribute('aria-label');
82
+ this._surface.setAttribute('aria-labelledby', 'result-heading');
83
+ }
84
+ };
85
+ }
86
+ export function defineResultComponents() { if (!customElements.get('hy-result'))
87
+ customElements.define('hy-result', HYResult); }
88
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1,19 @@
1
+ export type HYRibbonPlacement = 'start' | 'end';
2
+ /** Folded ribbon decorating content in the default slot. */
3
+ export declare class HYRibbon extends HTMLElement {
4
+ private readonly _ribbon;
5
+ private readonly _text;
6
+ private readonly _fallback;
7
+ static get observedAttributes(): string[];
8
+ constructor();
9
+ connectedCallback(): void;
10
+ attributeChangedCallback(): void;
11
+ get text(): string;
12
+ set text(value: string);
13
+ get color(): string;
14
+ set color(value: string);
15
+ get placement(): HYRibbonPlacement;
16
+ set placement(value: HYRibbonPlacement);
17
+ private _render;
18
+ }
19
+ export declare function defineRibbonComponents(): void;
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 28px 0 8px;
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% - 15px) 11px,
49
- calc(100% - 10px) 11px;
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) {