@meta-1/design 0.0.187 → 0.0.189

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meta-1/design",
3
- "version": "0.0.187",
3
+ "version": "0.0.189",
4
4
  "keywords": [
5
5
  "easykit",
6
6
  "design",
@@ -40,6 +40,7 @@
40
40
  "@radix-ui/react-scroll-area": "1.2.1",
41
41
  "@radix-ui/react-select": "2.1.2",
42
42
  "@radix-ui/react-separator": "1.1.0",
43
+ "@radix-ui/react-slider": "^1.3.6",
43
44
  "@radix-ui/react-slot": "1.1.0",
44
45
  "@radix-ui/react-switch": "1.1.1",
45
46
  "@radix-ui/react-tabs": "1.1.1",
@@ -0,0 +1,26 @@
1
+ import * as React from "react"
2
+ import * as SliderPrimitive from "@radix-ui/react-slider"
3
+
4
+ import { cn } from "@meta-1/design/lib/utils"
5
+
6
+ const Slider = React.forwardRef<
7
+ React.ElementRef<typeof SliderPrimitive.Root>,
8
+ React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root>
9
+ >(({ className, ...props }, ref) => (
10
+ <SliderPrimitive.Root
11
+ ref={ref}
12
+ className={cn(
13
+ "relative flex w-full touch-none select-none items-center",
14
+ className
15
+ )}
16
+ {...props}
17
+ >
18
+ <SliderPrimitive.Track className="relative h-2 w-full grow overflow-hidden rounded-full bg-secondary">
19
+ <SliderPrimitive.Range className="absolute h-full bg-primary" />
20
+ </SliderPrimitive.Track>
21
+ <SliderPrimitive.Thumb className="block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50" />
22
+ </SliderPrimitive.Root>
23
+ ))
24
+ Slider.displayName = SliderPrimitive.Root.displayName
25
+
26
+ export { Slider }
@@ -1,4 +1,4 @@
1
- import { forwardRef, type MouseEvent, type ReactNode, useState } from "react";
1
+ import { forwardRef, type MouseEvent, type ReactNode, useRef, useState } from "react";
2
2
  import { XIcon } from "lucide-react";
3
3
 
4
4
  import { Empty } from "@meta-1/design/components/uix/empty";
@@ -46,22 +46,25 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>((props, _ref) =
46
46
  onOpenChange,
47
47
  ...rest
48
48
  } = props;
49
-
50
- const [innerValue, setInnerValue] = useState<string | undefined>(defaultValue);
51
- const isControlled = value !== undefined;
49
+ const initValue = useRef(value);
50
+ const [innerValue, setInnerValue] = useState<string | undefined>();
51
+ const isControlled = initValue.current !== undefined;
52
52
  const currentValue = isControlled ? value : innerValue;
53
53
 
54
54
  const handleChange = (val: string) => {
55
- if (onChange) {
56
- // 尝试找到原始选项,返回原始类型的 value
57
- const option = options.find((opt) => String(opt.value) === val);
58
- if (option) {
59
- onChange(option.value);
60
- }
61
- }
62
55
  if (!isControlled) {
63
56
  setInnerValue(val);
64
57
  }
58
+ if (onChange) {
59
+ if (val === "") {
60
+ onChange("");
61
+ } else {
62
+ const option = options.find((opt) => String(opt.value) === val);
63
+ if (option) {
64
+ onChange(option.value);
65
+ }
66
+ }
67
+ }
65
68
  };
66
69
 
67
70
  const clear = (e: MouseEvent<HTMLDivElement>) => {
@@ -76,7 +79,7 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>((props, _ref) =
76
79
  onOpenChange={onOpenChange}
77
80
  onValueChange={handleChange}
78
81
  open={open}
79
- value={currentValue !== undefined ? String(currentValue) : undefined}
82
+ value={currentValue as string | undefined}
80
83
  >
81
84
  <div className={cn("relative inline-block", allowClear && currentValue ? "group" : "", className)}>
82
85
  <SelectTrigger className={cn("flex w-full", triggerClassName)}>
package/src/index.ts CHANGED
@@ -80,6 +80,7 @@ export {
80
80
  SheetTrigger,
81
81
  } from "./components/ui/sheet";
82
82
  export { Skeleton } from "./components/ui/skeleton";
83
+ export { Slider } from "./components/ui/slider";
83
84
  // base
84
85
  export { Toaster } from "./components/ui/sonner";
85
86
  export {