'use client'; import * as React from 'react'; import { AnimatePresence, HTMLMotionProps, motion, Transition, } from 'motion/react'; import { ArrowRight } from 'lucide-react'; import { cn } from '@workspace/ui/lib/utils'; type InputButtonContextType = { showInput: boolean; setShowInput: React.Dispatch>; transition: Transition; id: string; }; const InputButtonContext = React.createContext< InputButtonContextType | undefined >(undefined); const useInputButton = (): InputButtonContextType => { const context = React.useContext(InputButtonContext); if (!context) { throw new Error('useInputButton must be used within a InputButton'); } return context; }; type InputButtonProviderProps = React.ComponentProps<'div'> & Partial; function InputButtonProvider({ className, transition = { type: 'spring', stiffness: 300, damping: 20 }, showInput, setShowInput, id, ...props }: InputButtonProviderProps) { const localId = React.useId(); const [localShowInput, setLocalShowInput] = React.useState(false); return (
); } type InputButtonProps = HTMLMotionProps<'div'>; function InputButton({ className, ...props }: InputButtonProps) { return ( ); } type InputButtonActionProps = HTMLMotionProps<'button'>; function InputButtonAction({ className, ...props }: InputButtonActionProps) { const { transition, setShowInput, id } = useInputButton(); return ( setShowInput((prev) => !prev)} {...props} /> ); } type InputButtonSubmitProps = HTMLMotionProps<'button'> & { icon?: React.ElementType; }; function InputButtonSubmit({ className, children, icon: Icon = ArrowRight, ...props }: InputButtonSubmitProps) { const { transition, showInput, setShowInput, id } = useInputButton(); return ( setShowInput((prev) => !prev)} {...props} > {showInput ? ( {children} ) : ( )} ); } type InputButtonInputProps = React.ComponentProps<'input'>; function InputButtonInput({ className, ...props }: InputButtonInputProps) { const { transition, showInput, id } = useInputButton(); return ( {showInput && (
)}
); } export { InputButton, InputButtonProvider, InputButtonAction, InputButtonSubmit, InputButtonInput, useInputButton, type InputButtonProps, type InputButtonProviderProps, type InputButtonActionProps, type InputButtonSubmitProps, type InputButtonInputProps, };