'use client'; import * as React from 'react'; import { InputButton, InputButtonAction, InputButtonProvider, InputButtonSubmit, InputButtonInput, } from '@/registry/buttons/input'; import { Check, Loader2 } from 'lucide-react'; import { motion } from 'motion/react'; const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)); export const InputButtonLoadingDemo = () => { const [showInput, setShowInput] = React.useState(false); const [pending, startTransition] = React.useTransition(); const [success, setSuccess] = React.useState(false); const [value, setValue] = React.useState(''); const handleSubmit = React.useCallback( (e: React.FormEvent) => { e.preventDefault(); if (!showInput) { setShowInput(true); return; } startTransition(async () => { await sleep(2000); setSuccess(true); await sleep(2000); setSuccess(false); setShowInput(false); setValue(''); }); }, [showInput, setShowInput, setSuccess, setValue], ); return (
{}}> Join the newsletter {}} type="submit" disabled={pending} className={pending || success ? 'aspect-square px-0' : ''} > {success ? ( ) : pending ? ( ) : ( 'Subscribe' )} setValue(e.target.value)} disabled={pending} autoFocus />
); };