Skip to content

Commit

Permalink
🦄 refactor(prettier): auto format
Browse files Browse the repository at this point in the history
  • Loading branch information
phiko-misc committed Oct 24, 2023
1 parent bcdfd2c commit ebb4dc3
Show file tree
Hide file tree
Showing 17 changed files with 453 additions and 358 deletions.
49 changes: 25 additions & 24 deletions src/components/button/SimpleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@ import Link from "next/link";
import { ReactNode } from "react";

interface Props {
icon: ReactNode;
link?: string;
className?: string;
disabled?: boolean;
icon: ReactNode;
link?: string;
className?: string;
disabled?: boolean;
}

export default function SimpleButton(props: Props) {
return (
<button disabled={props.disabled} className={clsx(
"disabled:brightness-75 h-32 w-32 lg:h-44 lg:w-44 bg-gradient-to-r from-rose-700 to-rose-900 rounded-full shadow-lg",
props.className && props.className
)}>
{
props.disabled
?
<div className='w-full flex place-content-center'>
{props.icon}
</div>
:
<Link href={props.link ?? ""} className='w-full flex place-content-center'>
{props.icon}
</Link>
}

</button>
)
}
return (
<button
disabled={props.disabled}
className={clsx(
"h-32 w-32 rounded-full bg-gradient-to-r from-rose-700 to-rose-900 shadow-lg disabled:brightness-75 lg:h-44 lg:w-44",
props.className && props.className,
)}
>
{props.disabled ? (
<div className="flex w-full place-content-center">{props.icon}</div>
) : (
<Link
href={props.link ?? ""}
className="flex w-full place-content-center"
>
{props.icon}
</Link>
)}
</button>
);
}
63 changes: 32 additions & 31 deletions src/components/button/ThemeButton.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
import { useState, useEffect } from 'react'
import { useTheme } from 'next-themes'
import { SunIcon } from '@components/icons/SunIcon';
import { MoonIcon } from '@components/icons/MoonIcon';
import { useState, useEffect } from "react";
import { useTheme } from "next-themes";
import { SunIcon } from "@components/icons/SunIcon";
import { MoonIcon } from "@components/icons/MoonIcon";

export default function ThemeSwitch() {
const [mounted, setMounted] = useState(false);
const { theme, setTheme } = useTheme();
const [mounted, setMounted] = useState(false);
const { theme, setTheme } = useTheme();

// useEffect only runs on the client, so now we can safely show the UI
useEffect(() => {
setMounted(true)
}, [])
// useEffect only runs on the client, so now we can safely show the UI
useEffect(() => {
setMounted(true);
}, []);

if (!mounted) {
return null
}
if (!mounted) {
return null;
}

function switchTheme() {
if (theme === 'light') {
setTheme('dark');
} else {
setTheme('light');
}
function switchTheme() {
if (theme === "light") {
setTheme("dark");
} else {
setTheme("light");
}
}

return (

<button onClick={switchTheme} className="w-fit h-fit text-black dark:text-white ml-3 mt-3" >
{theme === "light"
?
<SunIcon className='w-5 h-5' />
:
<MoonIcon className='w-5 h-5 dark:text-coolGray-390' />
}
</button>
);
}
return (
<button
onClick={switchTheme}
className="ml-3 mt-3 h-fit w-fit text-black dark:text-white"
>
{theme === "light" ? (
<SunIcon className="h-5 w-5" />
) : (
<MoonIcon className="dark:text-coolGray-390 h-5 w-5" />
)}
</button>
);
}
155 changes: 80 additions & 75 deletions src/components/countdown/CountDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { useEffect, useState } from "react";
import NumberBox from "./NumberBox";

interface time {
days: number | string;
hours: number | string;
minutes: number | string;
seconds: number | string;
days: number | string;
hours: number | string;
minutes: number | string;
seconds: number | string;
}


/**
* CountDown component
* @returns {JSX.Element} The Countdown element
Expand All @@ -19,81 +18,87 @@ interface time {
* ```
*/
export default function Countdown(): JSX.Element {
const toDay = dayjs();
const christmasDate = dayjs(`${dayjs().get('year')}-12-24`);
const [timeBeforeChristmas, setTimeBeforeChristmas] = useState<time>();

useEffect(() => {
const updateTime = setInterval(() => {
const difference = toDay.millisecond() - christmasDate.millisecond();
const toDay = dayjs();
const christmasDate = dayjs(`${dayjs().get("year")}-12-24`);
const [timeBeforeChristmas, setTimeBeforeChristmas] = useState<time>();

setTimeBeforeChristmas({
...timeBeforeChristmas,
days: dayjs.duration(christmasDate.diff(toDay, "day"), "day").asDays(),
hours: 24 - toDay.hour(),
minutes: 60 - toDay.minute(),
seconds: 60 - toDay.second()
})
useEffect(() => {
const updateTime = setInterval(() => {
const difference = toDay.millisecond() - christmasDate.millisecond();

if (difference <= 0) {
clearInterval(updateTime);
setTimeBeforeChristmas({
days: 0,
hours: 0,
minutes: 0,
seconds: 0
})
}
setTimeBeforeChristmas({
...timeBeforeChristmas,
days: dayjs.duration(christmasDate.diff(toDay, "day"), "day").asDays(),
hours: 24 - toDay.hour(),
minutes: 60 - toDay.minute(),
seconds: 60 - toDay.second(),
});

}, 1000);
if (difference <= 0) {
clearInterval(updateTime);
setTimeBeforeChristmas({
days: 0,
hours: 0,
minutes: 0,
seconds: 0,
});
}
}, 1000);

return () => {
clearInterval(updateTime);
};
});

if (timeBeforeChristmas) {
timeBeforeChristmas.days = zeroInFrontOfNumber(timeBeforeChristmas.days);
timeBeforeChristmas.hours = zeroInFrontOfNumber(timeBeforeChristmas.hours);
timeBeforeChristmas.minutes = zeroInFrontOfNumber(timeBeforeChristmas.minutes);
timeBeforeChristmas.seconds = zeroInFrontOfNumber(timeBeforeChristmas.seconds);
}
return () => {
clearInterval(updateTime);
};
});

if (timeBeforeChristmas) {
timeBeforeChristmas.days = zeroInFrontOfNumber(timeBeforeChristmas.days);
timeBeforeChristmas.hours = zeroInFrontOfNumber(timeBeforeChristmas.hours);
timeBeforeChristmas.minutes = zeroInFrontOfNumber(
timeBeforeChristmas.minutes,
);
timeBeforeChristmas.seconds = zeroInFrontOfNumber(
timeBeforeChristmas.seconds,
);
}

/**
* Used to set 0 before a number if the number is small the 10
*
* @param {(number | string)} number
* @returns {string}
* ```js
* // Examples:
* // If the number is smaller then 10
* let number: string = "7";
* number = zeroInFrontOfNumber(number); //07
*
* // If the number is bigger then 10
* let number: string = "11"
* number = zeroInFrontOfNumber(number); //11
* ```
*/
function zeroInFrontOfNumber(number: number | string): string {
if (+number < 10) {
return "0" + +number;
}
return number.toString();
/**
* Used to set 0 before a number if the number is small the 10
*
* @param {(number | string)} number
* @returns {string}
* ```js
* // Examples:
* // If the number is smaller then 10
* let number: string = "7";
* number = zeroInFrontOfNumber(number); //07
*
* // If the number is bigger then 10
* let number: string = "11"
* number = zeroInFrontOfNumber(number); //11
* ```
*/
function zeroInFrontOfNumber(number: number | string): string {
if (+number < 10) {
return "0" + +number;
}
return number.toString();
}

return (

<div className="grid grid-cols-2 gap-4 py-6 px-10 md:flex md:items-center md:justify-between md:mt-2 rounded-xl md:px-6 md:py-8">
<NumberBox num={timeBeforeChristmas?.days ?? 0} unit="Days" />
<span className=" hidden text-5xl -mt-8 md:inline-block md:text-7xl font-normal text-gray-600 dark:text-gray-50">:</span>
<NumberBox num={timeBeforeChristmas?.hours ?? 0} unit="Hours" />
<span className="hidden text-5xl -mt-8 md:inline-block md:text-7xl font-normal text-gray-600 dark:text-gray-50">:</span>
<NumberBox num={timeBeforeChristmas?.minutes ?? 0} unit="Minutes" />
<span className="hidden text-5xl -mt-8 md:inline-block md:text-7xl font-normal text-gray-600 dark:text-gray-50">:</span>
<NumberBox num={timeBeforeChristmas?.seconds ?? 0} unit="Seconds" />
</div>

);
}
return (
<div className="grid grid-cols-2 gap-4 rounded-xl px-10 py-6 md:mt-2 md:flex md:items-center md:justify-between md:px-6 md:py-8">
<NumberBox num={timeBeforeChristmas?.days ?? 0} unit="Days" />
<span className=" -mt-8 hidden text-5xl font-normal text-gray-600 dark:text-gray-50 md:inline-block md:text-7xl">
:
</span>
<NumberBox num={timeBeforeChristmas?.hours ?? 0} unit="Hours" />
<span className="-mt-8 hidden text-5xl font-normal text-gray-600 dark:text-gray-50 md:inline-block md:text-7xl">
:
</span>
<NumberBox num={timeBeforeChristmas?.minutes ?? 0} unit="Minutes" />
<span className="-mt-8 hidden text-5xl font-normal text-gray-600 dark:text-gray-50 md:inline-block md:text-7xl">
:
</span>
<NumberBox num={timeBeforeChristmas?.seconds ?? 0} unit="Seconds" />
</div>
);
}
49 changes: 24 additions & 25 deletions src/components/countdown/NumberBox.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
interface Props {
num: string | number;
unit: string;
};

num: string | number;
unit: string;
}

/**
* NumberBox component used for display numbers in the countdown
* @param {string | number} num The number you wish to be displayed
* @param {string} unit The unit you wish to be displayed. Can fx. be "Days".
*
*
* ```js
* // Can be used like this:
* <NumberBox num={24} unit="Days"/>
* ```
*/
export default function NumberBox(props: Props) {
return (
<div className="flex flex-col items-center mt-4 px-2">
<div className=" relative bg-transparent flex flex-col items-center justify-center rounded-lg w-32 h-32 text-2xl md:text-4xl mt-4 ">
<div className="rounded-t-lg rounded-b-lg bg-[#343650] w-full h-full" />

<div className={`text-5xl absolute text-rose-500 z-10 font-bold font-redhat md:text-7xl font-mono`}>
{props.num}
</div>
return (
<div className="mt-4 flex flex-col items-center px-2">
<div className=" relative mt-4 flex h-32 w-32 flex-col items-center justify-center rounded-lg bg-transparent text-2xl md:text-4xl ">
<div className="h-full w-full rounded-b-lg rounded-t-lg bg-[#343650]" />

<div className=" rounded-b-lg rounded-t-lg bg-[#2c2e3f] w-full h-full" />
<div
className={`font-mono absolute z-10 font-redhat text-5xl font-bold text-rose-500 md:text-7xl`}
>
{props.num}
</div>

<div className={`absolute w-full h-1/2 top-0 rounded-t-lg z-5`} />
{/* Two Small Dots */}
<div className="absolute -right-1 top-[60px] rounded-full w-[12px] h-[12px] bg-[#1e1f29]" />
<div className="absolute -left-1 top-[60px] rounded-full w-[12px] h-[12px] bg-[#1e1f29]" />
<div className=" h-full w-full rounded-b-lg rounded-t-lg bg-[#2c2e3f]" />

</div>
<p className="text-lg mt-3 font-semibold text-black dark:text-rose-200 md:text-2xl ">
{props.unit}
</p>
</div>
);
<div className={`z-5 absolute top-0 h-1/2 w-full rounded-t-lg`} />
{/* Two Small Dots */}
<div className="absolute -right-1 top-[60px] h-[12px] w-[12px] rounded-full bg-[#1e1f29]" />
<div className="absolute -left-1 top-[60px] h-[12px] w-[12px] rounded-full bg-[#1e1f29]" />
</div>
<p className="mt-3 text-lg font-semibold text-black dark:text-rose-200 md:text-2xl ">
{props.unit}
</p>
</div>
);
}

Loading

0 comments on commit ebb4dc3

Please sign in to comment.