@particle-network/ui-react 0.4.5-beta.19 → 0.4.5-beta.20

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,33 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { renderFn } from "@heroui/react-utils";
3
+ import { forwardRef } from "@heroui/system";
4
+ import { Tooltip } from "@heroui/tooltip";
5
+ import { VisuallyHidden } from "@react-aria/visually-hidden";
6
+ import { useSliderThumb } from "./use-slider-thumb.js";
7
+ const SliderThumb = forwardRef((props, ref)=>{
8
+ const { Component, index, renderThumb, showTooltip, getTooltipProps, getThumbProps, getInputProps } = useSliderThumb({
9
+ ...props,
10
+ ref
11
+ });
12
+ const thumbProps = {
13
+ ...getThumbProps(),
14
+ index,
15
+ children: /*#__PURE__*/ jsx(VisuallyHidden, {
16
+ children: /*#__PURE__*/ jsx("input", {
17
+ ...getInputProps()
18
+ })
19
+ })
20
+ };
21
+ const content = renderFn({
22
+ Component,
23
+ props: thumbProps,
24
+ renderCustom: renderThumb
25
+ });
26
+ return showTooltip ? /*#__PURE__*/ jsx(Tooltip, {
27
+ ...getTooltipProps(),
28
+ children: content
29
+ }) : content;
30
+ });
31
+ SliderThumb.displayName = 'HeroUI.SliderThumb';
32
+ const slider_thumb = SliderThumb;
33
+ export { slider_thumb as default };
@@ -0,0 +1,4 @@
1
+ import type { UseSliderProps } from './use-slider';
2
+ export type SliderProps = Omit<UseSliderProps, 'isVertical' | 'hasMarks' | 'hasSingleThumb'>;
3
+ declare const Slider: import("@heroui/system-rsc").InternalForwardRefRenderFunction<"div", SliderProps, never>;
4
+ export default Slider;
@@ -0,0 +1,77 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { renderFn } from "@heroui/react-utils";
3
+ import { forwardRef } from "@heroui/system";
4
+ import slider_thumb from "./slider-thumb.js";
5
+ import { useSlider } from "./use-slider.js";
6
+ const Slider = forwardRef((props, ref)=>{
7
+ const { Component, state, label, steps, marks, startContent, endContent, showMarksSteps, minValue, step, getStepProps, getBaseProps, renderValue, renderLabel, getTrackWrapperProps, getLabelWrapperProps, getLabelProps, getValueProps, getTrackProps, getFillerProps, getThumbProps, getMarkProps, getStartContentProps, getEndContentProps } = useSlider({
8
+ ...props,
9
+ ref
10
+ });
11
+ return /*#__PURE__*/ jsxs(Component, {
12
+ ...getBaseProps(),
13
+ children: [
14
+ label && /*#__PURE__*/ jsxs("div", {
15
+ ...getLabelWrapperProps(),
16
+ children: [
17
+ renderFn({
18
+ Component: 'label',
19
+ props: getLabelProps(),
20
+ renderCustom: renderLabel
21
+ }),
22
+ renderFn({
23
+ Component: 'output',
24
+ props: getValueProps(),
25
+ renderCustom: renderValue
26
+ })
27
+ ]
28
+ }),
29
+ /*#__PURE__*/ jsxs("div", {
30
+ ...getTrackWrapperProps(),
31
+ children: [
32
+ startContent && /*#__PURE__*/ jsx("div", {
33
+ ...getStartContentProps(),
34
+ children: startContent
35
+ }),
36
+ /*#__PURE__*/ jsxs("div", {
37
+ ...getTrackProps(),
38
+ children: [
39
+ /*#__PURE__*/ jsx("div", {
40
+ ...getFillerProps()
41
+ }),
42
+ Number.isFinite(steps) && Array.from({
43
+ length: steps
44
+ }, (_, index)=>/*#__PURE__*/ jsx("div", {
45
+ ...getStepProps(index)
46
+ }, index)),
47
+ state.values.map((_, index)=>/*#__PURE__*/ jsx(slider_thumb, {
48
+ ...getThumbProps(index)
49
+ }, index)),
50
+ marks?.length > 0 && marks.map((mark, index)=>{
51
+ const isMarkAtThumbPosition = state.values.some((value)=>value === mark.value);
52
+ return /*#__PURE__*/ jsxs(Fragment, {
53
+ children: [
54
+ showMarksSteps && !isMarkAtThumbPosition && /*#__PURE__*/ jsx("div", {
55
+ ...getStepProps(Math.round((mark.value - minValue) / step))
56
+ }, `step-${index}`),
57
+ /*#__PURE__*/ jsx("div", {
58
+ ...getMarkProps(mark),
59
+ children: mark.label
60
+ }, `mark-${index}`)
61
+ ]
62
+ });
63
+ })
64
+ ]
65
+ }),
66
+ endContent && /*#__PURE__*/ jsx("div", {
67
+ ...getEndContentProps(),
68
+ children: endContent
69
+ })
70
+ ]
71
+ })
72
+ ]
73
+ });
74
+ });
75
+ Slider.displayName = 'HeroUI.Slider';
76
+ const slider = Slider;
77
+ export { slider as default };
@@ -0,0 +1,61 @@
1
+ import type { RefObject } from 'react';
2
+ import type { ReactRef } from '@heroui/react-utils';
3
+ import type { HTMLHeroUIProps, PropGetter } from '@heroui/system';
4
+ import type { SliderVariantProps } from '@heroui/theme';
5
+ import type { TooltipProps } from '@heroui/tooltip';
6
+ import type { AriaSliderThumbProps } from '@react-aria/slider';
7
+ import type { SliderState } from '@react-stately/slider';
8
+ import type { SliderValue, UseSliderProps } from './use-slider';
9
+ interface Props extends HTMLHeroUIProps {
10
+ /**
11
+ * Ref to the DOM node.
12
+ */
13
+ ref?: ReactRef<HTMLElement | null>;
14
+ /**
15
+ * slider state, created via `useSliderState`.
16
+ */
17
+ state: SliderState;
18
+ /**
19
+ * A ref to the track element.
20
+ */
21
+ trackRef: RefObject<HTMLDivElement>;
22
+ /**
23
+ * @internal
24
+ */
25
+ isVertical: boolean;
26
+ /**
27
+ * @internal
28
+ */
29
+ showTooltip?: boolean;
30
+ /**
31
+ * @internal
32
+ */
33
+ formatOptions?: Intl.NumberFormatOptions;
34
+ /**
35
+ * @internal
36
+ */
37
+ tooltipProps?: UseSliderProps['tooltipProps'];
38
+ /**
39
+ * A function that returns the content to display as the tooltip label. (in analogy to getValue)
40
+ * @param value - The value of the slider, array or single number.
41
+ * @param index - The index of the thumb, if multiple thumbs are used.
42
+ * In addition to formatting with tooltipValueFormatOptions if number is returned.
43
+ */
44
+ getTooltipValue?: (value: SliderValue, index?: number) => string | number;
45
+ /**
46
+ * Function to render the thumb. It can be used to add a tooltip or custom icon.
47
+ */
48
+ renderThumb?: UseSliderProps['renderThumb'];
49
+ }
50
+ export type UseSliderThumbProps = Props & AriaSliderThumbProps & SliderVariantProps;
51
+ export declare function useSliderThumb(props: UseSliderThumbProps): {
52
+ Component: import("@heroui/system-rsc").As<any>;
53
+ index: number | undefined;
54
+ showTooltip: boolean | undefined;
55
+ renderThumb: ((props: import("./use-slider").SliderRenderThumbProps) => React.ReactNode) | undefined;
56
+ getThumbProps: PropGetter;
57
+ getTooltipProps: () => TooltipProps;
58
+ getInputProps: PropGetter;
59
+ };
60
+ export type UseSliderThumbReturn = ReturnType<typeof useSliderThumb>;
61
+ export {};
@@ -0,0 +1,79 @@
1
+ import { useRef } from "react";
2
+ import { useDOMRef } from "@heroui/react-utils";
3
+ import { dataAttr, mergeProps } from "@heroui/shared-utils";
4
+ import { useFocusRing } from "@react-aria/focus";
5
+ import { useNumberFormatter } from "@react-aria/i18n";
6
+ import { useHover, usePress } from "@react-aria/interactions";
7
+ import { useSliderThumb } from "@react-aria/slider";
8
+ import { bgWithTextColorClasses } from "../../utils/classes.js";
9
+ function use_slider_thumb_useSliderThumb(props) {
10
+ const { ref, as, state, index, name, trackRef, className, tooltipProps, isVertical, showTooltip, getTooltipValue, formatOptions, renderThumb, ...otherProps } = props;
11
+ const Component = as || 'div';
12
+ const domRef = useDOMRef(ref);
13
+ const inputRef = useRef(null);
14
+ const numberFormatter = useNumberFormatter(formatOptions);
15
+ const { thumbProps, inputProps, isDragging, isFocused } = useSliderThumb({
16
+ index,
17
+ trackRef,
18
+ inputRef,
19
+ name,
20
+ ...otherProps
21
+ }, state);
22
+ const { hoverProps, isHovered } = useHover({
23
+ isDisabled: state.isDisabled
24
+ });
25
+ const { focusProps, isFocusVisible } = useFocusRing();
26
+ const { pressProps, isPressed } = usePress({
27
+ isDisabled: state.isDisabled
28
+ });
29
+ const getThumbProps = (props = {})=>({
30
+ ref: domRef,
31
+ 'data-slot': 'thumb',
32
+ 'data-hover': dataAttr(isHovered),
33
+ 'data-pressed': dataAttr(isPressed),
34
+ 'data-dragging': dataAttr(isDragging),
35
+ 'data-focused': dataAttr(isFocused),
36
+ 'data-focus-visible': dataAttr(isFocusVisible),
37
+ 'aria-label': props['aria-label'] || `Slider thumb ${void 0 !== index ? `${index + 1}` : ''}`,
38
+ ...mergeProps(thumbProps, pressProps, hoverProps, otherProps),
39
+ className,
40
+ ...props
41
+ });
42
+ const getTooltipProps = ()=>{
43
+ const stateValue = tooltipProps?.content ? tooltipProps.content : getTooltipValue ? 1 === state.values.length ? getTooltipValue(state.values[index ?? 0]) : getTooltipValue(state.values, index ?? 0) : state.values[index ?? 0];
44
+ const value = numberFormatter && 'number' == typeof stateValue ? numberFormatter.format(stateValue) : stateValue;
45
+ return {
46
+ ...tooltipProps,
47
+ placement: tooltipProps?.placement ? tooltipProps?.placement : isVertical ? 'right' : 'top',
48
+ content: tooltipProps?.content ? tooltipProps?.content : value,
49
+ updatePositionDeps: [
50
+ isDragging,
51
+ isHovered,
52
+ isFocused,
53
+ isFocusVisible,
54
+ value
55
+ ],
56
+ isOpen: tooltipProps?.isOpen !== void 0 ? tooltipProps?.isOpen : isHovered || isDragging || isFocused || isFocusVisible,
57
+ role: 'tooltip',
58
+ 'aria-label': `Current value: ${value}`,
59
+ classNames: {
60
+ content: bgWithTextColorClasses[tooltipProps?.color]
61
+ }
62
+ };
63
+ };
64
+ const getInputProps = (props = {})=>({
65
+ ref: inputRef,
66
+ ...mergeProps(inputProps, focusProps),
67
+ ...props
68
+ });
69
+ return {
70
+ Component,
71
+ index,
72
+ showTooltip,
73
+ renderThumb,
74
+ getThumbProps,
75
+ getTooltipProps,
76
+ getInputProps
77
+ };
78
+ }
79
+ export { use_slider_thumb_useSliderThumb as useSliderThumb };
@@ -0,0 +1,182 @@
1
+ import type React from 'react';
2
+ import { type ReactNode } from 'react';
3
+ import type { ReactRef } from '@heroui/react-utils';
4
+ import type { DOMAttributes, HTMLHeroUIProps, PropGetter } from '@heroui/system';
5
+ import type { SliderSlots, SliderVariantProps, SlotsToClasses } from '@heroui/theme';
6
+ import type { TooltipProps } from '@heroui/tooltip';
7
+ import type { AriaSliderProps } from '@react-aria/slider';
8
+ import type { ValueBase } from '@react-types/shared';
9
+ import type { SliderThumbProps } from './slider-thumb';
10
+ export type SliderValue = number | number[];
11
+ export interface SliderStepMark {
12
+ value: number;
13
+ label: string;
14
+ }
15
+ export type SliderRenderThumbProps = DOMAttributes<HTMLDivElement> & {
16
+ index?: number;
17
+ };
18
+ interface Props extends HTMLHeroUIProps {
19
+ /**
20
+ * Ref to the DOM node.
21
+ */
22
+ ref?: ReactRef<HTMLElement | null>;
23
+ /**
24
+ * The content to display as the label.
25
+ */
26
+ label?: ReactNode;
27
+ /**
28
+ * The input name.
29
+ */
30
+ name?: string;
31
+ /**
32
+ * The offset from which to start the fill.
33
+ */
34
+ fillOffset?: number;
35
+ /**
36
+ * The display format of the value label.
37
+ */
38
+ formatOptions?: Intl.NumberFormatOptions;
39
+ /**
40
+ * The display format of the tooltip value label.
41
+ * @default formatOptions
42
+ */
43
+ tooltipValueFormatOptions?: Intl.NumberFormatOptions;
44
+ /**
45
+ * Whether to show the step indicators.
46
+ * @default false
47
+ */
48
+ showSteps?: boolean;
49
+ /**
50
+ * Whether to show step indicators at mark positions.
51
+ * @default false
52
+ */
53
+ showMarksSteps?: boolean;
54
+ /**
55
+ * Whether the thumbs should have a tooltip with the value on hover the slider.
56
+ * @default false
57
+ */
58
+ showTooltip?: boolean;
59
+ /**
60
+ * Custom steps labels.
61
+ * @example [{value: 0, label: "0"}, {value: 50, label: "50"}, {value: 100, label: "100"}]
62
+ * @default []
63
+ */
64
+ marks?: SliderStepMark[];
65
+ /**
66
+ * Element to be rendered in the start side of the slider.
67
+ */
68
+ startContent?: React.ReactNode;
69
+ /**
70
+ * Element to be rendered in the end side of the slider.
71
+ */
72
+ endContent?: React.ReactNode;
73
+ /**
74
+ * Classname or List of classes to change the classNames of the element.
75
+ * if `className` is passed, it will be added to the base slot.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * <Slider classNames={{
80
+ * base:"base-classes",
81
+ * step: "step-classes",
82
+ * labelWrapper: "label-wrapper-classes",
83
+ * label: "label-classes",
84
+ * value: "value-classes",
85
+ * trackWrapper: "track-wrapper-classes",
86
+ * track: "track-classes",
87
+ * filler: "filler-classes",
88
+ * thumb: "thumb-classes",
89
+ * mark: "mark-classes",
90
+ * }} />
91
+ * ```
92
+ */
93
+ classNames?: SlotsToClasses<SliderSlots>;
94
+ /**
95
+ * Tooltip props.
96
+ * @see [Tooltip](https://heroui.com/components/tooltip) for more details.
97
+ * @default {
98
+ * offset: 15,
99
+ * delay: 0,
100
+ * size: "sm",
101
+ * showArrow: true,
102
+ * placement: "top", // "right" for vertical slider
103
+ * content: [sliderValue],
104
+ * color: sliderProps?.color, // same as the slider color
105
+ * isDisabled: sliderProps?.isDisabled,
106
+ * }
107
+ */
108
+ tooltipProps?: Partial<TooltipProps>;
109
+ /**
110
+ * A function that returns the content to display as the value label.
111
+ * Overrides default formatted number.
112
+ */
113
+ getValue?: (value: SliderValue) => string;
114
+ /**
115
+ * A function that returns the content to display as the tooltip label. (in analogy to getValue)
116
+ * @param value - The value of the slider, array or single number.
117
+ * @param index - The index of the thumb, if multiple thumbs are used.
118
+ * In addition to formatting with tooltipValueFormatOptions if number is returned.
119
+ */
120
+ getTooltipValue?: (value: SliderValue, index?: number) => string | number;
121
+ /**
122
+ * Function to render the label.
123
+ */
124
+ renderLabel?: (props: DOMAttributes<HTMLLabelElement>) => React.ReactNode;
125
+ /**
126
+ * Function to render the value label.
127
+ */
128
+ renderValue?: (props: DOMAttributes<HTMLOutputElement>) => React.ReactNode;
129
+ /**
130
+ * Function to render the thumb. It can be used to add a tooltip or custom icon.
131
+ */
132
+ renderThumb?: (props: SliderRenderThumbProps) => React.ReactNode;
133
+ }
134
+ export type UseSliderProps = Omit<Props, keyof ValueBase<SliderValue>> & AriaSliderProps & SliderVariantProps;
135
+ export declare function useSlider(originalProps: UseSliderProps): {
136
+ Component: import("@heroui/system-rsc").As<any>;
137
+ state: import("@react-stately/slider").SliderState;
138
+ value: any;
139
+ domRef: React.RefObject<HTMLElement>;
140
+ label: React.ReactNode;
141
+ steps: number;
142
+ marks: SliderStepMark[];
143
+ startContent: React.ReactNode;
144
+ endContent: React.ReactNode;
145
+ showMarksSteps: boolean;
146
+ minValue: number;
147
+ step: number;
148
+ getStepProps: (index: number) => {
149
+ className: string;
150
+ 'data-slot': string;
151
+ 'data-in-range': boolean;
152
+ style: {
153
+ [x: string]: string;
154
+ };
155
+ };
156
+ getBaseProps: PropGetter;
157
+ getValue: ((value: SliderValue) => string) | undefined;
158
+ renderLabel: ((props: DOMAttributes<HTMLLabelElement>) => React.ReactNode) | undefined;
159
+ renderValue: ((props: DOMAttributes<HTMLOutputElement>) => React.ReactNode) | undefined;
160
+ getTrackWrapperProps: PropGetter;
161
+ getLabelWrapperProps: PropGetter;
162
+ getLabelProps: PropGetter;
163
+ getValueProps: PropGetter;
164
+ getTrackProps: PropGetter;
165
+ getFillerProps: PropGetter;
166
+ getThumbProps: (index: number) => SliderThumbProps;
167
+ getMarkProps: (mark: SliderStepMark) => {
168
+ className: string;
169
+ 'data-slot': string;
170
+ 'data-in-range': boolean;
171
+ style: {
172
+ [x: string]: string;
173
+ };
174
+ onMouseDown: (e: React.MouseEvent) => void;
175
+ onPointerDown: (e: React.PointerEvent) => void;
176
+ onClick: (e: any) => void;
177
+ };
178
+ getStartContentProps: PropGetter;
179
+ getEndContentProps: PropGetter;
180
+ };
181
+ export type UseSliderReturn = ReturnType<typeof useSlider>;
182
+ export {};