@proyecto-viviana/solidaria-components 0.2.1 → 0.2.3

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 +2 -6
  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 +56 -56
  18. package/dist/index.js.map +2 -2
  19. package/dist/index.ssr.js +56 -56
  20. package/dist/index.ssr.js.map +2 -2
  21. package/package.json +10 -8
  22. package/src/Autocomplete.tsx +174 -0
  23. package/src/Breadcrumbs.tsx +264 -0
  24. package/src/Button.tsx +238 -0
  25. package/src/Calendar.tsx +471 -0
  26. package/src/Checkbox.tsx +387 -0
  27. package/src/Color.tsx +1370 -0
  28. package/src/ComboBox.tsx +824 -0
  29. package/src/DateField.tsx +337 -0
  30. package/src/DatePicker.tsx +367 -0
  31. package/src/Dialog.tsx +262 -0
  32. package/src/Disclosure.tsx +439 -0
  33. package/src/GridList.tsx +511 -0
  34. package/src/Landmark.tsx +203 -0
  35. package/src/Link.tsx +201 -0
  36. package/src/ListBox.tsx +346 -0
  37. package/src/Menu.tsx +544 -0
  38. package/src/Meter.tsx +157 -0
  39. package/src/Modal.tsx +433 -0
  40. package/src/NumberField.tsx +542 -0
  41. package/src/Popover.tsx +540 -0
  42. package/src/ProgressBar.tsx +162 -0
  43. package/src/RadioGroup.tsx +356 -0
  44. package/src/RangeCalendar.tsx +462 -0
  45. package/src/SearchField.tsx +479 -0
  46. package/src/Select.tsx +734 -0
  47. package/src/Separator.tsx +130 -0
  48. package/src/Slider.tsx +500 -0
  49. package/src/Switch.tsx +213 -0
  50. package/src/Table.tsx +857 -0
  51. package/src/Tabs.tsx +552 -0
  52. package/src/TagGroup.tsx +421 -0
  53. package/src/TextField.tsx +271 -0
  54. package/src/TimeField.tsx +455 -0
  55. package/src/Toast.tsx +503 -0
  56. package/src/Toolbar.tsx +160 -0
  57. package/src/Tooltip.tsx +423 -0
  58. package/src/Tree.tsx +551 -0
  59. package/src/VisuallyHidden.tsx +60 -0
  60. package/src/contexts.ts +74 -0
  61. package/src/index.ts +620 -0
  62. package/src/utils.tsx +329 -0
package/src/Switch.tsx ADDED
@@ -0,0 +1,213 @@
1
+ /**
2
+ * ToggleSwitch component for solidaria-components
3
+ *
4
+ * A pre-wired headless switch that combines state + aria hooks.
5
+ * Port of react-aria-components/src/Switch.tsx
6
+ *
7
+ * Named "ToggleSwitch" to avoid conflict with SolidJS's built-in Switch component.
8
+ */
9
+
10
+ import {
11
+ type JSX,
12
+ createContext,
13
+ createMemo,
14
+ splitProps,
15
+ } from 'solid-js';
16
+ import {
17
+ createSwitch,
18
+ createFocusRing,
19
+ createHover,
20
+ type AriaSwitchProps,
21
+ } from '@proyecto-viviana/solidaria';
22
+ import { createToggleState, type ToggleState } from '@proyecto-viviana/solid-stately';
23
+ import { VisuallyHidden } from './VisuallyHidden';
24
+ import {
25
+ type RenderChildren,
26
+ type ClassNameOrFunction,
27
+ type StyleOrFunction,
28
+ type SlotProps,
29
+ useRenderProps,
30
+ filterDOMProps,
31
+ } from './utils';
32
+
33
+ // ============================================
34
+ // TYPES
35
+ // ============================================
36
+
37
+ export interface ToggleSwitchRenderProps {
38
+ /** Whether the switch is selected. */
39
+ isSelected: boolean;
40
+ /** Whether the switch is currently hovered with a mouse. */
41
+ isHovered: boolean;
42
+ /** Whether the switch is currently in a pressed state. */
43
+ isPressed: boolean;
44
+ /** Whether the switch is focused, either via a mouse or keyboard. */
45
+ isFocused: boolean;
46
+ /** Whether the switch is keyboard focused. */
47
+ isFocusVisible: boolean;
48
+ /** Whether the switch is disabled. */
49
+ isDisabled: boolean;
50
+ /** Whether the switch is read only. */
51
+ isReadOnly: boolean;
52
+ /** State of the switch. */
53
+ state: ToggleState;
54
+ }
55
+
56
+ export interface ToggleSwitchProps
57
+ extends Omit<AriaSwitchProps, 'children'>,
58
+ SlotProps {
59
+ /** The children of the component. A function may be provided to receive render props. */
60
+ children?: RenderChildren<ToggleSwitchRenderProps>;
61
+ /** The CSS className for the element. */
62
+ class?: ClassNameOrFunction<ToggleSwitchRenderProps>;
63
+ /** The inline style for the element. */
64
+ style?: StyleOrFunction<ToggleSwitchRenderProps>;
65
+ }
66
+
67
+ // ============================================
68
+ // CONTEXT
69
+ // ============================================
70
+
71
+ export const ToggleSwitchContext = createContext<ToggleSwitchProps | null>(null);
72
+
73
+ // ============================================
74
+ // COMPONENT
75
+ // ============================================
76
+
77
+ /**
78
+ * A switch allows a user to turn a setting on or off.
79
+ *
80
+ * This is a headless component that provides accessibility and state management.
81
+ * Style it using the render props pattern or data attributes.
82
+ *
83
+ * Named "ToggleSwitch" to avoid conflict with SolidJS's built-in Switch component.
84
+ *
85
+ * @example
86
+ * ```tsx
87
+ * <ToggleSwitch>
88
+ * {({ isSelected }) => (
89
+ * <>
90
+ * <span class={`switch-track ${isSelected ? 'bg-blue-500' : 'bg-gray-300'}`}>
91
+ * <span class={`switch-thumb ${isSelected ? 'translate-x-5' : 'translate-x-0'}`} />
92
+ * </span>
93
+ * <span>Enable notifications</span>
94
+ * </>
95
+ * )}
96
+ * </ToggleSwitch>
97
+ * ```
98
+ */
99
+ export function ToggleSwitch(props: ToggleSwitchProps): JSX.Element {
100
+ let inputRef: HTMLInputElement | null = null;
101
+
102
+ // Split props
103
+ const [local, ariaProps] = splitProps(props, [
104
+ 'class',
105
+ 'style',
106
+ 'slot',
107
+ ]);
108
+
109
+ // Create toggle state
110
+ // Use getters to ensure props are read lazily inside reactive contexts
111
+ const state = createToggleState({
112
+ get isSelected() { return ariaProps.isSelected; },
113
+ get defaultSelected() { return ariaProps.defaultSelected; },
114
+ get onChange() { return ariaProps.onChange; },
115
+ get isReadOnly() { return ariaProps.isReadOnly; },
116
+ });
117
+
118
+ // Create switch aria props
119
+ const switchAria = createSwitch(
120
+ () => ({
121
+ ...ariaProps,
122
+ children: typeof props.children === 'function' ? true : props.children,
123
+ }),
124
+ state,
125
+ () => inputRef
126
+ );
127
+
128
+ // Create focus ring
129
+ const { isFocused, isFocusVisible, focusProps } = createFocusRing();
130
+
131
+ // Create hover
132
+ const { isHovered, hoverProps } = createHover({
133
+ get isDisabled() {
134
+ return ariaProps.isDisabled || ariaProps.isReadOnly;
135
+ },
136
+ });
137
+
138
+ // Render props values
139
+ const renderValues = createMemo<ToggleSwitchRenderProps>(() => ({
140
+ isSelected: switchAria.isSelected(),
141
+ isHovered: isHovered(),
142
+ isPressed: switchAria.isPressed(),
143
+ isFocused: isFocused(),
144
+ isFocusVisible: isFocusVisible(),
145
+ isDisabled: switchAria.isDisabled,
146
+ isReadOnly: switchAria.isReadOnly,
147
+ state,
148
+ }));
149
+
150
+ // Resolve render props
151
+ const renderProps = useRenderProps(
152
+ {
153
+ children: props.children,
154
+ class: local.class,
155
+ style: local.style,
156
+ defaultClassName: 'solidaria-ToggleSwitch',
157
+ },
158
+ renderValues
159
+ );
160
+
161
+ // Filter DOM props
162
+ const domProps = createMemo(() => {
163
+ const filtered = filterDOMProps(ariaProps, { global: true });
164
+ delete (filtered as Record<string, unknown>).id;
165
+ delete (filtered as Record<string, unknown>).onClick;
166
+ return filtered;
167
+ });
168
+
169
+ // Remove ref from spread props to avoid type conflicts
170
+ const cleanLabelProps = () => {
171
+ const { ref: _ref1, ...rest } = switchAria.labelProps as Record<string, unknown>;
172
+ return rest;
173
+ };
174
+ const cleanHoverProps = () => {
175
+ const { ref: _ref2, ...rest } = hoverProps as Record<string, unknown>;
176
+ return rest;
177
+ };
178
+ const cleanInputProps = () => {
179
+ const { ref: _ref3, ...rest } = switchAria.inputProps as Record<string, unknown>;
180
+ return rest;
181
+ };
182
+ const cleanFocusProps = () => {
183
+ const { ref: _ref4, ...rest } = focusProps as Record<string, unknown>;
184
+ return rest;
185
+ };
186
+
187
+ return (
188
+ <label
189
+ {...domProps()}
190
+ {...cleanLabelProps()}
191
+ {...cleanHoverProps()}
192
+ class={renderProps.class()}
193
+ style={renderProps.style()}
194
+ data-selected={switchAria.isSelected() || undefined}
195
+ data-pressed={switchAria.isPressed() || undefined}
196
+ data-hovered={isHovered() || undefined}
197
+ data-focused={isFocused() || undefined}
198
+ data-focus-visible={isFocusVisible() || undefined}
199
+ data-disabled={switchAria.isDisabled || undefined}
200
+ data-readonly={switchAria.isReadOnly || undefined}
201
+ >
202
+ <VisuallyHidden>
203
+ <input
204
+ ref={(el) => (inputRef = el)}
205
+ {...cleanInputProps()}
206
+ {...cleanFocusProps()}
207
+ />
208
+ </VisuallyHidden>
209
+ {renderProps.renderChildren()}
210
+ </label>
211
+ );
212
+ }
213
+