import { useRive, useStateMachineInput } from '@rive-app/react-canvas'; import { useState, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card } from '@/components/ui/card'; const RivePlayer = () => { const [cardNumValue, setCardNumValue] = useState('0'); const { RiveComponent, rive } = useRive({ src: '/AnyState_Test.riv', stateMachines: 'State Machine 1', autoplay: true, }); const cardNumInput = useStateMachineInput(rive, 'State Machine 1', 'Card_Num'); // Sync input in real-time as it changes and when Rive loads useEffect(() => { if (!cardNumInput) return; const value = parseInt(cardNumValue); if (!isNaN(value) && value >= 0 && value <= 3) { cardNumInput.value = value; } }, [cardNumInput, cardNumValue]); const handleRender = () => { const value = parseInt(cardNumValue); if (!isNaN(value) && value >= 0 && value <= 3 && cardNumInput) { cardNumInput.value = value; } }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { handleRender(); } }; return (
Enter a value between 0 and 3 to change the artboard state