Search

Back

Copy Link

Library

/

Free

/

54

Pomodoro Timer

54

Pomodoro Timer

Not loading? Preview

Made by

@frameroverrides

override

click

Override

Pomodoro Timer

Copy

Override

Copied to Clipboard!

Instructions

Apply to any text layer

Code Preview

import type { ComponentType } from "react"
import { useState, useEffect } from "react"

export function withCountdownTimer(Component): ComponentType {
    return (props) => {
        // Duration of countdown in milliseconds
        const countdownDuration = 10 * 60 * 1000 // 10 minutes
        // State to hold the end time
        const [endTime, setEndTime] = useState(null)
        // State to hold the remaining time
        const [remainingTime, setRemainingTime] = useState(countdownDuration)
        // State to hold the countdown status
        const [isRunning, setIsRunning] = useState(false)

        // Effect to start the timer when the isRunning state is true
        useEffect(() => {
            let timer = null
            if (isRunning) {
                setEndTime(Date.now() + remainingTime)
                timer = setInterval(() => {
                    const timeLeft = endTime - Date.now()
                    if (timeLeft <= 0) {
                        clearInterval(timer)
                        setRemainingTime(0)
                        setIsRunning(false)
                    } else {
                        setRemainingTime(timeLeft)
                    }
                }, 1000)
            } else {
                clearInterval(timer)
            }
            return () => clearInterval(timer)
        }, [isRunning, endTime, remainingTime])

        // Function to toggle the countdown status
        const toggleCountdown = () => {
            setIsRunning(!isRunning)
        }

        // Calculate minutes and seconds for display
        const minutes = Math.floor(remainingTime / 1000 / 60)
        const seconds = Math.floor((remainingTime / 1000) % 60)

        return (
            <Component
                {...props}
                onClick={toggleCountdown}
                text={
                    !isRunning && remainingTime === countdownDuration
                        ? "Start"
                        : `${minutes}:${seconds < 10 ? "0" + seconds : seconds}`
                }
            />
        )
    }
}

Terms of Use for Free Assets

By accessing and using this Framer Override Library, you agree to the following terms:

All code snippets provided are available for your personal and professional use. This includes personal websites, client projects, and other website projects in Framer. You are strictly prohibited from sharing, redistributing, selling these code snippets, or creating derivative works for resale or distribution. Unauthorized sharing, distribution, or selling of these code snippets is a breach of these terms and may result in termination of your access to this library, along with potential legal action.