@chromvoid/uikit 0.1.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 (246) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +96 -0
  3. package/dist/components/cv-accordion-item.d.ts +69 -0
  4. package/dist/components/cv-accordion-item.js +176 -0
  5. package/dist/components/cv-accordion.d.ts +79 -0
  6. package/dist/components/cv-accordion.js +310 -0
  7. package/dist/components/cv-alert-dialog.d.ts +86 -0
  8. package/dist/components/cv-alert-dialog.js +393 -0
  9. package/dist/components/cv-alert.d.ts +48 -0
  10. package/dist/components/cv-alert.js +156 -0
  11. package/dist/components/cv-badge.d.ts +56 -0
  12. package/dist/components/cv-badge.js +280 -0
  13. package/dist/components/cv-breadcrumb-item.d.ts +35 -0
  14. package/dist/components/cv-breadcrumb-item.js +64 -0
  15. package/dist/components/cv-breadcrumb.d.ts +39 -0
  16. package/dist/components/cv-breadcrumb.js +160 -0
  17. package/dist/components/cv-button.d.ts +83 -0
  18. package/dist/components/cv-button.js +541 -0
  19. package/dist/components/cv-callout.d.ts +32 -0
  20. package/dist/components/cv-callout.js +221 -0
  21. package/dist/components/cv-card.d.ts +48 -0
  22. package/dist/components/cv-card.js +269 -0
  23. package/dist/components/cv-carousel-slide.d.ts +25 -0
  24. package/dist/components/cv-carousel-slide.js +51 -0
  25. package/dist/components/cv-carousel.d.ts +96 -0
  26. package/dist/components/cv-carousel.js +457 -0
  27. package/dist/components/cv-checkbox.d.ts +84 -0
  28. package/dist/components/cv-checkbox.js +274 -0
  29. package/dist/components/cv-combobox-group.d.ts +15 -0
  30. package/dist/components/cv-combobox-group.js +34 -0
  31. package/dist/components/cv-combobox-option.d.ts +30 -0
  32. package/dist/components/cv-combobox-option.js +66 -0
  33. package/dist/components/cv-combobox.d.ts +135 -0
  34. package/dist/components/cv-combobox.js +834 -0
  35. package/dist/components/cv-command-item.d.ts +30 -0
  36. package/dist/components/cv-command-item.js +68 -0
  37. package/dist/components/cv-command-palette.d.ts +105 -0
  38. package/dist/components/cv-command-palette.js +578 -0
  39. package/dist/components/cv-context-menu.d.ts +98 -0
  40. package/dist/components/cv-context-menu.js +515 -0
  41. package/dist/components/cv-copy-button.d.ts +61 -0
  42. package/dist/components/cv-copy-button.js +318 -0
  43. package/dist/components/cv-date-picker.d.ts +161 -0
  44. package/dist/components/cv-date-picker.js +803 -0
  45. package/dist/components/cv-dialog.d.ts +89 -0
  46. package/dist/components/cv-dialog.js +459 -0
  47. package/dist/components/cv-disclosure.d.ts +57 -0
  48. package/dist/components/cv-disclosure.js +241 -0
  49. package/dist/components/cv-drawer.d.ts +102 -0
  50. package/dist/components/cv-drawer.js +595 -0
  51. package/dist/components/cv-feed-article.d.ts +26 -0
  52. package/dist/components/cv-feed-article.js +52 -0
  53. package/dist/components/cv-feed.d.ts +62 -0
  54. package/dist/components/cv-feed.js +310 -0
  55. package/dist/components/cv-grid-cell.d.ts +30 -0
  56. package/dist/components/cv-grid-cell.js +57 -0
  57. package/dist/components/cv-grid-column.d.ts +30 -0
  58. package/dist/components/cv-grid-column.js +43 -0
  59. package/dist/components/cv-grid-row.d.ts +30 -0
  60. package/dist/components/cv-grid-row.js +42 -0
  61. package/dist/components/cv-grid.d.ts +119 -0
  62. package/dist/components/cv-grid.js +567 -0
  63. package/dist/components/cv-icon.d.ts +57 -0
  64. package/dist/components/cv-icon.js +352 -0
  65. package/dist/components/cv-input.d.ts +127 -0
  66. package/dist/components/cv-input.js +482 -0
  67. package/dist/components/cv-landmark.d.ts +32 -0
  68. package/dist/components/cv-landmark.js +62 -0
  69. package/dist/components/cv-link.d.ts +22 -0
  70. package/dist/components/cv-link.js +99 -0
  71. package/dist/components/cv-listbox-group.d.ts +15 -0
  72. package/dist/components/cv-listbox-group.js +42 -0
  73. package/dist/components/cv-listbox.d.ts +81 -0
  74. package/dist/components/cv-listbox.js +388 -0
  75. package/dist/components/cv-menu-button.d.ts +118 -0
  76. package/dist/components/cv-menu-button.js +822 -0
  77. package/dist/components/cv-menu-group.d.ts +20 -0
  78. package/dist/components/cv-menu-group.js +48 -0
  79. package/dist/components/cv-menu-item.d.ts +52 -0
  80. package/dist/components/cv-menu-item.js +105 -0
  81. package/dist/components/cv-menu.d.ts +62 -0
  82. package/dist/components/cv-menu.js +414 -0
  83. package/dist/components/cv-meter.d.ts +66 -0
  84. package/dist/components/cv-meter.js +154 -0
  85. package/dist/components/cv-number.d.ts +139 -0
  86. package/dist/components/cv-number.js +553 -0
  87. package/dist/components/cv-option.d.ts +30 -0
  88. package/dist/components/cv-option.js +84 -0
  89. package/dist/components/cv-popover.d.ts +87 -0
  90. package/dist/components/cv-popover.js +373 -0
  91. package/dist/components/cv-progress-ring.d.ts +45 -0
  92. package/dist/components/cv-progress-ring.js +169 -0
  93. package/dist/components/cv-progress.d.ts +45 -0
  94. package/dist/components/cv-progress.js +148 -0
  95. package/dist/components/cv-radio-group.d.ts +79 -0
  96. package/dist/components/cv-radio-group.js +398 -0
  97. package/dist/components/cv-radio.d.ts +36 -0
  98. package/dist/components/cv-radio.js +123 -0
  99. package/dist/components/cv-select-group.d.ts +15 -0
  100. package/dist/components/cv-select-group.js +44 -0
  101. package/dist/components/cv-select-option.d.ts +30 -0
  102. package/dist/components/cv-select-option.js +66 -0
  103. package/dist/components/cv-select.d.ts +128 -0
  104. package/dist/components/cv-select.js +666 -0
  105. package/dist/components/cv-sidebar-item.d.ts +26 -0
  106. package/dist/components/cv-sidebar-item.js +142 -0
  107. package/dist/components/cv-sidebar.d.ts +171 -0
  108. package/dist/components/cv-sidebar.js +767 -0
  109. package/dist/components/cv-slider-multi-thumb.d.ts +73 -0
  110. package/dist/components/cv-slider-multi-thumb.js +374 -0
  111. package/dist/components/cv-slider.d.ts +84 -0
  112. package/dist/components/cv-slider.js +328 -0
  113. package/dist/components/cv-spinbutton.d.ts +121 -0
  114. package/dist/components/cv-spinbutton.js +486 -0
  115. package/dist/components/cv-spinner.d.ts +18 -0
  116. package/dist/components/cv-spinner.js +95 -0
  117. package/dist/components/cv-switch.d.ts +81 -0
  118. package/dist/components/cv-switch.js +285 -0
  119. package/dist/components/cv-tab-panel.d.ts +20 -0
  120. package/dist/components/cv-tab-panel.js +37 -0
  121. package/dist/components/cv-tab.d.ts +40 -0
  122. package/dist/components/cv-tab.js +132 -0
  123. package/dist/components/cv-table-cell.d.ts +31 -0
  124. package/dist/components/cv-table-cell.js +49 -0
  125. package/dist/components/cv-table-column.d.ts +37 -0
  126. package/dist/components/cv-table-column.js +63 -0
  127. package/dist/components/cv-table-row.d.ts +30 -0
  128. package/dist/components/cv-table-row.js +45 -0
  129. package/dist/components/cv-table.d.ts +147 -0
  130. package/dist/components/cv-table.js +607 -0
  131. package/dist/components/cv-tabs.d.ts +70 -0
  132. package/dist/components/cv-tabs.js +524 -0
  133. package/dist/components/cv-textarea.d.ts +108 -0
  134. package/dist/components/cv-textarea.js +328 -0
  135. package/dist/components/cv-toast-region.d.ts +39 -0
  136. package/dist/components/cv-toast-region.js +162 -0
  137. package/dist/components/cv-toast.d.ts +67 -0
  138. package/dist/components/cv-toast.js +315 -0
  139. package/dist/components/cv-toolbar-item.d.ts +25 -0
  140. package/dist/components/cv-toolbar-item.js +72 -0
  141. package/dist/components/cv-toolbar-separator.d.ts +25 -0
  142. package/dist/components/cv-toolbar-separator.js +45 -0
  143. package/dist/components/cv-toolbar.d.ts +63 -0
  144. package/dist/components/cv-toolbar.js +295 -0
  145. package/dist/components/cv-tooltip.d.ts +83 -0
  146. package/dist/components/cv-tooltip.js +455 -0
  147. package/dist/components/cv-treegrid-cell.d.ts +30 -0
  148. package/dist/components/cv-treegrid-cell.js +57 -0
  149. package/dist/components/cv-treegrid-column.d.ts +37 -0
  150. package/dist/components/cv-treegrid-column.js +53 -0
  151. package/dist/components/cv-treegrid-row.d.ts +55 -0
  152. package/dist/components/cv-treegrid-row.js +90 -0
  153. package/dist/components/cv-treegrid.d.ts +96 -0
  154. package/dist/components/cv-treegrid.js +632 -0
  155. package/dist/components/cv-treeitem.d.ts +58 -0
  156. package/dist/components/cv-treeitem.js +144 -0
  157. package/dist/components/cv-treeview.d.ts +70 -0
  158. package/dist/components/cv-treeview.js +396 -0
  159. package/dist/components/cv-window-splitter.d.ts +79 -0
  160. package/dist/components/cv-window-splitter.js +316 -0
  161. package/dist/components/index.d.ts +94 -0
  162. package/dist/components/index.js +79 -0
  163. package/dist/dialog/create-dialog-controller.d.ts +31 -0
  164. package/dist/dialog/create-dialog-controller.js +320 -0
  165. package/dist/dialog/index.d.ts +2 -0
  166. package/dist/dialog/index.js +1 -0
  167. package/dist/form-associated/FormAssociatedReatomElement.d.ts +25 -0
  168. package/dist/form-associated/FormAssociatedReatomElement.js +70 -0
  169. package/dist/form-associated/withFormAssociated.d.ts +5 -0
  170. package/dist/form-associated/withFormAssociated.js +1 -0
  171. package/dist/index.d.ts +10 -0
  172. package/dist/index.js +9 -0
  173. package/dist/reatom-lit/ReatomLitElement.d.ts +27 -0
  174. package/dist/reatom-lit/ReatomLitElement.js +118 -0
  175. package/dist/reatom-lit/html.d.ts +4 -0
  176. package/dist/reatom-lit/html.js +10 -0
  177. package/dist/reatom-lit/index.d.ts +4 -0
  178. package/dist/reatom-lit/index.js +4 -0
  179. package/dist/reatom-lit/watch.d.ts +15 -0
  180. package/dist/reatom-lit/watch.js +40 -0
  181. package/dist/reatom-lit/withReatomElement.d.ts +4 -0
  182. package/dist/reatom-lit/withReatomElement.js +57 -0
  183. package/dist/register.d.ts +1 -0
  184. package/dist/register.js +84 -0
  185. package/dist/styles/component-styles.d.ts +4 -0
  186. package/dist/styles/component-styles.js +78 -0
  187. package/dist/theme/cv-theme-provider.d.ts +32 -0
  188. package/dist/theme/cv-theme-provider.js +110 -0
  189. package/dist/theme/index.d.ts +4 -0
  190. package/dist/theme/index.js +2 -0
  191. package/dist/theme/theme-engine.d.ts +4 -0
  192. package/dist/theme/theme-engine.js +67 -0
  193. package/dist/theme/tokens.css +265 -0
  194. package/dist/theme/types.d.ts +7 -0
  195. package/dist/theme/types.js +1 -0
  196. package/dist/toast/create-toast-controller.d.ts +12 -0
  197. package/dist/toast/create-toast-controller.js +12 -0
  198. package/dist/toast/index.d.ts +2 -0
  199. package/dist/toast/index.js +1 -0
  200. package/package.json +146 -0
  201. package/specs/_template.md +110 -0
  202. package/specs/components/accordion.md +207 -0
  203. package/specs/components/alert.md +83 -0
  204. package/specs/components/badge.md +183 -0
  205. package/specs/components/breadcrumb.md +152 -0
  206. package/specs/components/button.md +227 -0
  207. package/specs/components/callout.md +153 -0
  208. package/specs/components/card.md +192 -0
  209. package/specs/components/carousel.md +232 -0
  210. package/specs/components/checkbox.md +141 -0
  211. package/specs/components/combobox.md +427 -0
  212. package/specs/components/context-menu.md +375 -0
  213. package/specs/components/copy-button.md +236 -0
  214. package/specs/components/date-picker.md +290 -0
  215. package/specs/components/dialog.md +184 -0
  216. package/specs/components/disclosure.md +151 -0
  217. package/specs/components/drawer.md +216 -0
  218. package/specs/components/feed.md +266 -0
  219. package/specs/components/grid.md +423 -0
  220. package/specs/components/input.md +237 -0
  221. package/specs/components/landmark.md +92 -0
  222. package/specs/components/link.md +117 -0
  223. package/specs/components/listbox.md +327 -0
  224. package/specs/components/menu.md +508 -0
  225. package/specs/components/meter.md +148 -0
  226. package/specs/components/number.md +268 -0
  227. package/specs/components/option.md +167 -0
  228. package/specs/components/popover.md +207 -0
  229. package/specs/components/progress-ring.md +134 -0
  230. package/specs/components/progress.md +110 -0
  231. package/specs/components/radio.md +208 -0
  232. package/specs/components/select.md +305 -0
  233. package/specs/components/sidebar.md +204 -0
  234. package/specs/components/spinbutton.md +157 -0
  235. package/specs/components/spinner.md +83 -0
  236. package/specs/components/switch.md +145 -0
  237. package/specs/components/table.md +372 -0
  238. package/specs/components/tabs.md +242 -0
  239. package/specs/components/textarea.md +166 -0
  240. package/specs/components/theme.md +364 -0
  241. package/specs/components/toast.md +198 -0
  242. package/specs/components/toolbar.md +258 -0
  243. package/specs/components/tooltip.md +152 -0
  244. package/specs/components/treegrid.md +363 -0
  245. package/specs/components/treeview.md +263 -0
  246. package/specs/components/window-splitter.md +225 -0
@@ -0,0 +1,45 @@
1
+ import type { PropertyValues } from 'lit';
2
+ import { ReatomLitElement } from '../reatom-lit/ReatomLitElement.js';
3
+ export declare class CVProgress extends ReatomLitElement {
4
+ static elementName: string;
5
+ static get properties(): {
6
+ value: {
7
+ type: NumberConstructor;
8
+ reflect: boolean;
9
+ };
10
+ min: {
11
+ type: NumberConstructor;
12
+ reflect: boolean;
13
+ };
14
+ max: {
15
+ type: NumberConstructor;
16
+ reflect: boolean;
17
+ };
18
+ indeterminate: {
19
+ type: BooleanConstructor;
20
+ reflect: boolean;
21
+ };
22
+ valueText: {
23
+ type: StringConstructor;
24
+ attribute: string;
25
+ };
26
+ ariaLabel: {
27
+ type: StringConstructor;
28
+ attribute: string;
29
+ };
30
+ };
31
+ value: number;
32
+ min: number;
33
+ max: number;
34
+ indeterminate: boolean;
35
+ valueText: string;
36
+ ariaLabel: string;
37
+ private readonly idBase;
38
+ private model;
39
+ constructor();
40
+ static styles: import("lit").CSSResult[];
41
+ static define(): void;
42
+ willUpdate(changedProperties: PropertyValues): void;
43
+ private createModel;
44
+ protected render(): import("lit").TemplateResult<1>;
45
+ }
@@ -0,0 +1,148 @@
1
+ import { createProgress } from '@chromvoid/headless-ui/progress';
2
+ import { css, html, nothing } from 'lit';
3
+ import { ReatomLitElement } from '../reatom-lit/ReatomLitElement.js';
4
+ let cvProgressNonce = 0;
5
+ export class CVProgress extends ReatomLitElement {
6
+ static elementName = 'cv-progress';
7
+ static get properties() {
8
+ return {
9
+ value: { type: Number, reflect: true },
10
+ min: { type: Number, reflect: true },
11
+ max: { type: Number, reflect: true },
12
+ indeterminate: { type: Boolean, reflect: true },
13
+ valueText: { type: String, attribute: 'value-text' },
14
+ ariaLabel: { type: String, attribute: 'aria-label' },
15
+ };
16
+ }
17
+ idBase = `cv-progress-${++cvProgressNonce}`;
18
+ model;
19
+ constructor() {
20
+ super();
21
+ this.value = 0;
22
+ this.min = 0;
23
+ this.max = 100;
24
+ this.indeterminate = false;
25
+ this.valueText = '';
26
+ this.ariaLabel = '';
27
+ this.model = this.createModel();
28
+ }
29
+ static styles = [
30
+ css `
31
+ :host {
32
+ display: block;
33
+ }
34
+
35
+ [part='base'] {
36
+ position: relative;
37
+ inline-size: 100%;
38
+ block-size: var(--cv-progress-height, 10px);
39
+ border-radius: 999px;
40
+ border: 1px solid var(--cv-color-border, #2a3245);
41
+ background: var(--cv-progress-track-color, var(--cv-color-surface, #141923));
42
+ overflow: hidden;
43
+ }
44
+
45
+ [part='indicator'] {
46
+ block-size: 100%;
47
+ inline-size: var(--cv-progress-width, 0%);
48
+ border-radius: inherit;
49
+ background: linear-gradient(
50
+ 90deg,
51
+ var(--cv-progress-indicator-color, var(--cv-color-primary, #65d7ff)) 0%,
52
+ color-mix(in oklab, var(--cv-progress-indicator-color, var(--cv-color-primary, #65d7ff)) 70%, white)
53
+ 100%
54
+ );
55
+ transition: inline-size var(--cv-duration-normal, 220ms) var(--cv-easing-standard, ease);
56
+ position: relative;
57
+ }
58
+
59
+ [part='label'] {
60
+ position: absolute;
61
+ inset: 0;
62
+ display: flex;
63
+ align-items: center;
64
+ justify-content: center;
65
+ color: var(--cv-progress-label-color, var(--cv-color-text, #e8ecf6));
66
+ }
67
+
68
+ :host([indeterminate]) [part='indicator'] {
69
+ inline-size: 35%;
70
+ animation: cv-progress-indeterminate 1.15s linear infinite;
71
+ }
72
+
73
+ :host([data-complete]) [part='indicator'] {
74
+ background: linear-gradient(
75
+ 90deg,
76
+ var(--cv-color-success, #6ef7c8) 0%,
77
+ color-mix(in oklab, var(--cv-color-success, #6ef7c8) 70%, white) 100%
78
+ );
79
+ }
80
+
81
+ @keyframes cv-progress-indeterminate {
82
+ 0% {
83
+ transform: translateX(-120%);
84
+ }
85
+ 100% {
86
+ transform: translateX(320%);
87
+ }
88
+ }
89
+ `,
90
+ ];
91
+ static define() {
92
+ if (!customElements.get(this.elementName)) {
93
+ customElements.define(this.elementName, this);
94
+ }
95
+ }
96
+ willUpdate(changedProperties) {
97
+ super.willUpdate(changedProperties);
98
+ if (changedProperties.has('min') ||
99
+ changedProperties.has('max') ||
100
+ changedProperties.has('valueText') ||
101
+ changedProperties.has('ariaLabel')) {
102
+ this.model = this.createModel();
103
+ return;
104
+ }
105
+ if (changedProperties.has('value') && this.model.state.value() !== this.value) {
106
+ this.model.actions.setValue(this.value);
107
+ }
108
+ if (changedProperties.has('indeterminate')) {
109
+ this.model.actions.setIndeterminate(this.indeterminate);
110
+ }
111
+ }
112
+ createModel() {
113
+ return createProgress({
114
+ idBase: this.idBase,
115
+ value: this.value,
116
+ min: this.min,
117
+ max: this.max,
118
+ isIndeterminate: this.indeterminate,
119
+ valueText: this.valueText || undefined,
120
+ ariaLabel: this.ariaLabel || undefined,
121
+ });
122
+ }
123
+ render() {
124
+ const props = this.model.contracts.getProgressProps();
125
+ const percentage = Math.max(0, Math.min(100, this.model.state.percentage()));
126
+ const isComplete = this.model.state.isComplete();
127
+ this.toggleAttribute('data-complete', isComplete);
128
+ return html `
129
+ <div
130
+ id=${props.id}
131
+ role=${props.role}
132
+ aria-valuenow=${props['aria-valuenow'] ?? nothing}
133
+ aria-valuemin=${props['aria-valuemin'] ?? nothing}
134
+ aria-valuemax=${props['aria-valuemax'] ?? nothing}
135
+ aria-valuetext=${props['aria-valuetext'] ?? nothing}
136
+ aria-label=${props['aria-label'] ?? nothing}
137
+ aria-labelledby=${props['aria-labelledby'] ?? nothing}
138
+ aria-describedby=${props['aria-describedby'] ?? nothing}
139
+ part="base"
140
+ >
141
+ <div
142
+ part="indicator"
143
+ style=${this.indeterminate ? nothing : `--cv-progress-width:${percentage}%;`}
144
+ ><span part="label"><slot></slot></span></div>
145
+ </div>
146
+ `;
147
+ }
148
+ }
@@ -0,0 +1,79 @@
1
+ import type { PropertyValues } from 'lit';
2
+ import { FormAssociatedReatomElement } from '../form-associated/FormAssociatedReatomElement.js';
3
+ import type { FormAssociatedValidity } from '../form-associated/withFormAssociated.js';
4
+ type CVRadioGroupOrientation = 'horizontal' | 'vertical';
5
+ export interface CVRadioGroupEventDetail {
6
+ value: string | null;
7
+ activeId: string | null;
8
+ }
9
+ export declare class CVRadioGroup extends FormAssociatedReatomElement {
10
+ static elementName: string;
11
+ static get properties(): {
12
+ name: {
13
+ type: StringConstructor;
14
+ };
15
+ value: {
16
+ type: StringConstructor;
17
+ reflect: boolean;
18
+ };
19
+ orientation: {
20
+ type: StringConstructor;
21
+ reflect: boolean;
22
+ };
23
+ disabled: {
24
+ type: BooleanConstructor;
25
+ reflect: boolean;
26
+ };
27
+ required: {
28
+ type: BooleanConstructor;
29
+ reflect: boolean;
30
+ };
31
+ ariaLabel: {
32
+ type: StringConstructor;
33
+ attribute: string;
34
+ };
35
+ };
36
+ name: string;
37
+ value: string;
38
+ orientation: CVRadioGroupOrientation;
39
+ disabled: boolean;
40
+ required: boolean;
41
+ ariaLabel: string;
42
+ private readonly idBase;
43
+ private radioRecords;
44
+ private radioListeners;
45
+ private model?;
46
+ private defaultValue;
47
+ private didCaptureDefaultValue;
48
+ constructor();
49
+ static styles: import("lit").CSSResult[];
50
+ static define(): void;
51
+ connectedCallback(): void;
52
+ disconnectedCallback(): void;
53
+ willUpdate(changedProperties: PropertyValues): void;
54
+ updated(changedProperties: PropertyValues): void;
55
+ private getRadioElements;
56
+ private ensureRadioValue;
57
+ private resolveConfiguredValue;
58
+ private rebuildModelFromSlot;
59
+ private detachRadioListeners;
60
+ private attachRadioListeners;
61
+ private syncRadioElements;
62
+ private focusActiveRadio;
63
+ private dispatchInput;
64
+ private dispatchChange;
65
+ private applyInteractionResult;
66
+ private handleRadioClick;
67
+ private handleGroupKeyDown;
68
+ private handleSlotChange;
69
+ protected onFormDisabledChanged(_disabled: boolean): void;
70
+ protected onFormReset(): void;
71
+ protected onFormStateRestore(state: string | File | FormData | null): void;
72
+ protected isFormAssociatedDisabled(): boolean;
73
+ protected getFormAssociatedValue(): string | File | FormData | null;
74
+ protected getFormAssociatedValidity(): FormAssociatedValidity;
75
+ private isEffectivelyDisabled;
76
+ private restoreValue;
77
+ protected render(): import("lit").TemplateResult<1>;
78
+ }
79
+ export {};
@@ -0,0 +1,398 @@
1
+ import { createRadioGroup } from '@chromvoid/headless-ui/radio-group';
2
+ import { css, html, nothing } from 'lit';
3
+ import { FormAssociatedReatomElement } from '../form-associated/FormAssociatedReatomElement.js';
4
+ import { CVRadio } from './cv-radio.js';
5
+ const radioGroupNavigationKeys = new Set([
6
+ 'ArrowUp',
7
+ 'ArrowDown',
8
+ 'ArrowLeft',
9
+ 'ArrowRight',
10
+ 'Home',
11
+ 'End',
12
+ ' ',
13
+ 'Spacebar',
14
+ ]);
15
+ let cvRadioGroupNonce = 0;
16
+ export class CVRadioGroup extends FormAssociatedReatomElement {
17
+ static elementName = 'cv-radio-group';
18
+ static get properties() {
19
+ return {
20
+ name: { type: String },
21
+ value: { type: String, reflect: true },
22
+ orientation: { type: String, reflect: true },
23
+ disabled: { type: Boolean, reflect: true },
24
+ required: { type: Boolean, reflect: true },
25
+ ariaLabel: { type: String, attribute: 'aria-label' },
26
+ };
27
+ }
28
+ idBase = `cv-radio-group-${++cvRadioGroupNonce}`;
29
+ radioRecords = [];
30
+ radioListeners = new WeakMap();
31
+ model;
32
+ defaultValue = '';
33
+ didCaptureDefaultValue = false;
34
+ constructor() {
35
+ super();
36
+ this.name = '';
37
+ this.value = '';
38
+ this.orientation = 'horizontal';
39
+ this.disabled = false;
40
+ this.required = false;
41
+ this.ariaLabel = '';
42
+ }
43
+ static styles = [
44
+ css `
45
+ :host {
46
+ display: inline-block;
47
+ --cv-radio-group-gap: var(--cv-space-2, 8px);
48
+ }
49
+
50
+ [part='base'] {
51
+ display: inline-flex;
52
+ flex-wrap: wrap;
53
+ align-items: center;
54
+ gap: var(--cv-radio-group-gap);
55
+ padding: var(--cv-space-1, 4px);
56
+ border-radius: var(--cv-radius-md, 10px);
57
+ border: 1px solid var(--cv-color-border, #2a3245);
58
+ background: var(--cv-color-surface, #141923);
59
+ }
60
+
61
+ :host([orientation='vertical']) [part='base'] {
62
+ display: inline-grid;
63
+ justify-items: start;
64
+ }
65
+
66
+ [part='base']:focus-visible {
67
+ outline: 2px solid var(--cv-color-primary, #65d7ff);
68
+ outline-offset: 1px;
69
+ }
70
+
71
+ :host([disabled]) [part='base'] {
72
+ opacity: 0.7;
73
+ }
74
+ `,
75
+ ];
76
+ static define() {
77
+ if (!customElements.get(this.elementName)) {
78
+ customElements.define(this.elementName, this);
79
+ }
80
+ }
81
+ connectedCallback() {
82
+ super.connectedCallback();
83
+ if (!this.model) {
84
+ this.rebuildModelFromSlot(false, false);
85
+ }
86
+ if (!this.didCaptureDefaultValue) {
87
+ this.defaultValue = this.model?.state.value() ?? '';
88
+ this.didCaptureDefaultValue = true;
89
+ }
90
+ this.syncFormAssociatedState();
91
+ }
92
+ disconnectedCallback() {
93
+ super.disconnectedCallback();
94
+ this.detachRadioListeners();
95
+ }
96
+ willUpdate(changedProperties) {
97
+ super.willUpdate(changedProperties);
98
+ if (changedProperties.has('orientation') || changedProperties.has('ariaLabel')) {
99
+ this.rebuildModelFromSlot(true, false);
100
+ this.syncFormAssociatedState();
101
+ return;
102
+ }
103
+ if (changedProperties.has('disabled')) {
104
+ this.model?.actions.setDisabled(this.isEffectivelyDisabled());
105
+ }
106
+ if (changedProperties.has('value') && this.model) {
107
+ const next = this.value.trim();
108
+ if (next.length === 0) {
109
+ this.restoreValue(null);
110
+ this.syncFormAssociatedState();
111
+ return;
112
+ }
113
+ const enabledIds = new Set(this.radioRecords.filter((record) => !record.disabled).map((record) => record.id));
114
+ if (!enabledIds.has(next)) {
115
+ this.syncFormAssociatedState();
116
+ return;
117
+ }
118
+ if (this.model.state.value() !== next) {
119
+ const previousValue = this.model.state.value();
120
+ const previousActive = this.model.state.activeId();
121
+ this.model.actions.select(next);
122
+ this.applyInteractionResult(previousValue, previousActive);
123
+ }
124
+ }
125
+ if (changedProperties.has('value') ||
126
+ changedProperties.has('disabled') ||
127
+ changedProperties.has('required') ||
128
+ changedProperties.has('name')) {
129
+ this.syncFormAssociatedState();
130
+ }
131
+ }
132
+ updated(changedProperties) {
133
+ super.updated(changedProperties);
134
+ if (!changedProperties.has('value')) {
135
+ this.syncRadioElements();
136
+ }
137
+ if (changedProperties.has('value') ||
138
+ changedProperties.has('disabled') ||
139
+ changedProperties.has('required') ||
140
+ changedProperties.has('name') ||
141
+ changedProperties.has('orientation') ||
142
+ changedProperties.has('ariaLabel')) {
143
+ this.syncFormAssociatedState();
144
+ }
145
+ }
146
+ getRadioElements() {
147
+ return Array.from(this.children).filter((element) => element.tagName.toLowerCase() === CVRadio.elementName);
148
+ }
149
+ ensureRadioValue(radio, index) {
150
+ const normalized = radio.value?.trim();
151
+ if (normalized)
152
+ return normalized;
153
+ const fallback = `radio-${index + 1}`;
154
+ radio.value = fallback;
155
+ return fallback;
156
+ }
157
+ resolveConfiguredValue(radios) {
158
+ const propertyValue = this.value.trim();
159
+ if (propertyValue.length > 0) {
160
+ return propertyValue;
161
+ }
162
+ for (const [index, radio] of radios.entries()) {
163
+ if (radio.checked && !radio.disabled) {
164
+ return this.ensureRadioValue(radio, index);
165
+ }
166
+ }
167
+ return null;
168
+ }
169
+ rebuildModelFromSlot(preserveSelection, requestRender = true) {
170
+ const radios = this.getRadioElements();
171
+ const configuredValue = this.resolveConfiguredValue(radios);
172
+ const previousValue = preserveSelection ? (this.model?.state.value() ?? configuredValue) : configuredValue;
173
+ const previousActive = preserveSelection ? (this.model?.state.activeId() ?? previousValue) : previousValue;
174
+ this.detachRadioListeners();
175
+ this.radioRecords = radios.map((element, index) => {
176
+ const id = this.ensureRadioValue(element, index);
177
+ const label = element.textContent?.trim() || id;
178
+ const hasDescription = element.querySelector('[slot="description"]') !== null;
179
+ return {
180
+ id,
181
+ label,
182
+ disabled: element.disabled,
183
+ hasDescription,
184
+ element,
185
+ };
186
+ });
187
+ const enabledIds = new Set(this.radioRecords.filter((record) => !record.disabled).map((record) => record.id));
188
+ const initialValue = previousValue && enabledIds.has(previousValue) ? previousValue : null;
189
+ const initialActiveId = previousActive && enabledIds.has(previousActive)
190
+ ? previousActive
191
+ : (initialValue ?? this.radioRecords.find((record) => !record.disabled)?.id ?? null);
192
+ this.model = createRadioGroup({
193
+ idBase: this.idBase,
194
+ items: this.radioRecords.map((record) => ({
195
+ id: record.id,
196
+ disabled: record.disabled,
197
+ describedBy: record.hasDescription ? `${this.idBase}-radio-${record.id}-desc` : undefined,
198
+ })),
199
+ orientation: this.orientation,
200
+ isDisabled: this.isEffectivelyDisabled(),
201
+ ariaLabel: this.ariaLabel || undefined,
202
+ initialValue,
203
+ initialActiveId,
204
+ });
205
+ this.attachRadioListeners();
206
+ this.syncRadioElements();
207
+ this.value = this.model.state.value() ?? '';
208
+ if (requestRender) {
209
+ this.requestUpdate();
210
+ }
211
+ }
212
+ detachRadioListeners() {
213
+ for (const record of this.radioRecords) {
214
+ const listeners = this.radioListeners.get(record.element);
215
+ if (!listeners)
216
+ continue;
217
+ record.element.removeEventListener('click', listeners.click);
218
+ record.element.removeEventListener('keydown', listeners.keydown);
219
+ this.radioListeners.delete(record.element);
220
+ }
221
+ }
222
+ attachRadioListeners() {
223
+ if (!this.model)
224
+ return;
225
+ for (const record of this.radioRecords) {
226
+ const click = () => {
227
+ this.handleRadioClick(record.id);
228
+ };
229
+ const keydown = (event) => {
230
+ event.stopPropagation();
231
+ this.handleGroupKeyDown(event);
232
+ };
233
+ record.element.addEventListener('click', click);
234
+ record.element.addEventListener('keydown', keydown);
235
+ this.radioListeners.set(record.element, { click, keydown });
236
+ }
237
+ }
238
+ syncRadioElements() {
239
+ if (!this.model)
240
+ return;
241
+ for (const record of this.radioRecords) {
242
+ const props = this.model.contracts.getRadioProps(record.id);
243
+ record.element.id = props.id;
244
+ record.element.setAttribute('role', props.role);
245
+ record.element.setAttribute('tabindex', props.tabindex);
246
+ record.element.setAttribute('aria-checked', props['aria-checked']);
247
+ if (props['aria-disabled']) {
248
+ record.element.setAttribute('aria-disabled', props['aria-disabled']);
249
+ }
250
+ else {
251
+ record.element.removeAttribute('aria-disabled');
252
+ }
253
+ if (props['aria-describedby']) {
254
+ record.element.setAttribute('aria-describedby', props['aria-describedby']);
255
+ }
256
+ else {
257
+ record.element.removeAttribute('aria-describedby');
258
+ }
259
+ if (props['data-active'] === 'true') {
260
+ record.element.setAttribute('data-active', 'true');
261
+ record.element.active = true;
262
+ }
263
+ else {
264
+ record.element.removeAttribute('data-active');
265
+ record.element.active = false;
266
+ }
267
+ record.element.checked = props['aria-checked'] === 'true';
268
+ record.element.disabled = props['aria-disabled'] === 'true';
269
+ }
270
+ }
271
+ focusActiveRadio() {
272
+ if (!this.model)
273
+ return;
274
+ const activeId = this.model.state.activeId();
275
+ if (!activeId)
276
+ return;
277
+ const activeRecord = this.radioRecords.find((record) => record.id === activeId);
278
+ activeRecord?.element.focus();
279
+ }
280
+ dispatchInput(detail) {
281
+ this.dispatchEvent(new CustomEvent('cv-input', {
282
+ detail,
283
+ bubbles: true,
284
+ composed: true,
285
+ }));
286
+ }
287
+ dispatchChange(detail) {
288
+ this.dispatchEvent(new CustomEvent('cv-change', {
289
+ detail,
290
+ bubbles: true,
291
+ composed: true,
292
+ }));
293
+ }
294
+ applyInteractionResult(previousValue, previousActive) {
295
+ if (!this.model)
296
+ return;
297
+ this.syncRadioElements();
298
+ const nextValue = this.model.state.value();
299
+ const nextActive = this.model.state.activeId();
300
+ const valueChanged = previousValue !== nextValue;
301
+ const activeChanged = previousActive !== nextActive;
302
+ this.value = nextValue ?? '';
303
+ this.syncFormAssociatedState();
304
+ if (!valueChanged && !activeChanged)
305
+ return;
306
+ const detail = {
307
+ value: nextValue,
308
+ activeId: nextActive,
309
+ };
310
+ this.dispatchInput(detail);
311
+ if (valueChanged) {
312
+ this.dispatchChange(detail);
313
+ }
314
+ if (activeChanged) {
315
+ this.focusActiveRadio();
316
+ }
317
+ }
318
+ handleRadioClick(id) {
319
+ if (!this.model)
320
+ return;
321
+ const previousValue = this.model.state.value();
322
+ const previousActive = this.model.state.activeId();
323
+ this.model.contracts.getRadioProps(id).onClick();
324
+ this.applyInteractionResult(previousValue, previousActive);
325
+ }
326
+ handleGroupKeyDown(event) {
327
+ if (!this.model)
328
+ return;
329
+ if (radioGroupNavigationKeys.has(event.key)) {
330
+ event.preventDefault();
331
+ }
332
+ const previousValue = this.model.state.value();
333
+ const previousActive = this.model.state.activeId();
334
+ this.model.contracts.getRootProps().onKeyDown(event);
335
+ this.applyInteractionResult(previousValue, previousActive);
336
+ }
337
+ handleSlotChange() {
338
+ this.rebuildModelFromSlot(true, true);
339
+ }
340
+ onFormDisabledChanged(_disabled) {
341
+ this.model?.actions.setDisabled(this.isEffectivelyDisabled());
342
+ }
343
+ onFormReset() {
344
+ this.restoreValue(this.defaultValue || null);
345
+ }
346
+ onFormStateRestore(state) {
347
+ this.restoreValue(typeof state === 'string' ? state : null);
348
+ }
349
+ isFormAssociatedDisabled() {
350
+ return this.isEffectivelyDisabled();
351
+ }
352
+ getFormAssociatedValue() {
353
+ return this.model?.state.value() ?? null;
354
+ }
355
+ getFormAssociatedValidity() {
356
+ if (this.required && !this.model?.state.value()) {
357
+ return {
358
+ flags: { valueMissing: true },
359
+ message: 'Please select an option.',
360
+ };
361
+ }
362
+ return { flags: {} };
363
+ }
364
+ isEffectivelyDisabled() {
365
+ return this.disabled || this.formDisabled;
366
+ }
367
+ restoreValue(nextValue) {
368
+ for (const record of this.radioRecords) {
369
+ record.element.checked = nextValue !== null && record.id === nextValue;
370
+ }
371
+ this.value = nextValue ?? '';
372
+ this.rebuildModelFromSlot(false, false);
373
+ this.syncRadioElements();
374
+ this.syncFormAssociatedState();
375
+ }
376
+ render() {
377
+ const rootProps = this.model?.contracts.getRootProps() ?? {
378
+ role: 'radiogroup',
379
+ 'aria-label': this.ariaLabel || undefined,
380
+ 'aria-labelledby': undefined,
381
+ 'aria-disabled': this.isEffectivelyDisabled() ? 'true' : undefined,
382
+ 'aria-orientation': this.orientation,
383
+ };
384
+ return html `
385
+ <div
386
+ role=${rootProps.role}
387
+ aria-label=${rootProps['aria-label'] ?? nothing}
388
+ aria-labelledby=${rootProps['aria-labelledby'] ?? nothing}
389
+ aria-disabled=${rootProps['aria-disabled'] ?? nothing}
390
+ aria-orientation=${rootProps['aria-orientation']}
391
+ part="base"
392
+ @keydown=${this.handleGroupKeyDown}
393
+ >
394
+ <slot @slotchange=${this.handleSlotChange}></slot>
395
+ </div>
396
+ `;
397
+ }
398
+ }
@@ -0,0 +1,36 @@
1
+ import { LitElement } from 'lit';
2
+ export type CVRadioSize = 'small' | 'medium' | 'large';
3
+ export declare class CVRadio extends LitElement {
4
+ static elementName: string;
5
+ static get properties(): {
6
+ value: {
7
+ type: StringConstructor;
8
+ reflect: boolean;
9
+ };
10
+ disabled: {
11
+ type: BooleanConstructor;
12
+ reflect: boolean;
13
+ };
14
+ checked: {
15
+ type: BooleanConstructor;
16
+ reflect: boolean;
17
+ };
18
+ active: {
19
+ type: BooleanConstructor;
20
+ reflect: boolean;
21
+ };
22
+ size: {
23
+ type: StringConstructor;
24
+ reflect: boolean;
25
+ };
26
+ };
27
+ value: string;
28
+ disabled: boolean;
29
+ checked: boolean;
30
+ active: boolean;
31
+ size: CVRadioSize;
32
+ constructor();
33
+ static styles: import("lit").CSSResult[];
34
+ static define(): void;
35
+ protected render(): import("lit").TemplateResult<1>;
36
+ }