@proyecto-viviana/solidaria-components 0.1.2 → 0.2.1

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 (62) hide show
  1. package/dist/Color.d.ts +6 -2
  2. package/dist/Color.d.ts.map +1 -1
  3. package/dist/ComboBox.d.ts +3 -3
  4. package/dist/ComboBox.d.ts.map +1 -1
  5. package/dist/GridList.d.ts +2 -2
  6. package/dist/GridList.d.ts.map +1 -1
  7. package/dist/ListBox.d.ts +5 -5
  8. package/dist/ListBox.d.ts.map +1 -1
  9. package/dist/Menu.d.ts +3 -3
  10. package/dist/Menu.d.ts.map +1 -1
  11. package/dist/Select.d.ts +3 -3
  12. package/dist/Select.d.ts.map +1 -1
  13. package/dist/Table.d.ts +2 -2
  14. package/dist/Table.d.ts.map +1 -1
  15. package/dist/Tabs.d.ts +1 -1
  16. package/dist/Tabs.d.ts.map +1 -1
  17. package/dist/index.js +15 -15
  18. package/dist/index.js.map +2 -2
  19. package/dist/index.ssr.js +15 -15
  20. package/dist/index.ssr.js.map +2 -2
  21. package/package.json +8 -9
  22. package/src/Autocomplete.tsx +0 -174
  23. package/src/Breadcrumbs.tsx +0 -264
  24. package/src/Button.tsx +0 -238
  25. package/src/Calendar.tsx +0 -471
  26. package/src/Checkbox.tsx +0 -387
  27. package/src/Color.tsx +0 -1370
  28. package/src/ComboBox.tsx +0 -824
  29. package/src/DateField.tsx +0 -337
  30. package/src/DatePicker.tsx +0 -367
  31. package/src/Dialog.tsx +0 -262
  32. package/src/Disclosure.tsx +0 -439
  33. package/src/GridList.tsx +0 -511
  34. package/src/Landmark.tsx +0 -203
  35. package/src/Link.tsx +0 -201
  36. package/src/ListBox.tsx +0 -346
  37. package/src/Menu.tsx +0 -544
  38. package/src/Meter.tsx +0 -157
  39. package/src/Modal.tsx +0 -433
  40. package/src/NumberField.tsx +0 -542
  41. package/src/Popover.tsx +0 -540
  42. package/src/ProgressBar.tsx +0 -162
  43. package/src/RadioGroup.tsx +0 -356
  44. package/src/RangeCalendar.tsx +0 -462
  45. package/src/SearchField.tsx +0 -479
  46. package/src/Select.tsx +0 -734
  47. package/src/Separator.tsx +0 -130
  48. package/src/Slider.tsx +0 -500
  49. package/src/Switch.tsx +0 -213
  50. package/src/Table.tsx +0 -857
  51. package/src/Tabs.tsx +0 -552
  52. package/src/TagGroup.tsx +0 -421
  53. package/src/TextField.tsx +0 -271
  54. package/src/TimeField.tsx +0 -455
  55. package/src/Toast.tsx +0 -503
  56. package/src/Toolbar.tsx +0 -160
  57. package/src/Tooltip.tsx +0 -423
  58. package/src/Tree.tsx +0 -551
  59. package/src/VisuallyHidden.tsx +0 -60
  60. package/src/contexts.ts +0 -74
  61. package/src/index.ts +0 -620
  62. package/src/utils.tsx +0 -329
@@ -1,356 +0,0 @@
1
- /**
2
- * RadioGroup and Radio components for solidaria-components
3
- *
4
- * Pre-wired headless radio components that combine state + aria hooks.
5
- * Port of react-aria-components/src/RadioGroup.tsx
6
- */
7
-
8
- import {
9
- type JSX,
10
- type ParentProps,
11
- createContext,
12
- useContext,
13
- createMemo,
14
- splitProps,
15
- Show,
16
- } from 'solid-js';
17
- import {
18
- createRadio,
19
- createRadioGroup,
20
- createFocusRing,
21
- createHover,
22
- type AriaRadioProps,
23
- type AriaRadioGroupProps,
24
- } from '@proyecto-viviana/solidaria';
25
- import {
26
- createRadioGroupState,
27
- type RadioGroupState,
28
- type RadioGroupProps as RadioGroupStateProps,
29
- } from '@proyecto-viviana/solid-stately';
30
- import { VisuallyHidden } from './VisuallyHidden';
31
- import {
32
- type RenderChildren,
33
- type ClassNameOrFunction,
34
- type StyleOrFunction,
35
- type SlotProps,
36
- useRenderProps,
37
- filterDOMProps,
38
- } from './utils';
39
-
40
- // ============================================
41
- // TYPES
42
- // ============================================
43
-
44
- export type Orientation = 'horizontal' | 'vertical';
45
-
46
- export interface RadioGroupRenderProps {
47
- /** The orientation of the radio group. */
48
- orientation: Orientation;
49
- /** Whether the radio group is disabled. */
50
- isDisabled: boolean;
51
- /** Whether the radio group is read only. */
52
- isReadOnly: boolean;
53
- /** Whether the radio group is required. */
54
- isRequired: boolean;
55
- /** Whether the radio group is invalid. */
56
- isInvalid: boolean;
57
- /** State of the radio group. */
58
- state: RadioGroupState;
59
- }
60
-
61
- export interface RadioRenderProps {
62
- /** Whether the radio is selected. */
63
- isSelected: boolean;
64
- /** Whether the radio is currently hovered with a mouse. */
65
- isHovered: boolean;
66
- /** Whether the radio is currently in a pressed state. */
67
- isPressed: boolean;
68
- /** Whether the radio is focused, either via a mouse or keyboard. */
69
- isFocused: boolean;
70
- /** Whether the radio is keyboard focused. */
71
- isFocusVisible: boolean;
72
- /** Whether the radio is disabled. */
73
- isDisabled: boolean;
74
- /** Whether the radio is read only. */
75
- isReadOnly: boolean;
76
- /** Whether the radio is invalid. */
77
- isInvalid: boolean;
78
- /** Whether the radio is required. */
79
- isRequired: boolean;
80
- }
81
-
82
- export interface RadioGroupProps
83
- extends Omit<AriaRadioGroupProps, 'children' | 'label' | 'description' | 'errorMessage'>,
84
- Pick<RadioGroupStateProps, 'value' | 'defaultValue' | 'onChange'>,
85
- SlotProps {
86
- /** The children of the component. A function may be provided to receive render props. */
87
- children?: RenderChildren<RadioGroupRenderProps>;
88
- /** The CSS className for the element. */
89
- class?: ClassNameOrFunction<RadioGroupRenderProps>;
90
- /** The inline style for the element. */
91
- style?: StyleOrFunction<RadioGroupRenderProps>;
92
- }
93
-
94
- export interface RadioProps
95
- extends Omit<AriaRadioProps, 'children'>,
96
- SlotProps {
97
- /** The children of the component. A function may be provided to receive render props. */
98
- children?: RenderChildren<RadioRenderProps>;
99
- /** The CSS className for the element. */
100
- class?: ClassNameOrFunction<RadioRenderProps>;
101
- /** The inline style for the element. */
102
- style?: StyleOrFunction<RadioRenderProps>;
103
- }
104
-
105
- // ============================================
106
- // CONTEXT
107
- // ============================================
108
-
109
- export const RadioGroupContext = createContext<RadioGroupProps | null>(null);
110
- export const RadioGroupStateContext = createContext<RadioGroupState | null>(null);
111
- export const RadioContext = createContext<RadioProps | null>(null);
112
-
113
- // ============================================
114
- // RADIO GROUP COMPONENT
115
- // ============================================
116
-
117
- /**
118
- * A radio group allows a user to select a single item from a list of mutually exclusive options.
119
- *
120
- * @example
121
- * ```tsx
122
- * <RadioGroup>
123
- * <Radio value="one">Option 1</Radio>
124
- * <Radio value="two">Option 2</Radio>
125
- * </RadioGroup>
126
- * ```
127
- */
128
- export function RadioGroup(props: ParentProps<RadioGroupProps>): JSX.Element {
129
- const [local, ariaProps] = splitProps(props, [
130
- 'class',
131
- 'style',
132
- 'slot',
133
- ]);
134
-
135
- // Create radio group state
136
- // We pass a function that returns props so that createRadioGroupState
137
- // can access props reactively. The props object itself is a proxy in SolidJS,
138
- // so accessing props.value inside a reactive context will track changes.
139
- const state = createRadioGroupState({
140
- get value() { return props.value; },
141
- get defaultValue() { return props.defaultValue; },
142
- get onChange() { return props.onChange; },
143
- get isDisabled() { return props.isDisabled; },
144
- get isReadOnly() { return props.isReadOnly; },
145
- get isRequired() { return props.isRequired; },
146
- get isInvalid() { return props.isInvalid; },
147
- });
148
-
149
- // Create radio group aria props
150
- const groupAria = createRadioGroup(() => ariaProps, state);
151
-
152
- // Render props values
153
- const renderValues = createMemo<RadioGroupRenderProps>(() => ({
154
- orientation: (ariaProps.orientation as Orientation) ?? 'vertical',
155
- isDisabled: state.isDisabled,
156
- isReadOnly: state.isReadOnly,
157
- isRequired: state.isRequired,
158
- isInvalid: groupAria.isInvalid,
159
- state,
160
- }));
161
-
162
- // Resolve render props
163
- const renderProps = useRenderProps(
164
- {
165
- children: props.children,
166
- class: local.class,
167
- style: local.style,
168
- defaultClassName: 'solidaria-RadioGroup',
169
- },
170
- renderValues
171
- );
172
-
173
- // Filter DOM props
174
- const domProps = createMemo(() => filterDOMProps(ariaProps, { global: true }));
175
-
176
- // Remove ref from spread props to avoid type conflicts
177
- const cleanGroupProps = () => {
178
- const { ref: _ref, ...rest } = groupAria.radioGroupProps as Record<string, unknown>;
179
- return rest;
180
- };
181
-
182
- // Resolve children - we need to pass render props if children is a function
183
- // but we use props.children directly (not renderProps.renderChildren())
184
- // to preserve SolidJS context propagation for nested components like Radio
185
- const resolvedChildren = () => {
186
- const children = props.children;
187
- if (typeof children === 'function') {
188
- return children(renderValues());
189
- }
190
- return children;
191
- };
192
-
193
- return (
194
- <RadioGroupStateContext.Provider value={state}>
195
- <div
196
- {...domProps()}
197
- {...cleanGroupProps()}
198
- class={renderProps.class()}
199
- style={renderProps.style()}
200
- data-orientation={ariaProps.orientation ?? 'vertical'}
201
- data-disabled={state.isDisabled || undefined}
202
- data-readonly={state.isReadOnly || undefined}
203
- data-required={state.isRequired || undefined}
204
- data-invalid={groupAria.isInvalid || undefined}
205
- >
206
- {resolvedChildren()}
207
- </div>
208
- </RadioGroupStateContext.Provider>
209
- );
210
- }
211
-
212
- // ============================================
213
- // RADIO COMPONENT
214
- // ============================================
215
-
216
- /**
217
- * Internal Radio implementation that has access to RadioGroupStateContext.
218
- * This is rendered inside the RadioGroup's context provider.
219
- */
220
- function RadioImpl(props: { radioProps: RadioProps; state: RadioGroupState }): JSX.Element {
221
- let inputRef: HTMLInputElement | null = null;
222
- const { radioProps, state } = props;
223
-
224
- const [local, ariaProps] = splitProps(radioProps, ['class', 'style', 'slot']);
225
-
226
- // Create radio aria props
227
- const radioAria = createRadio(
228
- () => ({
229
- ...ariaProps,
230
- children: typeof radioProps.children === 'function' ? true : radioProps.children,
231
- }),
232
- state,
233
- () => inputRef
234
- );
235
-
236
- // Create focus ring
237
- const { isFocused, isFocusVisible, focusProps } = createFocusRing();
238
-
239
- // Create hover
240
- const { isHovered, hoverProps } = createHover({
241
- get isDisabled() {
242
- return radioAria.isDisabled || state.isReadOnly;
243
- },
244
- });
245
-
246
- // Render props values
247
- const renderValues = createMemo<RadioRenderProps>(() => ({
248
- isSelected: radioAria.isSelected(),
249
- isHovered: isHovered(),
250
- isPressed: radioAria.isPressed(),
251
- isFocused: isFocused(),
252
- isFocusVisible: isFocusVisible(),
253
- isDisabled: radioAria.isDisabled,
254
- isReadOnly: state.isReadOnly,
255
- isInvalid: state.isInvalid,
256
- isRequired: state.isRequired,
257
- }));
258
-
259
- // Resolve render props
260
- const renderProps = useRenderProps(
261
- {
262
- children: radioProps.children,
263
- class: local.class,
264
- style: local.style,
265
- defaultClassName: 'solidaria-Radio',
266
- },
267
- renderValues
268
- );
269
-
270
- // Filter DOM props
271
- const domProps = createMemo(() => {
272
- const filtered = filterDOMProps(ariaProps, { global: true });
273
- delete (filtered as Record<string, unknown>).id;
274
- delete (filtered as Record<string, unknown>).onClick;
275
- return filtered;
276
- });
277
-
278
- // Remove ref from spread props to avoid type conflicts
279
- const cleanLabelProps = () => {
280
- const { ref: _ref1, ...rest } = radioAria.labelProps as Record<string, unknown>;
281
- return rest;
282
- };
283
- const cleanHoverProps = () => {
284
- const { ref: _ref2, ...rest } = hoverProps as Record<string, unknown>;
285
- return rest;
286
- };
287
- const cleanInputProps = () => {
288
- const { ref: _ref3, ...rest } = radioAria.inputProps as Record<string, unknown>;
289
- return rest;
290
- };
291
- const cleanFocusProps = () => {
292
- const { ref: _ref4, ...rest } = focusProps as Record<string, unknown>;
293
- return rest;
294
- };
295
-
296
- return (
297
- <label
298
- {...domProps()}
299
- {...cleanLabelProps()}
300
- {...cleanHoverProps()}
301
- class={renderProps.class()}
302
- style={renderProps.style()}
303
- data-selected={radioAria.isSelected() || undefined}
304
- data-pressed={radioAria.isPressed() || undefined}
305
- data-hovered={isHovered() || undefined}
306
- data-focused={isFocused() || undefined}
307
- data-focus-visible={isFocusVisible() || undefined}
308
- data-disabled={radioAria.isDisabled || undefined}
309
- data-readonly={state.isReadOnly || undefined}
310
- data-invalid={state.isInvalid || undefined}
311
- data-required={state.isRequired || undefined}
312
- >
313
- <VisuallyHidden>
314
- <input
315
- ref={(el) => (inputRef = el)}
316
- {...cleanInputProps()}
317
- {...cleanFocusProps()}
318
- />
319
- </VisuallyHidden>
320
- {renderProps.renderChildren()}
321
- </label>
322
- );
323
- }
324
-
325
- /**
326
- * A radio represents an individual option within a radio group.
327
- *
328
- * @example
329
- * ```tsx
330
- * <Radio value="option1">
331
- * {({ isSelected }) => (
332
- * <>
333
- * <span class={`radio ${isSelected ? 'selected' : ''}`}>
334
- * {isSelected && '●'}
335
- * </span>
336
- * <span>Option 1</span>
337
- * </>
338
- * )}
339
- * </Radio>
340
- * ```
341
- */
342
- export function Radio(props: RadioProps): JSX.Element {
343
- // Get context - will be null if not inside RadioGroup
344
- // The context is accessed reactively to work with solid-refresh HMR
345
- const getState = createMemo(() => useContext(RadioGroupStateContext));
346
-
347
- return (
348
- <Show
349
- when={getState()}
350
- fallback={null}
351
- keyed
352
- >
353
- {(state) => <RadioImpl radioProps={props} state={state} />}
354
- </Show>
355
- );
356
- }