mirror of
https://github.com/remvze/moodist.git
synced 2026-03-10 05:53:13 +08:00
feat: add reverse timer
This commit is contained in:
1
src/components/modals/sleep-timer/timer/index.ts
Normal file
1
src/components/modals/sleep-timer/timer/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { Timer } from './timer';
|
||||
1
src/components/modals/sleep-timer/timer/reverse/index.ts
Normal file
1
src/components/modals/sleep-timer/timer/reverse/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { Reverse } from './reverse';
|
||||
@@ -0,0 +1,30 @@
|
||||
.reverse {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
left: 8px;
|
||||
padding: 4px 8px;
|
||||
font-size: var(--font-2xsm);
|
||||
color: var(--color-foreground-subtle);
|
||||
background: linear-gradient(
|
||||
var(--color-neutral-50),
|
||||
var(--color-neutral-100)
|
||||
);
|
||||
border: 1px solid var(--color-neutral-200);
|
||||
border-radius: 4px;
|
||||
|
||||
&::after {
|
||||
position: absolute;
|
||||
bottom: -1px;
|
||||
left: 50%;
|
||||
width: 75%;
|
||||
height: 1px;
|
||||
content: '';
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
var(--color-neutral-300),
|
||||
transparent
|
||||
);
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
}
|
||||
27
src/components/modals/sleep-timer/timer/reverse/reverse.tsx
Normal file
27
src/components/modals/sleep-timer/timer/reverse/reverse.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { padNumber } from '@/helpers/number';
|
||||
|
||||
import styles from './reverse.module.css';
|
||||
|
||||
interface ReverseProps {
|
||||
time: number;
|
||||
}
|
||||
|
||||
export function Reverse({ time }: ReverseProps) {
|
||||
let hours = Math.floor(time / 3600);
|
||||
let minutes = Math.floor((time % 3600) / 60);
|
||||
let seconds = time % 60;
|
||||
|
||||
hours = isNaN(hours) ? 0 : hours;
|
||||
minutes = isNaN(minutes) ? 0 : minutes;
|
||||
seconds = isNaN(seconds) ? 0 : seconds;
|
||||
|
||||
const formattedHours = padNumber(hours);
|
||||
const formattedMinutes = padNumber(minutes);
|
||||
const formattedSeconds = padNumber(seconds);
|
||||
|
||||
return (
|
||||
<div className={styles.reverse}>
|
||||
- {formattedHours}:{formattedMinutes}:{formattedSeconds}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
29
src/components/modals/sleep-timer/timer/timer.module.css
Normal file
29
src/components/modals/sleep-timer/timer/timer.module.css
Normal file
@@ -0,0 +1,29 @@
|
||||
.timer {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
padding: 48px 0;
|
||||
font-size: var(--font-xlg);
|
||||
font-weight: 500;
|
||||
background-color: var(--color-neutral-50);
|
||||
border: 1px solid var(--color-neutral-200);
|
||||
border-radius: 12px;
|
||||
|
||||
&::after {
|
||||
position: absolute;
|
||||
bottom: -1px;
|
||||
left: 50%;
|
||||
width: 75%;
|
||||
height: 1px;
|
||||
content: '';
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
var(--color-neutral-400),
|
||||
transparent
|
||||
);
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
}
|
||||
31
src/components/modals/sleep-timer/timer/timer.tsx
Normal file
31
src/components/modals/sleep-timer/timer/timer.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Reverse } from './reverse';
|
||||
|
||||
import { padNumber } from '@/helpers/number';
|
||||
|
||||
import styles from './timer.module.css';
|
||||
|
||||
interface TimerProps {
|
||||
reverse: number;
|
||||
timer: number;
|
||||
}
|
||||
|
||||
export function Timer({ reverse, timer }: TimerProps) {
|
||||
let hours = Math.floor(timer / 3600);
|
||||
let minutes = Math.floor((timer % 3600) / 60);
|
||||
let seconds = timer % 60;
|
||||
|
||||
hours = isNaN(hours) ? 0 : hours;
|
||||
minutes = isNaN(minutes) ? 0 : minutes;
|
||||
seconds = isNaN(seconds) ? 0 : seconds;
|
||||
|
||||
const formattedHours = padNumber(hours);
|
||||
const formattedMinutes = padNumber(minutes);
|
||||
const formattedSeconds = padNumber(seconds);
|
||||
|
||||
return (
|
||||
<div className={styles.timer}>
|
||||
<Reverse time={reverse} />
|
||||
{formattedHours}:{formattedMinutes}:{formattedSeconds}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user