@sytechui/slider 2.4.29
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/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/chunk-CJCHSOKZ.mjs +67 -0
- package/dist/chunk-IQZHN75L.mjs +42 -0
- package/dist/chunk-M2PJK6HJ.mjs +97 -0
- package/dist/chunk-ORNKXCKK.mjs +305 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +518 -0
- package/dist/index.mjs +13 -0
- package/dist/slider-thumb.d.mts +9 -0
- package/dist/slider-thumb.d.ts +9 -0
- package/dist/slider-thumb.js +152 -0
- package/dist/slider-thumb.mjs +8 -0
- package/dist/slider.d.mts +15 -0
- package/dist/slider.d.ts +15 -0
- package/dist/slider.js +510 -0
- package/dist/slider.mjs +10 -0
- package/dist/use-slider-Bo_Y5OvC.d.mts +235 -0
- package/dist/use-slider-Bo_Y5OvC.d.ts +235 -0
- package/dist/use-slider-thumb.d.mts +9 -0
- package/dist/use-slider-thumb.d.ts +9 -0
- package/dist/use-slider-thumb.js +120 -0
- package/dist/use-slider-thumb.mjs +7 -0
- package/dist/use-slider.d.mts +9 -0
- package/dist/use-slider.d.ts +9 -0
- package/dist/use-slider.js +328 -0
- package/dist/use-slider.mjs +7 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Next UI Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @sytechui/slider
|
|
2
|
+
|
|
3
|
+
Slider allows a user to select one or more values within a range.
|
|
4
|
+
|
|
5
|
+
Please refer to the [documentation](https://heroui.com/docs/components/slider) for more information.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn add @sytechui/slider
|
|
11
|
+
# or
|
|
12
|
+
npm i @sytechui/slider
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Contribution
|
|
16
|
+
|
|
17
|
+
Yes please! See the
|
|
18
|
+
[contributing guidelines](https://github.com/heroui-inc/heroui/blob/master/CONTRIBUTING.md)
|
|
19
|
+
for details.
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
This project is licensed under the terms of the
|
|
24
|
+
[MIT license](https://github.com/heroui-inc/heroui/blob/master/LICENSE).
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
slider_thumb_default
|
|
4
|
+
} from "./chunk-IQZHN75L.mjs";
|
|
5
|
+
import {
|
|
6
|
+
useSlider
|
|
7
|
+
} from "./chunk-ORNKXCKK.mjs";
|
|
8
|
+
|
|
9
|
+
// src/slider.tsx
|
|
10
|
+
import { renderFn } from "@sytechui/react-utils";
|
|
11
|
+
import { forwardRef } from "@sytechui/system";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
var Slider = forwardRef((props, ref) => {
|
|
14
|
+
const {
|
|
15
|
+
Component,
|
|
16
|
+
state,
|
|
17
|
+
label,
|
|
18
|
+
steps,
|
|
19
|
+
marks,
|
|
20
|
+
startContent,
|
|
21
|
+
endContent,
|
|
22
|
+
getStepProps,
|
|
23
|
+
getBaseProps,
|
|
24
|
+
renderValue,
|
|
25
|
+
renderLabel,
|
|
26
|
+
getTrackWrapperProps,
|
|
27
|
+
getLabelWrapperProps,
|
|
28
|
+
getLabelProps,
|
|
29
|
+
getValueProps,
|
|
30
|
+
getTrackProps,
|
|
31
|
+
getFillerProps,
|
|
32
|
+
getThumbProps,
|
|
33
|
+
getMarkProps,
|
|
34
|
+
getStartContentProps,
|
|
35
|
+
getEndContentProps
|
|
36
|
+
} = useSlider({ ...props, ref });
|
|
37
|
+
return /* @__PURE__ */ jsxs(Component, { ...getBaseProps(), children: [
|
|
38
|
+
label && /* @__PURE__ */ jsxs("div", { ...getLabelWrapperProps(), children: [
|
|
39
|
+
renderFn({
|
|
40
|
+
Component: "label",
|
|
41
|
+
props: getLabelProps(),
|
|
42
|
+
renderCustom: renderLabel
|
|
43
|
+
}),
|
|
44
|
+
renderFn({
|
|
45
|
+
Component: "output",
|
|
46
|
+
props: getValueProps(),
|
|
47
|
+
renderCustom: renderValue
|
|
48
|
+
})
|
|
49
|
+
] }),
|
|
50
|
+
/* @__PURE__ */ jsxs("div", { ...getTrackWrapperProps(), children: [
|
|
51
|
+
startContent && /* @__PURE__ */ jsx("div", { ...getStartContentProps(), children: startContent }),
|
|
52
|
+
/* @__PURE__ */ jsxs("div", { ...getTrackProps(), children: [
|
|
53
|
+
/* @__PURE__ */ jsx("div", { ...getFillerProps() }),
|
|
54
|
+
Number.isFinite(steps) && Array.from({ length: steps }, (_, index) => /* @__PURE__ */ jsx("div", { ...getStepProps(index) }, index)),
|
|
55
|
+
state.values.map((_, index) => /* @__PURE__ */ jsx(slider_thumb_default, { ...getThumbProps(index) }, index)),
|
|
56
|
+
(marks == null ? void 0 : marks.length) > 0 && marks.map((mark, index) => /* @__PURE__ */ jsx("div", { ...getMarkProps(mark), children: mark.label }, index))
|
|
57
|
+
] }),
|
|
58
|
+
endContent && /* @__PURE__ */ jsx("div", { ...getEndContentProps(), children: endContent })
|
|
59
|
+
] })
|
|
60
|
+
] });
|
|
61
|
+
});
|
|
62
|
+
Slider.displayName = "HeroUI.Slider";
|
|
63
|
+
var slider_default = Slider;
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
slider_default
|
|
67
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useSliderThumb
|
|
4
|
+
} from "./chunk-M2PJK6HJ.mjs";
|
|
5
|
+
|
|
6
|
+
// src/slider-thumb.tsx
|
|
7
|
+
import { forwardRef } from "@sytechui/system";
|
|
8
|
+
import { Tooltip } from "@sytechui/tooltip";
|
|
9
|
+
import { renderFn } from "@sytechui/react-utils";
|
|
10
|
+
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
var SliderThumb = forwardRef((props, ref) => {
|
|
13
|
+
const {
|
|
14
|
+
Component,
|
|
15
|
+
index,
|
|
16
|
+
renderThumb,
|
|
17
|
+
showTooltip,
|
|
18
|
+
getTooltipProps,
|
|
19
|
+
getThumbProps,
|
|
20
|
+
getInputProps
|
|
21
|
+
} = useSliderThumb({
|
|
22
|
+
...props,
|
|
23
|
+
ref
|
|
24
|
+
});
|
|
25
|
+
const thumbProps = {
|
|
26
|
+
...getThumbProps(),
|
|
27
|
+
index,
|
|
28
|
+
children: /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", { ...getInputProps() }) })
|
|
29
|
+
};
|
|
30
|
+
const content = renderFn({
|
|
31
|
+
Component,
|
|
32
|
+
props: thumbProps,
|
|
33
|
+
renderCustom: renderThumb
|
|
34
|
+
});
|
|
35
|
+
return showTooltip ? /* @__PURE__ */ jsx(Tooltip, { ...getTooltipProps(), children: content }) : content;
|
|
36
|
+
});
|
|
37
|
+
SliderThumb.displayName = "HeroUI.SliderThumb";
|
|
38
|
+
var slider_thumb_default = SliderThumb;
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
slider_thumb_default
|
|
42
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/use-slider-thumb.ts
|
|
4
|
+
import { useSliderThumb as useAriaSliderThumb } from "@react-aria/slider";
|
|
5
|
+
import { useDOMRef } from "@sytechui/react-utils";
|
|
6
|
+
import { useRef } from "react";
|
|
7
|
+
import { useHover, usePress } from "@react-aria/interactions";
|
|
8
|
+
import { useFocusRing } from "@react-aria/focus";
|
|
9
|
+
import { dataAttr, mergeProps } from "@sytechui/shared-utils";
|
|
10
|
+
import { useNumberFormatter } from "@react-aria/i18n";
|
|
11
|
+
function useSliderThumb(props) {
|
|
12
|
+
const {
|
|
13
|
+
ref,
|
|
14
|
+
as,
|
|
15
|
+
state,
|
|
16
|
+
index,
|
|
17
|
+
name,
|
|
18
|
+
trackRef,
|
|
19
|
+
className,
|
|
20
|
+
tooltipProps,
|
|
21
|
+
isVertical,
|
|
22
|
+
showTooltip,
|
|
23
|
+
getTooltipValue,
|
|
24
|
+
formatOptions,
|
|
25
|
+
renderThumb,
|
|
26
|
+
...otherProps
|
|
27
|
+
} = props;
|
|
28
|
+
const Component = as || "div";
|
|
29
|
+
const domRef = useDOMRef(ref);
|
|
30
|
+
const inputRef = useRef(null);
|
|
31
|
+
const numberFormatter = useNumberFormatter(formatOptions);
|
|
32
|
+
const { thumbProps, inputProps, isDragging, isFocused } = useAriaSliderThumb(
|
|
33
|
+
{
|
|
34
|
+
index,
|
|
35
|
+
trackRef,
|
|
36
|
+
inputRef,
|
|
37
|
+
name,
|
|
38
|
+
...otherProps
|
|
39
|
+
},
|
|
40
|
+
state
|
|
41
|
+
);
|
|
42
|
+
const { hoverProps, isHovered } = useHover({
|
|
43
|
+
isDisabled: state.isDisabled
|
|
44
|
+
});
|
|
45
|
+
const { focusProps, isFocusVisible } = useFocusRing();
|
|
46
|
+
const { pressProps, isPressed } = usePress({
|
|
47
|
+
isDisabled: state.isDisabled
|
|
48
|
+
});
|
|
49
|
+
const getThumbProps = (props2 = {}) => {
|
|
50
|
+
return {
|
|
51
|
+
ref: domRef,
|
|
52
|
+
"data-slot": "thumb",
|
|
53
|
+
"data-hover": dataAttr(isHovered),
|
|
54
|
+
"data-pressed": dataAttr(isPressed),
|
|
55
|
+
"data-dragging": dataAttr(isDragging),
|
|
56
|
+
"data-focused": dataAttr(isFocused),
|
|
57
|
+
"data-focus-visible": dataAttr(isFocusVisible),
|
|
58
|
+
"aria-label": props2["aria-label"] || `Slider thumb ${index !== void 0 ? `${index + 1}` : ""}`,
|
|
59
|
+
...mergeProps(thumbProps, pressProps, hoverProps, otherProps),
|
|
60
|
+
className,
|
|
61
|
+
...props2
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
const getTooltipProps = () => {
|
|
65
|
+
const stateValue = (tooltipProps == null ? void 0 : tooltipProps.content) ? tooltipProps.content : getTooltipValue ? state.values.length === 1 ? getTooltipValue(state.values[index != null ? index : 0]) : getTooltipValue(state.values, index != null ? index : 0) : state.values[index != null ? index : 0];
|
|
66
|
+
const value = numberFormatter && typeof stateValue === "number" ? numberFormatter.format(stateValue) : stateValue;
|
|
67
|
+
return {
|
|
68
|
+
...tooltipProps,
|
|
69
|
+
placement: (tooltipProps == null ? void 0 : tooltipProps.placement) ? tooltipProps == null ? void 0 : tooltipProps.placement : isVertical ? "right" : "top",
|
|
70
|
+
content: (tooltipProps == null ? void 0 : tooltipProps.content) ? tooltipProps == null ? void 0 : tooltipProps.content : value,
|
|
71
|
+
updatePositionDeps: [isDragging, isHovered, isFocused, isFocusVisible, value],
|
|
72
|
+
isOpen: (tooltipProps == null ? void 0 : tooltipProps.isOpen) !== void 0 ? tooltipProps == null ? void 0 : tooltipProps.isOpen : isHovered || isDragging || isFocused || isFocusVisible,
|
|
73
|
+
role: "tooltip",
|
|
74
|
+
"aria-label": `Current value: ${value}`
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
const getInputProps = (props2 = {}) => {
|
|
78
|
+
return {
|
|
79
|
+
ref: inputRef,
|
|
80
|
+
...mergeProps(inputProps, focusProps),
|
|
81
|
+
...props2
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
Component,
|
|
86
|
+
index,
|
|
87
|
+
showTooltip,
|
|
88
|
+
renderThumb,
|
|
89
|
+
getThumbProps,
|
|
90
|
+
getTooltipProps,
|
|
91
|
+
getInputProps
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
useSliderThumb
|
|
97
|
+
};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/use-slider.ts
|
|
4
|
+
import { mapPropsVariants, useProviderContext } from "@sytechui/system";
|
|
5
|
+
import { slider, cn } from "@sytechui/theme";
|
|
6
|
+
import { useDOMRef, filterDOMProps } from "@sytechui/react-utils";
|
|
7
|
+
import { useSliderState } from "@react-stately/slider";
|
|
8
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
9
|
+
import { useNumberFormatter, useLocale } from "@react-aria/i18n";
|
|
10
|
+
import { useSlider as useAriaSlider } from "@react-aria/slider";
|
|
11
|
+
import { mergeProps, objectToDeps, warn } from "@sytechui/shared-utils";
|
|
12
|
+
import { useHover } from "@react-aria/interactions";
|
|
13
|
+
function useSlider(originalProps) {
|
|
14
|
+
var _a, _b, _c, _d;
|
|
15
|
+
const globalContext = useProviderContext();
|
|
16
|
+
const [props, variantProps] = mapPropsVariants(originalProps, slider.variantKeys);
|
|
17
|
+
const {
|
|
18
|
+
ref,
|
|
19
|
+
as,
|
|
20
|
+
name,
|
|
21
|
+
label,
|
|
22
|
+
formatOptions,
|
|
23
|
+
value: valueProp,
|
|
24
|
+
maxValue = 100,
|
|
25
|
+
minValue = 0,
|
|
26
|
+
step = 1,
|
|
27
|
+
showSteps = false,
|
|
28
|
+
showTooltip = false,
|
|
29
|
+
orientation = "horizontal",
|
|
30
|
+
marks = [],
|
|
31
|
+
startContent,
|
|
32
|
+
endContent,
|
|
33
|
+
fillOffset,
|
|
34
|
+
className,
|
|
35
|
+
classNames,
|
|
36
|
+
renderThumb,
|
|
37
|
+
renderLabel,
|
|
38
|
+
renderValue,
|
|
39
|
+
onChange,
|
|
40
|
+
onChangeEnd,
|
|
41
|
+
getValue,
|
|
42
|
+
getTooltipValue,
|
|
43
|
+
tooltipValueFormatOptions = formatOptions,
|
|
44
|
+
tooltipProps: userTooltipProps = {},
|
|
45
|
+
...otherProps
|
|
46
|
+
} = props;
|
|
47
|
+
const isFixedValue = minValue === maxValue;
|
|
48
|
+
if (isFixedValue) {
|
|
49
|
+
warn("Min and max values should not be the same. This may cause unexpected behavior.");
|
|
50
|
+
}
|
|
51
|
+
const Component = as || "div";
|
|
52
|
+
const shouldFilterDOMProps = typeof Component === "string";
|
|
53
|
+
const disableAnimation = (_b = (_a = originalProps == null ? void 0 : originalProps.disableAnimation) != null ? _a : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _b : false;
|
|
54
|
+
const domRef = useDOMRef(ref);
|
|
55
|
+
const trackRef = useRef(null);
|
|
56
|
+
const numberFormatter = useNumberFormatter(formatOptions);
|
|
57
|
+
const { direction } = useLocale();
|
|
58
|
+
const clampValue = useCallback(
|
|
59
|
+
(valueToClamp) => {
|
|
60
|
+
return Math.min(Math.max(valueToClamp, minValue), maxValue);
|
|
61
|
+
},
|
|
62
|
+
[minValue, maxValue]
|
|
63
|
+
);
|
|
64
|
+
const validatedValue = useMemo(() => {
|
|
65
|
+
if (isFixedValue) return minValue;
|
|
66
|
+
if (valueProp === void 0) return void 0;
|
|
67
|
+
if (Array.isArray(valueProp)) {
|
|
68
|
+
return valueProp.map(clampValue);
|
|
69
|
+
}
|
|
70
|
+
return clampValue(valueProp);
|
|
71
|
+
}, [valueProp, clampValue, isFixedValue, minValue]);
|
|
72
|
+
const state = useSliderState({
|
|
73
|
+
...otherProps,
|
|
74
|
+
value: validatedValue,
|
|
75
|
+
isDisabled: (_c = originalProps == null ? void 0 : originalProps.isDisabled) != null ? _c : false,
|
|
76
|
+
orientation,
|
|
77
|
+
step,
|
|
78
|
+
minValue,
|
|
79
|
+
maxValue,
|
|
80
|
+
numberFormatter,
|
|
81
|
+
onChange,
|
|
82
|
+
onChangeEnd
|
|
83
|
+
});
|
|
84
|
+
const tooltipProps = {
|
|
85
|
+
offset: 5,
|
|
86
|
+
delay: 0,
|
|
87
|
+
size: "sm",
|
|
88
|
+
showArrow: true,
|
|
89
|
+
color: (originalProps == null ? void 0 : originalProps.color) ? originalProps == null ? void 0 : originalProps.color : (_d = slider.defaultVariants) == null ? void 0 : _d.color,
|
|
90
|
+
isDisabled: originalProps.isDisabled,
|
|
91
|
+
...userTooltipProps
|
|
92
|
+
};
|
|
93
|
+
const { groupProps, trackProps, labelProps, outputProps } = useAriaSlider(
|
|
94
|
+
originalProps,
|
|
95
|
+
state,
|
|
96
|
+
trackRef
|
|
97
|
+
);
|
|
98
|
+
const { isHovered, hoverProps } = useHover({ isDisabled: originalProps.isDisabled });
|
|
99
|
+
const baseStyles = cn(classNames == null ? void 0 : classNames.base, className);
|
|
100
|
+
const isVertical = orientation === "vertical";
|
|
101
|
+
const hasMarks = (marks == null ? void 0 : marks.length) > 0;
|
|
102
|
+
const hasSingleThumb = fillOffset === void 0 ? state.values.length === 1 : false;
|
|
103
|
+
const slots = useMemo(
|
|
104
|
+
() => slider({
|
|
105
|
+
...variantProps,
|
|
106
|
+
hasMarks,
|
|
107
|
+
disableAnimation,
|
|
108
|
+
hasSingleThumb,
|
|
109
|
+
isVertical
|
|
110
|
+
}),
|
|
111
|
+
[objectToDeps(variantProps), isVertical, disableAnimation, hasSingleThumb, hasMarks]
|
|
112
|
+
);
|
|
113
|
+
const [startOffset, endOffset] = [
|
|
114
|
+
state.values.length > 1 ? state.getThumbPercent(0) : fillOffset !== void 0 ? state.getValuePercent(fillOffset) : 0,
|
|
115
|
+
state.getThumbPercent(state.values.length - 1)
|
|
116
|
+
].sort();
|
|
117
|
+
const value = state.values.length === 1 ? numberFormatter.format(state.values[0]) : numberFormatter.formatRange(state.values[0], state.values[state.values.length - 1]);
|
|
118
|
+
const steps = showSteps ? Math.floor((maxValue - minValue) / step) + 1 : 0;
|
|
119
|
+
const getBaseProps = (props2 = {}) => {
|
|
120
|
+
return {
|
|
121
|
+
ref: domRef,
|
|
122
|
+
"data-orientation": state.orientation,
|
|
123
|
+
"data-slot": "base",
|
|
124
|
+
"data-hover": isHovered,
|
|
125
|
+
className: slots.base({ class: baseStyles }),
|
|
126
|
+
...mergeProps(
|
|
127
|
+
groupProps,
|
|
128
|
+
hoverProps,
|
|
129
|
+
filterDOMProps(otherProps, {
|
|
130
|
+
enabled: shouldFilterDOMProps
|
|
131
|
+
}),
|
|
132
|
+
filterDOMProps(props2)
|
|
133
|
+
)
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
const getLabelWrapperProps = (props2 = {}) => {
|
|
137
|
+
return {
|
|
138
|
+
className: slots.labelWrapper({ class: classNames == null ? void 0 : classNames.labelWrapper }),
|
|
139
|
+
"data-slot": "labelWrapper",
|
|
140
|
+
...props2
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
const getLabelProps = (props2 = {}) => {
|
|
144
|
+
return {
|
|
145
|
+
"data-slot": "label",
|
|
146
|
+
className: slots.label({ class: classNames == null ? void 0 : classNames.label }),
|
|
147
|
+
children: label,
|
|
148
|
+
...labelProps,
|
|
149
|
+
...props2
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const getValueProps = (props2 = {}) => {
|
|
153
|
+
return {
|
|
154
|
+
"data-slot": "value",
|
|
155
|
+
className: slots.value({ class: classNames == null ? void 0 : classNames.value }),
|
|
156
|
+
children: getValue && typeof getValue === "function" ? getValue(state.values) : value,
|
|
157
|
+
...outputProps,
|
|
158
|
+
...props2
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
const getTrackProps = (props2 = {}) => {
|
|
162
|
+
const fillWidth = (endOffset - startOffset) * 100;
|
|
163
|
+
return {
|
|
164
|
+
ref: trackRef,
|
|
165
|
+
"data-slot": "track",
|
|
166
|
+
"data-thumb-hidden": !!(originalProps == null ? void 0 : originalProps.hideThumb),
|
|
167
|
+
"data-vertical": isVertical,
|
|
168
|
+
...hasSingleThumb ? {
|
|
169
|
+
"data-fill-start": fillWidth > 0,
|
|
170
|
+
"data-fill-end": fillWidth == 100
|
|
171
|
+
} : {
|
|
172
|
+
"data-fill-start": startOffset == 0,
|
|
173
|
+
"data-fill-end": startOffset * 100 + fillWidth == 100
|
|
174
|
+
},
|
|
175
|
+
className: slots.track({ class: classNames == null ? void 0 : classNames.track }),
|
|
176
|
+
...trackProps,
|
|
177
|
+
...props2
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
const getTrackWrapperProps = (props2 = {}) => {
|
|
181
|
+
return {
|
|
182
|
+
"data-slot": "track-wrapper",
|
|
183
|
+
className: slots.trackWrapper({ class: classNames == null ? void 0 : classNames.trackWrapper }),
|
|
184
|
+
...props2
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
const getFillerProps = (props2 = {}) => {
|
|
188
|
+
return {
|
|
189
|
+
"data-slot": "filler",
|
|
190
|
+
className: slots.filler({ class: classNames == null ? void 0 : classNames.filler }),
|
|
191
|
+
...props2,
|
|
192
|
+
style: {
|
|
193
|
+
...props2.style,
|
|
194
|
+
[isVertical ? "bottom" : direction === "rtl" ? "right" : "left"]: `${startOffset * 100}%`,
|
|
195
|
+
...isVertical ? {
|
|
196
|
+
height: `${(endOffset - startOffset) * 100}%`
|
|
197
|
+
} : {
|
|
198
|
+
width: `${(endOffset - startOffset) * 100}%`
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
const getThumbProps = (index) => {
|
|
204
|
+
return {
|
|
205
|
+
name,
|
|
206
|
+
index,
|
|
207
|
+
state,
|
|
208
|
+
trackRef,
|
|
209
|
+
orientation,
|
|
210
|
+
isVertical,
|
|
211
|
+
tooltipProps,
|
|
212
|
+
getTooltipValue,
|
|
213
|
+
showTooltip,
|
|
214
|
+
renderThumb,
|
|
215
|
+
formatOptions: tooltipValueFormatOptions,
|
|
216
|
+
className: slots.thumb({ class: classNames == null ? void 0 : classNames.thumb })
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
const getStepProps = (index) => {
|
|
220
|
+
const percent = state.getValuePercent(index * step + minValue);
|
|
221
|
+
return {
|
|
222
|
+
className: slots.step({ class: classNames == null ? void 0 : classNames.step }),
|
|
223
|
+
"data-slot": "step",
|
|
224
|
+
"data-in-range": percent <= endOffset && percent >= startOffset,
|
|
225
|
+
style: {
|
|
226
|
+
[isVertical ? "bottom" : direction === "rtl" ? "right" : "left"]: `${percent * 100}%`
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
const getMarkProps = (mark) => {
|
|
231
|
+
const percent = state.getValuePercent(mark.value);
|
|
232
|
+
return {
|
|
233
|
+
className: slots.mark({ class: classNames == null ? void 0 : classNames.mark }),
|
|
234
|
+
"data-slot": "mark",
|
|
235
|
+
"data-in-range": percent <= endOffset && percent >= startOffset,
|
|
236
|
+
style: {
|
|
237
|
+
[isVertical ? "bottom" : direction === "rtl" ? "right" : "left"]: `${percent * 100}%`
|
|
238
|
+
},
|
|
239
|
+
// avoid `onDownTrack` is being called since when you click the mark,
|
|
240
|
+
// `onDownTrack` will calculate the percent based on the position you click
|
|
241
|
+
// the calculated value will be set instead of the actual value defined in `marks`
|
|
242
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
243
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
244
|
+
onClick: (e) => {
|
|
245
|
+
e.stopPropagation();
|
|
246
|
+
if (isFixedValue) return;
|
|
247
|
+
if (state.values.length === 1) {
|
|
248
|
+
state.setThumbPercent(0, percent);
|
|
249
|
+
} else {
|
|
250
|
+
const leftThumbVal = state.values[0];
|
|
251
|
+
const rightThumbVal = state.values[1];
|
|
252
|
+
if (mark.value < leftThumbVal) {
|
|
253
|
+
state.setThumbPercent(0, percent);
|
|
254
|
+
} else if (mark.value > rightThumbVal) {
|
|
255
|
+
state.setThumbPercent(1, percent);
|
|
256
|
+
} else if (Math.abs(mark.value - leftThumbVal) < Math.abs(mark.value - rightThumbVal)) {
|
|
257
|
+
state.setThumbPercent(0, percent);
|
|
258
|
+
} else {
|
|
259
|
+
state.setThumbPercent(1, percent);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
const getStartContentProps = (props2 = {}) => ({
|
|
266
|
+
"data-slot": "startContent",
|
|
267
|
+
className: slots.startContent({ class: classNames == null ? void 0 : classNames.startContent }),
|
|
268
|
+
...props2
|
|
269
|
+
});
|
|
270
|
+
const getEndContentProps = (props2 = {}) => ({
|
|
271
|
+
"data-slot": "endContent",
|
|
272
|
+
className: slots.endContent({ class: classNames == null ? void 0 : classNames.endContent }),
|
|
273
|
+
...props2
|
|
274
|
+
});
|
|
275
|
+
return {
|
|
276
|
+
Component,
|
|
277
|
+
state,
|
|
278
|
+
value,
|
|
279
|
+
domRef,
|
|
280
|
+
label,
|
|
281
|
+
steps,
|
|
282
|
+
marks,
|
|
283
|
+
startContent,
|
|
284
|
+
endContent,
|
|
285
|
+
getStepProps,
|
|
286
|
+
getBaseProps,
|
|
287
|
+
getValue,
|
|
288
|
+
renderLabel,
|
|
289
|
+
renderValue,
|
|
290
|
+
getTrackWrapperProps,
|
|
291
|
+
getLabelWrapperProps,
|
|
292
|
+
getLabelProps,
|
|
293
|
+
getValueProps,
|
|
294
|
+
getTrackProps,
|
|
295
|
+
getFillerProps,
|
|
296
|
+
getThumbProps,
|
|
297
|
+
getMarkProps,
|
|
298
|
+
getStartContentProps,
|
|
299
|
+
getEndContentProps
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export {
|
|
304
|
+
useSlider
|
|
305
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as Slider, SliderProps } from './slider.mjs';
|
|
2
|
+
export { S as SliderRenderThumbProps, a as SliderStepMark, b as SliderValue, u as useSlider } from './use-slider-Bo_Y5OvC.mjs';
|
|
3
|
+
import '@sytechui/system';
|
|
4
|
+
import 'react';
|
|
5
|
+
import '@react-stately/slider';
|
|
6
|
+
import '@sytechui/theme';
|
|
7
|
+
import '@sytechui/react-utils';
|
|
8
|
+
import '@react-aria/slider';
|
|
9
|
+
import '@sytechui/tooltip';
|
|
10
|
+
import '@react-types/shared';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as Slider, SliderProps } from './slider.js';
|
|
2
|
+
export { S as SliderRenderThumbProps, a as SliderStepMark, b as SliderValue, u as useSlider } from './use-slider-Bo_Y5OvC.js';
|
|
3
|
+
import '@sytechui/system';
|
|
4
|
+
import 'react';
|
|
5
|
+
import '@react-stately/slider';
|
|
6
|
+
import '@sytechui/theme';
|
|
7
|
+
import '@sytechui/react-utils';
|
|
8
|
+
import '@react-aria/slider';
|
|
9
|
+
import '@sytechui/tooltip';
|
|
10
|
+
import '@react-types/shared';
|