+
+ setTimerOn(true)} className={'clickable-button'}>
+ setTimerOn(false)} className={'clickable-button'}>
+ setLapTimes([...lapTimes, time])} timerOn={timerOn} lapTimes={lapTimes} className={'clickable-button'}>
+
+
+
+
{formatTime(time)}
+ {/* Display the numbered lap times */}
+ {lapTimes.length > 0 && (
+
+
Lap Times
+
- return(
-
-
StopWatch
-
-
- setTimerOn(true)}>
- setTimerOn(false)}>
- setLapTimes([...lapTimes, time])} timerOn={timerOn} lapTimes={lapTimes}>
-
-
-
-
{formatTime(time)}
- {/* Display the numbered lap times */}
- {lapTimes.length > 0 && (
-
-
Lap times
-
- {lapTimes.map((lapTime, index) => {
- return - {(index + 1)+'.'} {formatTime(lapTime)}
- })}
-
-
- )}
-
+
-
+ Total Time: {formatTime(time)}
+
+ {lapTimes.slice().reverse().map((lapTime, index) => {
+ const lapDifference = index === 0 ? 0 : lapTimes[index - 1] - lapTime;
+ return (
+
-
+ Lap {lapTimes.length - index}: {formatTime(lapTime)}
+ {index > 0 && (
+
+ ({lapDifference >= 0 ? '+' : '-'}{formatTime(Math.abs(lapDifference))})
+
+ )}
+
+ );
+ })}
+
+ )}
- )
+
+
+ );
}
\ No newline at end of file
diff --git a/src/StopWatchButton.tsx b/src/StopWatchButton.tsx
index 7f12a5f1..5f09d585 100644
--- a/src/StopWatchButton.tsx
+++ b/src/StopWatchButton.tsx
@@ -1,54 +1,56 @@
-import React from 'react'
+import React from 'react';
// Maximum number of laps that can be recorded
const maxLaps = 25;
// Define the props for the StopWatchButton component
type StopWatchButtonProps = {
- type: 'start' | 'stop' | 'lap' | 'reset';
- onClick?: () => void;
- timerOn?: boolean;
- time?: number;
- lapTimes?: number[];
+ type: 'start' | 'stop' | 'lap' | 'reset';
+ onClick?: () => void;
+ timerOn?: boolean;
+ time?: number;
+ lapTimes?: number[];
+ className?: string;
};
-
- export default function StopWatchButton({ type, onClick, timerOn, time, lapTimes }: StopWatchButtonProps) {
- // Determine the button text based on the type and add corresponding tabIndex
- let buttonText, tabIndex;
- switch(type) {
- case 'start':
- buttonText = 'Start';
- tabIndex = 1;
- break;
- case 'stop':
- buttonText = 'Stop';
- tabIndex = 2;
- break;
- case 'lap':
- buttonText = 'Record Lap';
- tabIndex = 3;
- break;
- case 'reset':
- buttonText = 'Reset';
- tabIndex = 4;
- break;
- default:
- buttonText = '';
- tabIndex = 0;
- }
- // Determine whether the reset or lap buttons should be disabled
- const isLapDisabled = !timerOn || (lapTimes && lapTimes.length === 25);
- const isResetDisabled = time === 0;
- return(
-
- )
+
+export default function StopWatchButton({ type, onClick, timerOn, time, lapTimes, className }: StopWatchButtonProps) {
+ // Determine the button text based on the type and add corresponding tabIndex
+ let buttonText, tabIndex;
+ switch (type) {
+ case 'start':
+ buttonText = 'Start';
+ tabIndex = 1;
+ break;
+ case 'stop':
+ buttonText = 'Stop';
+ tabIndex = 2;
+ break;
+ case 'lap':
+ buttonText = 'Record Lap';
+ tabIndex = 3;
+ break;
+ case 'reset':
+ buttonText = 'Reset';
+ tabIndex = 4;
+ break;
+ default:
+ buttonText = '';
+ tabIndex = 0;
+ }
+ // Determine whether the reset or lap buttons should be disabled
+ const isLapDisabled = !timerOn || (lapTimes && lapTimes.length === 25);
+ const isResetDisabled = time === 0;
+ return (
+
+ );
}
\ No newline at end of file