mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
refactor: use state for flap ops instead of ref in envelope comp
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { WavesIcon } from "@phosphor-icons/react";
|
import { WavesIcon } from "@phosphor-icons/react";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import candle from "../../assets/envelope/candle.png";
|
import candle from "../../assets/envelope/candle.png";
|
||||||
import stamp from "../../assets/envelope/stamp.png";
|
import stamp from "../../assets/envelope/stamp.png";
|
||||||
import waxSeal from "../../assets/envelope/waxSeal.png";
|
import waxSeal from "../../assets/envelope/waxSeal.png";
|
||||||
@@ -11,6 +11,7 @@ export interface EnvelopeRevealProps {
|
|||||||
ignite: boolean;
|
ignite: boolean;
|
||||||
isFlip?: boolean;
|
isFlip?: boolean;
|
||||||
isInteractive?: boolean;
|
isInteractive?: boolean;
|
||||||
|
openFlap?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function EnvelopeReveal({
|
export function EnvelopeReveal({
|
||||||
@@ -20,9 +21,11 @@ export function EnvelopeReveal({
|
|||||||
ignite,
|
ignite,
|
||||||
isFlip,
|
isFlip,
|
||||||
isInteractive = true,
|
isInteractive = true,
|
||||||
|
openFlap = false,
|
||||||
}: EnvelopeRevealProps) {
|
}: EnvelopeRevealProps) {
|
||||||
const [revealLetter, setRevealLetter] = useState(false);
|
const [revealLetter, setRevealLetter] = useState(false);
|
||||||
const [isFlipped, setIsFlipped] = useState(!!isFlip);
|
const [isFlipped, setIsFlipped] = useState(!!isFlip);
|
||||||
|
const [isFlapOpen, setIsFlapOpen] = useState(!!openFlap);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsFlipped(!!isFlip);
|
setIsFlipped(!!isFlip);
|
||||||
@@ -33,7 +36,9 @@ export function EnvelopeReveal({
|
|||||||
height: 0,
|
height: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
const flapCheckbox = useRef<HTMLInputElement>(null);
|
useEffect(() => {
|
||||||
|
setIsFlapOpen(openFlap);
|
||||||
|
}, [openFlap]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ignite) {
|
if (!ignite) {
|
||||||
@@ -69,7 +74,8 @@ export function EnvelopeReveal({
|
|||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="transition checkbox absolute h-full w-full text-transparent bg-transparent z-100"
|
className="transition checkbox absolute h-full w-full text-transparent bg-transparent z-100"
|
||||||
ref={flapCheckbox}
|
checked={isFlapOpen}
|
||||||
|
onChange={() => setIsFlapOpen((prev) => !prev)}
|
||||||
disabled={!isInteractive}
|
disabled={!isInteractive}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -79,8 +85,8 @@ export function EnvelopeReveal({
|
|||||||
}
|
}
|
||||||
src={waxSeal}
|
src={waxSeal}
|
||||||
alt="Seal"
|
alt="Seal"
|
||||||
onClick={() => flapCheckbox.current?.click()}
|
onClick={() => setIsFlapOpen((prev) => !prev)}
|
||||||
onKeyDown={() => flapCheckbox.current?.click()}
|
onKeyDown={() => setIsFlapOpen((prev) => !prev)}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
Reference in New Issue
Block a user