@particle-network/ui-react 0.5.1-beta.21 → 0.5.1-beta.23

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,42 @@
1
+ import React from 'react';
2
+ import { type UXNumberInputProps } from '../UXNumberInput';
3
+ export interface UXRangeInputValue {
4
+ min?: number;
5
+ max?: number;
6
+ }
7
+ export type UXRangeInputProps = Omit<UXNumberInputProps, 'value' | 'defaultValue' | 'onValueChange' | 'minValue' | 'maxValue'> & {
8
+ /**
9
+ * The current value of the range input (controlled)
10
+ */
11
+ value?: UXRangeInputValue;
12
+ /**
13
+ * The default value of the range input (uncontrolled)
14
+ */
15
+ defaultValue?: UXRangeInputValue;
16
+ /**
17
+ * The minimum value allowed for both inputs
18
+ */
19
+ minValue?: number;
20
+ /**
21
+ * The maximum value allowed for both inputs
22
+ */
23
+ maxValue?: number;
24
+ /**
25
+ * Props for the minimum input
26
+ */
27
+ minInputProps?: Partial<UXNumberInputProps>;
28
+ /**
29
+ * Props for the maximum input
30
+ */
31
+ maxInputProps?: Partial<UXNumberInputProps>;
32
+ /**
33
+ * Separator between the two inputs
34
+ * @default '-'
35
+ */
36
+ separator?: React.ReactNode;
37
+ /**
38
+ * Callback fired when the value changes
39
+ */
40
+ onValueChange?: (value: UXRangeInputValue) => void;
41
+ };
42
+ export declare const UXRangeInput: React.ForwardRefExoticComponent<UXRangeInputProps & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,80 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import react, { forwardRef, useCallback, useMemo } from "react";
3
+ import { HStack } from "../layout/index.js";
4
+ import { UXNumberInput } from "../UXNumberInput/index.js";
5
+ const UXRangeInput = /*#__PURE__*/ forwardRef((props, ref)=>{
6
+ const { value, defaultValue, onValueChange, minValue, maxValue, minInputProps = {}, maxInputProps = {}, separator = '', className, ...restProps } = props;
7
+ const [internalValue, setInternalValue] = react.useState(defaultValue || {
8
+ min: void 0,
9
+ max: void 0
10
+ });
11
+ const currentValue = void 0 !== value ? value : internalValue;
12
+ const handleMinChange = useCallback((newMin)=>{
13
+ const minValue = isNaN(newMin) ? 0 : newMin;
14
+ const newValue = {
15
+ min: minValue,
16
+ max: currentValue.max
17
+ };
18
+ if (void 0 !== currentValue.max && !isNaN(currentValue.max) && minValue > currentValue.max) newValue.max = minValue;
19
+ if (void 0 === value) setInternalValue(newValue);
20
+ onValueChange?.(newValue);
21
+ }, [
22
+ currentValue.max,
23
+ value,
24
+ onValueChange
25
+ ]);
26
+ const handleMaxChange = useCallback((newMax)=>{
27
+ const maxValue = isNaN(newMax) ? 0 : newMax;
28
+ const newValue = {
29
+ min: currentValue.min,
30
+ max: maxValue
31
+ };
32
+ if (void 0 !== currentValue.min && !isNaN(currentValue.min) && maxValue < currentValue.min) newValue.min = maxValue;
33
+ if (void 0 === value) setInternalValue(newValue);
34
+ onValueChange?.(newValue);
35
+ }, [
36
+ currentValue.min,
37
+ value,
38
+ onValueChange
39
+ ]);
40
+ const minInputMaxValue = useMemo(()=>{
41
+ if (void 0 !== currentValue.max && !isNaN(currentValue.max)) return currentValue.max;
42
+ return maxValue;
43
+ }, [
44
+ currentValue.max,
45
+ maxValue
46
+ ]);
47
+ const maxInputMinValue = useMemo(()=>{
48
+ if (void 0 !== currentValue.min && !isNaN(currentValue.min)) return currentValue.min;
49
+ return minValue;
50
+ }, [
51
+ currentValue.min,
52
+ minValue
53
+ ]);
54
+ return /*#__PURE__*/ jsxs(HStack, {
55
+ ref: ref,
56
+ gap: 2,
57
+ className: className,
58
+ children: [
59
+ /*#__PURE__*/ jsx(UXNumberInput, {
60
+ ...restProps,
61
+ ...minInputProps,
62
+ value: currentValue.min,
63
+ minValue: minValue,
64
+ maxValue: minInputMaxValue,
65
+ onValueChange: handleMinChange
66
+ }),
67
+ separator,
68
+ /*#__PURE__*/ jsx(UXNumberInput, {
69
+ ...restProps,
70
+ ...maxInputProps,
71
+ value: currentValue.max,
72
+ minValue: maxInputMinValue,
73
+ maxValue: maxValue,
74
+ onValueChange: handleMaxChange
75
+ })
76
+ ]
77
+ });
78
+ });
79
+ UXRangeInput.displayName = 'UX.RangeInput';
80
+ export { UXRangeInput };
@@ -1,7 +1,6 @@
1
- import { hexColorToHSLValue, themeData, themeKeys } from "@particle-network/ui-shared";
1
+ import { hexColorToHSLValue, objectEntries, themeData, themeKeys } from "@particle-network/ui-shared";
2
2
  import { readableColor } from "color2k";
3
3
  import { generateThemeColor } from "../../heroui/utils/colors.js";
4
- import { objectEntries } from "../../utils/index.js";
5
4
  import { DEFAULT_FONT_FAMILY, PRELOAD_FONTS_URL } from "./constants.js";
6
5
  const getCSSProperties = (theme)=>{
7
6
  const { colorVariables } = theme;
@@ -21,6 +21,7 @@ export * from './UXNumberInput';
21
21
  export * from './UXPagination';
22
22
  export * from './UXPopover';
23
23
  export * from './UXRadio';
24
+ export * from './UXRangeInput';
24
25
  export * from './UXSelect';
25
26
  export * from './UXSlider';
26
27
  export * from './UXSpinner';
@@ -21,6 +21,7 @@ export * from "./UXNumberInput/index.js";
21
21
  export * from "./UXPagination/index.js";
22
22
  export * from "./UXPopover/index.js";
23
23
  export * from "./UXRadio/index.js";
24
+ export * from "./UXRangeInput/index.js";
24
25
  export * from "./UXSelect/index.js";
25
26
  export * from "./UXSlider/index.js";
26
27
  export * from "./UXSpinner/index.js";
@@ -67,6 +67,10 @@ export declare const useI18n: () => {
67
67
  readonly on: "On";
68
68
  readonly off: "Off";
69
69
  };
70
+ readonly rangeInput: {
71
+ readonly min: "Min";
72
+ readonly max: "Max";
73
+ };
70
74
  } | {
71
75
  readonly table: {
72
76
  readonly emptyContent: "暂无数据";
@@ -136,4 +140,8 @@ export declare const useI18n: () => {
136
140
  readonly on: "开";
137
141
  readonly off: "关";
138
142
  };
143
+ readonly rangeInput: {
144
+ readonly min: "最小值";
145
+ readonly max: "最大值";
146
+ };
139
147
  };
@@ -68,6 +68,10 @@ const en = {
68
68
  switch: {
69
69
  on: 'On',
70
70
  off: 'Off'
71
+ },
72
+ rangeInput: {
73
+ min: 'Min',
74
+ max: 'Max'
71
75
  }
72
76
  };
73
77
  const zh = {
@@ -138,6 +142,10 @@ const zh = {
138
142
  switch: {
139
143
  on: '开',
140
144
  off: '关'
145
+ },
146
+ rangeInput: {
147
+ min: '最小值',
148
+ max: '最大值'
141
149
  }
142
150
  };
143
151
  const useI18n = ()=>{
@@ -1 +1,4 @@
1
1
  export declare function objectEntries<T extends object>(obj: T): [keyof T & string, T[keyof T & string]][];
2
+ export declare function objectKeys<T extends object>(obj: T): (keyof T & string)[];
3
+ export declare function objectValues<T extends object>(obj: T): T[keyof T & string][];
4
+ export declare function objectFromEntries<T extends object>(entries: [keyof T & string, T[keyof T & string]][]): T;
@@ -1,4 +1,13 @@
1
1
  function objectEntries(obj) {
2
2
  return Object.entries(obj);
3
3
  }
4
- export { objectEntries };
4
+ function objectKeys(obj) {
5
+ return Object.keys(obj);
6
+ }
7
+ function objectValues(obj) {
8
+ return Object.values(obj);
9
+ }
10
+ function objectFromEntries(entries) {
11
+ return Object.fromEntries(entries);
12
+ }
13
+ export { objectEntries, objectFromEntries, objectKeys, objectValues };
@@ -1,6 +1,5 @@
1
1
  export { absoluteFullClasses, baseStyles, collapseAdjacentVariantBorders, dataFocusVisibleClasses, focusVisibleClasses, groupDataFocusVisibleClasses, hiddenInputClasses, ringClasses, translateCenterClasses, } from './classes';
2
2
  export { cn } from './cn';
3
- export { objectEntries } from './common';
4
3
  export * from './detect';
5
4
  export * from './input-classes';
6
5
  export { colorVariants } from './variants';
@@ -1,7 +1,6 @@
1
1
  import { absoluteFullClasses, baseStyles, collapseAdjacentVariantBorders, dataFocusVisibleClasses, focusVisibleClasses, groupDataFocusVisibleClasses, hiddenInputClasses, ringClasses, translateCenterClasses } from "./classes.js";
2
2
  import { cn } from "./cn.js";
3
- import { objectEntries } from "./common.js";
4
3
  import { colorVariants } from "./variants.js";
5
4
  export * from "./detect.js";
6
5
  export * from "./input-classes.js";
7
- export { absoluteFullClasses, baseStyles, cn, collapseAdjacentVariantBorders, colorVariants, dataFocusVisibleClasses, focusVisibleClasses, groupDataFocusVisibleClasses, hiddenInputClasses, objectEntries, ringClasses, translateCenterClasses };
6
+ export { absoluteFullClasses, baseStyles, cn, collapseAdjacentVariantBorders, colorVariants, 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.5.1-beta.21",
3
+ "version": "0.5.1-beta.23",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -38,8 +38,8 @@
38
38
  "@rslib/core": "^0.12.3",
39
39
  "@types/react": "^19.1.10",
40
40
  "react": "^19.1.0",
41
- "@particle-network/lintstaged-config": "0.1.0",
42
- "@particle-network/eslint-config": "0.3.0"
41
+ "@particle-network/eslint-config": "0.3.0",
42
+ "@particle-network/lintstaged-config": "0.1.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "react": ">=16.9.0",
@@ -52,8 +52,8 @@
52
52
  "react-aria-components": "^1.14.0",
53
53
  "values.js": "^2.1.1",
54
54
  "zustand": "^5.0.8",
55
- "@particle-network/icons": "0.5.1-beta.8",
56
- "@particle-network/ui-shared": "0.4.1-beta.6"
55
+ "@particle-network/icons": "0.5.1-beta.9",
56
+ "@particle-network/ui-shared": "0.4.1-beta.7"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "rslib build",