@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/dist/index.js ADDED
@@ -0,0 +1,518 @@
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/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ Slider: () => slider_default,
25
+ useSlider: () => useSlider
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/slider.tsx
30
+ var import_react_utils4 = require("@sytechui/react-utils");
31
+ var import_system3 = require("@sytechui/system");
32
+
33
+ // src/slider-thumb.tsx
34
+ var import_system = require("@sytechui/system");
35
+ var import_tooltip = require("@sytechui/tooltip");
36
+ var import_react_utils2 = require("@sytechui/react-utils");
37
+ var import_visually_hidden = require("@react-aria/visually-hidden");
38
+
39
+ // src/use-slider-thumb.ts
40
+ var import_slider = require("@react-aria/slider");
41
+ var import_react_utils = require("@sytechui/react-utils");
42
+ var import_react = require("react");
43
+ var import_interactions = require("@react-aria/interactions");
44
+ var import_focus = require("@react-aria/focus");
45
+ var import_shared_utils = require("@sytechui/shared-utils");
46
+ var import_i18n = require("@react-aria/i18n");
47
+ function useSliderThumb(props) {
48
+ const {
49
+ ref,
50
+ as,
51
+ state,
52
+ index,
53
+ name,
54
+ trackRef,
55
+ className,
56
+ tooltipProps,
57
+ isVertical,
58
+ showTooltip,
59
+ getTooltipValue,
60
+ formatOptions,
61
+ renderThumb,
62
+ ...otherProps
63
+ } = props;
64
+ const Component = as || "div";
65
+ const domRef = (0, import_react_utils.useDOMRef)(ref);
66
+ const inputRef = (0, import_react.useRef)(null);
67
+ const numberFormatter = (0, import_i18n.useNumberFormatter)(formatOptions);
68
+ const { thumbProps, inputProps, isDragging, isFocused } = (0, import_slider.useSliderThumb)(
69
+ {
70
+ index,
71
+ trackRef,
72
+ inputRef,
73
+ name,
74
+ ...otherProps
75
+ },
76
+ state
77
+ );
78
+ const { hoverProps, isHovered } = (0, import_interactions.useHover)({
79
+ isDisabled: state.isDisabled
80
+ });
81
+ const { focusProps, isFocusVisible } = (0, import_focus.useFocusRing)();
82
+ const { pressProps, isPressed } = (0, import_interactions.usePress)({
83
+ isDisabled: state.isDisabled
84
+ });
85
+ const getThumbProps = (props2 = {}) => {
86
+ return {
87
+ ref: domRef,
88
+ "data-slot": "thumb",
89
+ "data-hover": (0, import_shared_utils.dataAttr)(isHovered),
90
+ "data-pressed": (0, import_shared_utils.dataAttr)(isPressed),
91
+ "data-dragging": (0, import_shared_utils.dataAttr)(isDragging),
92
+ "data-focused": (0, import_shared_utils.dataAttr)(isFocused),
93
+ "data-focus-visible": (0, import_shared_utils.dataAttr)(isFocusVisible),
94
+ "aria-label": props2["aria-label"] || `Slider thumb ${index !== void 0 ? `${index + 1}` : ""}`,
95
+ ...(0, import_shared_utils.mergeProps)(thumbProps, pressProps, hoverProps, otherProps),
96
+ className,
97
+ ...props2
98
+ };
99
+ };
100
+ const getTooltipProps = () => {
101
+ 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];
102
+ const value = numberFormatter && typeof stateValue === "number" ? numberFormatter.format(stateValue) : stateValue;
103
+ return {
104
+ ...tooltipProps,
105
+ placement: (tooltipProps == null ? void 0 : tooltipProps.placement) ? tooltipProps == null ? void 0 : tooltipProps.placement : isVertical ? "right" : "top",
106
+ content: (tooltipProps == null ? void 0 : tooltipProps.content) ? tooltipProps == null ? void 0 : tooltipProps.content : value,
107
+ updatePositionDeps: [isDragging, isHovered, isFocused, isFocusVisible, value],
108
+ isOpen: (tooltipProps == null ? void 0 : tooltipProps.isOpen) !== void 0 ? tooltipProps == null ? void 0 : tooltipProps.isOpen : isHovered || isDragging || isFocused || isFocusVisible,
109
+ role: "tooltip",
110
+ "aria-label": `Current value: ${value}`
111
+ };
112
+ };
113
+ const getInputProps = (props2 = {}) => {
114
+ return {
115
+ ref: inputRef,
116
+ ...(0, import_shared_utils.mergeProps)(inputProps, focusProps),
117
+ ...props2
118
+ };
119
+ };
120
+ return {
121
+ Component,
122
+ index,
123
+ showTooltip,
124
+ renderThumb,
125
+ getThumbProps,
126
+ getTooltipProps,
127
+ getInputProps
128
+ };
129
+ }
130
+
131
+ // src/slider-thumb.tsx
132
+ var import_jsx_runtime = require("react/jsx-runtime");
133
+ var SliderThumb = (0, import_system.forwardRef)((props, ref) => {
134
+ const {
135
+ Component,
136
+ index,
137
+ renderThumb,
138
+ showTooltip,
139
+ getTooltipProps,
140
+ getThumbProps,
141
+ getInputProps
142
+ } = useSliderThumb({
143
+ ...props,
144
+ ref
145
+ });
146
+ const thumbProps = {
147
+ ...getThumbProps(),
148
+ index,
149
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_visually_hidden.VisuallyHidden, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { ...getInputProps() }) })
150
+ };
151
+ const content = (0, import_react_utils2.renderFn)({
152
+ Component,
153
+ props: thumbProps,
154
+ renderCustom: renderThumb
155
+ });
156
+ return showTooltip ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tooltip.Tooltip, { ...getTooltipProps(), children: content }) : content;
157
+ });
158
+ SliderThumb.displayName = "HeroUI.SliderThumb";
159
+ var slider_thumb_default = SliderThumb;
160
+
161
+ // src/use-slider.ts
162
+ var import_system2 = require("@sytechui/system");
163
+ var import_theme = require("@sytechui/theme");
164
+ var import_react_utils3 = require("@sytechui/react-utils");
165
+ var import_slider2 = require("@react-stately/slider");
166
+ var import_react2 = require("react");
167
+ var import_i18n2 = require("@react-aria/i18n");
168
+ var import_slider3 = require("@react-aria/slider");
169
+ var import_shared_utils2 = require("@sytechui/shared-utils");
170
+ var import_interactions2 = require("@react-aria/interactions");
171
+ function useSlider(originalProps) {
172
+ var _a, _b, _c, _d;
173
+ const globalContext = (0, import_system2.useProviderContext)();
174
+ const [props, variantProps] = (0, import_system2.mapPropsVariants)(originalProps, import_theme.slider.variantKeys);
175
+ const {
176
+ ref,
177
+ as,
178
+ name,
179
+ label,
180
+ formatOptions,
181
+ value: valueProp,
182
+ maxValue = 100,
183
+ minValue = 0,
184
+ step = 1,
185
+ showSteps = false,
186
+ showTooltip = false,
187
+ orientation = "horizontal",
188
+ marks = [],
189
+ startContent,
190
+ endContent,
191
+ fillOffset,
192
+ className,
193
+ classNames,
194
+ renderThumb,
195
+ renderLabel,
196
+ renderValue,
197
+ onChange,
198
+ onChangeEnd,
199
+ getValue,
200
+ getTooltipValue,
201
+ tooltipValueFormatOptions = formatOptions,
202
+ tooltipProps: userTooltipProps = {},
203
+ ...otherProps
204
+ } = props;
205
+ const isFixedValue = minValue === maxValue;
206
+ if (isFixedValue) {
207
+ (0, import_shared_utils2.warn)("Min and max values should not be the same. This may cause unexpected behavior.");
208
+ }
209
+ const Component = as || "div";
210
+ const shouldFilterDOMProps = typeof Component === "string";
211
+ const disableAnimation = (_b = (_a = originalProps == null ? void 0 : originalProps.disableAnimation) != null ? _a : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _b : false;
212
+ const domRef = (0, import_react_utils3.useDOMRef)(ref);
213
+ const trackRef = (0, import_react2.useRef)(null);
214
+ const numberFormatter = (0, import_i18n2.useNumberFormatter)(formatOptions);
215
+ const { direction } = (0, import_i18n2.useLocale)();
216
+ const clampValue = (0, import_react2.useCallback)(
217
+ (valueToClamp) => {
218
+ return Math.min(Math.max(valueToClamp, minValue), maxValue);
219
+ },
220
+ [minValue, maxValue]
221
+ );
222
+ const validatedValue = (0, import_react2.useMemo)(() => {
223
+ if (isFixedValue) return minValue;
224
+ if (valueProp === void 0) return void 0;
225
+ if (Array.isArray(valueProp)) {
226
+ return valueProp.map(clampValue);
227
+ }
228
+ return clampValue(valueProp);
229
+ }, [valueProp, clampValue, isFixedValue, minValue]);
230
+ const state = (0, import_slider2.useSliderState)({
231
+ ...otherProps,
232
+ value: validatedValue,
233
+ isDisabled: (_c = originalProps == null ? void 0 : originalProps.isDisabled) != null ? _c : false,
234
+ orientation,
235
+ step,
236
+ minValue,
237
+ maxValue,
238
+ numberFormatter,
239
+ onChange,
240
+ onChangeEnd
241
+ });
242
+ const tooltipProps = {
243
+ offset: 5,
244
+ delay: 0,
245
+ size: "sm",
246
+ showArrow: true,
247
+ color: (originalProps == null ? void 0 : originalProps.color) ? originalProps == null ? void 0 : originalProps.color : (_d = import_theme.slider.defaultVariants) == null ? void 0 : _d.color,
248
+ isDisabled: originalProps.isDisabled,
249
+ ...userTooltipProps
250
+ };
251
+ const { groupProps, trackProps, labelProps, outputProps } = (0, import_slider3.useSlider)(
252
+ originalProps,
253
+ state,
254
+ trackRef
255
+ );
256
+ const { isHovered, hoverProps } = (0, import_interactions2.useHover)({ isDisabled: originalProps.isDisabled });
257
+ const baseStyles = (0, import_theme.cn)(classNames == null ? void 0 : classNames.base, className);
258
+ const isVertical = orientation === "vertical";
259
+ const hasMarks = (marks == null ? void 0 : marks.length) > 0;
260
+ const hasSingleThumb = fillOffset === void 0 ? state.values.length === 1 : false;
261
+ const slots = (0, import_react2.useMemo)(
262
+ () => (0, import_theme.slider)({
263
+ ...variantProps,
264
+ hasMarks,
265
+ disableAnimation,
266
+ hasSingleThumb,
267
+ isVertical
268
+ }),
269
+ [(0, import_shared_utils2.objectToDeps)(variantProps), isVertical, disableAnimation, hasSingleThumb, hasMarks]
270
+ );
271
+ const [startOffset, endOffset] = [
272
+ state.values.length > 1 ? state.getThumbPercent(0) : fillOffset !== void 0 ? state.getValuePercent(fillOffset) : 0,
273
+ state.getThumbPercent(state.values.length - 1)
274
+ ].sort();
275
+ const value = state.values.length === 1 ? numberFormatter.format(state.values[0]) : numberFormatter.formatRange(state.values[0], state.values[state.values.length - 1]);
276
+ const steps = showSteps ? Math.floor((maxValue - minValue) / step) + 1 : 0;
277
+ const getBaseProps = (props2 = {}) => {
278
+ return {
279
+ ref: domRef,
280
+ "data-orientation": state.orientation,
281
+ "data-slot": "base",
282
+ "data-hover": isHovered,
283
+ className: slots.base({ class: baseStyles }),
284
+ ...(0, import_shared_utils2.mergeProps)(
285
+ groupProps,
286
+ hoverProps,
287
+ (0, import_react_utils3.filterDOMProps)(otherProps, {
288
+ enabled: shouldFilterDOMProps
289
+ }),
290
+ (0, import_react_utils3.filterDOMProps)(props2)
291
+ )
292
+ };
293
+ };
294
+ const getLabelWrapperProps = (props2 = {}) => {
295
+ return {
296
+ className: slots.labelWrapper({ class: classNames == null ? void 0 : classNames.labelWrapper }),
297
+ "data-slot": "labelWrapper",
298
+ ...props2
299
+ };
300
+ };
301
+ const getLabelProps = (props2 = {}) => {
302
+ return {
303
+ "data-slot": "label",
304
+ className: slots.label({ class: classNames == null ? void 0 : classNames.label }),
305
+ children: label,
306
+ ...labelProps,
307
+ ...props2
308
+ };
309
+ };
310
+ const getValueProps = (props2 = {}) => {
311
+ return {
312
+ "data-slot": "value",
313
+ className: slots.value({ class: classNames == null ? void 0 : classNames.value }),
314
+ children: getValue && typeof getValue === "function" ? getValue(state.values) : value,
315
+ ...outputProps,
316
+ ...props2
317
+ };
318
+ };
319
+ const getTrackProps = (props2 = {}) => {
320
+ const fillWidth = (endOffset - startOffset) * 100;
321
+ return {
322
+ ref: trackRef,
323
+ "data-slot": "track",
324
+ "data-thumb-hidden": !!(originalProps == null ? void 0 : originalProps.hideThumb),
325
+ "data-vertical": isVertical,
326
+ ...hasSingleThumb ? {
327
+ "data-fill-start": fillWidth > 0,
328
+ "data-fill-end": fillWidth == 100
329
+ } : {
330
+ "data-fill-start": startOffset == 0,
331
+ "data-fill-end": startOffset * 100 + fillWidth == 100
332
+ },
333
+ className: slots.track({ class: classNames == null ? void 0 : classNames.track }),
334
+ ...trackProps,
335
+ ...props2
336
+ };
337
+ };
338
+ const getTrackWrapperProps = (props2 = {}) => {
339
+ return {
340
+ "data-slot": "track-wrapper",
341
+ className: slots.trackWrapper({ class: classNames == null ? void 0 : classNames.trackWrapper }),
342
+ ...props2
343
+ };
344
+ };
345
+ const getFillerProps = (props2 = {}) => {
346
+ return {
347
+ "data-slot": "filler",
348
+ className: slots.filler({ class: classNames == null ? void 0 : classNames.filler }),
349
+ ...props2,
350
+ style: {
351
+ ...props2.style,
352
+ [isVertical ? "bottom" : direction === "rtl" ? "right" : "left"]: `${startOffset * 100}%`,
353
+ ...isVertical ? {
354
+ height: `${(endOffset - startOffset) * 100}%`
355
+ } : {
356
+ width: `${(endOffset - startOffset) * 100}%`
357
+ }
358
+ }
359
+ };
360
+ };
361
+ const getThumbProps = (index) => {
362
+ return {
363
+ name,
364
+ index,
365
+ state,
366
+ trackRef,
367
+ orientation,
368
+ isVertical,
369
+ tooltipProps,
370
+ getTooltipValue,
371
+ showTooltip,
372
+ renderThumb,
373
+ formatOptions: tooltipValueFormatOptions,
374
+ className: slots.thumb({ class: classNames == null ? void 0 : classNames.thumb })
375
+ };
376
+ };
377
+ const getStepProps = (index) => {
378
+ const percent = state.getValuePercent(index * step + minValue);
379
+ return {
380
+ className: slots.step({ class: classNames == null ? void 0 : classNames.step }),
381
+ "data-slot": "step",
382
+ "data-in-range": percent <= endOffset && percent >= startOffset,
383
+ style: {
384
+ [isVertical ? "bottom" : direction === "rtl" ? "right" : "left"]: `${percent * 100}%`
385
+ }
386
+ };
387
+ };
388
+ const getMarkProps = (mark) => {
389
+ const percent = state.getValuePercent(mark.value);
390
+ return {
391
+ className: slots.mark({ class: classNames == null ? void 0 : classNames.mark }),
392
+ "data-slot": "mark",
393
+ "data-in-range": percent <= endOffset && percent >= startOffset,
394
+ style: {
395
+ [isVertical ? "bottom" : direction === "rtl" ? "right" : "left"]: `${percent * 100}%`
396
+ },
397
+ // avoid `onDownTrack` is being called since when you click the mark,
398
+ // `onDownTrack` will calculate the percent based on the position you click
399
+ // the calculated value will be set instead of the actual value defined in `marks`
400
+ onMouseDown: (e) => e.stopPropagation(),
401
+ onPointerDown: (e) => e.stopPropagation(),
402
+ onClick: (e) => {
403
+ e.stopPropagation();
404
+ if (isFixedValue) return;
405
+ if (state.values.length === 1) {
406
+ state.setThumbPercent(0, percent);
407
+ } else {
408
+ const leftThumbVal = state.values[0];
409
+ const rightThumbVal = state.values[1];
410
+ if (mark.value < leftThumbVal) {
411
+ state.setThumbPercent(0, percent);
412
+ } else if (mark.value > rightThumbVal) {
413
+ state.setThumbPercent(1, percent);
414
+ } else if (Math.abs(mark.value - leftThumbVal) < Math.abs(mark.value - rightThumbVal)) {
415
+ state.setThumbPercent(0, percent);
416
+ } else {
417
+ state.setThumbPercent(1, percent);
418
+ }
419
+ }
420
+ }
421
+ };
422
+ };
423
+ const getStartContentProps = (props2 = {}) => ({
424
+ "data-slot": "startContent",
425
+ className: slots.startContent({ class: classNames == null ? void 0 : classNames.startContent }),
426
+ ...props2
427
+ });
428
+ const getEndContentProps = (props2 = {}) => ({
429
+ "data-slot": "endContent",
430
+ className: slots.endContent({ class: classNames == null ? void 0 : classNames.endContent }),
431
+ ...props2
432
+ });
433
+ return {
434
+ Component,
435
+ state,
436
+ value,
437
+ domRef,
438
+ label,
439
+ steps,
440
+ marks,
441
+ startContent,
442
+ endContent,
443
+ getStepProps,
444
+ getBaseProps,
445
+ getValue,
446
+ renderLabel,
447
+ renderValue,
448
+ getTrackWrapperProps,
449
+ getLabelWrapperProps,
450
+ getLabelProps,
451
+ getValueProps,
452
+ getTrackProps,
453
+ getFillerProps,
454
+ getThumbProps,
455
+ getMarkProps,
456
+ getStartContentProps,
457
+ getEndContentProps
458
+ };
459
+ }
460
+
461
+ // src/slider.tsx
462
+ var import_jsx_runtime2 = require("react/jsx-runtime");
463
+ var Slider = (0, import_system3.forwardRef)((props, ref) => {
464
+ const {
465
+ Component,
466
+ state,
467
+ label,
468
+ steps,
469
+ marks,
470
+ startContent,
471
+ endContent,
472
+ getStepProps,
473
+ getBaseProps,
474
+ renderValue,
475
+ renderLabel,
476
+ getTrackWrapperProps,
477
+ getLabelWrapperProps,
478
+ getLabelProps,
479
+ getValueProps,
480
+ getTrackProps,
481
+ getFillerProps,
482
+ getThumbProps,
483
+ getMarkProps,
484
+ getStartContentProps,
485
+ getEndContentProps
486
+ } = useSlider({ ...props, ref });
487
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Component, { ...getBaseProps(), children: [
488
+ label && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { ...getLabelWrapperProps(), children: [
489
+ (0, import_react_utils4.renderFn)({
490
+ Component: "label",
491
+ props: getLabelProps(),
492
+ renderCustom: renderLabel
493
+ }),
494
+ (0, import_react_utils4.renderFn)({
495
+ Component: "output",
496
+ props: getValueProps(),
497
+ renderCustom: renderValue
498
+ })
499
+ ] }),
500
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { ...getTrackWrapperProps(), children: [
501
+ startContent && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...getStartContentProps(), children: startContent }),
502
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { ...getTrackProps(), children: [
503
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...getFillerProps() }),
504
+ Number.isFinite(steps) && Array.from({ length: steps }, (_, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...getStepProps(index) }, index)),
505
+ state.values.map((_, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(slider_thumb_default, { ...getThumbProps(index) }, index)),
506
+ (marks == null ? void 0 : marks.length) > 0 && marks.map((mark, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...getMarkProps(mark), children: mark.label }, index))
507
+ ] }),
508
+ endContent && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...getEndContentProps(), children: endContent })
509
+ ] })
510
+ ] });
511
+ });
512
+ Slider.displayName = "HeroUI.Slider";
513
+ var slider_default = Slider;
514
+ // Annotate the CommonJS export names for ESM import in node:
515
+ 0 && (module.exports = {
516
+ Slider,
517
+ useSlider
518
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import {
3
+ slider_default
4
+ } from "./chunk-CJCHSOKZ.mjs";
5
+ import "./chunk-IQZHN75L.mjs";
6
+ import "./chunk-M2PJK6HJ.mjs";
7
+ import {
8
+ useSlider
9
+ } from "./chunk-ORNKXCKK.mjs";
10
+ export {
11
+ slider_default as Slider,
12
+ useSlider
13
+ };
@@ -0,0 +1,9 @@
1
+ import '@sytechui/system';
2
+ export { f as SliderThumbProps, g as default } from './use-slider-Bo_Y5OvC.mjs';
3
+ import 'react';
4
+ import '@react-stately/slider';
5
+ import '@sytechui/theme';
6
+ import '@sytechui/react-utils';
7
+ import '@react-aria/slider';
8
+ import '@sytechui/tooltip';
9
+ import '@react-types/shared';
@@ -0,0 +1,9 @@
1
+ import '@sytechui/system';
2
+ export { f as SliderThumbProps, g as default } from './use-slider-Bo_Y5OvC.js';
3
+ import 'react';
4
+ import '@react-stately/slider';
5
+ import '@sytechui/theme';
6
+ import '@sytechui/react-utils';
7
+ import '@react-aria/slider';
8
+ import '@sytechui/tooltip';
9
+ import '@react-types/shared';