opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Activity
  4. Pomodoro
Back to Activity

Components / Activity

Pomodoro

Free Activity React component — PomodoroWidget. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Dark pomodoro timer — thin ring, split monospace time, tap to start or pause. Polished to match the DND card size and proportions.

Preview

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/activity/pomodoro-widget.tsx in your project.

  4. 4

    Import and render:

    Example

    import { PomodoroWidget } from "@/components/activity/pomodoro-widget";

    <PomodoroWidget minutes={25} label="Focus" />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/activity/pomodoro-widget.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"use client";
 
import {
forwardRef,
useEffect,
useState,
type ComponentPropsWithoutRef,
} from "react";
 
import { cn } from "@/lib/cn";
import { Pause, Play } from "lucide-react";
 
const DIAL = { cx: 88, cy: 88, r: 56 } as const;
const CIRC = 2 * Math.PI * DIAL.r;
const TOMATO = "#E85D4C";
 
function formatTime(totalSeconds: number) {
const mins = Math.floor(totalSeconds / 60);
const secs = totalSeconds % 60;
return {
mins: String(mins).padStart(2, "0"),
secs: String(secs).padStart(2, "0"),
};
}
 
export type PomodoroWidgetProps = Readonly<
{
minutes?: number;
label?: string;
} & ComponentPropsWithoutRef<"button">
>;
 
// Pomodoro — dark timer card with a thin ring, tap to start or pause.
export const PomodoroWidget = forwardRef<HTMLButtonElement, PomodoroWidgetProps>(
(
{
className,
minutes = 25,
label = "Focus",
onClick,
...props
},
ref,
) => {
const totalSeconds = minutes * 60;
const [remaining, setRemaining] = useState(totalSeconds);
const [running, setRunning] = useState(false);
 
useEffect(() => {
if (!running || remaining <= 0) return;
const timer = globalThis.setInterval(() => {
setRemaining((prev) => {
if (prev <= 1) {
setRunning(false);
return 0;
}
return prev - 1;
});
}, 1000);
return () => globalThis.clearInterval(timer);
}, [running, remaining]);
 
const progress = remaining / totalSeconds;
const dashOffset = CIRC * (1 - progress);
const { mins, secs } = formatTime(remaining);
const isDone = remaining <= 0;
 
const handleToggle = () => {
if (isDone) {
setRemaining(totalSeconds);
setRunning(true);
return;
}
setRunning((prev) => !prev);
};
 
return (
<button
ref={ref}
type="button"
aria-pressed={running}
aria-label={running ? "Pause timer" : isDone ? "Restart timer" : "Start timer"}
data-slot="pomodoro-widget"
onClick={(event) => {
handleToggle();
onClick?.(event);
}}
className={cn(
"relative h-44 w-44 max-w-full cursor-pointer overflow-hidden rounded-[1.75rem] bg-[#0C0C0C] font-sans shadow-lg shadow-black/5 select-none transition-transform active:scale-[0.98]",
className,
)}
{...props}
>
<svg
viewBox="0 0 176 176"
className="absolute inset-0 size-full"
aria-hidden
>
<rect width="176" height="176" fill="#0C0C0C" />
<circle
cx={DIAL.cx}
cy={DIAL.cy}
r={DIAL.r}
fill="none"
stroke="rgba(255,255,255,0.07)"
strokeWidth="1.5"
/>
<circle
cx={DIAL.cx}
cy={DIAL.cy}
r={DIAL.r}
fill="none"
stroke={running ? TOMATO : "rgba(255,255,255,0.32)"}
strokeWidth="1.5"
strokeLinecap="round"
strokeDasharray={CIRC}
strokeDashoffset={dashOffset}
transform={`rotate(-90 ${DIAL.cx} ${DIAL.cy})`}
className="transition-[stroke,stroke-dashoffset] duration-1000 ease-linear"
/>
</svg>
 
<div className="absolute inset-0 flex flex-col items-center justify-center">
<p className="flex items-baseline font-mono text-[1.75rem] leading-none font-light tracking-[-0.03em] tabular-nums">
<span className="text-white">{mins}</span>
<span className="mx-px text-white/30">:</span>
<span className={cn(running ? "text-white/90" : "text-white/55")}>
{secs}
</span>
</p>
<p
className={cn(
"mt-2 text-[10px] font-medium tracking-[0.14em] uppercase",
running ? "text-[#E85D4C]/80" : "text-white/30",
)}
>
{isDone ? "Done" : running ? "Running" : label}
</p>
</div>
 
<span
className="absolute right-3.5 bottom-3.5 z-10 flex size-7 items-center justify-center rounded-full bg-white/[0.07] text-white/70"
aria-hidden
>
{running ? (
<Pause size={11} strokeWidth={2.5} fill="currentColor"/>
) : (
<Play size={11} strokeWidth={2.5} className="ml-0.5" fill="currentColor" />
)}
</span>
</button>
);
},
);
 
PomodoroWidget.displayName = "PomodoroWidget";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/activity/pomodoro-widget.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.