@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,553 @@
1
+ import { createNumber } from '@chromvoid/headless-ui/number';
2
+ import { css, html, nothing } from 'lit';
3
+ import { FormAssociatedReatomElement } from '../form-associated/FormAssociatedReatomElement.js';
4
+ let cvNumberNonce = 0;
5
+ export class CVNumber extends FormAssociatedReatomElement {
6
+ static elementName = 'cv-number';
7
+ static hostDisplay = 'inline-block';
8
+ static get properties() {
9
+ return {
10
+ value: { type: Number },
11
+ defaultValue: { type: Number, attribute: 'default-value' },
12
+ min: { type: Number },
13
+ max: { type: Number },
14
+ step: { type: Number },
15
+ largeStep: { type: Number, attribute: 'large-step' },
16
+ name: { type: String },
17
+ disabled: { type: Boolean, reflect: true },
18
+ readOnly: { type: Boolean, attribute: 'read-only', reflect: true },
19
+ required: { type: Boolean, reflect: true },
20
+ clearable: { type: Boolean, reflect: true },
21
+ stepper: { type: Boolean, reflect: true },
22
+ placeholder: { type: String },
23
+ size: { type: String, reflect: true },
24
+ variant: { type: String, reflect: true },
25
+ ariaLabel: { type: String, attribute: 'aria-label' },
26
+ ariaLabelledBy: { type: String, attribute: 'aria-labelledby' },
27
+ ariaDescribedBy: { type: String, attribute: 'aria-describedby' },
28
+ };
29
+ }
30
+ idBase = `cv-number-${++cvNumberNonce}`;
31
+ model;
32
+ modelInitialized = false;
33
+ _valueOnFocus = null;
34
+ constructor() {
35
+ super();
36
+ this.value = 0;
37
+ this.defaultValue = undefined;
38
+ this.min = undefined;
39
+ this.max = undefined;
40
+ this.step = 1;
41
+ this.largeStep = 10;
42
+ this.name = '';
43
+ this.disabled = false;
44
+ this.readOnly = false;
45
+ this.required = false;
46
+ this.clearable = false;
47
+ this.stepper = false;
48
+ this.placeholder = '';
49
+ this.size = 'medium';
50
+ this.variant = 'outlined';
51
+ this.ariaLabel = '';
52
+ this.ariaLabelledBy = '';
53
+ this.ariaDescribedBy = '';
54
+ }
55
+ static styles = [
56
+ css `
57
+ :host {
58
+ --cv-number-height: 36px;
59
+ --cv-number-padding-inline: var(--cv-space-3, 12px);
60
+ --cv-number-font-size: var(--cv-font-size-base, 14px);
61
+ --cv-number-border-radius: var(--cv-radius-sm, 6px);
62
+ --cv-number-border-color: var(--cv-color-border, #2a3245);
63
+ --cv-number-background: transparent;
64
+ --cv-number-color: var(--cv-color-text, #e8ecf6);
65
+ --cv-number-placeholder-color: var(--cv-color-text-muted, #6b7a99);
66
+ --cv-number-focus-ring: 0 0 0 2px var(--cv-color-primary, #65d7ff);
67
+ --cv-number-icon-size: 1em;
68
+ --cv-number-gap: var(--cv-space-2, 8px);
69
+ --cv-number-transition-duration: var(--cv-duration-fast, 120ms);
70
+ --cv-number-stepper-width: 24px;
71
+ }
72
+
73
+ [part='base'] {
74
+ gap: var(--cv-number-gap);
75
+ padding-inline: var(--cv-number-padding-inline);
76
+ height: var(--cv-number-height);
77
+ font-size: var(--cv-number-font-size);
78
+ border-radius: var(--cv-number-border-radius);
79
+ border: 1px solid var(--cv-number-border-color);
80
+ background: var(--cv-number-background);
81
+ color: var(--cv-number-color);
82
+ cursor: text;
83
+ transition:
84
+ border-color var(--cv-number-transition-duration) var(--cv-easing-standard, ease),
85
+ background var(--cv-number-transition-duration) var(--cv-easing-standard, ease),
86
+ box-shadow var(--cv-number-transition-duration) var(--cv-easing-standard, ease);
87
+ box-sizing: border-box;
88
+ width: 100%;
89
+ }
90
+
91
+ [part='input'] {
92
+ border: none;
93
+ outline: none;
94
+ background: transparent;
95
+ color: inherit;
96
+ font: inherit;
97
+ padding: 0;
98
+ margin: 0;
99
+ font-variant-numeric: tabular-nums;
100
+ }
101
+
102
+ [part='input']::placeholder {
103
+ color: var(--cv-number-placeholder-color);
104
+ }
105
+
106
+ [part='prefix'],
107
+ [part='suffix'],
108
+ [part='clear-button'] {
109
+ font-size: var(--cv-number-icon-size);
110
+ }
111
+
112
+ [part='clear-button'] {
113
+ cursor: pointer;
114
+ user-select: none;
115
+ }
116
+
117
+ [part='stepper'] {
118
+ display: inline-flex;
119
+ flex-direction: column;
120
+ gap: 1px;
121
+ }
122
+
123
+ [part='increment'],
124
+ [part='decrement'] {
125
+ width: var(--cv-number-stepper-width);
126
+ border-radius: 4px;
127
+ border: 1px solid var(--cv-color-border, #2a3245);
128
+ background: var(--cv-color-surface-elevated, #1d2432);
129
+ color: var(--cv-color-text, #e8ecf6);
130
+ padding: 0;
131
+ line-height: 1;
132
+ cursor: pointer;
133
+ }
134
+
135
+ [part='form-control-label'] {
136
+ display: block;
137
+ }
138
+
139
+ [part='form-control-help-text'] {
140
+ display: block;
141
+ }
142
+
143
+ /* --- variant: outlined (default) --- */
144
+ :host([variant='outlined']) [part='base'] {
145
+ border-color: var(--cv-number-border-color);
146
+ background: var(--cv-number-background);
147
+ }
148
+
149
+ /* --- variant: filled --- */
150
+ :host([variant='filled']) [part='base'] {
151
+ background: var(--cv-color-surface, #141923);
152
+ border-color: transparent;
153
+ }
154
+
155
+ /* --- focused --- */
156
+ :host([focused]) [part='base'] {
157
+ box-shadow: var(--cv-number-focus-ring);
158
+ }
159
+
160
+ /* --- sizes --- */
161
+ :host([size='small']) {
162
+ --cv-number-height: 30px;
163
+ --cv-number-padding-inline: var(--cv-space-2, 8px);
164
+ --cv-number-font-size: var(--cv-font-size-sm, 13px);
165
+ }
166
+
167
+ :host([size='large']) {
168
+ --cv-number-height: 42px;
169
+ --cv-number-padding-inline: var(--cv-space-4, 16px);
170
+ --cv-number-font-size: var(--cv-font-size-md, 16px);
171
+ }
172
+
173
+ /* --- disabled --- */
174
+ :host([disabled]) {
175
+ pointer-events: none;
176
+ }
177
+
178
+ :host([disabled]) [part='base'] {
179
+ opacity: 0.55;
180
+ cursor: not-allowed;
181
+ }
182
+
183
+ :host([disabled]) [part='input'] {
184
+ cursor: not-allowed;
185
+ }
186
+
187
+ /* --- read-only --- */
188
+ :host([read-only]) [part='base'] {
189
+ cursor: default;
190
+ }
191
+
192
+ :host([read-only]) [part='input'] {
193
+ cursor: default;
194
+ }
195
+
196
+ /* --- required --- */
197
+ :host([required]) {
198
+ /* No default visual change; stylable via part selectors */
199
+ }
200
+
201
+ /* --- clearable --- */
202
+ :host([clearable]) {
203
+ /* Clear button space reserved in layout */
204
+ }
205
+
206
+ /* --- stepper --- */
207
+ :host([stepper]) {
208
+ /* Stepper buttons rendered and visible */
209
+ }
210
+ `,
211
+ ];
212
+ static define() {
213
+ if (!customElements.get(this.elementName)) {
214
+ customElements.define(this.elementName, this);
215
+ }
216
+ }
217
+ isEffectivelyDisabled() {
218
+ return this.disabled || this.formDisabled;
219
+ }
220
+ isFormAssociatedDisabled() {
221
+ return this.isEffectivelyDisabled();
222
+ }
223
+ getFormAssociatedValue() {
224
+ if (!this.modelInitialized)
225
+ return String(this.value);
226
+ return String(this.model.state.value());
227
+ }
228
+ toFiniteOrUndefined(value) {
229
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
230
+ }
231
+ createModel() {
232
+ return createNumber({
233
+ idBase: this.idBase,
234
+ value: this.value,
235
+ defaultValue: this.toFiniteOrUndefined(this.defaultValue),
236
+ min: this.toFiniteOrUndefined(this.min),
237
+ max: this.toFiniteOrUndefined(this.max),
238
+ step: this.step,
239
+ largeStep: this.largeStep,
240
+ disabled: this.isEffectivelyDisabled(),
241
+ readonly: this.readOnly,
242
+ required: this.required,
243
+ clearable: this.clearable,
244
+ stepper: this.stepper,
245
+ placeholder: this.placeholder,
246
+ ariaLabel: this.ariaLabel || undefined,
247
+ ariaLabelledBy: this.ariaLabelledBy || undefined,
248
+ ariaDescribedBy: this.ariaDescribedBy || undefined,
249
+ onClear: () => {
250
+ this.syncValueFromModel();
251
+ this.dispatchEvent(new CustomEvent('cv-clear', {
252
+ detail: {},
253
+ bubbles: true,
254
+ composed: true,
255
+ }));
256
+ },
257
+ });
258
+ }
259
+ ensureModel() {
260
+ if (!this.modelInitialized) {
261
+ this.model = this.createModel();
262
+ this.modelInitialized = true;
263
+ }
264
+ }
265
+ willUpdate(changedProperties) {
266
+ super.willUpdate(changedProperties);
267
+ // First render: create the model with all finalized properties
268
+ if (!this.modelInitialized) {
269
+ this.ensureModel();
270
+ this.syncValueFromModel();
271
+ this.reflectHostAttributes();
272
+ this.syncFormAssociatedState();
273
+ return;
274
+ }
275
+ // Recreate model when immutable spinbutton options change after initialization
276
+ if (changedProperties.has('min') ||
277
+ changedProperties.has('max') ||
278
+ changedProperties.has('step') ||
279
+ changedProperties.has('largeStep') ||
280
+ changedProperties.has('defaultValue') ||
281
+ changedProperties.has('ariaLabel') ||
282
+ changedProperties.has('ariaLabelledBy') ||
283
+ changedProperties.has('ariaDescribedBy')) {
284
+ this.model = this.createModel();
285
+ this.syncValueFromModel();
286
+ this.syncFormAssociatedState();
287
+ this.reflectHostAttributes();
288
+ return;
289
+ }
290
+ // Sync mutable state to headless
291
+ if (changedProperties.has('value') && this.model.state.value() !== this.value) {
292
+ this.model.actions.setValue(this.value);
293
+ this.syncValueFromModel();
294
+ }
295
+ if (changedProperties.has('disabled')) {
296
+ this.model.actions.setDisabled(this.isEffectivelyDisabled());
297
+ }
298
+ if (changedProperties.has('readOnly')) {
299
+ this.model.actions.setReadOnly(this.readOnly);
300
+ }
301
+ if (changedProperties.has('required')) {
302
+ this.model.actions.setRequired(this.required);
303
+ }
304
+ if (changedProperties.has('clearable')) {
305
+ this.model.actions.setClearable(this.clearable);
306
+ }
307
+ if (changedProperties.has('stepper')) {
308
+ this.model.actions.setStepper(this.stepper);
309
+ }
310
+ if (changedProperties.has('placeholder')) {
311
+ this.model.actions.setPlaceholder(this.placeholder);
312
+ }
313
+ this.reflectHostAttributes();
314
+ this.syncFormAssociatedState();
315
+ }
316
+ reflectHostAttributes() {
317
+ this.toggleAttribute('focused', this.model.state.focused());
318
+ this.toggleAttribute('filled', this.model.state.filled());
319
+ }
320
+ syncValueFromModel() {
321
+ const nextValue = this.model.state.value();
322
+ if (this.value !== nextValue) {
323
+ this.value = nextValue;
324
+ }
325
+ }
326
+ // --- Form association ---
327
+ onFormDisabledChanged(_disabled) {
328
+ if (!this.modelInitialized)
329
+ return;
330
+ this.model.actions.setDisabled(this.isEffectivelyDisabled());
331
+ }
332
+ onFormReset() {
333
+ if (!this.modelInitialized)
334
+ return;
335
+ const defaultVal = this.model.state.defaultValue();
336
+ this.model.actions.setValue(defaultVal);
337
+ this.syncValueFromModel();
338
+ }
339
+ onFormStateRestore(state) {
340
+ if (typeof state !== 'string')
341
+ return;
342
+ if (!this.modelInitialized)
343
+ return;
344
+ const parsed = Number(state);
345
+ if (!Number.isFinite(parsed))
346
+ return;
347
+ this.model.actions.setValue(parsed);
348
+ this.syncValueFromModel();
349
+ }
350
+ get type() {
351
+ return 'cv-number';
352
+ }
353
+ focus(options) {
354
+ const input = this.shadowRoot?.querySelector('[part="input"]');
355
+ if (input) {
356
+ input.focus(options);
357
+ return;
358
+ }
359
+ super.focus(options);
360
+ }
361
+ select() {
362
+ const input = this.shadowRoot?.querySelector('[part="input"]');
363
+ input?.select();
364
+ }
365
+ // --- Event handlers ---
366
+ handleNativeInput(event) {
367
+ const target = event.target;
368
+ this.model.actions.handleInput(target.value);
369
+ this.requestUpdate();
370
+ }
371
+ handleNativeFocus() {
372
+ this._valueOnFocus = this.model.state.value();
373
+ this.model.actions.setFocused(true);
374
+ this.requestUpdate();
375
+ this.dispatchEvent(new CustomEvent('cv-focus', {
376
+ detail: {},
377
+ bubbles: true,
378
+ composed: true,
379
+ }));
380
+ }
381
+ handleNativeBlur() {
382
+ this.model.actions.setFocused(false);
383
+ this.syncValueFromModel();
384
+ this.requestUpdate();
385
+ this.dispatchEvent(new CustomEvent('cv-blur', {
386
+ detail: {},
387
+ bubbles: true,
388
+ composed: true,
389
+ }));
390
+ const valueAfterCommit = this.model.state.value();
391
+ if (this._valueOnFocus !== null && valueAfterCommit !== this._valueOnFocus) {
392
+ this.dispatchEvent(new CustomEvent('cv-change', {
393
+ detail: { value: valueAfterCommit },
394
+ bubbles: true,
395
+ composed: true,
396
+ }));
397
+ }
398
+ this._valueOnFocus = null;
399
+ }
400
+ handleNativeKeyDown(event) {
401
+ const previousValue = this.model.state.value();
402
+ this.model.actions.handleKeyDown(event);
403
+ this.syncValueFromModel();
404
+ this.requestUpdate();
405
+ const newValue = this.model.state.value();
406
+ if (event.key === 'Enter') {
407
+ if (newValue !== previousValue) {
408
+ this.dispatchEvent(new CustomEvent('cv-change', {
409
+ detail: { value: newValue },
410
+ bubbles: true,
411
+ composed: true,
412
+ }));
413
+ }
414
+ }
415
+ else if (event.key === 'ArrowUp' ||
416
+ event.key === 'ArrowDown' ||
417
+ event.key === 'PageUp' ||
418
+ event.key === 'PageDown' ||
419
+ event.key === 'Home' ||
420
+ event.key === 'End') {
421
+ if (newValue !== previousValue) {
422
+ this.dispatchEvent(new CustomEvent('cv-change', {
423
+ detail: { value: newValue },
424
+ bubbles: true,
425
+ composed: true,
426
+ }));
427
+ }
428
+ }
429
+ // Escape is handled by the onClear callback in the model
430
+ }
431
+ handleIncrementClick() {
432
+ const previousValue = this.model.state.value();
433
+ this.model.actions.increment();
434
+ this.syncValueFromModel();
435
+ this.requestUpdate();
436
+ const newValue = this.model.state.value();
437
+ if (newValue !== previousValue) {
438
+ this.dispatchEvent(new CustomEvent('cv-change', {
439
+ detail: { value: newValue },
440
+ bubbles: true,
441
+ composed: true,
442
+ }));
443
+ }
444
+ }
445
+ handleDecrementClick() {
446
+ const previousValue = this.model.state.value();
447
+ this.model.actions.decrement();
448
+ this.syncValueFromModel();
449
+ this.requestUpdate();
450
+ const newValue = this.model.state.value();
451
+ if (newValue !== previousValue) {
452
+ this.dispatchEvent(new CustomEvent('cv-change', {
453
+ detail: { value: newValue },
454
+ bubbles: true,
455
+ composed: true,
456
+ }));
457
+ }
458
+ }
459
+ handleClearClick() {
460
+ this.model.actions.clear();
461
+ this.syncValueFromModel();
462
+ this.requestUpdate();
463
+ // cv-clear event is dispatched by the onClear callback in createModel
464
+ }
465
+ // --- Render ---
466
+ render() {
467
+ this.ensureModel();
468
+ const inputProps = this.model.contracts.getInputProps();
469
+ const incrementProps = this.model.contracts.getIncrementButtonProps();
470
+ const decrementProps = this.model.contracts.getDecrementButtonProps();
471
+ const clearButtonProps = this.model.contracts.getClearButtonProps();
472
+ // Draft text management: display draftText when non-null, otherwise String(value)
473
+ const draftText = this.model.state.draftText();
474
+ const displayValue = draftText !== null ? draftText : String(this.model.state.value());
475
+ return html `
476
+ <span part="form-control-label"><slot name="label"></slot></span>
477
+ <div part="base" class="cv-u-control-shell">
478
+ <span part="prefix" class="cv-u-icon-slot"><slot name="prefix"></slot></span>
479
+ <input
480
+ part="input"
481
+ class="cv-u-fill"
482
+ id=${inputProps.id}
483
+ role=${inputProps.role}
484
+ tabindex=${inputProps.tabindex}
485
+ inputmode=${inputProps.inputmode}
486
+ aria-valuenow=${inputProps['aria-valuenow']}
487
+ aria-valuemin=${inputProps['aria-valuemin'] ?? nothing}
488
+ aria-valuemax=${inputProps['aria-valuemax'] ?? nothing}
489
+ aria-valuetext=${inputProps['aria-valuetext'] ?? nothing}
490
+ aria-disabled=${inputProps['aria-disabled'] ?? nothing}
491
+ aria-readonly=${inputProps['aria-readonly'] ?? nothing}
492
+ aria-required=${inputProps['aria-required'] ?? nothing}
493
+ aria-label=${inputProps['aria-label'] ?? nothing}
494
+ aria-labelledby=${inputProps['aria-labelledby'] ?? nothing}
495
+ aria-describedby=${inputProps['aria-describedby'] ?? nothing}
496
+ placeholder=${inputProps.placeholder ?? nothing}
497
+ autocomplete=${inputProps.autocomplete}
498
+ .value=${displayValue}
499
+ @input=${this.handleNativeInput}
500
+ @focus=${this.handleNativeFocus}
501
+ @blur=${this.handleNativeBlur}
502
+ @keydown=${this.handleNativeKeyDown}
503
+ />
504
+ <span
505
+ part="clear-button"
506
+ class="cv-u-icon-slot"
507
+ role=${clearButtonProps.role}
508
+ aria-label=${clearButtonProps['aria-label']}
509
+ tabindex=${clearButtonProps.tabindex}
510
+ ?hidden=${clearButtonProps.hidden}
511
+ aria-hidden=${clearButtonProps['aria-hidden'] ?? nothing}
512
+ @click=${this.handleClearClick}
513
+ >
514
+ <slot name="clear-icon">&times;</slot>
515
+ </span>
516
+ <span
517
+ part="stepper"
518
+ ?hidden=${incrementProps.hidden}
519
+ aria-hidden=${incrementProps['aria-hidden'] ?? nothing}
520
+ >
521
+ <button
522
+ part="increment"
523
+ type="button"
524
+ id=${incrementProps.id}
525
+ tabindex=${incrementProps.tabindex}
526
+ aria-label=${incrementProps['aria-label']}
527
+ aria-disabled=${incrementProps['aria-disabled'] ?? nothing}
528
+ ?hidden=${incrementProps.hidden}
529
+ aria-hidden=${incrementProps['aria-hidden'] ?? nothing}
530
+ @click=${this.handleIncrementClick}
531
+ >
532
+ +
533
+ </button>
534
+ <button
535
+ part="decrement"
536
+ type="button"
537
+ id=${decrementProps.id}
538
+ tabindex=${decrementProps.tabindex}
539
+ aria-label=${decrementProps['aria-label']}
540
+ aria-disabled=${decrementProps['aria-disabled'] ?? nothing}
541
+ ?hidden=${decrementProps.hidden}
542
+ aria-hidden=${decrementProps['aria-hidden'] ?? nothing}
543
+ @click=${this.handleDecrementClick}
544
+ >
545
+ -
546
+ </button>
547
+ </span>
548
+ <span part="suffix" class="cv-u-icon-slot"><slot name="suffix"></slot></span>
549
+ </div>
550
+ <span part="form-control-help-text"><slot name="help-text"></slot></span>
551
+ `;
552
+ }
553
+ }
@@ -0,0 +1,30 @@
1
+ import { LitElement } from 'lit';
2
+ export declare class CVOption extends LitElement {
3
+ static elementName: string;
4
+ static get properties(): {
5
+ value: {
6
+ type: StringConstructor;
7
+ reflect: boolean;
8
+ };
9
+ disabled: {
10
+ type: BooleanConstructor;
11
+ reflect: boolean;
12
+ };
13
+ selected: {
14
+ type: BooleanConstructor;
15
+ reflect: boolean;
16
+ };
17
+ active: {
18
+ type: BooleanConstructor;
19
+ reflect: boolean;
20
+ };
21
+ };
22
+ value: string;
23
+ disabled: boolean;
24
+ selected: boolean;
25
+ active: boolean;
26
+ constructor();
27
+ static styles: import("lit").CSSResult[];
28
+ static define(): void;
29
+ protected render(): import("lit").TemplateResult<1>;
30
+ }
@@ -0,0 +1,84 @@
1
+ import { LitElement, css, html } from 'lit';
2
+ import { componentResetStyles, getComponentHostDisplayStyles } from '../styles/component-styles.js';
3
+ export class CVOption extends LitElement {
4
+ static elementName = 'cv-option';
5
+ static get properties() {
6
+ return {
7
+ value: { type: String, reflect: true },
8
+ disabled: { type: Boolean, reflect: true },
9
+ selected: { type: Boolean, reflect: true },
10
+ active: { type: Boolean, reflect: true },
11
+ };
12
+ }
13
+ constructor() {
14
+ super();
15
+ this.value = '';
16
+ this.disabled = false;
17
+ this.selected = false;
18
+ this.active = false;
19
+ }
20
+ static styles = [
21
+ componentResetStyles,
22
+ css `
23
+ :host {
24
+ display: inline-block;
25
+ outline: none;
26
+ }
27
+
28
+ [part='base'] {
29
+ padding-block: var(--cv-option-padding-block, var(--cv-space-2, 8px));
30
+ padding-inline: var(--cv-option-padding-inline, var(--cv-space-3, 12px));
31
+ border-radius: var(--cv-option-border-radius, var(--cv-radius-sm, 6px));
32
+ color: var(--cv-color-text, #e8ecf6);
33
+ background: transparent;
34
+ transition:
35
+ background var(--cv-duration-fast, 120ms) var(--cv-easing-standard, ease),
36
+ color var(--cv-duration-fast, 120ms) var(--cv-easing-standard, ease);
37
+ }
38
+
39
+ [part='prefix'],
40
+ [part='label'],
41
+ [part='suffix'] {
42
+ display: contents;
43
+ }
44
+
45
+ :host([active]) [part='base'] {
46
+ background: var(
47
+ --cv-option-active-background,
48
+ color-mix(in oklab, var(--cv-color-primary, #65d7ff) 22%, transparent)
49
+ );
50
+ }
51
+
52
+ :host([selected]) [part='base'] {
53
+ background: var(
54
+ --cv-option-selected-background,
55
+ color-mix(in oklab, var(--cv-color-primary, #65d7ff) 34%, transparent)
56
+ );
57
+ color: var(--cv-color-text, #e8ecf6);
58
+ }
59
+
60
+ :host([disabled]) [part='base'] {
61
+ opacity: var(--cv-option-disabled-opacity, 0.55);
62
+ }
63
+
64
+ :host(:focus-visible) [part='base'] {
65
+ outline: 2px solid var(--cv-option-focus-outline-color, var(--cv-color-primary, #65d7ff));
66
+ outline-offset: 1px;
67
+ }
68
+ `,
69
+ ];
70
+ static define() {
71
+ if (!customElements.get(this.elementName)) {
72
+ customElements.define(this.elementName, this);
73
+ }
74
+ }
75
+ render() {
76
+ return html `
77
+ <div part="base" class="cv-u-row">
78
+ <span part="prefix"><slot name="prefix"></slot></span>
79
+ <span part="label"><slot></slot></span>
80
+ <span part="suffix"><slot name="suffix"></slot></span>
81
+ </div>
82
+ `;
83
+ }
84
+ }