Skip to content

Commit

Permalink
fix: fix button disabled and reset to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperMeepBoy committed Apr 28, 2024
1 parent 0517c31 commit 58bf28b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/components/generic/button/button.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@
&.smallIcon {
font-size: var(--font-xsm);
}

&:disabled {
cursor: not-allowed;
opacity: 0.4;
}
}
10 changes: 9 additions & 1 deletion src/components/generic/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ import { cn } from '@/helpers/styles';
import styles from './button.module.css';

interface ButtonProps {
disabled?: boolean;
icon: React.ReactElement;
onClick: () => void;
smallIcon?: boolean;
tooltip: string;
}

export function Button({ icon, onClick, smallIcon, tooltip }: ButtonProps) {
export function Button({
disabled = false,
icon,
onClick,
smallIcon,
tooltip,
}: ButtonProps) {
return (
<Tooltip content={tooltip} placement="bottom" showDelay={0}>
<button
className={cn(styles.button, smallIcon && styles.smallIcon)}
disabled={disabled}
onClick={onClick}
>
{icon}
Expand Down
3 changes: 3 additions & 0 deletions src/components/modals/sleep-timer/sleep-timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export function SleepTimerModal({ onClose, show }: SleepTimerModalProps) {
const handleReset = () => {
if (timerId.current) clearInterval(timerId.current);
setTimeLeft(0);
setHours('0');
setMinutes('0');
setRunning(false);
};

Expand Down Expand Up @@ -114,6 +116,7 @@ export function SleepTimerModal({ onClose, show }: SleepTimerModalProps) {
/>
{!running && (
<Button
disabled={calculateTotalSeconds() <= 0}
icon={<FaPlay />}
smallIcon
tooltip={'Start'}
Expand Down

0 comments on commit 58bf28b

Please sign in to comment.