{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "comp-264",
  "type": "registry:component",
  "title": "Comp 264",
  "description": "Comp 264",
  "files": [
    {
      "path": "registry/ui-basic/comp-264.tsx",
      "content": "\"use client\";\r\n\r\nimport React, { useRef } from \"react\";\r\n\r\nimport { Button } from \"@/components/ui/button\";\r\nimport { Input } from \"@/components/ui/input\";\r\nimport { Label } from \"@/components/ui/label\";\r\nimport { Slider } from \"@/components/ui/slider\";\r\nimport { RotateCcwIcon } from \"lucide-react\";\r\n\r\nimport { useSliderWithInput } from \"../utilities/useSliderWithInput\";\r\n\r\nexport default function Component() {\r\n\t// Create refs to store reset functions\r\n\tconst resetFunctionsRef = useRef<(() => void)[]>([]);\r\n\r\n\t// Function to reset all sliders to default\r\n\tconst resetAll = () => {\r\n\t\tresetFunctionsRef.current.forEach((resetFn) => resetFn());\r\n\t};\r\n\r\n\t// Function to register reset functions\r\n\tconst registerResetFunction = (resetFn: () => void, index: number) => {\r\n\t\tresetFunctionsRef.current[index] = resetFn;\r\n\t};\r\n\r\n\treturn (\r\n\t\t<div className=\"space-y-4\">\r\n\t\t\t<legend className=\"text-foreground text-sm font-medium\">\r\n\t\t\t\tObject position\r\n\t\t\t</legend>\r\n\t\t\t<div className=\"space-y-2\">\r\n\t\t\t\t<SliderWithInput\r\n\t\t\t\t\tminValue={-10}\r\n\t\t\t\t\tmaxValue={10}\r\n\t\t\t\t\tinitialValue={[-2]}\r\n\t\t\t\t\tdefaultValue={[0]}\r\n\t\t\t\t\tlabel=\"X\"\r\n\t\t\t\t\tonRegisterReset={(resetFn) => registerResetFunction(resetFn, 0)}\r\n\t\t\t\t/>\r\n\t\t\t\t<SliderWithInput\r\n\t\t\t\t\tminValue={-10}\r\n\t\t\t\t\tmaxValue={10}\r\n\t\t\t\t\tinitialValue={[4]}\r\n\t\t\t\t\tdefaultValue={[0]}\r\n\t\t\t\t\tlabel=\"Y\"\r\n\t\t\t\t\tonRegisterReset={(resetFn) => registerResetFunction(resetFn, 1)}\r\n\t\t\t\t/>\r\n\t\t\t\t<SliderWithInput\r\n\t\t\t\t\tminValue={-10}\r\n\t\t\t\t\tmaxValue={10}\r\n\t\t\t\t\tinitialValue={[2]}\r\n\t\t\t\t\tdefaultValue={[0]}\r\n\t\t\t\t\tlabel=\"Z\"\r\n\t\t\t\t\tonRegisterReset={(resetFn) => registerResetFunction(resetFn, 2)}\r\n\t\t\t\t/>\r\n\t\t\t</div>\r\n\t\t\t<Button className=\"w-full\" variant=\"outline\" onClick={resetAll}>\r\n\t\t\t\t<RotateCcwIcon\r\n\t\t\t\t\tclassName=\"-ms-1 opacity-60\"\r\n\t\t\t\t\tsize={16}\r\n\t\t\t\t\taria-hidden=\"true\"\r\n\t\t\t\t/>\r\n\t\t\t\tReset\r\n\t\t\t</Button>\r\n\t\t</div>\r\n\t);\r\n}\r\n\r\nfunction SliderWithInput({\r\n\tminValue,\r\n\tmaxValue,\r\n\tinitialValue,\r\n\tdefaultValue,\r\n\tlabel,\r\n\tonRegisterReset,\r\n}: {\r\n\tminValue: number;\r\n\tmaxValue: number;\r\n\tinitialValue: number[];\r\n\tdefaultValue: number[];\r\n\tlabel: string;\r\n\tonRegisterReset: (resetFn: () => void) => void;\r\n}) {\r\n\tconst {\r\n\t\tsliderValue,\r\n\t\tinputValues,\r\n\t\tvalidateAndUpdateValue,\r\n\t\thandleInputChange,\r\n\t\thandleSliderChange,\r\n\t\tresetToDefault,\r\n\t} = useSliderWithInput({ minValue, maxValue, initialValue, defaultValue });\r\n\r\n\t// Register the reset function when the component mounts\r\n\tReact.useEffect(() => {\r\n\t\tonRegisterReset(resetToDefault);\r\n\t}, [onRegisterReset, resetToDefault]);\r\n\r\n\treturn (\r\n\t\t<div className=\"flex items-center gap-2\">\r\n\t\t\t<Label className=\"text-muted-foreground text-xs\">{label}</Label>\r\n\t\t\t<Slider\r\n\t\t\t\tclassName=\"grow [&>:last-child>span]:rounded\"\r\n\t\t\t\tvalue={sliderValue}\r\n\t\t\t\tonValueChange={handleSliderChange}\r\n\t\t\t\tmin={minValue}\r\n\t\t\t\tmax={maxValue}\r\n\t\t\t\taria-label={label}\r\n\t\t\t/>\r\n\t\t\t<Input\r\n\t\t\t\tclassName=\"h-8 w-12 px-2 py-1\"\r\n\t\t\t\ttype=\"text\"\r\n\t\t\t\tinputMode=\"decimal\"\r\n\t\t\t\tvalue={inputValues[0]}\r\n\t\t\t\tonChange={(e) => handleInputChange(e, 0)}\r\n\t\t\t\tonBlur={() => validateAndUpdateValue(inputValues[0], 0)}\r\n\t\t\t\tonKeyDown={(e) => {\r\n\t\t\t\t\tif (e.key === \"Enter\") {\r\n\t\t\t\t\t\tvalidateAndUpdateValue(inputValues[0], 0);\r\n\t\t\t\t\t}\r\n\t\t\t\t}}\r\n\t\t\t\taria-label=\"Enter value\"\r\n\t\t\t/>\r\n\t\t</div>\r\n\t);\r\n}\r\n",
      "type": "registry:ui"
    },
    {
      "path": "components/ui/button.tsx",
      "content": "import * as React from \"react\";\r\n\r\nimport { cn } from \"@/registry/utilities/cn\";\r\nimport { Slot } from \"@radix-ui/react-slot\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\n\r\nconst buttonVariants = cva(\r\n\t\"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm text-white hover:text-gray-400 font-medium ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50\",\r\n\t{\r\n\t\tvariants: {\r\n\t\t\tvariant: {\r\n\t\t\t\tsimple:\r\n\t\t\t\t\t\"bg-secondary relative z-10 bg-transparent hover:border-secondary hover:bg-secondary/50  border border-transparent dark:text-white text-sm md:text-sm transition font-medium duration-200  rounded-md px-4 py-2  flex items-center justify-center\",\r\n\t\t\t\tdefault: \"bg-primary text-primary-foreground hover:bg-primary/90\",\r\n\t\t\t\tdestructive:\r\n\t\t\t\t\t\"bg-destructive text-destructive-foreground hover:bg-destructive/90\",\r\n\t\t\t\toutline:\r\n\t\t\t\t\t\"border border-input bg-background hover:bg-accent hover:text-accent-foreground\",\r\n\t\t\t\tsecondary:\r\n\t\t\t\t\t\"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\r\n\t\t\t\tghost: \"hover:bg-accent hover:text-black hover:stroke-black dark:text-white text-black\",\r\n\t\t\t\tlink: \"text-primary underline-offset-4 hover:underline\",\r\n\t\t\t},\r\n\t\t\tsize: {\r\n\t\t\t\tdefault: \"h-10 px-4 py-2\",\r\n\t\t\t\tsm: \"h-9 rounded-md px-3\",\r\n\t\t\t\tlg: \"h-11 rounded-md px-8\",\r\n\t\t\t\ticon: \"h-10 w-10\",\r\n\t\t\t},\r\n\t\t},\r\n\t\tdefaultVariants: {\r\n\t\t\tvariant: \"default\",\r\n\t\t\tsize: \"default\",\r\n\t\t},\r\n\t}\r\n);\r\n\r\nexport interface ButtonProps\r\n\textends React.ButtonHTMLAttributes<HTMLButtonElement>,\r\n\t\tVariantProps<typeof buttonVariants> {\r\n\tasChild?: boolean;\r\n}\r\n\r\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\r\n\t({ className, variant, size, asChild = false, ...props }, ref) => {\r\n\t\tconst Comp = asChild ? Slot : \"button\";\r\n\t\treturn (\r\n\t\t\t<Comp\r\n\t\t\t\tclassName={cn(buttonVariants({ variant, size, className }))}\r\n\t\t\t\tref={ref}\r\n\t\t\t\t{...props}\r\n\t\t\t/>\r\n\t\t);\r\n\t}\r\n);\r\nButton.displayName = \"Button\";\r\n\r\nexport { Button, buttonVariants };\r\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/utilities/cn.ts",
      "content": "import { ClassValue, clsx } from \"clsx\";\r\nimport { twMerge } from \"tailwind-merge\";\r\n\r\nexport function cn(...inputs: ClassValue[]) {\r\n\treturn twMerge(clsx(inputs));\r\n}\r\n",
      "type": "registry:ui"
    },
    {
      "path": "components/ui/input.tsx",
      "content": "// SHADCN UI GENERATED CODE\n\nimport React from \"react\";\n\nimport { cn } from \"@/registry/utilities/cn\";\n\nexport interface InputProps\n\textends React.InputHTMLAttributes<HTMLInputElement> {}\n\nconst Input = React.forwardRef<HTMLInputElement, InputProps>(\n\t({ className, type, ...props }, ref) => {\n\t\treturn (\n\t\t\t<input\n\t\t\t\ttype={type}\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50\",\n\t\t\t\t\tclassName\n\t\t\t\t)}\n\t\t\t\tref={ref}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t);\n\t}\n);\nInput.displayName = \"Input\";\n\nexport { Input };\n",
      "type": "registry:ui"
    },
    {
      "path": "components/ui/label.tsx",
      "content": "\"use client\";\n\nimport React from \"react\";\n\nimport { cn } from \"@/registry/utilities/cn\";\nimport * as LabelPrimitive from \"@radix-ui/react-label\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\n\nconst labelVariants = cva(\n\t\"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\"\n);\n\nconst Label = React.forwardRef<\n\tReact.ElementRef<typeof LabelPrimitive.Root>,\n\tReact.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &\n\t\tVariantProps<typeof labelVariants>\n>(({ className, ...props }, ref) => (\n\t<LabelPrimitive.Root\n\t\tref={ref}\n\t\tclassName={cn(labelVariants(), className)}\n\t\t{...props}\n\t/>\n));\nLabel.displayName = LabelPrimitive.Root.displayName;\n\nexport { Label };\n",
      "type": "registry:ui"
    },
    {
      "path": "components/ui/slider.tsx",
      "content": "\"use client\";\r\n\r\nimport React from \"react\";\r\n\r\nimport { cn } from \"@/registry/utilities/cn\";\r\nimport * as SliderPrimitive from \"@radix-ui/react-slider\";\r\n\r\nconst Slider = React.forwardRef<\r\n\tReact.ElementRef<typeof SliderPrimitive.Root>,\r\n\tReact.ComponentPropsWithoutRef<typeof SliderPrimitive.Root>\r\n>(({ className, ...props }, ref) => (\r\n\t<SliderPrimitive.Root\r\n\t\tref={ref}\r\n\t\tclassName={cn(\r\n\t\t\t\"relative flex w-full touch-none select-none items-center\",\r\n\t\t\tclassName\r\n\t\t)}\r\n\t\t{...props}\r\n\t>\r\n\t\t<SliderPrimitive.Track className=\"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary\">\r\n\t\t\t<SliderPrimitive.Range className=\"absolute h-full bg-primary\" />\r\n\t\t</SliderPrimitive.Track>\r\n\t\t<SliderPrimitive.Thumb className=\"block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50\" />\r\n\t\t<SliderPrimitive.Thumb className=\"block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50\" />\r\n\t</SliderPrimitive.Root>\r\n));\r\nSlider.displayName = SliderPrimitive.Root.displayName;\r\n\r\nexport { Slider };\r\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/utilities/useSliderWithInput.ts",
      "content": "\"use client\"\r\n\r\nimport { useCallback, useState } from \"react\"\r\n\r\ntype UseSliderWithInputProps = {\r\n    minValue?: number\r\n    maxValue?: number\r\n    initialValue?: number[]\r\n    defaultValue?: number[]\r\n}\r\n\r\nexport function useSliderWithInput({\r\n    minValue = 0,\r\n    maxValue = 100,\r\n    initialValue = [minValue],\r\n    defaultValue = [minValue],\r\n}: UseSliderWithInputProps) {\r\n    const [sliderValue, setSliderValue] = useState(initialValue)\r\n    const [inputValues, setInputValues] = useState(\r\n        initialValue.map((v) => v.toString())\r\n    )\r\n\r\n    const showReset =\r\n        sliderValue.length === defaultValue.length &&\r\n        !sliderValue.every((value, index) => value === defaultValue[index])\r\n\r\n    const validateAndUpdateValue = useCallback(\r\n        (rawValue: string, index: number) => {\r\n            if (rawValue === \"\" || rawValue === \"-\") {\r\n                const newInputValues = [...inputValues]\r\n                newInputValues[index] = \"0\"\r\n                setInputValues(newInputValues)\r\n\r\n                const newSliderValues = [...sliderValue]\r\n                newSliderValues[index] = 0\r\n                setSliderValue(newSliderValues)\r\n                return\r\n            }\r\n\r\n            const numValue = parseFloat(rawValue)\r\n\r\n            if (isNaN(numValue)) {\r\n                const newInputValues = [...inputValues]\r\n                newInputValues[index] = sliderValue[index]!.toString()\r\n                setInputValues(newInputValues)\r\n                return\r\n            }\r\n\r\n            let clampedValue = Math.min(maxValue, Math.max(minValue, numValue))\r\n\r\n            if (sliderValue.length > 1) {\r\n                if (index === 0) {\r\n                    clampedValue = Math.min(clampedValue, sliderValue[1]!)\r\n                } else {\r\n                    clampedValue = Math.max(clampedValue, sliderValue[0]!)\r\n                }\r\n            }\r\n\r\n            const newSliderValues = [...sliderValue]\r\n            newSliderValues[index] = clampedValue\r\n            setSliderValue(newSliderValues)\r\n\r\n            const newInputValues = [...inputValues]\r\n            newInputValues[index] = clampedValue.toString()\r\n            setInputValues(newInputValues)\r\n        },\r\n        [sliderValue, inputValues, minValue, maxValue]\r\n    )\r\n\r\n    const handleInputChange = useCallback(\r\n        (e: React.ChangeEvent<HTMLInputElement>, index: number) => {\r\n            const newValue = e.target.value\r\n            if (newValue === \"\" || /^-?\\d*\\.?\\d*$/.test(newValue)) {\r\n                const newInputValues = [...inputValues]\r\n                newInputValues[index] = newValue\r\n                setInputValues(newInputValues)\r\n            }\r\n        },\r\n        [inputValues]\r\n    )\r\n\r\n    const handleSliderChange = useCallback((newValue: number[]) => {\r\n        setSliderValue(newValue)\r\n        setInputValues(newValue.map((v) => v.toString()))\r\n    }, [])\r\n\r\n    const resetToDefault = useCallback(() => {\r\n        setSliderValue(defaultValue)\r\n        setInputValues(defaultValue.map((v) => v.toString()))\r\n    }, [defaultValue])\r\n\r\n    return {\r\n        sliderValue,\r\n        inputValues,\r\n        validateAndUpdateValue,\r\n        handleInputChange,\r\n        handleSliderChange,\r\n        resetToDefault,\r\n        showReset,\r\n    }\r\n}",
      "type": "registry:ui"
    }
  ]
}