fix: fix button disabled and reset to 0

This commit is contained in:
Jef Roelandt 2024-04-28 19:11:51 +02:00
parent 0517c31fc1
commit 58bf28bb24
3 changed files with 17 additions and 1 deletions

View file

@ -26,4 +26,9 @@
&.smallIcon { &.smallIcon {
font-size: var(--font-xsm); font-size: var(--font-xsm);
} }
&:disabled {
cursor: not-allowed;
opacity: 0.4;
}
} }

View file

@ -5,17 +5,25 @@ import { cn } from '@/helpers/styles';
import styles from './button.module.css'; import styles from './button.module.css';
interface ButtonProps { interface ButtonProps {
disabled?: boolean;
icon: React.ReactElement; icon: React.ReactElement;
onClick: () => void; onClick: () => void;
smallIcon?: boolean; smallIcon?: boolean;
tooltip: string; tooltip: string;
} }
export function Button({ icon, onClick, smallIcon, tooltip }: ButtonProps) { export function Button({
disabled = false,
icon,
onClick,
smallIcon,
tooltip,
}: ButtonProps) {
return ( return (
<Tooltip content={tooltip} placement="bottom" showDelay={0}> <Tooltip content={tooltip} placement="bottom" showDelay={0}>
<button <button
className={cn(styles.button, smallIcon && styles.smallIcon)} className={cn(styles.button, smallIcon && styles.smallIcon)}
disabled={disabled}
onClick={onClick} onClick={onClick}
> >
{icon} {icon}

View file

@ -61,6 +61,8 @@ export function SleepTimerModal({ onClose, show }: SleepTimerModalProps) {
const handleReset = () => { const handleReset = () => {
if (timerId.current) clearInterval(timerId.current); if (timerId.current) clearInterval(timerId.current);
setTimeLeft(0); setTimeLeft(0);
setHours('0');
setMinutes('0');
setRunning(false); setRunning(false);
}; };
@ -114,6 +116,7 @@ export function SleepTimerModal({ onClose, show }: SleepTimerModalProps) {
/> />
{!running && ( {!running && (
<Button <Button
disabled={calculateTotalSeconds() <= 0}
icon={<FaPlay />} icon={<FaPlay />}
smallIcon smallIcon
tooltip={'Start'} tooltip={'Start'}