@proyecto-viviana/solidaria-components 0.1.3 → 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.
- package/dist/Color.d.ts +6 -2
- package/dist/Color.d.ts.map +1 -1
- package/dist/ComboBox.d.ts +3 -3
- package/dist/ComboBox.d.ts.map +1 -1
- package/dist/GridList.d.ts +2 -2
- package/dist/GridList.d.ts.map +1 -1
- package/dist/ListBox.d.ts +5 -5
- package/dist/ListBox.d.ts.map +1 -1
- package/dist/Menu.d.ts +3 -3
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Select.d.ts +3 -3
- package/dist/Select.d.ts.map +1 -1
- package/dist/Table.d.ts +2 -2
- package/dist/Table.d.ts.map +1 -1
- package/dist/Tabs.d.ts +1 -1
- package/dist/Tabs.d.ts.map +1 -1
- package/dist/index.js +15 -15
- package/dist/index.js.map +2 -2
- package/dist/index.ssr.js +15 -15
- package/dist/index.ssr.js.map +2 -2
- package/package.json +8 -10
- package/src/Autocomplete.tsx +0 -174
- package/src/Breadcrumbs.tsx +0 -264
- package/src/Button.tsx +0 -238
- package/src/Calendar.tsx +0 -471
- package/src/Checkbox.tsx +0 -387
- package/src/Color.tsx +0 -1370
- package/src/ComboBox.tsx +0 -824
- package/src/DateField.tsx +0 -337
- package/src/DatePicker.tsx +0 -367
- package/src/Dialog.tsx +0 -262
- package/src/Disclosure.tsx +0 -439
- package/src/GridList.tsx +0 -511
- package/src/Landmark.tsx +0 -203
- package/src/Link.tsx +0 -201
- package/src/ListBox.tsx +0 -346
- package/src/Menu.tsx +0 -544
- package/src/Meter.tsx +0 -157
- package/src/Modal.tsx +0 -433
- package/src/NumberField.tsx +0 -542
- package/src/Popover.tsx +0 -540
- package/src/ProgressBar.tsx +0 -162
- package/src/RadioGroup.tsx +0 -356
- package/src/RangeCalendar.tsx +0 -462
- package/src/SearchField.tsx +0 -479
- package/src/Select.tsx +0 -734
- package/src/Separator.tsx +0 -130
- package/src/Slider.tsx +0 -500
- package/src/Switch.tsx +0 -213
- package/src/Table.tsx +0 -857
- package/src/Tabs.tsx +0 -552
- package/src/TagGroup.tsx +0 -421
- package/src/TextField.tsx +0 -271
- package/src/TimeField.tsx +0 -455
- package/src/Toast.tsx +0 -503
- package/src/Toolbar.tsx +0 -160
- package/src/Tooltip.tsx +0 -423
- package/src/Tree.tsx +0 -551
- package/src/VisuallyHidden.tsx +0 -60
- package/src/contexts.ts +0 -74
- package/src/index.ts +0 -620
- package/src/utils.tsx +0 -329
package/src/Switch.tsx
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
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
|
-
|