@proyecto-viviana/solidaria-components 0.2.9 → 0.3.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.
- package/README.md +39 -272
- package/dist/ActionBar.d.ts +21 -13
- package/dist/ActionBar.d.ts.map +1 -1
- package/dist/ActionGroup.d.ts +8 -8
- package/dist/ActionGroup.d.ts.map +1 -1
- package/dist/Alert.d.ts +5 -5
- package/dist/Alert.d.ts.map +1 -1
- package/dist/Autocomplete.d.ts +5 -5
- package/dist/Autocomplete.d.ts.map +1 -1
- package/dist/Breadcrumbs.d.ts +18 -7
- package/dist/Breadcrumbs.d.ts.map +1 -1
- package/dist/Button.d.ts +24 -5
- package/dist/Button.d.ts.map +1 -1
- package/dist/Calendar.d.ts +38 -7
- package/dist/Calendar.d.ts.map +1 -1
- package/dist/Checkbox.d.ts +32 -7
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/Collection.d.ts +19 -14
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Color.d.ts +103 -14
- package/dist/Color.d.ts.map +1 -1
- package/dist/ColorEditor.d.ts +6 -6
- package/dist/ColorEditor.d.ts.map +1 -1
- package/dist/ComboBox.d.ts +85 -19
- package/dist/ComboBox.d.ts.map +1 -1
- package/dist/ContextualHelpTrigger.d.ts +2 -2
- package/dist/ContextualHelpTrigger.d.ts.map +1 -1
- package/dist/DateField.d.ts +8 -6
- package/dist/DateField.d.ts.map +1 -1
- package/dist/DatePicker.d.ts +53 -22
- package/dist/DatePicker.d.ts.map +1 -1
- package/dist/DateRangePickerContext.d.ts +30 -0
- package/dist/DateRangePickerContext.d.ts.map +1 -0
- package/dist/Dialog.d.ts +5 -5
- package/dist/Dialog.d.ts.map +1 -1
- package/dist/Disclosure.d.ts +23 -5
- package/dist/Disclosure.d.ts.map +1 -1
- package/dist/DragAndDrop.d.ts +6 -6
- package/dist/DragAndDrop.d.ts.map +1 -1
- package/dist/DragPreview.d.ts +2 -2
- package/dist/DragPreview.d.ts.map +1 -1
- package/dist/DropZone.d.ts +4 -4
- package/dist/DropZone.d.ts.map +1 -1
- package/dist/FieldError.d.ts +9 -5
- package/dist/FieldError.d.ts.map +1 -1
- package/dist/FileTrigger.d.ts +3 -3
- package/dist/FileTrigger.d.ts.map +1 -1
- package/dist/Focusable.d.ts +2 -2
- package/dist/Focusable.d.ts.map +1 -1
- package/dist/Form.d.ts +18 -4
- package/dist/Form.d.ts.map +1 -1
- package/dist/GridList.d.ts +32 -12
- package/dist/GridList.d.ts.map +1 -1
- package/dist/HiddenDateInput.d.ts +26 -0
- package/dist/HiddenDateInput.d.ts.map +1 -0
- package/dist/HiddenTimeInput.d.ts +25 -0
- package/dist/HiddenTimeInput.d.ts.map +1 -0
- package/dist/Icon.d.ts +5 -5
- package/dist/Icon.d.ts.map +1 -1
- package/dist/Keyboard.d.ts +1 -1
- package/dist/Landmark.d.ts +3 -3
- package/dist/Landmark.d.ts.map +1 -1
- package/dist/Link.d.ts +10 -4
- package/dist/Link.d.ts.map +1 -1
- package/dist/ListBox.d.ts +32 -12
- package/dist/ListBox.d.ts.map +1 -1
- package/dist/ListDropTargetDelegate.d.ts +6 -6
- package/dist/ListDropTargetDelegate.d.ts.map +1 -1
- package/dist/Menu.d.ts +65 -14
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Meter.d.ts +3 -3
- package/dist/Meter.d.ts.map +1 -1
- package/dist/Modal.d.ts +5 -5
- package/dist/Modal.d.ts.map +1 -1
- package/dist/NumberField.d.ts +8 -12
- package/dist/NumberField.d.ts.map +1 -1
- package/dist/Popover.d.ts +28 -5
- package/dist/Popover.d.ts.map +1 -1
- package/dist/Pressable.d.ts +2 -2
- package/dist/Pressable.d.ts.map +1 -1
- package/dist/ProgressBar.d.ts +5 -3
- package/dist/ProgressBar.d.ts.map +1 -1
- package/dist/RadioGroup.d.ts +43 -9
- package/dist/RadioGroup.d.ts.map +1 -1
- package/dist/RangeCalendar.d.ts +34 -7
- package/dist/RangeCalendar.d.ts.map +1 -1
- package/dist/RouterProvider.d.ts +2 -2
- package/dist/RouterProvider.d.ts.map +1 -1
- package/dist/SearchField.d.ts +23 -20
- package/dist/SearchField.d.ts.map +1 -1
- package/dist/Select.d.ts +41 -11
- package/dist/Select.d.ts.map +1 -1
- package/dist/SelectionIndicator.d.ts +3 -3
- package/dist/SelectionIndicator.d.ts.map +1 -1
- package/dist/Separator.d.ts +9 -3
- package/dist/Separator.d.ts.map +1 -1
- package/dist/SharedElementTransition.d.ts +6 -4
- package/dist/SharedElementTransition.d.ts.map +1 -1
- package/dist/Slider.d.ts +12 -8
- package/dist/Slider.d.ts.map +1 -1
- package/dist/StepList.d.ts +90 -0
- package/dist/StepList.d.ts.map +1 -0
- package/dist/Switch.d.ts +11 -5
- package/dist/Switch.d.ts.map +1 -1
- package/dist/Table.d.ts +187 -23
- package/dist/Table.d.ts.map +1 -1
- package/dist/Tabs.d.ts +45 -9
- package/dist/Tabs.d.ts.map +1 -1
- package/dist/TagGroup.d.ts +12 -10
- package/dist/TagGroup.d.ts.map +1 -1
- package/dist/Text.d.ts +2 -2
- package/dist/TextField.d.ts +15 -11
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TimeField.d.ts +6 -6
- package/dist/TimeField.d.ts.map +1 -1
- package/dist/Toast.d.ts +29 -14
- package/dist/Toast.d.ts.map +1 -1
- package/dist/ToggleButton.d.ts +11 -5
- package/dist/ToggleButton.d.ts.map +1 -1
- package/dist/ToggleButtonGroup.d.ts +7 -7
- package/dist/ToggleButtonGroup.d.ts.map +1 -1
- package/dist/Toolbar.d.ts +7 -3
- package/dist/Toolbar.d.ts.map +1 -1
- package/dist/Tooltip.d.ts +50 -8
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tree.d.ts +66 -17
- package/dist/Tree.d.ts.map +1 -1
- package/dist/Virtualizer.d.ts +12 -12
- package/dist/Virtualizer.d.ts.map +1 -1
- package/dist/VirtualizerLayouts.d.ts +2 -2
- package/dist/VirtualizerLayouts.d.ts.map +1 -1
- package/dist/VisuallyHidden.d.ts +1 -1
- package/dist/VisuallyHidden.d.ts.map +1 -1
- package/dist/contexts.d.ts +5 -1
- package/dist/contexts.d.ts.map +1 -1
- package/dist/index.d.ts +73 -71
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23247 -18564
- package/dist/index.js.map +1 -1
- package/dist/index.jsx +18110 -0
- package/dist/index.jsx.map +1 -0
- package/dist/useDragAndDrop.d.ts +13 -13
- package/dist/useDragAndDrop.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/virtualizer/Layout.d.ts +1 -1
- package/dist/virtualizer/Layout.d.ts.map +1 -1
- package/package.json +31 -32
- package/src/ActionBar.tsx +75 -72
- package/src/ActionGroup.tsx +53 -61
- package/src/Alert.tsx +17 -42
- package/src/Autocomplete.tsx +39 -44
- package/src/Breadcrumbs.tsx +149 -80
- package/src/Button.tsx +267 -70
- package/src/Calendar.tsx +218 -138
- package/src/Checkbox.tsx +413 -121
- package/src/Collection.tsx +67 -58
- package/src/Color.tsx +803 -380
- package/src/ColorEditor.tsx +131 -149
- package/src/ComboBox.tsx +414 -249
- package/src/ContextualHelpTrigger.tsx +86 -74
- package/src/DateField.tsx +185 -91
- package/src/DatePicker.tsx +524 -213
- package/src/DateRangePickerContext.tsx +44 -0
- package/src/Dialog.tsx +156 -118
- package/src/Disclosure.tsx +127 -80
- package/src/DragAndDrop.tsx +60 -54
- package/src/DragPreview.tsx +13 -11
- package/src/DropZone.tsx +42 -22
- package/src/FieldError.tsx +45 -23
- package/src/FileTrigger.tsx +19 -19
- package/src/Focusable.tsx +21 -24
- package/src/Form.tsx +71 -16
- package/src/GridList.tsx +273 -197
- package/src/HiddenDateInput.tsx +153 -0
- package/src/HiddenTimeInput.tsx +133 -0
- package/src/Icon.tsx +22 -43
- package/src/Keyboard.tsx +3 -3
- package/src/Landmark.tsx +37 -63
- package/src/Link.tsx +125 -75
- package/src/ListBox.tsx +332 -233
- package/src/ListDropTargetDelegate.ts +81 -80
- package/src/Menu.tsx +1023 -274
- package/src/Meter.tsx +38 -56
- package/src/Modal.tsx +243 -175
- package/src/NumberField.tsx +139 -143
- package/src/Popover.tsx +386 -233
- package/src/Pressable.tsx +21 -21
- package/src/ProgressBar.tsx +48 -57
- package/src/RadioGroup.tsx +524 -122
- package/src/RangeCalendar.tsx +157 -90
- package/src/RouterProvider.tsx +30 -47
- package/src/SearchField.tsx +362 -143
- package/src/Select.tsx +656 -233
- package/src/SelectionIndicator.tsx +18 -15
- package/src/Separator.tsx +47 -49
- package/src/SharedElementTransition.tsx +103 -97
- package/src/Slider.tsx +138 -98
- package/src/StepList.tsx +272 -0
- package/src/Switch.tsx +93 -46
- package/src/Table.tsx +1308 -342
- package/src/Tabs.tsx +324 -103
- package/src/TagGroup.tsx +139 -126
- package/src/Text.tsx +3 -3
- package/src/TextField.tsx +389 -79
- package/src/TimeField.tsx +136 -76
- package/src/Toast.tsx +209 -157
- package/src/ToggleButton.tsx +47 -37
- package/src/ToggleButtonGroup.tsx +39 -34
- package/src/Toolbar.tsx +54 -69
- package/src/Tooltip.tsx +387 -119
- package/src/Tree.tsx +651 -368
- package/src/Virtualizer.tsx +208 -180
- package/src/VirtualizerLayouts.ts +45 -30
- package/src/VisuallyHidden.tsx +19 -19
- package/src/contexts.ts +29 -37
- package/src/index.ts +110 -195
- package/src/useDragAndDrop.ts +87 -71
- package/src/utils.tsx +40 -55
- package/src/virtualizer/Layout.ts +14 -22
- package/dist/index.ssr.js +0 -16996
- package/dist/index.ssr.js.map +0 -1
package/src/Slider.tsx
CHANGED
|
@@ -5,25 +5,19 @@
|
|
|
5
5
|
* Port of react-aria-components/src/Slider.tsx
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
type JSX,
|
|
10
|
-
createContext,
|
|
11
|
-
createMemo,
|
|
12
|
-
splitProps,
|
|
13
|
-
useContext,
|
|
14
|
-
Show,
|
|
15
|
-
} from 'solid-js';
|
|
8
|
+
import { type JSX, createContext, createMemo, splitProps, useContext, Show } from "solid-js";
|
|
16
9
|
import {
|
|
17
10
|
createSlider,
|
|
18
11
|
createFocusRing,
|
|
19
12
|
createHover,
|
|
13
|
+
mergeProps,
|
|
20
14
|
type AriaSliderProps,
|
|
21
|
-
} from
|
|
15
|
+
} from "@proyecto-viviana/solidaria";
|
|
22
16
|
import {
|
|
23
17
|
createSliderState,
|
|
24
18
|
type SliderState,
|
|
25
19
|
type SliderOrientation,
|
|
26
|
-
} from
|
|
20
|
+
} from "@proyecto-viviana/solid-stately";
|
|
27
21
|
import {
|
|
28
22
|
type RenderChildren,
|
|
29
23
|
type ClassNameOrFunction,
|
|
@@ -31,11 +25,8 @@ import {
|
|
|
31
25
|
type SlotProps,
|
|
32
26
|
useRenderProps,
|
|
33
27
|
filterDOMProps,
|
|
34
|
-
} from
|
|
35
|
-
|
|
36
|
-
// ============================================
|
|
37
|
-
// TYPES
|
|
38
|
-
// ============================================
|
|
28
|
+
} from "./utils";
|
|
29
|
+
import { VisuallyHidden } from "./VisuallyHidden";
|
|
39
30
|
|
|
40
31
|
export interface SliderRenderProps {
|
|
41
32
|
/** Whether the slider is disabled. */
|
|
@@ -52,7 +43,7 @@ export interface SliderRenderProps {
|
|
|
52
43
|
orientation: SliderOrientation;
|
|
53
44
|
}
|
|
54
45
|
|
|
55
|
-
export interface SliderProps extends Omit<AriaSliderProps,
|
|
46
|
+
export interface SliderProps extends Omit<AriaSliderProps, "label">, SlotProps {
|
|
56
47
|
/** The current value (controlled). */
|
|
57
48
|
value?: number;
|
|
58
49
|
/** The default value (uncontrolled). */
|
|
@@ -81,6 +72,8 @@ export interface SliderProps extends Omit<AriaSliderProps, 'label'>, SlotProps {
|
|
|
81
72
|
class?: ClassNameOrFunction<SliderRenderProps>;
|
|
82
73
|
/** The inline style for the element. */
|
|
83
74
|
style?: StyleOrFunction<SliderRenderProps>;
|
|
75
|
+
/** Ref for the slider root element. */
|
|
76
|
+
ref?: (el: HTMLDivElement) => void;
|
|
84
77
|
}
|
|
85
78
|
|
|
86
79
|
export interface SliderTrackRenderProps {
|
|
@@ -94,7 +87,8 @@ export interface SliderTrackRenderProps {
|
|
|
94
87
|
orientation: SliderOrientation;
|
|
95
88
|
}
|
|
96
89
|
|
|
97
|
-
export interface SliderTrackProps
|
|
90
|
+
export interface SliderTrackProps
|
|
91
|
+
extends SlotProps, Omit<JSX.HTMLAttributes<HTMLDivElement>, "class" | "style" | "children"> {
|
|
98
92
|
/** The children of the track. */
|
|
99
93
|
children?: RenderChildren<SliderTrackRenderProps>;
|
|
100
94
|
/** The CSS className for the element. */
|
|
@@ -120,7 +114,8 @@ export interface SliderThumbRenderProps {
|
|
|
120
114
|
valuePercent: number;
|
|
121
115
|
}
|
|
122
116
|
|
|
123
|
-
export interface SliderThumbProps
|
|
117
|
+
export interface SliderThumbProps
|
|
118
|
+
extends SlotProps, Omit<JSX.HTMLAttributes<HTMLDivElement>, "class" | "style" | "children"> {
|
|
124
119
|
/** The children of the thumb. */
|
|
125
120
|
children?: RenderChildren<SliderThumbRenderProps>;
|
|
126
121
|
/** The CSS className for the element. */
|
|
@@ -136,7 +131,8 @@ export interface SliderOutputRenderProps {
|
|
|
136
131
|
formattedValue: string;
|
|
137
132
|
}
|
|
138
133
|
|
|
139
|
-
export interface SliderOutputProps
|
|
134
|
+
export interface SliderOutputProps
|
|
135
|
+
extends SlotProps, Omit<JSX.HTMLAttributes<HTMLElement>, "class" | "style" | "children"> {
|
|
140
136
|
/** The children of the output. */
|
|
141
137
|
children?: RenderChildren<SliderOutputRenderProps>;
|
|
142
138
|
/** The CSS className for the element. */
|
|
@@ -145,10 +141,6 @@ export interface SliderOutputProps extends SlotProps, Omit<JSX.HTMLAttributes<HT
|
|
|
145
141
|
style?: StyleOrFunction<SliderOutputRenderProps>;
|
|
146
142
|
}
|
|
147
143
|
|
|
148
|
-
// ============================================
|
|
149
|
-
// CONTEXT
|
|
150
|
-
// ============================================
|
|
151
|
-
|
|
152
144
|
interface SliderContextValue {
|
|
153
145
|
state: SliderState;
|
|
154
146
|
trackProps: JSX.HTMLAttributes<HTMLElement>;
|
|
@@ -157,6 +149,8 @@ interface SliderContextValue {
|
|
|
157
149
|
inputProps: JSX.InputHTMLAttributes<HTMLInputElement>;
|
|
158
150
|
trackRef: HTMLElement | undefined;
|
|
159
151
|
setTrackRef: (el: HTMLElement) => void;
|
|
152
|
+
inputRef: HTMLInputElement | undefined;
|
|
153
|
+
setInputRef: (el: HTMLInputElement) => void;
|
|
160
154
|
}
|
|
161
155
|
|
|
162
156
|
export const SliderContext = createContext<SliderContextValue | null>(null);
|
|
@@ -164,22 +158,37 @@ export const SliderStateContext = SliderContext;
|
|
|
164
158
|
export const SliderTrackContext = SliderContext;
|
|
165
159
|
export const SliderOutputContext = SliderContext;
|
|
166
160
|
|
|
167
|
-
// ============================================
|
|
168
|
-
// COMPONENTS
|
|
169
|
-
// ============================================
|
|
170
|
-
|
|
171
161
|
/**
|
|
172
162
|
* A slider allows users to select a value from a range.
|
|
173
163
|
*/
|
|
174
164
|
export function Slider(props: SliderProps): JSX.Element {
|
|
175
165
|
const [local, stateProps, ariaProps, rest] = splitProps(
|
|
176
166
|
props,
|
|
177
|
-
[
|
|
178
|
-
[
|
|
179
|
-
|
|
167
|
+
["class", "style", "slot", "ref"],
|
|
168
|
+
[
|
|
169
|
+
"value",
|
|
170
|
+
"defaultValue",
|
|
171
|
+
"onChange",
|
|
172
|
+
"onChangeEnd",
|
|
173
|
+
"minValue",
|
|
174
|
+
"maxValue",
|
|
175
|
+
"step",
|
|
176
|
+
"orientation",
|
|
177
|
+
"locale",
|
|
178
|
+
"formatOptions",
|
|
179
|
+
],
|
|
180
|
+
[
|
|
181
|
+
"label",
|
|
182
|
+
"aria-label",
|
|
183
|
+
"aria-labelledby",
|
|
184
|
+
"aria-describedby",
|
|
185
|
+
"isDisabled",
|
|
186
|
+
"id",
|
|
187
|
+
"name",
|
|
188
|
+
"form",
|
|
189
|
+
],
|
|
180
190
|
);
|
|
181
191
|
|
|
182
|
-
// Create slider state
|
|
183
192
|
const state = createSliderState({
|
|
184
193
|
get value() {
|
|
185
194
|
return stateProps.value;
|
|
@@ -216,23 +225,22 @@ export function Slider(props: SliderProps): JSX.Element {
|
|
|
216
225
|
},
|
|
217
226
|
});
|
|
218
227
|
|
|
219
|
-
// Track ref for pointer handling
|
|
220
228
|
let trackRef: HTMLElement | undefined;
|
|
221
229
|
const setTrackRef = (el: HTMLElement) => {
|
|
222
230
|
trackRef = el;
|
|
223
231
|
};
|
|
232
|
+
let inputRef: HTMLInputElement | undefined;
|
|
233
|
+
const setInputRef = (el: HTMLInputElement) => {
|
|
234
|
+
inputRef = el;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const sliderAria = createSlider(
|
|
238
|
+
ariaProps,
|
|
239
|
+
state,
|
|
240
|
+
() => trackRef ?? null,
|
|
241
|
+
() => inputRef ?? null,
|
|
242
|
+
);
|
|
224
243
|
|
|
225
|
-
// Create slider aria props
|
|
226
|
-
const {
|
|
227
|
-
labelProps,
|
|
228
|
-
groupProps,
|
|
229
|
-
trackProps,
|
|
230
|
-
thumbProps,
|
|
231
|
-
inputProps,
|
|
232
|
-
outputProps,
|
|
233
|
-
} = createSlider(ariaProps, state, () => trackRef ?? null);
|
|
234
|
-
|
|
235
|
-
// Render props values
|
|
236
244
|
const renderValues = createMemo<SliderRenderProps>(() => ({
|
|
237
245
|
isDisabled: state.isDisabled,
|
|
238
246
|
isDragging: state.isDragging(),
|
|
@@ -242,23 +250,48 @@ export function Slider(props: SliderProps): JSX.Element {
|
|
|
242
250
|
orientation: state.orientation,
|
|
243
251
|
}));
|
|
244
252
|
|
|
245
|
-
// Resolve render props
|
|
246
253
|
const renderProps = useRenderProps(
|
|
247
254
|
{
|
|
248
255
|
children: props.children,
|
|
249
256
|
class: local.class,
|
|
250
257
|
style: local.style,
|
|
251
|
-
defaultClassName:
|
|
258
|
+
defaultClassName: "solidaria-Slider",
|
|
252
259
|
},
|
|
253
|
-
renderValues
|
|
260
|
+
renderValues,
|
|
254
261
|
);
|
|
255
262
|
|
|
256
|
-
|
|
257
|
-
|
|
263
|
+
const childRenderValues: SliderRenderProps = {
|
|
264
|
+
get isDisabled() {
|
|
265
|
+
return state.isDisabled;
|
|
266
|
+
},
|
|
267
|
+
get isDragging() {
|
|
268
|
+
return state.isDragging();
|
|
269
|
+
},
|
|
270
|
+
get isFocused() {
|
|
271
|
+
return state.isFocused();
|
|
272
|
+
},
|
|
273
|
+
get value() {
|
|
274
|
+
return state.value();
|
|
275
|
+
},
|
|
276
|
+
get valuePercent() {
|
|
277
|
+
return state.getValuePercent();
|
|
278
|
+
},
|
|
279
|
+
get orientation() {
|
|
280
|
+
return state.orientation;
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const sliderChildren = () => {
|
|
285
|
+
const children = props.children;
|
|
286
|
+
return typeof children === "function" ? children(childRenderValues) : children;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const domProps = createMemo(() =>
|
|
290
|
+
filterDOMProps(rest as Record<string, unknown>, { global: true }),
|
|
291
|
+
);
|
|
258
292
|
|
|
259
|
-
// Clean props helpers
|
|
260
293
|
const cleanGroupProps = () => {
|
|
261
|
-
const { ref: _ref, ...rest } = groupProps as Record<string, unknown>;
|
|
294
|
+
const { ref: _ref, ...rest } = sliderAria.groupProps as Record<string, unknown>;
|
|
262
295
|
return rest;
|
|
263
296
|
};
|
|
264
297
|
|
|
@@ -266,32 +299,43 @@ export function Slider(props: SliderProps): JSX.Element {
|
|
|
266
299
|
<SliderContext.Provider
|
|
267
300
|
value={{
|
|
268
301
|
state,
|
|
269
|
-
trackProps
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
302
|
+
get trackProps() {
|
|
303
|
+
return sliderAria.trackProps;
|
|
304
|
+
},
|
|
305
|
+
get thumbProps() {
|
|
306
|
+
return sliderAria.thumbProps;
|
|
307
|
+
},
|
|
308
|
+
get outputProps() {
|
|
309
|
+
return sliderAria.outputProps;
|
|
310
|
+
},
|
|
311
|
+
get inputProps() {
|
|
312
|
+
return sliderAria.inputProps;
|
|
313
|
+
},
|
|
314
|
+
get trackRef() {
|
|
315
|
+
return trackRef;
|
|
316
|
+
},
|
|
274
317
|
setTrackRef,
|
|
318
|
+
get inputRef() {
|
|
319
|
+
return inputRef;
|
|
320
|
+
},
|
|
321
|
+
setInputRef,
|
|
275
322
|
}}
|
|
276
323
|
>
|
|
277
324
|
<div
|
|
278
325
|
{...domProps()}
|
|
279
326
|
{...cleanGroupProps()}
|
|
327
|
+
ref={local.ref}
|
|
280
328
|
class={renderProps.class()}
|
|
281
329
|
style={renderProps.style()}
|
|
282
330
|
data-disabled={state.isDisabled || undefined}
|
|
283
331
|
data-orientation={state.orientation}
|
|
284
332
|
data-dragging={state.isDragging() || undefined}
|
|
285
333
|
>
|
|
286
|
-
{/* Label */}
|
|
287
334
|
<Show when={ariaProps.label}>
|
|
288
|
-
<span {...labelProps}>{ariaProps.label}</span>
|
|
335
|
+
<span {...sliderAria.labelProps}>{ariaProps.label}</span>
|
|
289
336
|
</Show>
|
|
290
337
|
|
|
291
|
-
{
|
|
292
|
-
|
|
293
|
-
{/* Hidden input for form submission */}
|
|
294
|
-
<input {...inputProps} />
|
|
338
|
+
{sliderChildren()}
|
|
295
339
|
</div>
|
|
296
340
|
</SliderContext.Provider>
|
|
297
341
|
);
|
|
@@ -301,16 +345,15 @@ export function Slider(props: SliderProps): JSX.Element {
|
|
|
301
345
|
* The track element of a slider.
|
|
302
346
|
*/
|
|
303
347
|
export function SliderTrack(props: SliderTrackProps): JSX.Element {
|
|
304
|
-
const [local, domProps] = splitProps(props, [
|
|
348
|
+
const [local, domProps] = splitProps(props, ["class", "style", "slot", "children"]);
|
|
305
349
|
|
|
306
350
|
const context = useContext(SliderContext);
|
|
307
351
|
if (!context) {
|
|
308
|
-
throw new Error(
|
|
352
|
+
throw new Error("SliderTrack must be used within a Slider");
|
|
309
353
|
}
|
|
310
354
|
|
|
311
|
-
const { state,
|
|
355
|
+
const { state, setTrackRef } = context;
|
|
312
356
|
|
|
313
|
-
// Render props values
|
|
314
357
|
const renderValues = createMemo<SliderTrackRenderProps>(() => ({
|
|
315
358
|
isDisabled: state.isDisabled,
|
|
316
359
|
isDragging: state.isDragging(),
|
|
@@ -318,26 +361,23 @@ export function SliderTrack(props: SliderTrackProps): JSX.Element {
|
|
|
318
361
|
orientation: state.orientation,
|
|
319
362
|
}));
|
|
320
363
|
|
|
321
|
-
// Resolve render props
|
|
322
364
|
const renderProps = useRenderProps(
|
|
323
365
|
{
|
|
324
366
|
children: props.children,
|
|
325
367
|
class: local.class,
|
|
326
368
|
style: local.style,
|
|
327
|
-
defaultClassName:
|
|
369
|
+
defaultClassName: "solidaria-Slider-track",
|
|
328
370
|
},
|
|
329
|
-
renderValues
|
|
371
|
+
renderValues,
|
|
330
372
|
);
|
|
331
373
|
|
|
332
|
-
// Clean props
|
|
333
374
|
const cleanTrackProps = () => {
|
|
334
|
-
const { ref: _ref, style: trackStyle, ...rest } = trackProps as Record<string, unknown>;
|
|
375
|
+
const { ref: _ref, style: trackStyle, ...rest } = context.trackProps as Record<string, unknown>;
|
|
335
376
|
return rest;
|
|
336
377
|
};
|
|
337
378
|
|
|
338
|
-
// Merge styles
|
|
339
379
|
const mergedStyle = () => {
|
|
340
|
-
const trackStyle = (trackProps as { style?: Record<string, string> }).style || {};
|
|
380
|
+
const trackStyle = (context.trackProps as { style?: Record<string, string> }).style || {};
|
|
341
381
|
const renderStyle = renderProps.style() || {};
|
|
342
382
|
return { ...trackStyle, ...renderStyle };
|
|
343
383
|
};
|
|
@@ -362,26 +402,23 @@ export function SliderTrack(props: SliderTrackProps): JSX.Element {
|
|
|
362
402
|
* The thumb element of a slider.
|
|
363
403
|
*/
|
|
364
404
|
export function SliderThumb(props: SliderThumbProps): JSX.Element {
|
|
365
|
-
const [local, domProps] = splitProps(props, [
|
|
405
|
+
const [local, domProps] = splitProps(props, ["class", "style", "slot", "children"]);
|
|
366
406
|
|
|
367
407
|
const context = useContext(SliderContext);
|
|
368
408
|
if (!context) {
|
|
369
|
-
throw new Error(
|
|
409
|
+
throw new Error("SliderThumb must be used within a Slider");
|
|
370
410
|
}
|
|
371
411
|
|
|
372
|
-
const { state,
|
|
412
|
+
const { state, setInputRef } = context;
|
|
373
413
|
|
|
374
|
-
// Create focus ring
|
|
375
414
|
const { isFocused, isFocusVisible, focusProps } = createFocusRing();
|
|
376
415
|
|
|
377
|
-
// Create hover
|
|
378
416
|
const { isHovered, hoverProps } = createHover({
|
|
379
417
|
get isDisabled() {
|
|
380
418
|
return state.isDisabled;
|
|
381
419
|
},
|
|
382
420
|
});
|
|
383
421
|
|
|
384
|
-
// Render props values
|
|
385
422
|
const renderValues = createMemo<SliderThumbRenderProps>(() => ({
|
|
386
423
|
isDisabled: state.isDisabled,
|
|
387
424
|
isDragging: state.isDragging(),
|
|
@@ -392,20 +429,18 @@ export function SliderThumb(props: SliderThumbProps): JSX.Element {
|
|
|
392
429
|
valuePercent: state.getValuePercent(),
|
|
393
430
|
}));
|
|
394
431
|
|
|
395
|
-
// Resolve render props
|
|
396
432
|
const renderProps = useRenderProps(
|
|
397
433
|
{
|
|
398
434
|
children: props.children,
|
|
399
435
|
class: local.class,
|
|
400
436
|
style: local.style,
|
|
401
|
-
defaultClassName:
|
|
437
|
+
defaultClassName: "solidaria-Slider-thumb",
|
|
402
438
|
},
|
|
403
|
-
renderValues
|
|
439
|
+
renderValues,
|
|
404
440
|
);
|
|
405
441
|
|
|
406
|
-
// Clean props
|
|
407
442
|
const cleanThumbProps = () => {
|
|
408
|
-
const { ref: _ref, style: thumbStyle, ...rest } = thumbProps as Record<string, unknown>;
|
|
443
|
+
const { ref: _ref, style: thumbStyle, ...rest } = context.thumbProps as Record<string, unknown>;
|
|
409
444
|
return rest;
|
|
410
445
|
};
|
|
411
446
|
const cleanFocusProps = () => {
|
|
@@ -417,27 +452,37 @@ export function SliderThumb(props: SliderThumbProps): JSX.Element {
|
|
|
417
452
|
return rest;
|
|
418
453
|
};
|
|
419
454
|
|
|
420
|
-
// Merge styles
|
|
421
455
|
const mergedStyle = () => {
|
|
422
|
-
const thumbStyle = (thumbProps as { style?: Record<string, string> }).style || {};
|
|
456
|
+
const thumbStyle = (context.thumbProps as { style?: Record<string, string> }).style || {};
|
|
423
457
|
const renderStyle = renderProps.style() || {};
|
|
424
458
|
return { ...thumbStyle, ...renderStyle };
|
|
425
459
|
};
|
|
460
|
+
const cleanInputProps = () => {
|
|
461
|
+
const { ref: _ref, ...rest } = context.inputProps as Record<string, unknown>;
|
|
462
|
+
return rest;
|
|
463
|
+
};
|
|
464
|
+
const mergedInputProps = () =>
|
|
465
|
+
mergeProps(
|
|
466
|
+
cleanInputProps() as Record<string, unknown>,
|
|
467
|
+
cleanFocusProps() as Record<string, unknown>,
|
|
468
|
+
) as JSX.InputHTMLAttributes<HTMLInputElement>;
|
|
426
469
|
|
|
427
470
|
return (
|
|
428
471
|
<div
|
|
429
472
|
{...domProps}
|
|
430
473
|
{...cleanThumbProps()}
|
|
431
|
-
{...cleanFocusProps()}
|
|
432
474
|
{...cleanHoverProps()}
|
|
433
475
|
class={renderProps.class()}
|
|
434
476
|
style={mergedStyle()}
|
|
435
477
|
data-disabled={state.isDisabled || undefined}
|
|
436
478
|
data-dragging={state.isDragging() || undefined}
|
|
437
|
-
data-focused={isFocused() || undefined}
|
|
479
|
+
data-focused={isFocused() || state.isFocused() || undefined}
|
|
438
480
|
data-focus-visible={isFocusVisible() || undefined}
|
|
439
481
|
data-hovered={isHovered() || undefined}
|
|
440
482
|
>
|
|
483
|
+
<VisuallyHidden>
|
|
484
|
+
<input ref={setInputRef} {...mergedInputProps()} />
|
|
485
|
+
</VisuallyHidden>
|
|
441
486
|
{renderProps.renderChildren()}
|
|
442
487
|
</div>
|
|
443
488
|
);
|
|
@@ -447,43 +492,39 @@ export function SliderThumb(props: SliderThumbProps): JSX.Element {
|
|
|
447
492
|
* The output element of a slider, displaying the current value.
|
|
448
493
|
*/
|
|
449
494
|
export function SliderOutput(props: SliderOutputProps): JSX.Element {
|
|
450
|
-
const [local, domProps] = splitProps(props, [
|
|
495
|
+
const [local, domProps] = splitProps(props, ["class", "style", "slot", "children"]);
|
|
451
496
|
|
|
452
497
|
const context = useContext(SliderContext);
|
|
453
498
|
if (!context) {
|
|
454
|
-
throw new Error(
|
|
499
|
+
throw new Error("SliderOutput must be used within a Slider");
|
|
455
500
|
}
|
|
456
501
|
|
|
457
|
-
const { state
|
|
502
|
+
const { state } = context;
|
|
458
503
|
|
|
459
|
-
// Render props values
|
|
460
504
|
const renderValues = createMemo<SliderOutputRenderProps>(() => ({
|
|
461
505
|
value: state.value(),
|
|
462
506
|
formattedValue: state.getFormattedValue(),
|
|
463
507
|
}));
|
|
464
508
|
|
|
465
|
-
// Resolve render props
|
|
466
509
|
const renderProps = useRenderProps(
|
|
467
510
|
{
|
|
468
511
|
children: props.children,
|
|
469
512
|
class: local.class,
|
|
470
513
|
style: local.style,
|
|
471
|
-
defaultClassName:
|
|
514
|
+
defaultClassName: "solidaria-Slider-output",
|
|
472
515
|
},
|
|
473
|
-
renderValues
|
|
516
|
+
renderValues,
|
|
474
517
|
);
|
|
475
518
|
|
|
476
|
-
// Clean props
|
|
477
519
|
const cleanDomProps = () => {
|
|
478
520
|
const { ref: _ref, ...rest } = domProps as Record<string, unknown>;
|
|
479
521
|
return rest;
|
|
480
522
|
};
|
|
481
523
|
const cleanOutputProps = () => {
|
|
482
|
-
const { ref: _ref, ...rest } = outputProps as Record<string, unknown>;
|
|
524
|
+
const { ref: _ref, ...rest } = context.outputProps as Record<string, unknown>;
|
|
483
525
|
return rest;
|
|
484
526
|
};
|
|
485
527
|
|
|
486
|
-
// Default children shows formatted value
|
|
487
528
|
const renderedChildren = () => {
|
|
488
529
|
// Check if raw children prop exists before calling renderChildren
|
|
489
530
|
if (renderProps.children === undefined || renderProps.children === null) {
|
|
@@ -504,7 +545,6 @@ export function SliderOutput(props: SliderOutputProps): JSX.Element {
|
|
|
504
545
|
);
|
|
505
546
|
}
|
|
506
547
|
|
|
507
|
-
// Attach sub-components
|
|
508
548
|
Slider.Track = SliderTrack;
|
|
509
549
|
Slider.Thumb = SliderThumb;
|
|
510
550
|
Slider.Output = SliderOutput;
|