-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from sliit-foss/feat/add-countdown
Add Countdown
- Loading branch information
Showing
10 changed files
with
3,341 additions
and
2,310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as SeparatorPrimitive from '@radix-ui/react-separator'; | ||
import * as React from 'react'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
const Separator = React.forwardRef(({ className, orientation = 'vertical', decorative = true, ...props }, ref) => ( | ||
<SeparatorPrimitive.Root | ||
ref={ref} | ||
decorative={decorative} | ||
orientation={orientation} | ||
className={twMerge( | ||
'shrink-0 bg-border', | ||
'bg-black/10', | ||
'mx-4', | ||
'lg:mx-7', | ||
orientation === 'vertical' ? 'h-100px w-[1px] ' : 'h-[1px] w-full', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
Separator.displayName = SeparatorPrimitive.Root.displayName; | ||
|
||
export { Separator }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Separator } from '@/components/common/separator/index'; | ||
import useCountdown from '@/hooks/countdown'; | ||
import TimeItem from './time-item'; | ||
|
||
const CountDown = () => { | ||
const { days, hours, minutes, seconds } = useCountdown({ targetDate: new Date('September 7, 2024 00:00:00') }); | ||
|
||
return ( | ||
<div className="bg-white text-center rounded-[15px] "> | ||
<div className="pt-3 lg:pt-5 font-consolas text-black/70">Registration Ends In...</div> | ||
<div className="flex px-6 lg:px-8 pb-4 lg:pb-5 pt-2 font-inter"> | ||
<TimeItem key={'d'} value={days} unit="DD" /> | ||
<Separator /> | ||
<TimeItem key={'h'} value={hours} unit="HH" /> | ||
<Separator /> | ||
<TimeItem key={'m'} value={minutes} unit="MM" /> | ||
<Separator /> | ||
<TimeItem key={'s'} value={seconds} unit="SS" /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CountDown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const TimeItem = ({ value, unit }) => { | ||
return ( | ||
<div className="w-14"> | ||
<div className="font-bold text-2xl lg:text-4xl">{value}</div> | ||
<div className="font-light text-black text-xs lg:text-sm lg:mt-2">{unit}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TimeItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useEffect } from 'react'; | ||
import { useState } from 'react'; | ||
|
||
function useCountdown({ targetDate }) { | ||
const countDownDate = targetDate.getTime(); | ||
const [remainingTime, setRemainingTime] = useState(countDownDate - new Date().getTime()); | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
setRemainingTime(countDownDate - new Date().getTime()); | ||
}, 1000); | ||
|
||
return () => clearInterval(interval); | ||
}, [targetDate]); | ||
|
||
const formatTimeUnit = (val) => | ||
Number(val).toLocaleString('en-US', { | ||
minimumIntegerDigits: 2 | ||
}); | ||
|
||
const extractUnitVals = (remainingTime) => { | ||
const days = formatTimeUnit(Math.floor(remainingTime / (1000 * 60 * 60 * 24))); | ||
const hours = formatTimeUnit(Math.floor((remainingTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))); | ||
const minutes = formatTimeUnit(Math.floor((remainingTime % (1000 * 60 * 60)) / (1000 * 60))); | ||
const seconds = formatTimeUnit(Math.floor((remainingTime % (1000 * 60)) / 1000)); | ||
|
||
return { | ||
days, | ||
hours, | ||
minutes, | ||
seconds, | ||
milliSeconds: remainingTime | ||
}; | ||
}; | ||
|
||
return extractUnitVals(remainingTime); | ||
} | ||
|
||
export default useCountdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.