Non-Functional Calender Nav and Days of The Week #8
@@ -1,41 +0,0 @@
|
||||
import React from "react";
|
||||
import { Box, SimpleGrid } from "@chakra-ui/react";
|
||||
import { endOfMonth, getDate } from "date-fns";
|
||||
|
||||
const Calender = (): JSX.Element => {
|
||||
const today = new Date();
|
||||
|
||||
const endOfCurrMonth = endOfMonth(today);
|
||||
const lastDay = getDate(endOfCurrMonth);
|
||||
|
||||
// console.info(`This month has ${lastDay} days.`);
|
||||
|
||||
const daysArr = [];
|
||||
for (let i = daysArr.length; i < lastDay; i++) {
|
||||
daysArr.push(daysArr.length + 1);
|
||||
}
|
||||
return (
|
||||
<SimpleGrid
|
||||
px={6}
|
||||
spacing={2}
|
||||
// bg="brand.main"
|
||||
w="100%"
|
||||
h="100vh"
|
||||
columns={7}
|
||||
>
|
||||
{daysArr.map((day) => {
|
||||
return (
|
||||
<Box
|
||||
bg="transparent"
|
||||
border="2px solid #0068ff"
|
||||
w="100%"
|
||||
h="100%"
|
||||
key={day}
|
||||
>{`Day ${day}`}</Box>
|
||||
);
|
||||
})}
|
||||
</SimpleGrid>
|
||||
);
|
||||
};
|
||||
|
||||
export default Calender;
|
||||
106
components/calender/Calender.tsx
Normal file
106
components/calender/Calender.tsx
Normal file
@@ -0,0 +1,106 @@
|
||||
import React from "react";
|
||||
import { Box, HStack, SimpleGrid, Text, VStack } from "@chakra-ui/react";
|
||||
import { endOfMonth, getDate } from "date-fns";
|
||||
import CalenderNav from "./CalenderNav";
|
||||
|
||||
const Calender = (): JSX.Element => {
|
||||
const today = new Date();
|
||||
|
||||
const endOfCurrMonth = endOfMonth(today);
|
||||
const lastDay = getDate(endOfCurrMonth);
|
||||
|
||||
// console.info(`This month has ${lastDay} days.`);
|
||||
|
||||
const daysOfMonth = [];
|
||||
for (let i = daysOfMonth.length; i < lastDay; i++) {
|
||||
daysOfMonth.push(daysOfMonth.length + 1);
|
||||
}
|
||||
|
||||
const daysOfWeek = {
|
||||
Sunday: [
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
],
|
||||
Monday: [
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
"Sunday",
|
||||
],
|
||||
};
|
||||
|
||||
const userSettings = {
|
||||
theme: "default",
|
||||
startOfWeek: "Sunday",
|
||||
};
|
||||
|
||||
return (
|
||||
<VStack h="100vh" w="100%">
|
||||
<CalenderNav />
|
||||
<HStack
|
||||
px={6}
|
||||
spacing={2}
|
||||
// bg="brand.main"
|
||||
w="100%"
|
||||
h="auto"
|
||||
alignContent="center"
|
||||
alignItems="center"
|
||||
>
|
||||
{daysOfWeek[userSettings.startOfWeek].map((weekDay) => {
|
||||
return (
|
||||
<Box
|
||||
d="flex"
|
||||
alignContent="center"
|
||||
alignItems="center"
|
||||
bg="transparent"
|
||||
border="2px solid #0068ff"
|
||||
w="100%"
|
||||
h={10}
|
||||
key={weekDay}
|
||||
>
|
||||
<Text w="100%" h="auto">
|
||||
{weekDay}
|
||||
</Text>
|
||||
</Box>
|
||||
);
|
||||
})}
|
||||
</HStack>
|
||||
<SimpleGrid
|
||||
px={6}
|
||||
spacing={2}
|
||||
// bg="brand.main"
|
||||
w="100%"
|
||||
h="100%"
|
||||
columns={7}
|
||||
// alignContent="center"
|
||||
alignItems="center"
|
||||
>
|
||||
{daysOfMonth.map((monthDay) => {
|
||||
return (
|
||||
<Box
|
||||
bg="transparent"
|
||||
border="2px solid #0068ff"
|
||||
w="100%"
|
||||
h="100%"
|
||||
key={monthDay}
|
||||
>
|
||||
<Text w="100%" h="100%">
|
||||
{`Day ${monthDay}`}
|
||||
</Text>
|
||||
</Box>
|
||||
);
|
||||
})}
|
||||
</SimpleGrid>
|
||||
</VStack>
|
||||
);
|
||||
};
|
||||
|
||||
export default Calender;
|
||||
28
components/calender/CalenderNav.tsx
Normal file
28
components/calender/CalenderNav.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import React from "react";
|
||||
import { Heading, HStack, IconButton } from "@chakra-ui/react";
|
||||
import { Icon } from "@iconify/react";
|
||||
import { format } from "date-fns";
|
||||
|
||||
const CalenderNav = (): JSX.Element => {
|
||||
const today = new Date();
|
||||
|
||||
const currentMonth = format(today, "LLLL uuuu");
|
||||
|
||||
return (
|
||||
<HStack spacing={10} as="nav" w="auto" h="10vh" textAlign="center">
|
||||
<IconButton
|
||||
aria-label="Previous Month"
|
||||
icon={<Icon icon="akar-icons:chevron-left" />}
|
||||
/>
|
||||
<Heading w="100%" h="auto">
|
||||
{currentMonth}
|
||||
</Heading>
|
||||
<IconButton
|
||||
aria-label="Next Month"
|
||||
icon={<Icon icon="akar-icons:chevron-right" />}
|
||||
/>
|
||||
</HStack>
|
||||
);
|
||||
};
|
||||
|
||||
export default CalenderNav;
|
||||
@@ -19,7 +19,6 @@
|
||||
"@chakra-ui/react": "^1.7.2",
|
||||
"@emotion/react": "^11.6.0",
|
||||
"@emotion/styled": "^11.6.0",
|
||||
"@iconify/react": "^3.1.0",
|
||||
"@types/react": "^17.0.37",
|
||||
"date-fns": "^2.26.0",
|
||||
"framer-motion": "^5.3.3",
|
||||
@@ -29,6 +28,7 @@
|
||||
"sharp": "^0.29.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@iconify/react": "^3.1.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
||||
"eslint": "<8.0.0",
|
||||
"eslint-config-next": "12.0.3",
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
import React from "react";
|
||||
import { Box, Heading } from "@chakra-ui/react";
|
||||
import Calender from "../component/calender";
|
||||
import { Box } from "@chakra-ui/react";
|
||||
import Calender from "../components/calender/Calender";
|
||||
|
||||
const IndexPage = (): JSX.Element => {
|
||||
return (
|
||||
<Box textAlign="center" w="100%" h="auto" pt="50px" pb="10vh">
|
||||
{Calender ? (
|
||||
<Calender />
|
||||
) : (
|
||||
<Heading as="h1" size="2xl">
|
||||
Hello World
|
||||
</Heading>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user