@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.
@@ -0,0 +1,328 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/use-slider.ts
22
+ var use_slider_exports = {};
23
+ __export(use_slider_exports, {
24
+ useSlider: () => useSlider
25
+ });
26
+ module.exports = __toCommonJS(use_slider_exports);
27
+ var import_system = require("@sytechui/system");
28
+ var import_theme = require("@sytechui/theme");
29
+ var import_react_utils = require("@sytechui/react-utils");
30
+ var import_slider = require("@react-stately/slider");
31
+ var import_react = require("react");
32
+ var import_i18n = require("@react-aria/i18n");
33
+ var import_slider2 = require("@react-aria/slider");
34
+ var import_shared_utils = require("@sytechui/shared-utils");
35
+ var import_interactions = require("@react-aria/interactions");
36
+ function useSlider(originalProps) {
37
+ var _a, _b, _c, _d;
38
+ const globalContext = (0, import_system.useProviderContext)();
39
+ const [props, variantProps] = (0, import_system.mapPropsVariants)(originalProps, import_theme.slider.variantKeys);
40
+ const {
41
+ ref,
42
+ as,
43
+ name,
44
+ label,
45
+ formatOptions,
46
+ value: valueProp,
47
+ maxValue = 100,
48
+ minValue = 0,
49
+ step = 1,
50
+ showSteps = false,
51
+ showTooltip = false,
52
+ orientation = "horizontal",
53
+ marks = [],
54
+ startContent,
55
+ endContent,
56
+ fillOffset,
57
+ className,
58
+ classNames,
59
+ renderThumb,
60
+ renderLabel,
61
+ renderValue,
62
+ onChange,
63
+ onChangeEnd,
64
+ getValue,
65
+ getTooltipValue,
66
+ tooltipValueFormatOptions = formatOptions,
67
+ tooltipProps: userTooltipProps = {},
68
+ ...otherProps
69
+ } = props;
70
+ const isFixedValue = minValue === maxValue;
71
+ if (isFixedValue) {
72
+ (0, import_shared_utils.warn)("Min and max values should not be the same. This may cause unexpected behavior.");
73
+ }
74
+ const Component = as || "div";
75
+ const shouldFilterDOMProps = typeof Component === "string";
76
+ const disableAnimation = (_b = (_a = originalProps == null ? void 0 : originalProps.disableAnimation) != null ? _a : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _b : false;
77
+ const domRef = (0, import_react_utils.useDOMRef)(ref);
78
+ const trackRef = (0, import_react.useRef)(null);
79
+ const numberFormatter = (0, import_i18n.useNumberFormatter)(formatOptions);
80
+ const { direction } = (0, import_i18n.useLocale)();
81
+ const clampValue = (0, import_react.useCallback)(
82
+ (valueToClamp) => {
83
+ return Math.min(Math.max(valueToClamp, minValue), maxValue);
84
+ },
85
+ [minValue, maxValue]
86
+ );
87
+ const validatedValue = (0, import_react.useMemo)(() => {
88
+ if (isFixedValue) return minValue;
89
+ if (valueProp === void 0) return void 0;
90
+ if (Array.isArray(valueProp)) {
91
+ return valueProp.map(clampValue);
92
+ }
93
+ return clampValue(valueProp);
94
+ }, [valueProp, clampValue, isFixedValue, minValue]);
95
+ const state = (0, import_slider.useSliderState)({
96
+ ...otherProps,
97
+ value: validatedValue,
98
+ isDisabled: (_c = originalProps == null ? void 0 : originalProps.isDisabled) != null ? _c : false,
99
+ orientation,
100
+ step,
101
+ minValue,
102
+ maxValue,
103
+ numberFormatter,
104
+ onChange,
105
+ onChangeEnd
106
+ });
107
+ const tooltipProps = {
108
+ offset: 5,
109
+ delay: 0,
110
+ size: "sm",
111
+ showArrow: true,
112
+ color: (originalProps == null ? void 0 : originalProps.color) ? originalProps == null ? void 0 : originalProps.color : (_d = import_theme.slider.defaultVariants) == null ? void 0 : _d.color,
113
+ isDisabled: originalProps.isDisabled,
114
+ ...userTooltipProps
115
+ };
116
+ const { groupProps, trackProps, labelProps, outputProps } = (0, import_slider2.useSlider)(
117
+ originalProps,
118
+ state,
119
+ trackRef
120
+ );
121
+ const { isHovered, hoverProps } = (0, import_interactions.useHover)({ isDisabled: originalProps.isDisabled });
122
+ const baseStyles = (0, import_theme.cn)(classNames == null ? void 0 : classNames.base, className);
123
+ const isVertical = orientation === "vertical";
124
+ const hasMarks = (marks == null ? void 0 : marks.length) > 0;
125
+ const hasSingleThumb = fillOffset === void 0 ? state.values.length === 1 : false;
126
+ const slots = (0, import_react.useMemo)(
127
+ () => (0, import_theme.slider)({
128
+ ...variantProps,
129
+ hasMarks,
130
+ disableAnimation,
131
+ hasSingleThumb,
132
+ isVertical
133
+ }),
134
+ [(0, import_shared_utils.objectToDeps)(variantProps), isVertical, disableAnimation, hasSingleThumb, hasMarks]
135
+ );
136
+ const [startOffset, endOffset] = [
137
+ state.values.length > 1 ? state.getThumbPercent(0) : fillOffset !== void 0 ? state.getValuePercent(fillOffset) : 0,
138
+ state.getThumbPercent(state.values.length - 1)
139
+ ].sort();
140
+ const value = state.values.length === 1 ? numberFormatter.format(state.values[0]) : numberFormatter.formatRange(state.values[0], state.values[state.values.length - 1]);
141
+ const steps = showSteps ? Math.floor((maxValue - minValue) / step) + 1 : 0;
142
+ const getBaseProps = (props2 = {}) => {
143
+ return {
144
+ ref: domRef,
145
+ "data-orientation": state.orientation,
146
+ "data-slot": "base",
147
+ "data-hover": isHovered,
148
+ className: slots.base({ class: baseStyles }),
149
+ ...(0, import_shared_utils.mergeProps)(
150
+ groupProps,
151
+ hoverProps,
152
+ (0, import_react_utils.filterDOMProps)(otherProps, {
153
+ enabled: shouldFilterDOMProps
154
+ }),
155
+ (0, import_react_utils.filterDOMProps)(props2)
156
+ )
157
+ };
158
+ };
159
+ const getLabelWrapperProps = (props2 = {}) => {
160
+ return {
161
+ className: slots.labelWrapper({ class: classNames == null ? void 0 : classNames.labelWrapper }),
162
+ "data-slot": "labelWrapper",
163
+ ...props2
164
+ };
165
+ };
166
+ const getLabelProps = (props2 = {}) => {
167
+ return {
168
+ "data-slot": "label",
169
+ className: slots.label({ class: classNames == null ? void 0 : classNames.label }),
170
+ children: label,
171
+ ...labelProps,
172
+ ...props2
173
+ };
174
+ };
175
+ const getValueProps = (props2 = {}) => {
176
+ return {
177
+ "data-slot": "value",
178
+ className: slots.value({ class: classNames == null ? void 0 : classNames.value }),
179
+ children: getValue && typeof getValue === "function" ? getValue(state.values) : value,
180
+ ...outputProps,
181
+ ...props2
182
+ };
183
+ };
184
+ const getTrackProps = (props2 = {}) => {
185
+ const fillWidth = (endOffset - startOffset) * 100;
186
+ return {
187
+ ref: trackRef,
188
+ "data-slot": "track",
189
+ "data-thumb-hidden": !!(originalProps == null ? void 0 : originalProps.hideThumb),
190
+ "data-vertical": isVertical,
191
+ ...hasSingleThumb ? {
192
+ "data-fill-start": fillWidth > 0,
193
+ "data-fill-end": fillWidth == 100
194
+ } : {
195
+ "data-fill-start": startOffset == 0,
196
+ "data-fill-end": startOffset * 100 + fillWidth == 100
197
+ },
198
+ className: slots.track({ class: classNames == null ? void 0 : classNames.track }),
199
+ ...trackProps,
200
+ ...props2
201
+ };
202
+ };
203
+ const getTrackWrapperProps = (props2 = {}) => {
204
+ return {
205
+ "data-slot": "track-wrapper",
206
+ className: slots.trackWrapper({ class: classNames == null ? void 0 : classNames.trackWrapper }),
207
+ ...props2
208
+ };
209
+ };
210
+ const getFillerProps = (props2 = {}) => {
211
+ return {
212
+ "data-slot": "filler",
213
+ className: slots.filler({ class: classNames == null ? void 0 : classNames.filler }),
214
+ ...props2,
215
+ style: {
216
+ ...props2.style,
217
+ [isVertical ? "bottom" : direction === "rtl" ? "right" : "left"]: `${startOffset * 100}%`,
218
+ ...isVertical ? {
219
+ height: `${(endOffset - startOffset) * 100}%`
220
+ } : {
221
+ width: `${(endOffset - startOffset) * 100}%`
222
+ }
223
+ }
224
+ };
225
+ };
226
+ const getThumbProps = (index) => {
227
+ return {
228
+ name,
229
+ index,
230
+ state,
231
+ trackRef,
232
+ orientation,
233
+ isVertical,
234
+ tooltipProps,
235
+ getTooltipValue,
236
+ showTooltip,
237
+ renderThumb,
238
+ formatOptions: tooltipValueFormatOptions,
239
+ className: slots.thumb({ class: classNames == null ? void 0 : classNames.thumb })
240
+ };
241
+ };
242
+ const getStepProps = (index) => {
243
+ const percent = state.getValuePercent(index * step + minValue);
244
+ return {
245
+ className: slots.step({ class: classNames == null ? void 0 : classNames.step }),
246
+ "data-slot": "step",
247
+ "data-in-range": percent <= endOffset && percent >= startOffset,
248
+ style: {
249
+ [isVertical ? "bottom" : direction === "rtl" ? "right" : "left"]: `${percent * 100}%`
250
+ }
251
+ };
252
+ };
253
+ const getMarkProps = (mark) => {
254
+ const percent = state.getValuePercent(mark.value);
255
+ return {
256
+ className: slots.mark({ class: classNames == null ? void 0 : classNames.mark }),
257
+ "data-slot": "mark",
258
+ "data-in-range": percent <= endOffset && percent >= startOffset,
259
+ style: {
260
+ [isVertical ? "bottom" : direction === "rtl" ? "right" : "left"]: `${percent * 100}%`
261
+ },
262
+ // avoid `onDownTrack` is being called since when you click the mark,
263
+ // `onDownTrack` will calculate the percent based on the position you click
264
+ // the calculated value will be set instead of the actual value defined in `marks`
265
+ onMouseDown: (e) => e.stopPropagation(),
266
+ onPointerDown: (e) => e.stopPropagation(),
267
+ onClick: (e) => {
268
+ e.stopPropagation();
269
+ if (isFixedValue) return;
270
+ if (state.values.length === 1) {
271
+ state.setThumbPercent(0, percent);
272
+ } else {
273
+ const leftThumbVal = state.values[0];
274
+ const rightThumbVal = state.values[1];
275
+ if (mark.value < leftThumbVal) {
276
+ state.setThumbPercent(0, percent);
277
+ } else if (mark.value > rightThumbVal) {
278
+ state.setThumbPercent(1, percent);
279
+ } else if (Math.abs(mark.value - leftThumbVal) < Math.abs(mark.value - rightThumbVal)) {
280
+ state.setThumbPercent(0, percent);
281
+ } else {
282
+ state.setThumbPercent(1, percent);
283
+ }
284
+ }
285
+ }
286
+ };
287
+ };
288
+ const getStartContentProps = (props2 = {}) => ({
289
+ "data-slot": "startContent",
290
+ className: slots.startContent({ class: classNames == null ? void 0 : classNames.startContent }),
291
+ ...props2
292
+ });
293
+ const getEndContentProps = (props2 = {}) => ({
294
+ "data-slot": "endContent",
295
+ className: slots.endContent({ class: classNames == null ? void 0 : classNames.endContent }),
296
+ ...props2
297
+ });
298
+ return {
299
+ Component,
300
+ state,
301
+ value,
302
+ domRef,
303
+ label,
304
+ steps,
305
+ marks,
306
+ startContent,
307
+ endContent,
308
+ getStepProps,
309
+ getBaseProps,
310
+ getValue,
311
+ renderLabel,
312
+ renderValue,
313
+ getTrackWrapperProps,
314
+ getLabelWrapperProps,
315
+ getLabelProps,
316
+ getValueProps,
317
+ getTrackProps,
318
+ getFillerProps,
319
+ getThumbProps,
320
+ getMarkProps,
321
+ getStartContentProps,
322
+ getEndContentProps
323
+ };
324
+ }
325
+ // Annotate the CommonJS export names for ESM import in node:
326
+ 0 && (module.exports = {
327
+ useSlider
328
+ });
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import {
3
+ useSlider
4
+ } from "./chunk-ORNKXCKK.mjs";
5
+ export {
6
+ useSlider
7
+ };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@sytechui/slider",
3
+ "version": "2.4.29",
4
+ "description": "A slider allows a user to select one or more values within a range.",
5
+ "keywords": [
6
+ "slider"
7
+ ],
8
+ "author": "HeroUI <support@heroui.com>",
9
+ "homepage": "https://heroui.com",
10
+ "license": "MIT",
11
+ "main": "dist/index.js",
12
+ "sideEffects": false,
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/heroui-inc/heroui.git",
22
+ "directory": "packages/components/slider"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/heroui-inc/heroui/issues"
26
+ },
27
+ "peerDependencies": {
28
+ "react": ">=18 || >=19.0.0-rc.0",
29
+ "react-dom": ">=18 || >=19.0.0-rc.0",
30
+ "@sytechui/theme": ">=2.4.24",
31
+ "@sytechui/system": ">=2.4.18"
32
+ },
33
+ "dependencies": {
34
+ "@react-aria/focus": "3.21.5",
35
+ "@react-aria/i18n": "3.12.16",
36
+ "@react-aria/interactions": "3.27.1",
37
+ "@react-aria/slider": "3.8.5",
38
+ "@react-aria/visually-hidden": "3.8.31",
39
+ "@react-stately/slider": "3.7.5",
40
+ "@sytechui/shared-utils": "2.1.12",
41
+ "@sytechui/react-utils": "2.1.14",
42
+ "@sytechui/tooltip": "2.2.29"
43
+ },
44
+ "clean-package": "../../../clean-package.config.json",
45
+ "module": "dist/index.mjs",
46
+ "types": "dist/index.d.ts",
47
+ "exports": {
48
+ ".": {
49
+ "types": "./dist/index.d.ts",
50
+ "import": "./dist/index.mjs",
51
+ "require": "./dist/index.js"
52
+ },
53
+ "./package.json": "./package.json"
54
+ },
55
+ "scripts": {
56
+ "build": "tsup src --dts",
57
+ "build:fast": "tsup src",
58
+ "dev": "pnpm build:fast --watch",
59
+ "clean": "rimraf dist .turbo",
60
+ "typecheck": "tsc --noEmit"
61
+ }
62
+ }