@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,277 @@
1
+ import { useCallback, useMemo, useRef } from "react";
2
+ import { filterDOMProps, useDOMRef } from "@heroui/react-utils";
3
+ import { mergeProps, objectToDeps, warn } from "@heroui/shared-utils";
4
+ import { mapPropsVariants, useProviderContext } from "@heroui/system";
5
+ import { cn } from "@heroui/theme";
6
+ import { useLocale, useNumberFormatter } from "@react-aria/i18n";
7
+ import { useHover } from "@react-aria/interactions";
8
+ import { useSlider } from "@react-aria/slider";
9
+ import { useSliderState } from "@react-stately/slider";
10
+ import { slider } from "./slider-theme.js";
11
+ function use_slider_useSlider(originalProps) {
12
+ const globalContext = useProviderContext();
13
+ const [props, variantProps] = mapPropsVariants(originalProps, slider.variantKeys);
14
+ const { ref, as, name, label, formatOptions, value: valueProp, maxValue = 100, minValue = 0, step = 1, showSteps = false, showMarksSteps = false, showTooltip = false, orientation = 'horizontal', marks = [], startContent, endContent, fillOffset, className, classNames, renderThumb, renderLabel, renderValue, onChange, onChangeEnd, getValue, getTooltipValue, tooltipValueFormatOptions = formatOptions, tooltipProps: userTooltipProps = {}, ...otherProps } = props;
15
+ const isFixedValue = minValue === maxValue;
16
+ if (isFixedValue) warn('Min and max values should not be the same. This may cause unexpected behavior.');
17
+ const Component = as || 'div';
18
+ const shouldFilterDOMProps = 'string' == typeof Component;
19
+ const disableAnimation = originalProps?.disableAnimation ?? globalContext?.disableAnimation ?? false;
20
+ const domRef = useDOMRef(ref);
21
+ const trackRef = useRef(null);
22
+ const numberFormatter = useNumberFormatter(formatOptions);
23
+ const { direction } = useLocale();
24
+ const clampValue = useCallback((valueToClamp)=>Math.min(Math.max(valueToClamp, minValue), maxValue), [
25
+ minValue,
26
+ maxValue
27
+ ]);
28
+ const validatedValue = useMemo(()=>{
29
+ if (isFixedValue) return minValue;
30
+ if (void 0 === valueProp) return;
31
+ if (Array.isArray(valueProp)) return valueProp.map(clampValue);
32
+ return clampValue(valueProp);
33
+ }, [
34
+ valueProp,
35
+ clampValue,
36
+ isFixedValue,
37
+ minValue
38
+ ]);
39
+ const handleValueChange = useCallback((value)=>{
40
+ onChangeEnd?.(value);
41
+ setTimeout(()=>{
42
+ if (document.activeElement) document.activeElement.blur();
43
+ }, 500);
44
+ }, [
45
+ onChangeEnd
46
+ ]);
47
+ const state = useSliderState({
48
+ ...otherProps,
49
+ value: validatedValue,
50
+ isDisabled: originalProps?.isDisabled ?? false,
51
+ orientation,
52
+ step,
53
+ minValue,
54
+ maxValue,
55
+ numberFormatter,
56
+ onChange,
57
+ onChangeEnd: handleValueChange
58
+ });
59
+ const tooltipProps = {
60
+ offset: 5,
61
+ delay: 0,
62
+ size: 'sm',
63
+ showArrow: true,
64
+ color: originalProps?.color ? originalProps?.color : slider.defaultVariants?.color,
65
+ isDisabled: originalProps.isDisabled,
66
+ ...userTooltipProps
67
+ };
68
+ const { groupProps, trackProps, labelProps, outputProps } = useSlider(originalProps, state, trackRef);
69
+ const { isHovered, hoverProps } = useHover({
70
+ isDisabled: originalProps.isDisabled
71
+ });
72
+ const baseStyles = cn(classNames?.base, className);
73
+ const isVertical = 'vertical' === orientation;
74
+ const hasMarks = marks?.length > 0;
75
+ const hasSingleThumb = void 0 === fillOffset ? 1 === state.values.length : false;
76
+ const slots = useMemo(()=>slider({
77
+ ...variantProps,
78
+ hasMarks,
79
+ disableAnimation,
80
+ hasSingleThumb,
81
+ isVertical
82
+ }), [
83
+ objectToDeps(variantProps),
84
+ isVertical,
85
+ disableAnimation,
86
+ hasSingleThumb,
87
+ hasMarks
88
+ ]);
89
+ const [startOffset, endOffset] = [
90
+ state.values.length > 1 ? state.getThumbPercent(0) : void 0 !== fillOffset ? state.getValuePercent(fillOffset) : 0,
91
+ state.getThumbPercent(state.values.length - 1)
92
+ ].sort();
93
+ const value = 1 === state.values.length ? numberFormatter.format(state.values[0]) : numberFormatter.formatRange(state.values[0], state.values[state.values.length - 1]);
94
+ const steps = showSteps ? Math.floor((maxValue - minValue) / step) + 1 : 0;
95
+ const getBaseProps = (props = {})=>({
96
+ ref: domRef,
97
+ 'data-orientation': state.orientation,
98
+ 'data-slot': 'base',
99
+ 'data-hover': isHovered,
100
+ className: slots.base({
101
+ class: baseStyles
102
+ }),
103
+ ...mergeProps(groupProps, hoverProps, filterDOMProps(otherProps, {
104
+ enabled: shouldFilterDOMProps
105
+ }), filterDOMProps(props))
106
+ });
107
+ const getLabelWrapperProps = (props = {})=>({
108
+ className: slots.labelWrapper({
109
+ class: classNames?.labelWrapper
110
+ }),
111
+ 'data-slot': 'labelWrapper',
112
+ ...props
113
+ });
114
+ const getLabelProps = (props = {})=>({
115
+ 'data-slot': 'label',
116
+ className: slots.label({
117
+ class: classNames?.label
118
+ }),
119
+ children: label,
120
+ ...labelProps,
121
+ ...props
122
+ });
123
+ const getValueProps = (props = {})=>({
124
+ 'data-slot': 'value',
125
+ className: slots.value({
126
+ class: classNames?.value
127
+ }),
128
+ children: getValue && 'function' == typeof getValue ? getValue(state.values) : value,
129
+ ...outputProps,
130
+ ...props
131
+ });
132
+ const getTrackProps = (props = {})=>{
133
+ const fillWidth = (endOffset - startOffset) * 100;
134
+ return {
135
+ ref: trackRef,
136
+ 'data-slot': 'track',
137
+ 'data-thumb-hidden': !!originalProps?.hideThumb,
138
+ 'data-vertical': isVertical,
139
+ ...hasSingleThumb ? {
140
+ 'data-fill-start': fillWidth > 0,
141
+ 'data-fill-end': 100 === fillWidth
142
+ } : {
143
+ 'data-fill-start': 0 === startOffset,
144
+ 'data-fill-end': 100 * startOffset + fillWidth === 100
145
+ },
146
+ className: slots.track({
147
+ class: classNames?.track
148
+ }),
149
+ ...trackProps,
150
+ ...props
151
+ };
152
+ };
153
+ const getTrackWrapperProps = (props = {})=>({
154
+ 'data-slot': 'track-wrapper',
155
+ className: slots.trackWrapper({
156
+ class: classNames?.trackWrapper
157
+ }),
158
+ ...props
159
+ });
160
+ const getFillerProps = (props = {})=>({
161
+ 'data-slot': 'filler',
162
+ className: slots.filler({
163
+ class: classNames?.filler
164
+ }),
165
+ ...props,
166
+ style: {
167
+ ...props.style,
168
+ [isVertical ? 'bottom' : 'rtl' === direction ? 'right' : 'left']: `${100 * startOffset}%`,
169
+ ...isVertical ? {
170
+ height: `${(endOffset - startOffset) * 100}%`
171
+ } : {
172
+ width: `${(endOffset - startOffset) * 100}%`
173
+ }
174
+ }
175
+ });
176
+ const getThumbProps = (index)=>({
177
+ name,
178
+ index,
179
+ state,
180
+ trackRef,
181
+ orientation,
182
+ isVertical,
183
+ tooltipProps,
184
+ getTooltipValue,
185
+ showTooltip,
186
+ renderThumb,
187
+ formatOptions: tooltipValueFormatOptions,
188
+ className: slots.thumb({
189
+ class: classNames?.thumb
190
+ })
191
+ });
192
+ const getStepProps = (index)=>{
193
+ const percent = state.getValuePercent(index * step + minValue);
194
+ return {
195
+ className: slots.step({
196
+ class: classNames?.step
197
+ }),
198
+ 'data-slot': 'step',
199
+ 'data-in-range': percent <= endOffset && percent >= startOffset,
200
+ style: {
201
+ [isVertical ? 'bottom' : 'rtl' === direction ? 'right' : 'left']: `${100 * percent}%`
202
+ }
203
+ };
204
+ };
205
+ const getMarkProps = (mark)=>{
206
+ const percent = state.getValuePercent(mark.value);
207
+ return {
208
+ className: slots.mark({
209
+ class: classNames?.mark
210
+ }),
211
+ 'data-slot': 'mark',
212
+ 'data-in-range': percent <= endOffset && percent >= startOffset,
213
+ style: {
214
+ [isVertical ? 'bottom' : 'rtl' === direction ? 'right' : 'left']: `${100 * percent}%`
215
+ },
216
+ onMouseDown: (e)=>e.stopPropagation(),
217
+ onPointerDown: (e)=>e.stopPropagation(),
218
+ onClick: (e)=>{
219
+ e.stopPropagation();
220
+ if (isFixedValue) return;
221
+ if (1 === state.values.length) state.setThumbPercent(0, percent);
222
+ else {
223
+ const leftThumbVal = state.values[0];
224
+ const rightThumbVal = state.values[1];
225
+ if (mark.value < leftThumbVal) state.setThumbPercent(0, percent);
226
+ else if (mark.value > rightThumbVal) state.setThumbPercent(1, percent);
227
+ else if (Math.abs(mark.value - leftThumbVal) < Math.abs(mark.value - rightThumbVal)) state.setThumbPercent(0, percent);
228
+ else state.setThumbPercent(1, percent);
229
+ }
230
+ }
231
+ };
232
+ };
233
+ const getStartContentProps = (props = {})=>({
234
+ 'data-slot': 'startContent',
235
+ className: slots.startContent({
236
+ class: classNames?.startContent
237
+ }),
238
+ ...props
239
+ });
240
+ const getEndContentProps = (props = {})=>({
241
+ 'data-slot': 'endContent',
242
+ className: slots.endContent({
243
+ class: classNames?.endContent
244
+ }),
245
+ ...props
246
+ });
247
+ return {
248
+ Component,
249
+ state,
250
+ value,
251
+ domRef,
252
+ label,
253
+ steps,
254
+ marks,
255
+ startContent,
256
+ endContent,
257
+ showMarksSteps,
258
+ minValue,
259
+ step,
260
+ getStepProps,
261
+ getBaseProps,
262
+ getValue,
263
+ renderLabel,
264
+ renderValue,
265
+ getTrackWrapperProps,
266
+ getLabelWrapperProps,
267
+ getLabelProps,
268
+ getValueProps,
269
+ getTrackProps,
270
+ getFillerProps,
271
+ getThumbProps,
272
+ getMarkProps,
273
+ getStartContentProps,
274
+ getEndContentProps
275
+ };
276
+ }
277
+ export { use_slider_useSlider as useSlider };
@@ -163,7 +163,7 @@ const UXThemeSwitchModal = ({ as = 'modal', omitThemes = [], backdrop, isOpen, o
163
163
  })
164
164
  });
165
165
  };
166
- const UXThemeSwitch = ({ as = 'modal', backdrop, children })=>{
166
+ const UXThemeSwitch = ({ children, ...restProps })=>{
167
167
  const { isOpen, onOpen, onClose, onOpenChange } = useDisclosure();
168
168
  const renderChildren = ()=>{
169
169
  if (children) return children(onOpen);
@@ -178,8 +178,7 @@ const UXThemeSwitch = ({ as = 'modal', backdrop, children })=>{
178
178
  children: [
179
179
  renderChildren(),
180
180
  /*#__PURE__*/ jsx(UXThemeSwitchModal, {
181
- as: as,
182
- backdrop: backdrop,
181
+ ...restProps,
183
182
  isOpen: isOpen,
184
183
  onClose: onClose,
185
184
  onOpenChange: onOpenChange
@@ -33,3 +33,14 @@ export declare const collapseAdjacentVariantBorders: {
33
33
  bearish: string[];
34
34
  };
35
35
  export declare const hiddenInputClasses: string[];
36
+ export declare const bgWithTextColorClasses: {
37
+ readonly foreground: "bg-foreground text-background";
38
+ readonly primary: "bg-primary text-primary-foreground";
39
+ readonly secondary: "bg-secondary text-secondary-foreground";
40
+ readonly success: "bg-success text-success-foreground";
41
+ readonly warning: "bg-warning text-warning-foreground";
42
+ readonly alert: "bg-alert text-alert-foreground";
43
+ readonly danger: "bg-danger text-danger-foreground";
44
+ readonly bullish: "bg-bullish text-bullish-foreground";
45
+ readonly bearish: "bg-bearish text-bearish-foreground";
46
+ };
@@ -84,4 +84,15 @@ const hiddenInputClasses = [
84
84
  'cursor-pointer',
85
85
  'disabled:cursor-default'
86
86
  ];
87
- export { absoluteFullClasses, baseStyles, collapseAdjacentVariantBorders, dataFocusVisibleClasses, focusVisibleClasses, groupDataFocusVisibleClasses, hiddenInputClasses, ringClasses, translateCenterClasses };
87
+ const bgWithTextColorClasses = {
88
+ foreground: 'bg-foreground text-background',
89
+ primary: 'bg-primary text-primary-foreground',
90
+ secondary: 'bg-secondary text-secondary-foreground',
91
+ success: 'bg-success text-success-foreground',
92
+ warning: 'bg-warning text-warning-foreground',
93
+ alert: 'bg-alert text-alert-foreground',
94
+ danger: 'bg-danger text-danger-foreground',
95
+ bullish: 'bg-bullish text-bullish-foreground',
96
+ bearish: 'bg-bearish text-bearish-foreground'
97
+ };
98
+ export { absoluteFullClasses, baseStyles, bgWithTextColorClasses, collapseAdjacentVariantBorders, dataFocusVisibleClasses, focusVisibleClasses, groupDataFocusVisibleClasses, hiddenInputClasses, ringClasses, translateCenterClasses };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle-network/ui-react",
3
- "version": "0.4.5-beta.19",
3
+ "version": "0.4.5-beta.20",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -49,8 +49,8 @@
49
49
  "ahooks": "^3.9.4",
50
50
  "copy-to-clipboard": "^3.3.3",
51
51
  "zustand": "^5.0.8",
52
- "@particle-network/icons": "0.4.2-beta.8",
53
- "@particle-network/ui-shared": "0.3.2-beta.4"
52
+ "@particle-network/icons": "0.4.2-beta.9",
53
+ "@particle-network/ui-shared": "0.3.2-beta.5"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "rslib build",
@@ -1,208 +0,0 @@
1
- export declare const sliderClasses: {
2
- variants: {
3
- size: {
4
- sm: {
5
- label: string;
6
- value: string;
7
- thumb: string;
8
- step: string;
9
- mark: string;
10
- track: string;
11
- };
12
- md: {
13
- thumb: string;
14
- label: string;
15
- value: string;
16
- mark: string;
17
- track: string;
18
- };
19
- lg: {
20
- thumb: string;
21
- step: string;
22
- label: string;
23
- value: string;
24
- mark: string;
25
- track: string;
26
- };
27
- };
28
- radius: {
29
- none: {
30
- thumb: string;
31
- };
32
- sm: {
33
- thumb: string;
34
- };
35
- md: {
36
- thumb: string;
37
- };
38
- lg: {
39
- thumb: string;
40
- };
41
- full: {
42
- thumb: string;
43
- };
44
- };
45
- color: {
46
- foreground: {
47
- filler: string;
48
- thumb: string;
49
- };
50
- primary: {
51
- filler: string;
52
- thumb: string;
53
- };
54
- secondary: {
55
- filler: string;
56
- thumb: string;
57
- };
58
- success: {
59
- filler: string;
60
- thumb: string;
61
- };
62
- warning: {
63
- filler: string;
64
- thumb: string;
65
- };
66
- danger: {
67
- filler: string;
68
- thumb: string;
69
- };
70
- alert: {
71
- filler: string;
72
- thumb: string;
73
- };
74
- bullish: {
75
- filler: string;
76
- thumb: string;
77
- };
78
- bearish: {
79
- filler: string;
80
- thumb: string;
81
- };
82
- };
83
- isVertical: {
84
- true: {
85
- base: string;
86
- trackWrapper: string;
87
- filler: string;
88
- thumb: string;
89
- track: string;
90
- labelWrapper: string;
91
- step: string[];
92
- mark: string[];
93
- };
94
- false: {
95
- thumb: string;
96
- trackWrapper: string;
97
- track: string;
98
- step: string[];
99
- mark: string[];
100
- };
101
- };
102
- isDisabled: {
103
- false: {
104
- thumb: string[];
105
- };
106
- true: {
107
- base: string;
108
- thumb: string;
109
- };
110
- };
111
- hasMarks: {
112
- true: {
113
- base: string;
114
- mark: string;
115
- };
116
- false: {};
117
- };
118
- showOutline: {
119
- true: {
120
- thumb: string;
121
- };
122
- false: {
123
- thumb: string;
124
- };
125
- };
126
- hideValue: {
127
- true: {
128
- value: string;
129
- };
130
- };
131
- hideThumb: {
132
- true: {
133
- thumb: string;
134
- track: string;
135
- };
136
- };
137
- hasSingleThumb: {
138
- true: {};
139
- false: {};
140
- };
141
- disableAnimation: {
142
- true: {
143
- thumb: string;
144
- };
145
- false: {
146
- thumb: string;
147
- mark: string;
148
- };
149
- };
150
- disableThumbScale: {
151
- true: {};
152
- false: {
153
- thumb: string;
154
- };
155
- };
156
- };
157
- compoundVariants: ({
158
- size: string[];
159
- showOutline: boolean;
160
- class: {
161
- thumb: string;
162
- step?: undefined;
163
- track?: undefined;
164
- };
165
- color?: undefined;
166
- isVertical?: undefined;
167
- } | {
168
- size: string;
169
- color: string;
170
- class: {
171
- step: string;
172
- thumb?: undefined;
173
- track?: undefined;
174
- };
175
- showOutline?: undefined;
176
- isVertical?: undefined;
177
- } | {
178
- size: string;
179
- isVertical: boolean;
180
- class: {
181
- track: string;
182
- thumb?: undefined;
183
- step?: undefined;
184
- };
185
- showOutline?: undefined;
186
- color?: undefined;
187
- } | {
188
- color: string;
189
- isVertical: boolean;
190
- class: {
191
- track: string;
192
- thumb?: undefined;
193
- step?: undefined;
194
- };
195
- size?: undefined;
196
- showOutline?: undefined;
197
- })[];
198
- defaultVariants: {
199
- size: string;
200
- color: string;
201
- radius: string;
202
- hideValue: boolean;
203
- hideThumb: boolean;
204
- isDisabled: boolean;
205
- disableThumbScale: boolean;
206
- showOutline: boolean;
207
- };
208
- };
@@ -1,5 +0,0 @@
1
- import type React from 'react';
2
- import { type SliderProps } from '@heroui/slider';
3
- type ExtendedSliderProps = SliderProps;
4
- declare const ExtendedSlider: React.ForwardRefExoticComponent<ExtendedSliderProps>;
5
- export default ExtendedSlider;
@@ -1,6 +0,0 @@
1
- import { Slider } from "@heroui/slider";
2
- import { extendVariants } from "@heroui/system-rsc";
3
- import { sliderClasses } from "./slider.classes.js";
4
- const ExtendedSlider = extendVariants(Slider, sliderClasses);
5
- const slider_extend = ExtendedSlider;
6
- export { slider_extend as default };