@adamosuiteservices/ui 2.11.15 → 2.11.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/colors.css +1 -1
- package/dist/styles.css +1 -1
- package/docs/AI-GUIDE.md +321 -321
- package/docs/components/layout/sidebar.md +399 -399
- package/docs/components/layout/toaster.md +436 -436
- package/docs/components/ui/accordion-rounded.md +584 -584
- package/docs/components/ui/accordion.md +269 -269
- package/docs/components/ui/button-group.md +984 -984
- package/docs/components/ui/button.md +1137 -1137
- package/docs/components/ui/calendar.md +1159 -1159
- package/docs/components/ui/card.md +1455 -1455
- package/docs/components/ui/checkbox.md +292 -292
- package/docs/components/ui/collapsible.md +323 -323
- package/docs/components/ui/command.md +454 -454
- package/docs/components/ui/context-menu.md +540 -540
- package/docs/components/ui/dialog.md +628 -628
- package/docs/components/ui/dropdown-menu.md +709 -709
- package/docs/components/ui/field.md +706 -706
- package/docs/components/ui/hover-card.md +446 -446
- package/docs/components/ui/input.md +362 -362
- package/docs/components/ui/kbd.md +434 -434
- package/docs/components/ui/label.md +359 -359
- package/docs/components/ui/pagination.md +650 -650
- package/docs/components/ui/popover.md +536 -536
- package/docs/components/ui/progress.md +182 -182
- package/docs/components/ui/radio-group.md +311 -311
- package/docs/components/ui/select.md +352 -352
- package/docs/components/ui/separator.md +214 -214
- package/docs/components/ui/sheet.md +142 -142
- package/docs/components/ui/skeleton.md +140 -140
- package/docs/components/ui/slider.md +341 -341
- package/docs/components/ui/spinner.md +170 -170
- package/docs/components/ui/switch.md +408 -408
- package/docs/components/ui/tabs-underline.md +106 -106
- package/docs/components/ui/tabs.md +122 -122
- package/docs/components/ui/textarea.md +243 -243
- package/docs/components/ui/toggle.md +237 -237
- package/docs/components/ui/tooltip.md +317 -317
- package/docs/components/ui/typography.md +280 -280
- package/package.json +1 -1
|
@@ -1,311 +1,311 @@
|
|
|
1
|
-
# Radio Group
|
|
2
|
-
|
|
3
|
-
Grupo de opciones mutuamente excluyentes. Usuario selecciona una opción. Basado en Radix UI.
|
|
4
|
-
|
|
5
|
-
## Descripción
|
|
6
|
-
|
|
7
|
-
El componente `RadioGroup` permite seleccionar una opción de un conjunto de opciones mutuamente excluyentes.
|
|
8
|
-
|
|
9
|
-
## Importación
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
import { RadioGroup, RadioGroupItem } from "@adamosuiteservices/ui/radio-group";
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Anatomía
|
|
16
|
-
|
|
17
|
-
```tsx
|
|
18
|
-
<RadioGroup defaultValue="option-one">
|
|
19
|
-
<div className="flex items-center space-x-2">
|
|
20
|
-
<RadioGroupItem value="option-one" id="option-one" />
|
|
21
|
-
<Label htmlFor="option-one">Option One</Label>
|
|
22
|
-
</div>
|
|
23
|
-
<div className="flex items-center space-x-2">
|
|
24
|
-
<RadioGroupItem value="option-two" id="option-two" />
|
|
25
|
-
<Label htmlFor="option-two">Option Two</Label>
|
|
26
|
-
</div>
|
|
27
|
-
</RadioGroup>
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
**Componentes**: 2 (RadioGroup, RadioGroupItem)
|
|
31
|
-
|
|
32
|
-
## Props
|
|
33
|
-
|
|
34
|
-
### RadioGroup
|
|
35
|
-
|
|
36
|
-
| Prop | Tipo | Descripción |
|
|
37
|
-
| --------------- | ------------------------- | ------------------------------ |
|
|
38
|
-
| `defaultValue` | `string` | Valor inicial (uncontrolled) |
|
|
39
|
-
| `value` | `string` | Valor controlado |
|
|
40
|
-
| `onValueChange` | `(value: string) => void` | Callback al cambiar valor |
|
|
41
|
-
| `disabled` | `boolean` | Deshabilita todo el grupo |
|
|
42
|
-
| `required` | `boolean` | Campo requerido |
|
|
43
|
-
| `name` | `string` | Nombre del grupo (formularios) |
|
|
44
|
-
| `className` | `string` | Clases CSS adicionales |
|
|
45
|
-
|
|
46
|
-
**Nota**: Acepta todas las props de Radix UI RadioGroup.Root
|
|
47
|
-
|
|
48
|
-
### RadioGroupItem
|
|
49
|
-
|
|
50
|
-
| Prop | Tipo | Descripción |
|
|
51
|
-
| ----------- | --------- | ------------------------- |
|
|
52
|
-
| `value` | `string` | Valor único del item |
|
|
53
|
-
| `id` | `string` | ID para asociar con Label |
|
|
54
|
-
| `disabled` | `boolean` | Deshabilita este item |
|
|
55
|
-
| `className` | `string` | Clases CSS adicionales |
|
|
56
|
-
|
|
57
|
-
**Nota**: Acepta todas las props de Radix UI RadioGroup.Item
|
|
58
|
-
|
|
59
|
-
## Patrones de Uso
|
|
60
|
-
|
|
61
|
-
### Básico
|
|
62
|
-
|
|
63
|
-
```tsx
|
|
64
|
-
import { RadioGroup, RadioGroupItem } from "@adamosuiteservices/ui/radio-group";
|
|
65
|
-
import { Label } from "@adamosuiteservices/ui/label";
|
|
66
|
-
|
|
67
|
-
<RadioGroup defaultValue="option-one">
|
|
68
|
-
<div className="flex items-center gap-3">
|
|
69
|
-
<RadioGroupItem value="option-one" id="option-one" />
|
|
70
|
-
<Label htmlFor="option-one">Option One</Label>
|
|
71
|
-
</div>
|
|
72
|
-
<div className="flex items-center gap-3">
|
|
73
|
-
<RadioGroupItem value="option-two" id="option-two" />
|
|
74
|
-
<Label htmlFor="option-two">Option Two</Label>
|
|
75
|
-
</div>
|
|
76
|
-
</RadioGroup>;
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Controlado
|
|
80
|
-
|
|
81
|
-
```tsx
|
|
82
|
-
import { useState } from "react";
|
|
83
|
-
|
|
84
|
-
function App() {
|
|
85
|
-
const [value, setValue] = useState("red");
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<RadioGroup value={value} onValueChange={setValue}>
|
|
89
|
-
<div className="flex items-center gap-3">
|
|
90
|
-
<RadioGroupItem value="red" id="red" />
|
|
91
|
-
<Label htmlFor="red">Red</Label>
|
|
92
|
-
</div>
|
|
93
|
-
<div className="flex items-center gap-3">
|
|
94
|
-
<RadioGroupItem value="green" id="green" />
|
|
95
|
-
<Label htmlFor="green">Green</Label>
|
|
96
|
-
</div>
|
|
97
|
-
</RadioGroup>
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### Con Descripciones
|
|
103
|
-
|
|
104
|
-
```tsx
|
|
105
|
-
<RadioGroup defaultValue="comfortable">
|
|
106
|
-
<div className="flex items-start gap-3">
|
|
107
|
-
<RadioGroupItem value="default" id="default" />
|
|
108
|
-
<div className="grid gap-2">
|
|
109
|
-
<Label htmlFor="default">Default</Label>
|
|
110
|
-
<p className="text-muted-foreground text-sm">
|
|
111
|
-
Recommended for most users. Provides a balanced experience.
|
|
112
|
-
</p>
|
|
113
|
-
</div>
|
|
114
|
-
</div>
|
|
115
|
-
<div className="flex items-start gap-3">
|
|
116
|
-
<RadioGroupItem value="comfortable" id="comfortable" />
|
|
117
|
-
<div className="grid gap-2">
|
|
118
|
-
<Label htmlFor="comfortable">Comfortable</Label>
|
|
119
|
-
<p className="text-muted-foreground text-sm">
|
|
120
|
-
More spacing and larger elements for better accessibility.
|
|
121
|
-
</p>
|
|
122
|
-
</div>
|
|
123
|
-
</div>
|
|
124
|
-
</RadioGroup>
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### Layout Horizontal
|
|
128
|
-
|
|
129
|
-
```tsx
|
|
130
|
-
<RadioGroup defaultValue="medium" className="flex gap-6">
|
|
131
|
-
<div className="flex items-center gap-2">
|
|
132
|
-
<RadioGroupItem value="small" id="small" />
|
|
133
|
-
<Label htmlFor="small">Small</Label>
|
|
134
|
-
</div>
|
|
135
|
-
<div className="flex items-center gap-2">
|
|
136
|
-
<RadioGroupItem value="medium" id="medium" />
|
|
137
|
-
<Label htmlFor="medium">Medium</Label>
|
|
138
|
-
</div>
|
|
139
|
-
<div className="flex items-center gap-2">
|
|
140
|
-
<RadioGroupItem value="large" id="large" />
|
|
141
|
-
<Label htmlFor="large">Large</Label>
|
|
142
|
-
</div>
|
|
143
|
-
</RadioGroup>
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Con Badges
|
|
147
|
-
|
|
148
|
-
```tsx
|
|
149
|
-
import { Badge } from "@adamosuiteservices/ui/badge";
|
|
150
|
-
|
|
151
|
-
<RadioGroup defaultValue="pro">
|
|
152
|
-
<div className="flex items-center gap-3">
|
|
153
|
-
<RadioGroupItem value="free" id="free" />
|
|
154
|
-
<div className="flex items-center gap-2">
|
|
155
|
-
<Label htmlFor="free">Free Plan</Label>
|
|
156
|
-
<Badge variant="secondary">$0/month</Badge>
|
|
157
|
-
</div>
|
|
158
|
-
</div>
|
|
159
|
-
<div className="flex items-center gap-3">
|
|
160
|
-
<RadioGroupItem value="pro" id="pro" />
|
|
161
|
-
<div className="flex items-center gap-2">
|
|
162
|
-
<Label htmlFor="pro">Pro Plan</Label>
|
|
163
|
-
<Badge variant="default">$9/month</Badge>
|
|
164
|
-
</div>
|
|
165
|
-
</div>
|
|
166
|
-
</RadioGroup>;
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### En Formularios
|
|
170
|
-
|
|
171
|
-
```tsx
|
|
172
|
-
import { Button } from "@adamosuiteservices/ui/button";
|
|
173
|
-
|
|
174
|
-
function App() {
|
|
175
|
-
const [formData, setFormData] = useState({
|
|
176
|
-
notification: "email",
|
|
177
|
-
frequency: "weekly",
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
const handleSubmit = (e: React.FormEvent) => {
|
|
181
|
-
e.preventDefault();
|
|
182
|
-
console.log("Form submitted:", formData);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
return (
|
|
186
|
-
<form onSubmit={handleSubmit} className="space-y-6">
|
|
187
|
-
<div className="space-y-3">
|
|
188
|
-
<p className="text-sm font-medium">Notification method</p>
|
|
189
|
-
<RadioGroup
|
|
190
|
-
value={formData.notification}
|
|
191
|
-
onValueChange={(value) =>
|
|
192
|
-
setFormData((prev) => ({ ...prev, notification: value }))
|
|
193
|
-
}
|
|
194
|
-
>
|
|
195
|
-
<div className="flex items-center gap-3">
|
|
196
|
-
<RadioGroupItem value="email" id="email" />
|
|
197
|
-
<Label htmlFor="email">Email notifications</Label>
|
|
198
|
-
</div>
|
|
199
|
-
<div className="flex items-center gap-3">
|
|
200
|
-
<RadioGroupItem value="sms" id="sms" />
|
|
201
|
-
<Label htmlFor="sms">SMS notifications</Label>
|
|
202
|
-
</div>
|
|
203
|
-
</RadioGroup>
|
|
204
|
-
</div>
|
|
205
|
-
<Button type="submit">Save preferences</Button>
|
|
206
|
-
</form>
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
### Nested (Conditional)
|
|
212
|
-
|
|
213
|
-
```tsx
|
|
214
|
-
function App() {
|
|
215
|
-
const [paymentMethod, setPaymentMethod] = useState("card");
|
|
216
|
-
const [cardType, setCardType] = useState("visa");
|
|
217
|
-
|
|
218
|
-
return (
|
|
219
|
-
<div className="space-y-6">
|
|
220
|
-
<RadioGroup value={paymentMethod} onValueChange={setPaymentMethod}>
|
|
221
|
-
<div className="flex items-center gap-3">
|
|
222
|
-
<RadioGroupItem value="card" id="card" />
|
|
223
|
-
<Label htmlFor="card">Credit/Debit Card</Label>
|
|
224
|
-
</div>
|
|
225
|
-
<div className="flex items-center gap-3">
|
|
226
|
-
<RadioGroupItem value="bank" id="bank" />
|
|
227
|
-
<Label htmlFor="bank">Bank Transfer</Label>
|
|
228
|
-
</div>
|
|
229
|
-
</RadioGroup>
|
|
230
|
-
|
|
231
|
-
{paymentMethod === "card" && (
|
|
232
|
-
<div className="ml-6 space-y-3">
|
|
233
|
-
<p className="text-sm font-medium">Card type</p>
|
|
234
|
-
<RadioGroup value={cardType} onValueChange={setCardType}>
|
|
235
|
-
<div className="flex items-center gap-3">
|
|
236
|
-
<RadioGroupItem value="visa" id="visa" />
|
|
237
|
-
<Label htmlFor="visa">Visa</Label>
|
|
238
|
-
</div>
|
|
239
|
-
<div className="flex items-center gap-3">
|
|
240
|
-
<RadioGroupItem value="mastercard" id="mastercard" />
|
|
241
|
-
<Label htmlFor="mastercard">Mastercard</Label>
|
|
242
|
-
</div>
|
|
243
|
-
</RadioGroup>
|
|
244
|
-
</div>
|
|
245
|
-
)}
|
|
246
|
-
</div>
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### Deshabilitado
|
|
252
|
-
|
|
253
|
-
```tsx
|
|
254
|
-
<RadioGroup defaultValue="option-one" disabled>
|
|
255
|
-
<div className="flex items-center gap-3">
|
|
256
|
-
<RadioGroupItem value="option-one" id="disabled-one" />
|
|
257
|
-
<Label htmlFor="disabled-one">Option One</Label>
|
|
258
|
-
</div>
|
|
259
|
-
<div className="flex items-center gap-3">
|
|
260
|
-
<RadioGroupItem value="option-two" id="disabled-two" />
|
|
261
|
-
<Label htmlFor="disabled-two">Option Two</Label>
|
|
262
|
-
</div>
|
|
263
|
-
</RadioGroup>
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
## Casos de Uso
|
|
267
|
-
|
|
268
|
-
**Opciones mutuamente excluyentes**: Una sola selección de múltiples opciones
|
|
269
|
-
**Settings**: Preferencias de configuración (theme, size, mode)
|
|
270
|
-
**Formularios**: Selección de método de pago, envío, categoría
|
|
271
|
-
**Surveys**: Preguntas con opciones de respuesta única
|
|
272
|
-
**Filtros**: Filtrado por categoría, tipo, estado
|
|
273
|
-
|
|
274
|
-
## Estilos Base
|
|
275
|
-
|
|
276
|
-
- **Size**: `size-5` (20px)
|
|
277
|
-
- **Border**: `border-input` con `shadow-xs`
|
|
278
|
-
- **Checked**: Icon `circle` con `text-primary`
|
|
279
|
-
- **Focus**: `ring-ring/50` con `ring-[3px]`
|
|
280
|
-
- **Invalid**: `border-destructive` con `ring-destructive/20`
|
|
281
|
-
- **Spacing**: `gap-3` default entre item y label
|
|
282
|
-
|
|
283
|
-
## Accesibilidad
|
|
284
|
-
|
|
285
|
-
- ✅ **Role**: `role="radio"` y `role="radiogroup"`
|
|
286
|
-
- ✅ **ARIA**: `aria-checked`, `aria-disabled`, `aria-invalid`
|
|
287
|
-
- ✅ **Keyboard**: Arrow keys para navegar, Space para seleccionar
|
|
288
|
-
- ✅ **Label**: Asociar con `htmlFor` e `id`
|
|
289
|
-
- ✅ **Focus**: Focus ring visible en navegación por teclado
|
|
290
|
-
|
|
291
|
-
## Notas de Implementación
|
|
292
|
-
|
|
293
|
-
- **Radix UI**: Basado en `@radix-ui/react-radio-group`
|
|
294
|
-
- **Indicador**: Usa Icon component con symbol `circle` y `text-primary`
|
|
295
|
-
- **Grid layout**: Default usa `grid gap-3` para vertical spacing
|
|
296
|
-
- **Data attributes**: `data-slot` para identificar componentes
|
|
297
|
-
- **Controlled**: Usa `value` + `onValueChange`
|
|
298
|
-
- **Uncontrolled**: Usa `defaultValue`
|
|
299
|
-
|
|
300
|
-
## Troubleshooting
|
|
301
|
-
|
|
302
|
-
**No se puede seleccionar**: Verifica que cada item tenga `value` único
|
|
303
|
-
**Label no clickeable**: Asegura `htmlFor` en Label coincida con `id` del RadioGroupItem
|
|
304
|
-
**Grupo deshabilitado**: `disabled` en RadioGroup deshabilita todos los items
|
|
305
|
-
**Item individual disabled**: `disabled` en RadioGroupItem específico
|
|
306
|
-
**Estado no actualiza**: En modo controlado usa `value` + `onValueChange`, no `defaultValue`
|
|
307
|
-
|
|
308
|
-
## Referencias
|
|
309
|
-
|
|
310
|
-
- **Radix UI Radio Group**: <https://www.radix-ui.com/primitives/docs/components/radio-group>
|
|
311
|
-
- **shadcn/ui Radio Group**: <https://ui.shadcn.com/docs/components/radio-group>
|
|
1
|
+
# Radio Group
|
|
2
|
+
|
|
3
|
+
Grupo de opciones mutuamente excluyentes. Usuario selecciona una opción. Basado en Radix UI.
|
|
4
|
+
|
|
5
|
+
## Descripción
|
|
6
|
+
|
|
7
|
+
El componente `RadioGroup` permite seleccionar una opción de un conjunto de opciones mutuamente excluyentes.
|
|
8
|
+
|
|
9
|
+
## Importación
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { RadioGroup, RadioGroupItem } from "@adamosuiteservices/ui/radio-group";
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Anatomía
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
<RadioGroup defaultValue="option-one">
|
|
19
|
+
<div className="flex items-center space-x-2">
|
|
20
|
+
<RadioGroupItem value="option-one" id="option-one" />
|
|
21
|
+
<Label htmlFor="option-one">Option One</Label>
|
|
22
|
+
</div>
|
|
23
|
+
<div className="flex items-center space-x-2">
|
|
24
|
+
<RadioGroupItem value="option-two" id="option-two" />
|
|
25
|
+
<Label htmlFor="option-two">Option Two</Label>
|
|
26
|
+
</div>
|
|
27
|
+
</RadioGroup>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Componentes**: 2 (RadioGroup, RadioGroupItem)
|
|
31
|
+
|
|
32
|
+
## Props
|
|
33
|
+
|
|
34
|
+
### RadioGroup
|
|
35
|
+
|
|
36
|
+
| Prop | Tipo | Descripción |
|
|
37
|
+
| --------------- | ------------------------- | ------------------------------ |
|
|
38
|
+
| `defaultValue` | `string` | Valor inicial (uncontrolled) |
|
|
39
|
+
| `value` | `string` | Valor controlado |
|
|
40
|
+
| `onValueChange` | `(value: string) => void` | Callback al cambiar valor |
|
|
41
|
+
| `disabled` | `boolean` | Deshabilita todo el grupo |
|
|
42
|
+
| `required` | `boolean` | Campo requerido |
|
|
43
|
+
| `name` | `string` | Nombre del grupo (formularios) |
|
|
44
|
+
| `className` | `string` | Clases CSS adicionales |
|
|
45
|
+
|
|
46
|
+
**Nota**: Acepta todas las props de Radix UI RadioGroup.Root
|
|
47
|
+
|
|
48
|
+
### RadioGroupItem
|
|
49
|
+
|
|
50
|
+
| Prop | Tipo | Descripción |
|
|
51
|
+
| ----------- | --------- | ------------------------- |
|
|
52
|
+
| `value` | `string` | Valor único del item |
|
|
53
|
+
| `id` | `string` | ID para asociar con Label |
|
|
54
|
+
| `disabled` | `boolean` | Deshabilita este item |
|
|
55
|
+
| `className` | `string` | Clases CSS adicionales |
|
|
56
|
+
|
|
57
|
+
**Nota**: Acepta todas las props de Radix UI RadioGroup.Item
|
|
58
|
+
|
|
59
|
+
## Patrones de Uso
|
|
60
|
+
|
|
61
|
+
### Básico
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { RadioGroup, RadioGroupItem } from "@adamosuiteservices/ui/radio-group";
|
|
65
|
+
import { Label } from "@adamosuiteservices/ui/label";
|
|
66
|
+
|
|
67
|
+
<RadioGroup defaultValue="option-one">
|
|
68
|
+
<div className="flex items-center gap-3">
|
|
69
|
+
<RadioGroupItem value="option-one" id="option-one" />
|
|
70
|
+
<Label htmlFor="option-one">Option One</Label>
|
|
71
|
+
</div>
|
|
72
|
+
<div className="flex items-center gap-3">
|
|
73
|
+
<RadioGroupItem value="option-two" id="option-two" />
|
|
74
|
+
<Label htmlFor="option-two">Option Two</Label>
|
|
75
|
+
</div>
|
|
76
|
+
</RadioGroup>;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Controlado
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import { useState } from "react";
|
|
83
|
+
|
|
84
|
+
function App() {
|
|
85
|
+
const [value, setValue] = useState("red");
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<RadioGroup value={value} onValueChange={setValue}>
|
|
89
|
+
<div className="flex items-center gap-3">
|
|
90
|
+
<RadioGroupItem value="red" id="red" />
|
|
91
|
+
<Label htmlFor="red">Red</Label>
|
|
92
|
+
</div>
|
|
93
|
+
<div className="flex items-center gap-3">
|
|
94
|
+
<RadioGroupItem value="green" id="green" />
|
|
95
|
+
<Label htmlFor="green">Green</Label>
|
|
96
|
+
</div>
|
|
97
|
+
</RadioGroup>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Con Descripciones
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
<RadioGroup defaultValue="comfortable">
|
|
106
|
+
<div className="flex items-start gap-3">
|
|
107
|
+
<RadioGroupItem value="default" id="default" />
|
|
108
|
+
<div className="grid gap-2">
|
|
109
|
+
<Label htmlFor="default">Default</Label>
|
|
110
|
+
<p className="text-muted-foreground text-sm">
|
|
111
|
+
Recommended for most users. Provides a balanced experience.
|
|
112
|
+
</p>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
<div className="flex items-start gap-3">
|
|
116
|
+
<RadioGroupItem value="comfortable" id="comfortable" />
|
|
117
|
+
<div className="grid gap-2">
|
|
118
|
+
<Label htmlFor="comfortable">Comfortable</Label>
|
|
119
|
+
<p className="text-muted-foreground text-sm">
|
|
120
|
+
More spacing and larger elements for better accessibility.
|
|
121
|
+
</p>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
</RadioGroup>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Layout Horizontal
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
<RadioGroup defaultValue="medium" className="flex gap-6">
|
|
131
|
+
<div className="flex items-center gap-2">
|
|
132
|
+
<RadioGroupItem value="small" id="small" />
|
|
133
|
+
<Label htmlFor="small">Small</Label>
|
|
134
|
+
</div>
|
|
135
|
+
<div className="flex items-center gap-2">
|
|
136
|
+
<RadioGroupItem value="medium" id="medium" />
|
|
137
|
+
<Label htmlFor="medium">Medium</Label>
|
|
138
|
+
</div>
|
|
139
|
+
<div className="flex items-center gap-2">
|
|
140
|
+
<RadioGroupItem value="large" id="large" />
|
|
141
|
+
<Label htmlFor="large">Large</Label>
|
|
142
|
+
</div>
|
|
143
|
+
</RadioGroup>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Con Badges
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import { Badge } from "@adamosuiteservices/ui/badge";
|
|
150
|
+
|
|
151
|
+
<RadioGroup defaultValue="pro">
|
|
152
|
+
<div className="flex items-center gap-3">
|
|
153
|
+
<RadioGroupItem value="free" id="free" />
|
|
154
|
+
<div className="flex items-center gap-2">
|
|
155
|
+
<Label htmlFor="free">Free Plan</Label>
|
|
156
|
+
<Badge variant="secondary">$0/month</Badge>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
<div className="flex items-center gap-3">
|
|
160
|
+
<RadioGroupItem value="pro" id="pro" />
|
|
161
|
+
<div className="flex items-center gap-2">
|
|
162
|
+
<Label htmlFor="pro">Pro Plan</Label>
|
|
163
|
+
<Badge variant="default">$9/month</Badge>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
</RadioGroup>;
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### En Formularios
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
import { Button } from "@adamosuiteservices/ui/button";
|
|
173
|
+
|
|
174
|
+
function App() {
|
|
175
|
+
const [formData, setFormData] = useState({
|
|
176
|
+
notification: "email",
|
|
177
|
+
frequency: "weekly",
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const handleSubmit = (e: React.FormEvent) => {
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
console.log("Form submitted:", formData);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<form onSubmit={handleSubmit} className="space-y-6">
|
|
187
|
+
<div className="space-y-3">
|
|
188
|
+
<p className="text-sm font-medium">Notification method</p>
|
|
189
|
+
<RadioGroup
|
|
190
|
+
value={formData.notification}
|
|
191
|
+
onValueChange={(value) =>
|
|
192
|
+
setFormData((prev) => ({ ...prev, notification: value }))
|
|
193
|
+
}
|
|
194
|
+
>
|
|
195
|
+
<div className="flex items-center gap-3">
|
|
196
|
+
<RadioGroupItem value="email" id="email" />
|
|
197
|
+
<Label htmlFor="email">Email notifications</Label>
|
|
198
|
+
</div>
|
|
199
|
+
<div className="flex items-center gap-3">
|
|
200
|
+
<RadioGroupItem value="sms" id="sms" />
|
|
201
|
+
<Label htmlFor="sms">SMS notifications</Label>
|
|
202
|
+
</div>
|
|
203
|
+
</RadioGroup>
|
|
204
|
+
</div>
|
|
205
|
+
<Button type="submit">Save preferences</Button>
|
|
206
|
+
</form>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Nested (Conditional)
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
function App() {
|
|
215
|
+
const [paymentMethod, setPaymentMethod] = useState("card");
|
|
216
|
+
const [cardType, setCardType] = useState("visa");
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<div className="space-y-6">
|
|
220
|
+
<RadioGroup value={paymentMethod} onValueChange={setPaymentMethod}>
|
|
221
|
+
<div className="flex items-center gap-3">
|
|
222
|
+
<RadioGroupItem value="card" id="card" />
|
|
223
|
+
<Label htmlFor="card">Credit/Debit Card</Label>
|
|
224
|
+
</div>
|
|
225
|
+
<div className="flex items-center gap-3">
|
|
226
|
+
<RadioGroupItem value="bank" id="bank" />
|
|
227
|
+
<Label htmlFor="bank">Bank Transfer</Label>
|
|
228
|
+
</div>
|
|
229
|
+
</RadioGroup>
|
|
230
|
+
|
|
231
|
+
{paymentMethod === "card" && (
|
|
232
|
+
<div className="ml-6 space-y-3">
|
|
233
|
+
<p className="text-sm font-medium">Card type</p>
|
|
234
|
+
<RadioGroup value={cardType} onValueChange={setCardType}>
|
|
235
|
+
<div className="flex items-center gap-3">
|
|
236
|
+
<RadioGroupItem value="visa" id="visa" />
|
|
237
|
+
<Label htmlFor="visa">Visa</Label>
|
|
238
|
+
</div>
|
|
239
|
+
<div className="flex items-center gap-3">
|
|
240
|
+
<RadioGroupItem value="mastercard" id="mastercard" />
|
|
241
|
+
<Label htmlFor="mastercard">Mastercard</Label>
|
|
242
|
+
</div>
|
|
243
|
+
</RadioGroup>
|
|
244
|
+
</div>
|
|
245
|
+
)}
|
|
246
|
+
</div>
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Deshabilitado
|
|
252
|
+
|
|
253
|
+
```tsx
|
|
254
|
+
<RadioGroup defaultValue="option-one" disabled>
|
|
255
|
+
<div className="flex items-center gap-3">
|
|
256
|
+
<RadioGroupItem value="option-one" id="disabled-one" />
|
|
257
|
+
<Label htmlFor="disabled-one">Option One</Label>
|
|
258
|
+
</div>
|
|
259
|
+
<div className="flex items-center gap-3">
|
|
260
|
+
<RadioGroupItem value="option-two" id="disabled-two" />
|
|
261
|
+
<Label htmlFor="disabled-two">Option Two</Label>
|
|
262
|
+
</div>
|
|
263
|
+
</RadioGroup>
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Casos de Uso
|
|
267
|
+
|
|
268
|
+
**Opciones mutuamente excluyentes**: Una sola selección de múltiples opciones
|
|
269
|
+
**Settings**: Preferencias de configuración (theme, size, mode)
|
|
270
|
+
**Formularios**: Selección de método de pago, envío, categoría
|
|
271
|
+
**Surveys**: Preguntas con opciones de respuesta única
|
|
272
|
+
**Filtros**: Filtrado por categoría, tipo, estado
|
|
273
|
+
|
|
274
|
+
## Estilos Base
|
|
275
|
+
|
|
276
|
+
- **Size**: `size-5` (20px)
|
|
277
|
+
- **Border**: `border-input` con `shadow-xs`
|
|
278
|
+
- **Checked**: Icon `circle` con `text-primary`
|
|
279
|
+
- **Focus**: `ring-ring/50` con `ring-[3px]`
|
|
280
|
+
- **Invalid**: `border-destructive` con `ring-destructive/20`
|
|
281
|
+
- **Spacing**: `gap-3` default entre item y label
|
|
282
|
+
|
|
283
|
+
## Accesibilidad
|
|
284
|
+
|
|
285
|
+
- ✅ **Role**: `role="radio"` y `role="radiogroup"`
|
|
286
|
+
- ✅ **ARIA**: `aria-checked`, `aria-disabled`, `aria-invalid`
|
|
287
|
+
- ✅ **Keyboard**: Arrow keys para navegar, Space para seleccionar
|
|
288
|
+
- ✅ **Label**: Asociar con `htmlFor` e `id`
|
|
289
|
+
- ✅ **Focus**: Focus ring visible en navegación por teclado
|
|
290
|
+
|
|
291
|
+
## Notas de Implementación
|
|
292
|
+
|
|
293
|
+
- **Radix UI**: Basado en `@radix-ui/react-radio-group`
|
|
294
|
+
- **Indicador**: Usa Icon component con symbol `circle` y `text-primary`
|
|
295
|
+
- **Grid layout**: Default usa `grid gap-3` para vertical spacing
|
|
296
|
+
- **Data attributes**: `data-slot` para identificar componentes
|
|
297
|
+
- **Controlled**: Usa `value` + `onValueChange`
|
|
298
|
+
- **Uncontrolled**: Usa `defaultValue`
|
|
299
|
+
|
|
300
|
+
## Troubleshooting
|
|
301
|
+
|
|
302
|
+
**No se puede seleccionar**: Verifica que cada item tenga `value` único
|
|
303
|
+
**Label no clickeable**: Asegura `htmlFor` en Label coincida con `id` del RadioGroupItem
|
|
304
|
+
**Grupo deshabilitado**: `disabled` en RadioGroup deshabilita todos los items
|
|
305
|
+
**Item individual disabled**: `disabled` en RadioGroupItem específico
|
|
306
|
+
**Estado no actualiza**: En modo controlado usa `value` + `onValueChange`, no `defaultValue`
|
|
307
|
+
|
|
308
|
+
## Referencias
|
|
309
|
+
|
|
310
|
+
- **Radix UI Radio Group**: <https://www.radix-ui.com/primitives/docs/components/radio-group>
|
|
311
|
+
- **shadcn/ui Radio Group**: <https://ui.shadcn.com/docs/components/radio-group>
|