snice 1.14.3 → 2.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 (185) hide show
  1. package/bin/templates/base/tsconfig.json +5 -4
  2. package/components/accordion/demo.html +403 -0
  3. package/components/accordion/snice-accordion-item.css +85 -0
  4. package/components/accordion/snice-accordion-item.ts +226 -0
  5. package/components/accordion/snice-accordion.css +31 -0
  6. package/components/accordion/snice-accordion.ts +182 -0
  7. package/components/accordion/snice-accordion.types.ts +32 -0
  8. package/components/alert/demo.html +445 -0
  9. package/components/alert/snice-alert.css +195 -0
  10. package/components/alert/snice-alert.ts +141 -0
  11. package/components/alert/snice-alert.types.ts +12 -0
  12. package/components/avatar/demo.html +598 -0
  13. package/components/avatar/snice-avatar.css +131 -0
  14. package/components/avatar/snice-avatar.ts +136 -0
  15. package/components/avatar/snice-avatar.types.ts +13 -0
  16. package/components/badge/demo.html +523 -0
  17. package/components/badge/snice-badge.css +161 -0
  18. package/components/badge/snice-badge.ts +117 -0
  19. package/components/badge/snice-badge.types.ts +16 -0
  20. package/components/breadcrumbs/demo.html +404 -0
  21. package/components/breadcrumbs/snice-breadcrumbs.css +133 -0
  22. package/components/breadcrumbs/snice-breadcrumbs.ts +191 -0
  23. package/components/breadcrumbs/snice-breadcrumbs.types.ts +26 -0
  24. package/components/breadcrumbs/snice-crumb.ts +26 -0
  25. package/components/button/demo.html +42 -0
  26. package/components/button/snice-button.css +230 -0
  27. package/components/button/snice-button.ts +169 -0
  28. package/components/button/snice-button.types.ts +25 -0
  29. package/components/card/demo.html +525 -0
  30. package/components/card/snice-card.css +140 -0
  31. package/components/card/snice-card.ts +102 -0
  32. package/components/card/snice-card.types.ts +10 -0
  33. package/components/checkbox/demo.html +253 -0
  34. package/components/checkbox/snice-checkbox.css +164 -0
  35. package/components/checkbox/snice-checkbox.ts +223 -0
  36. package/components/checkbox/snice-checkbox.types.ts +22 -0
  37. package/components/chip/demo.html +383 -0
  38. package/components/chip/snice-chip.css +195 -0
  39. package/components/chip/snice-chip.ts +139 -0
  40. package/components/chip/snice-chip.types.ts +15 -0
  41. package/components/date-picker/README.md +233 -0
  42. package/components/date-picker/demo.html +191 -0
  43. package/components/date-picker/snice-date-picker.css +330 -0
  44. package/components/date-picker/snice-date-picker.ts +777 -0
  45. package/components/date-picker/snice-date-picker.types.ts +83 -0
  46. package/components/divider/demo.html +233 -0
  47. package/components/divider/snice-divider.css +155 -0
  48. package/components/divider/snice-divider.ts +69 -0
  49. package/components/divider/snice-divider.types.ts +15 -0
  50. package/components/drawer/demo.html +328 -0
  51. package/components/drawer/snice-drawer.css +476 -0
  52. package/components/drawer/snice-drawer.ts +287 -0
  53. package/components/drawer/snice-drawer.types.ts +17 -0
  54. package/components/global.d.ts +14 -0
  55. package/components/input/demo.html +303 -0
  56. package/components/input/snice-input.css +257 -0
  57. package/components/input/snice-input.ts +442 -0
  58. package/components/input/snice-input.types.ts +59 -0
  59. package/components/input/test.html +77 -0
  60. package/components/layout/README.md +260 -0
  61. package/components/layout/demo.html +538 -0
  62. package/components/layout/snice-layout-blog.css +129 -0
  63. package/components/layout/snice-layout-blog.ts +48 -0
  64. package/components/layout/snice-layout-card.css +104 -0
  65. package/components/layout/snice-layout-card.ts +35 -0
  66. package/components/layout/snice-layout-centered.css +51 -0
  67. package/components/layout/snice-layout-centered.ts +22 -0
  68. package/components/layout/snice-layout-dashboard.css +98 -0
  69. package/components/layout/snice-layout-dashboard.ts +45 -0
  70. package/components/layout/snice-layout-fullscreen.css +72 -0
  71. package/components/layout/snice-layout-fullscreen.ts +34 -0
  72. package/components/layout/snice-layout-landing.css +92 -0
  73. package/components/layout/snice-layout-landing.ts +47 -0
  74. package/components/layout/snice-layout-minimal.css +16 -0
  75. package/components/layout/snice-layout-minimal.ts +19 -0
  76. package/components/layout/snice-layout-sidebar.css +117 -0
  77. package/components/layout/snice-layout-sidebar.ts +48 -0
  78. package/components/layout/snice-layout-split.css +103 -0
  79. package/components/layout/snice-layout-split.ts +29 -0
  80. package/components/layout/snice-layout.css +72 -0
  81. package/components/layout/snice-layout.ts +35 -0
  82. package/components/layout/snice-layout.types.ts +5 -0
  83. package/components/login/demo-auth-controller.ts +185 -0
  84. package/components/login/demo.html +470 -0
  85. package/components/login/snice-login.css +204 -0
  86. package/components/login/snice-login.ts +337 -0
  87. package/components/login/snice-login.types.ts +34 -0
  88. package/components/modal/demo.html +291 -0
  89. package/components/modal/snice-modal.css +203 -0
  90. package/components/modal/snice-modal.ts +233 -0
  91. package/components/modal/snice-modal.types.ts +21 -0
  92. package/components/pagination/demo.html +395 -0
  93. package/components/pagination/snice-pagination.ts +333 -0
  94. package/components/pagination/snice-pagination.types.ts +21 -0
  95. package/components/progress/demo.html +510 -0
  96. package/components/progress/snice-progress.css +267 -0
  97. package/components/progress/snice-progress.ts +247 -0
  98. package/components/progress/snice-progress.types.ts +19 -0
  99. package/components/radio/demo.html +287 -0
  100. package/components/radio/snice-radio.css +171 -0
  101. package/components/radio/snice-radio.ts +218 -0
  102. package/components/radio/snice-radio.types.ts +21 -0
  103. package/components/select/demo.html +511 -0
  104. package/components/select/snice-option.ts +52 -0
  105. package/components/select/snice-option.types.ts +14 -0
  106. package/components/select/snice-select.css +392 -0
  107. package/components/select/snice-select.ts +796 -0
  108. package/components/select/snice-select.types.ts +55 -0
  109. package/components/skeleton/demo.html +514 -0
  110. package/components/skeleton/snice-skeleton.css +109 -0
  111. package/components/skeleton/snice-skeleton.ts +126 -0
  112. package/components/skeleton/snice-skeleton.types.ts +11 -0
  113. package/components/switch/demo.html +284 -0
  114. package/components/switch/snice-switch.css +221 -0
  115. package/components/switch/snice-switch.ts +229 -0
  116. package/components/switch/snice-switch.types.ts +23 -0
  117. package/components/symbols.ts +23 -0
  118. package/components/table/demo-table-controller.ts +100 -0
  119. package/components/table/demo.html +480 -0
  120. package/components/table/snice-cell-boolean.ts +112 -0
  121. package/components/table/snice-cell-date.ts +210 -0
  122. package/components/table/snice-cell-duration.ts +91 -0
  123. package/components/table/snice-cell-filesize.ts +90 -0
  124. package/components/table/snice-cell-number.ts +165 -0
  125. package/components/table/snice-cell-progress.ts +83 -0
  126. package/components/table/snice-cell-rating.ts +82 -0
  127. package/components/table/snice-cell-sparkline.ts +253 -0
  128. package/components/table/snice-cell-text.ts +125 -0
  129. package/components/table/snice-cell.css +296 -0
  130. package/components/table/snice-cell.ts +473 -0
  131. package/components/table/snice-column.ts +353 -0
  132. package/components/table/snice-header.css +243 -0
  133. package/components/table/snice-header.ts +261 -0
  134. package/components/table/snice-progress.ts +66 -0
  135. package/components/table/snice-rating.ts +45 -0
  136. package/components/table/snice-row.css +255 -0
  137. package/components/table/snice-row.ts +331 -0
  138. package/components/table/snice-table.css +241 -0
  139. package/components/table/snice-table.ts +737 -0
  140. package/components/table/snice-table.types.ts +158 -0
  141. package/components/tabs/demo.html +487 -0
  142. package/components/tabs/snice-tab-panel.css +264 -0
  143. package/components/tabs/snice-tab-panel.ts +47 -0
  144. package/components/tabs/snice-tab.css +96 -0
  145. package/components/tabs/snice-tab.ts +65 -0
  146. package/components/tabs/snice-tabs.css +189 -0
  147. package/components/tabs/snice-tabs.ts +332 -0
  148. package/components/tabs/snice-tabs.types.ts +28 -0
  149. package/components/theme/theme.css +234 -0
  150. package/components/toast/demo.html +329 -0
  151. package/components/toast/snice-toast-container.ts +256 -0
  152. package/components/toast/snice-toast.css +213 -0
  153. package/components/toast/snice-toast.ts +276 -0
  154. package/components/toast/snice-toast.types.ts +35 -0
  155. package/components/tooltip/demo.html +350 -0
  156. package/components/tooltip/snice-tooltip-portal.css +79 -0
  157. package/components/tooltip/snice-tooltip.css +117 -0
  158. package/components/tooltip/snice-tooltip.ts +612 -0
  159. package/components/tooltip/snice-tooltip.types.ts +32 -0
  160. package/components/transitions.ts +94 -0
  161. package/components/tsconfig.json +18 -0
  162. package/dist/index.cjs +441 -329
  163. package/dist/index.cjs.map +1 -1
  164. package/dist/index.cjs.min.map +1 -1
  165. package/dist/index.esm.js +441 -329
  166. package/dist/index.esm.js.map +1 -1
  167. package/dist/index.esm.min.js +3 -3
  168. package/dist/index.esm.min.js.map +1 -1
  169. package/dist/index.iife.js +441 -329
  170. package/dist/index.iife.js.map +1 -1
  171. package/dist/index.iife.min.js +3 -3
  172. package/dist/index.iife.min.js.map +1 -1
  173. package/dist/symbols.esm.js +1 -1
  174. package/dist/transitions.esm.js +1 -1
  175. package/dist/types/controller.d.ts +1 -1
  176. package/dist/types/element.d.ts +10 -10
  177. package/dist/types/events.d.ts +2 -2
  178. package/dist/types/index.d.ts +1 -1
  179. package/dist/types/observe.d.ts +1 -1
  180. package/dist/types/request-response.d.ts +2 -3
  181. package/dist/types/router.d.ts +1 -1
  182. package/package.json +9 -3
  183. package/dist/index.cjs.min +0 -15
  184. package/dist/symbols.cjs +0 -103
  185. package/dist/transitions.cjs +0 -219
@@ -0,0 +1,287 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Radio Button Demo</title>
7
+ <link rel="stylesheet" href="../theme/theme.css">
8
+ <style>
9
+ body {
10
+ padding: 40px;
11
+ font-family: var(--snice-font-family);
12
+ background: var(--snice-color-background);
13
+ color: var(--snice-color-text);
14
+ max-width: 800px;
15
+ margin: 0 auto;
16
+ }
17
+
18
+ .section {
19
+ margin-bottom: 40px;
20
+ }
21
+
22
+ h2 {
23
+ color: var(--snice-color-text);
24
+ margin-bottom: 20px;
25
+ font-size: var(--snice-font-size-2xl);
26
+ }
27
+
28
+ h3 {
29
+ color: var(--snice-color-text-secondary);
30
+ margin-bottom: 16px;
31
+ font-size: var(--snice-font-size-lg);
32
+ }
33
+
34
+ .radio-group {
35
+ display: flex;
36
+ flex-direction: column;
37
+ gap: 12px;
38
+ margin-bottom: 20px;
39
+ }
40
+
41
+ .row {
42
+ display: flex;
43
+ gap: 20px;
44
+ align-items: center;
45
+ flex-wrap: wrap;
46
+ }
47
+
48
+ .output {
49
+ padding: 10px;
50
+ background: var(--snice-color-background-secondary);
51
+ border-radius: var(--snice-border-radius-md);
52
+ font-family: monospace;
53
+ font-size: var(--snice-font-size-sm);
54
+ margin-top: 10px;
55
+ }
56
+
57
+ button {
58
+ padding: 8px 16px;
59
+ background: var(--snice-color-primary);
60
+ color: white;
61
+ border: none;
62
+ border-radius: var(--snice-border-radius-md);
63
+ cursor: pointer;
64
+ font-size: var(--snice-font-size-md);
65
+ margin-right: 8px;
66
+ }
67
+
68
+ button:hover {
69
+ background: var(--snice-color-primary-hover);
70
+ }
71
+
72
+ fieldset {
73
+ border: 1px solid var(--snice-color-border);
74
+ border-radius: var(--snice-border-radius-md);
75
+ padding: 16px;
76
+ margin: 0;
77
+ }
78
+
79
+ legend {
80
+ padding: 0 8px;
81
+ font-weight: 500;
82
+ }
83
+ </style>
84
+ </head>
85
+ <body>
86
+ <h2>Radio Button Component Demo</h2>
87
+
88
+ <div class="section">
89
+ <h3>Basic Radio Buttons</h3>
90
+ <div class="radio-group">
91
+ <snice-radio name="basic" value="option1" label="Option 1" checked></snice-radio>
92
+ <snice-radio name="basic" value="option2" label="Option 2"></snice-radio>
93
+ <snice-radio name="basic" value="option3" label="Option 3"></snice-radio>
94
+ <snice-radio name="basic" value="option4" label="Option 4" disabled></snice-radio>
95
+ </div>
96
+ </div>
97
+
98
+ <div class="section">
99
+ <h3>Sizes</h3>
100
+ <fieldset>
101
+ <legend>Small</legend>
102
+ <div class="radio-group">
103
+ <snice-radio size="small" name="size-small" value="1" label="Small Option 1"></snice-radio>
104
+ <snice-radio size="small" name="size-small" value="2" label="Small Option 2"></snice-radio>
105
+ </div>
106
+ </fieldset>
107
+
108
+ <fieldset style="margin-top: 16px;">
109
+ <legend>Medium (Default)</legend>
110
+ <div class="radio-group">
111
+ <snice-radio size="medium" name="size-medium" value="1" label="Medium Option 1"></snice-radio>
112
+ <snice-radio size="medium" name="size-medium" value="2" label="Medium Option 2"></snice-radio>
113
+ </div>
114
+ </fieldset>
115
+
116
+ <fieldset style="margin-top: 16px;">
117
+ <legend>Large</legend>
118
+ <div class="radio-group">
119
+ <snice-radio size="large" name="size-large" value="1" label="Large Option 1"></snice-radio>
120
+ <snice-radio size="large" name="size-large" value="2" label="Large Option 2"></snice-radio>
121
+ </div>
122
+ </fieldset>
123
+ </div>
124
+
125
+ <div class="section">
126
+ <h3>States</h3>
127
+ <div class="radio-group">
128
+ <snice-radio name="states" value="required" label="Required field" required></snice-radio>
129
+ <snice-radio name="states" value="invalid" label="Invalid state" invalid></snice-radio>
130
+ <snice-radio name="states" value="disabled" label="Disabled" disabled></snice-radio>
131
+ <snice-radio name="states" value="disabled-checked" label="Disabled checked" disabled checked></snice-radio>
132
+ </div>
133
+ </div>
134
+
135
+ <div class="section">
136
+ <h3>Payment Method Example</h3>
137
+ <fieldset>
138
+ <legend>Select Payment Method</legend>
139
+ <div class="radio-group">
140
+ <snice-radio name="payment" value="card" label="Credit/Debit Card" checked></snice-radio>
141
+ <snice-radio name="payment" value="paypal" label="PayPal"></snice-radio>
142
+ <snice-radio name="payment" value="bank" label="Bank Transfer"></snice-radio>
143
+ <snice-radio name="payment" value="crypto" label="Cryptocurrency"></snice-radio>
144
+ </div>
145
+ </fieldset>
146
+ <button onclick="getPaymentMethod()">Get Selected Payment</button>
147
+ <div id="payment-output" class="output">Selected: Credit/Debit Card</div>
148
+ </div>
149
+
150
+ <div class="section">
151
+ <h3>Theme Selection</h3>
152
+ <fieldset>
153
+ <legend>Choose Theme</legend>
154
+ <div class="radio-group">
155
+ <snice-radio id="theme-light" name="theme" value="light" label="Light" checked></snice-radio>
156
+ <snice-radio id="theme-dark" name="theme" value="dark" label="Dark"></snice-radio>
157
+ <snice-radio id="theme-auto" name="theme" value="auto" label="System"></snice-radio>
158
+ </div>
159
+ </fieldset>
160
+ <div id="theme-output" class="output">Current theme: light</div>
161
+ </div>
162
+
163
+ <div class="section">
164
+ <h3>Interactive Example</h3>
165
+ <div class="radio-group">
166
+ <snice-radio id="interactive-1" name="interactive" value="option1" label="Option 1"></snice-radio>
167
+ <snice-radio id="interactive-2" name="interactive" value="option2" label="Option 2"></snice-radio>
168
+ <snice-radio id="interactive-3" name="interactive" value="option3" label="Option 3"></snice-radio>
169
+ </div>
170
+ <div class="row">
171
+ <button onclick="document.getElementById('interactive-2').select()">Select Option 2</button>
172
+ <button onclick="document.getElementById('interactive-1').focus()">Focus Option 1</button>
173
+ <button onclick="getInteractiveValue()">Get Value</button>
174
+ </div>
175
+ <div id="interactive-output" class="output">Events will appear here...</div>
176
+ </div>
177
+
178
+ <div class="section">
179
+ <h3>Form Example</h3>
180
+ <form id="demo-form">
181
+ <fieldset>
182
+ <legend>Survey</legend>
183
+ <div style="margin-bottom: 16px;">
184
+ <strong>How satisfied are you?</strong>
185
+ <div class="radio-group" style="margin-top: 8px;">
186
+ <snice-radio name="satisfaction" value="very-satisfied" label="Very Satisfied" required></snice-radio>
187
+ <snice-radio name="satisfaction" value="satisfied" label="Satisfied" required></snice-radio>
188
+ <snice-radio name="satisfaction" value="neutral" label="Neutral" required></snice-radio>
189
+ <snice-radio name="satisfaction" value="dissatisfied" label="Dissatisfied" required></snice-radio>
190
+ <snice-radio name="satisfaction" value="very-dissatisfied" label="Very Dissatisfied" required></snice-radio>
191
+ </div>
192
+ </div>
193
+
194
+ <div>
195
+ <strong>Would you recommend us?</strong>
196
+ <div class="radio-group" style="margin-top: 8px;">
197
+ <snice-radio name="recommend" value="yes" label="Yes" required></snice-radio>
198
+ <snice-radio name="recommend" value="no" label="No" required></snice-radio>
199
+ <snice-radio name="recommend" value="maybe" label="Maybe" required></snice-radio>
200
+ </div>
201
+ </div>
202
+ </fieldset>
203
+ <button type="submit" style="margin-top: 16px;">Submit Survey</button>
204
+ </form>
205
+ <div id="form-output" class="output">Form data will appear here...</div>
206
+ </div>
207
+
208
+ <script type="module">
209
+ import './snice-radio.ts';
210
+
211
+ // Payment method
212
+ window.getPaymentMethod = function() {
213
+ const radios = document.querySelectorAll('snice-radio[name="payment"]');
214
+ let selected = null;
215
+ radios.forEach(radio => {
216
+ if (radio.checked) {
217
+ selected = radio;
218
+ }
219
+ });
220
+ const output = document.getElementById('payment-output');
221
+ if (selected) {
222
+ output.textContent = `Selected: ${selected.label}`;
223
+ }
224
+ };
225
+
226
+ // Theme selection
227
+ const themeRadios = document.querySelectorAll('snice-radio[name="theme"]');
228
+ themeRadios.forEach(radio => {
229
+ radio.addEventListener('@snice/radio-change', (e) => {
230
+ if (e.detail.checked) {
231
+ document.getElementById('theme-output').textContent =
232
+ `Current theme: ${e.detail.value}`;
233
+ }
234
+ });
235
+ });
236
+
237
+ // Interactive example
238
+ const interactiveRadios = document.querySelectorAll('snice-radio[name="interactive"]');
239
+ interactiveRadios.forEach(radio => {
240
+ radio.addEventListener('@snice/radio-change', (e) => {
241
+ document.getElementById('interactive-output').textContent =
242
+ `Changed: value=${e.detail.value}, checked=${e.detail.checked}`;
243
+ });
244
+ });
245
+
246
+ window.getInteractiveValue = function() {
247
+ const radios = document.querySelectorAll('snice-radio[name="interactive"]');
248
+ let selected = null;
249
+ radios.forEach(radio => {
250
+ if (radio.checked) {
251
+ selected = radio;
252
+ }
253
+ });
254
+ document.getElementById('interactive-output').textContent =
255
+ selected ? `Current value: ${selected.value}` : 'No selection';
256
+ };
257
+
258
+ // Form submission
259
+ document.getElementById('demo-form').addEventListener('submit', (e) => {
260
+ e.preventDefault();
261
+ const data = {};
262
+ const radios = e.target.querySelectorAll('snice-radio');
263
+ const groups = new Set();
264
+
265
+ radios.forEach(radio => {
266
+ if (radio.name) {
267
+ groups.add(radio.name);
268
+ }
269
+ });
270
+
271
+ groups.forEach(groupName => {
272
+ const radios = e.target.querySelectorAll(`snice-radio[name="${groupName}"]`);
273
+ let selected = null;
274
+ radios.forEach(radio => {
275
+ if (radio.checked) {
276
+ selected = radio;
277
+ }
278
+ });
279
+ data[groupName] = selected ? selected.value : null;
280
+ });
281
+
282
+ document.getElementById('form-output').textContent =
283
+ `Form data: ${JSON.stringify(data, null, 2)}`;
284
+ });
285
+ </script>
286
+ </body>
287
+ </html>
@@ -0,0 +1,171 @@
1
+ :host {
2
+ display: inline-block;
3
+ font-family: var(--snice-font-family);
4
+ }
5
+
6
+ .radio-wrapper {
7
+ display: inline-flex;
8
+ align-items: center;
9
+ position: relative;
10
+ cursor: pointer;
11
+ user-select: none;
12
+ }
13
+
14
+ .radio-wrapper--disabled {
15
+ cursor: not-allowed;
16
+ opacity: 0.6;
17
+ }
18
+
19
+ /* Hide native radio */
20
+ .radio-input {
21
+ position: absolute;
22
+ opacity: 0;
23
+ width: 0;
24
+ height: 0;
25
+ }
26
+
27
+ /* Custom radio */
28
+ .radio {
29
+ position: relative;
30
+ display: inline-flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ background: var(--snice-color-background);
34
+ border: 2px solid var(--snice-color-border);
35
+ border-radius: 50%;
36
+ transition: all var(--snice-transition-fast) ease;
37
+ }
38
+
39
+ /* Size variants */
40
+ .radio--small {
41
+ width: 1rem; /* 16px */
42
+ height: 1rem; /* 16px */
43
+ }
44
+
45
+ .radio--medium {
46
+ width: 1.25rem; /* 20px */
47
+ height: 1.25rem; /* 20px */
48
+ }
49
+
50
+ .radio--large {
51
+ width: 1.5rem; /* 24px */
52
+ height: 1.5rem; /* 24px */
53
+ }
54
+
55
+ /* States */
56
+ .radio-input:checked ~ .radio {
57
+ border-color: var(--snice-color-primary);
58
+ }
59
+
60
+ .radio-input:focus-visible ~ .radio {
61
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
62
+ }
63
+
64
+ .radio-input:disabled ~ .radio {
65
+ background: var(--snice-color-background-secondary);
66
+ border-color: var(--snice-color-border);
67
+ }
68
+
69
+ .radio-input:disabled:checked ~ .radio {
70
+ border-color: var(--snice-color-text-secondary);
71
+ }
72
+
73
+ .radio-input:disabled:checked ~ .radio .radio-dot {
74
+ background: var(--snice-color-text-secondary);
75
+ }
76
+
77
+ /* Invalid state */
78
+ .radio--invalid {
79
+ border-color: var(--snice-color-danger);
80
+ }
81
+
82
+ .radio-input:checked ~ .radio--invalid {
83
+ border-color: var(--snice-color-danger);
84
+ }
85
+
86
+ .radio-input:checked ~ .radio--invalid .radio-dot {
87
+ background: var(--snice-color-danger);
88
+ }
89
+
90
+ /* Radio dot */
91
+ .radio-dot {
92
+ position: absolute;
93
+ border-radius: 50%;
94
+ background: var(--snice-color-primary);
95
+ transform: scale(0);
96
+ transition: transform var(--snice-transition-fast) ease;
97
+ }
98
+
99
+ .radio-input:checked ~ .radio .radio-dot {
100
+ transform: scale(1);
101
+ }
102
+
103
+ /* Dot sizes */
104
+ .radio--small .radio-dot {
105
+ width: 0.375rem; /* 6px */
106
+ height: 0.375rem; /* 6px */
107
+ }
108
+
109
+ .radio--medium .radio-dot {
110
+ width: 0.5rem; /* 8px */
111
+ height: 0.5rem; /* 8px */
112
+ }
113
+
114
+ .radio--large .radio-dot {
115
+ width: 0.625rem; /* 10px */
116
+ height: 0.625rem; /* 10px */
117
+ }
118
+
119
+ /* Label */
120
+ .radio-label {
121
+ margin-left: 0.5rem; /* 8px */
122
+ color: var(--snice-color-text);
123
+ cursor: pointer;
124
+ }
125
+
126
+ .radio-label--small {
127
+ font-size: var(--snice-font-size-sm);
128
+ }
129
+
130
+ .radio-label--medium {
131
+ font-size: var(--snice-font-size-md);
132
+ }
133
+
134
+ .radio-label--large {
135
+ font-size: var(--snice-font-size-lg);
136
+ }
137
+
138
+ .radio-wrapper--disabled .radio-label {
139
+ color: var(--snice-color-text-secondary);
140
+ cursor: not-allowed;
141
+ }
142
+
143
+ /* Required indicator */
144
+ .radio-label--required::after {
145
+ content: ' *';
146
+ color: var(--snice-color-danger);
147
+ }
148
+
149
+ /* Focus ring for keyboard navigation */
150
+ .radio-input:focus-visible ~ .radio {
151
+ outline: 2px solid var(--snice-color-primary);
152
+ outline-offset: 2px;
153
+ }
154
+
155
+ /* Hover effect */
156
+ .radio-wrapper:not(.radio-wrapper--disabled):hover .radio {
157
+ border-color: var(--snice-color-primary);
158
+ }
159
+
160
+ /* Radio Group styling (when used together) */
161
+ :host {
162
+ --radio-group-gap: 0.75rem; /* 12px */
163
+ }
164
+
165
+ :host([data-group]) {
166
+ display: block;
167
+ }
168
+
169
+ :host([data-group]) + :host([data-group]) {
170
+ margin-top: var(--radio-group-gap);
171
+ }
@@ -0,0 +1,218 @@
1
+ import { element, property, query, on, watch, dispatch, ready } from 'snice';
2
+ import css from './snice-radio.css?inline';
3
+ import type { RadioSize, SniceRadioElement } from './snice-radio.types';
4
+
5
+ @element('snice-radio')
6
+ export class SniceRadio extends HTMLElement implements SniceRadioElement {
7
+ @property({ type: Boolean, reflect: true })
8
+ checked = false;
9
+
10
+ @property({ type: Boolean, reflect: true })
11
+ disabled = false;
12
+
13
+ @property({ type: Boolean, reflect: true })
14
+ required = false;
15
+
16
+ @property({ type: Boolean, reflect: true })
17
+ invalid = false;
18
+
19
+ @property({ reflect: true })
20
+ size: RadioSize = 'medium';
21
+
22
+ @property({ reflect: true })
23
+ name = '';
24
+
25
+ @property({ reflect: true })
26
+ value = '';
27
+
28
+ @property({ reflect: true })
29
+ label = '';
30
+
31
+ @query('.radio-input')
32
+ input?: HTMLInputElement;
33
+
34
+ @query('.radio')
35
+ radio?: HTMLElement;
36
+
37
+ @query('.radio-label')
38
+ labelElement?: HTMLElement;
39
+
40
+ @query('.radio-wrapper')
41
+ wrapper?: HTMLElement;
42
+
43
+ html() {
44
+ return /*html*/`
45
+ <label class="radio-wrapper ${this.disabled ? 'radio-wrapper--disabled' : ''}">
46
+ <input
47
+ type="radio"
48
+ class="radio-input"
49
+ ${this.checked ? 'checked' : ''}
50
+ ${this.disabled ? 'disabled' : ''}
51
+ ${this.required ? 'required' : ''}
52
+ ${this.name ? `name="${this.name}"` : ''}
53
+ ${this.value ? `value="${this.value}"` : ''}
54
+ aria-invalid="${this.invalid}"
55
+ part="input"
56
+ />
57
+
58
+ <span class="radio
59
+ radio--${this.size}
60
+ ${this.invalid ? 'radio--invalid' : ''}"
61
+ part="radio">
62
+ <span class="radio-dot" part="dot"></span>
63
+ </span>
64
+
65
+ ${this.label ? /*html*/`
66
+ <span class="radio-label radio-label--${this.size} ${this.required ? 'radio-label--required' : ''}" part="label">
67
+ ${this.label}
68
+ </span>
69
+ ` : ''}
70
+ </label>
71
+ `;
72
+ }
73
+
74
+ css() {
75
+ return css;
76
+ }
77
+
78
+ @ready()
79
+ init() {
80
+ // Set initial states
81
+ if (this.input) {
82
+ this.input.checked = this.checked;
83
+
84
+ // Set form value
85
+ if (this.name) {
86
+ this.input.name = this.name;
87
+ }
88
+ if (this.value) {
89
+ this.input.value = this.value;
90
+ }
91
+ }
92
+ }
93
+
94
+ @on('change', '.radio-input')
95
+ handleChange(e: Event) {
96
+ const target = e.target as HTMLInputElement;
97
+ const wasChecked = this.checked;
98
+ this.checked = target.checked;
99
+
100
+ // If this radio was just checked, uncheck others in the same group
101
+ if (this.checked && !wasChecked && this.name) {
102
+ this.uncheckOthersInGroup();
103
+ }
104
+
105
+ this.dispatchChangeEvent();
106
+ }
107
+
108
+ @on('click', '.radio-input')
109
+ handleClick(e: Event) {
110
+ // Allow click to propagate for label association
111
+ e.stopPropagation();
112
+ }
113
+
114
+ @watch('checked')
115
+ handleCheckedChange() {
116
+ if (this.input) {
117
+ this.input.checked = this.checked;
118
+ }
119
+
120
+ // If checked, uncheck others in the same group
121
+ if (this.checked && this.name) {
122
+ this.uncheckOthersInGroup();
123
+ }
124
+ }
125
+
126
+ @watch('disabled')
127
+ handleDisabledChange() {
128
+ if (this.input) {
129
+ this.input.disabled = this.disabled;
130
+ }
131
+ if (this.wrapper) {
132
+ this.wrapper.classList.toggle('radio-wrapper--disabled', this.disabled);
133
+ }
134
+ }
135
+
136
+ @watch('invalid')
137
+ handleInvalidChange() {
138
+ if (this.input) {
139
+ this.input.setAttribute('aria-invalid', String(this.invalid));
140
+ }
141
+ if (this.radio) {
142
+ this.radio.classList.toggle('radio--invalid', this.invalid);
143
+ }
144
+ }
145
+
146
+ @watch('required')
147
+ handleRequiredChange() {
148
+ if (this.input) {
149
+ this.input.required = this.required;
150
+ }
151
+ if (this.labelElement) {
152
+ this.labelElement.classList.toggle('radio-label--required', this.required);
153
+ }
154
+ }
155
+
156
+ @watch('label')
157
+ handleLabelChange() {
158
+ if (this.labelElement) {
159
+ this.labelElement.textContent = this.label;
160
+ this.labelElement.style.display = this.label ? '' : 'none';
161
+ }
162
+ }
163
+
164
+ @watch('name')
165
+ handleNameChange() {
166
+ if (this.input) {
167
+ this.input.name = this.name;
168
+ }
169
+ }
170
+
171
+ @watch('value')
172
+ handleValueChange() {
173
+ if (this.input) {
174
+ this.input.value = this.value;
175
+ }
176
+ }
177
+
178
+ private uncheckOthersInGroup() {
179
+ if (!this.name) return;
180
+
181
+ // Find all radios with the same name
182
+ const radios = document.querySelectorAll(`snice-radio[name="${this.name}"]`) as NodeListOf<SniceRadio>;
183
+ radios.forEach(radio => {
184
+ if (radio !== this && radio.checked) {
185
+ radio.checked = false;
186
+ }
187
+ });
188
+ }
189
+
190
+ @dispatch('@snice/radio-change', { bubbles: true, composed: true })
191
+ private dispatchChangeEvent() {
192
+ return {
193
+ checked: this.checked,
194
+ value: this.value,
195
+ radio: this
196
+ };
197
+ }
198
+
199
+ // Public API
200
+ focus() {
201
+ this.input?.focus();
202
+ }
203
+
204
+ blur() {
205
+ this.input?.blur();
206
+ }
207
+
208
+ click() {
209
+ this.input?.click();
210
+ }
211
+
212
+ select() {
213
+ if (!this.checked) {
214
+ this.checked = true;
215
+ this.dispatchChangeEvent();
216
+ }
217
+ }
218
+ }
@@ -0,0 +1,21 @@
1
+ export type RadioSize = 'small' | 'medium' | 'large';
2
+
3
+ export interface SniceRadioElement extends HTMLElement {
4
+ checked: boolean;
5
+ disabled: boolean;
6
+ required: boolean;
7
+ invalid: boolean;
8
+ size: RadioSize;
9
+ name: string;
10
+ value: string;
11
+ label: string;
12
+ focus(): void;
13
+ blur(): void;
14
+ click(): void;
15
+ }
16
+
17
+ export interface RadioChangeDetail {
18
+ checked: boolean;
19
+ value: string;
20
+ radio: SniceRadioElement;
21
+ }