Added TSdoc

This commit is contained in:
Sianida26 2024-01-22 01:01:20 +07:00
parent 2e01142689
commit 1cae4e924d
8 changed files with 76 additions and 34 deletions

View File

@ -1,19 +1,23 @@
import { AppShell, ScrollArea } from '@mantine/core' import React from 'react';
import React from 'react' import { AppShell, ScrollArea } from '@mantine/core';
import allMenu from './_data/allMenu'
import MenuItem from './_components/MenuItem'
import allMenu from "./_data/allMenu";
import MenuItem from "./_components/MenuItem";
/**
* `AppNavbar` is a React functional component that renders the application's navigation bar.
* It utilizes data from `allMenu` to create a list of menu items displayed in a scrollable area.
*
* @returns A React element representing the application's navigation bar.
*/
export default function AppNavbar() { export default function AppNavbar() {
const menus = allMenu.map((menu, i) => <MenuItem menu={menu} key={i} />) // Mapping all menu items to MenuItem components
const menus = allMenu.map((menu, i) => <MenuItem menu={menu} key={i} />);
return ( return (
<AppShell.Navbar p="md"> <AppShell.Navbar p="md">
<ScrollArea style={{flex: "1"}}> <ScrollArea style={{ flex: "1" }}>{menus}</ScrollArea>
<div> </AppShell.Navbar>
{menus} );
</div>
</ScrollArea>
</AppShell.Navbar>
)
} }

View File

@ -1,14 +1,22 @@
import { Text } from "@mantine/core";
import React from "react"; import React from "react";
import { Text } from "@mantine/core";
import classNames from "./childMenu.module.css"; import classNames from "./childMenu.module.css";
import { MenuItem } from "../_data/allMenu"; import { MenuItem } from "../../_data/allMenu";
import { isNotEmpty } from "@mantine/form";
interface Props { interface Props {
item: NonNullable<MenuItem["children"]>[number]; item: NonNullable<MenuItem["children"]>[number];
} }
/**
* `ChildMenu` is a React functional component that renders a child menu item.
* It displays the item as a text link.
*
* @param props - The component props.
* @param props.item - The child menu item data.
* @returns A React element representing a child menu item.
*/
export default function ChildMenu(props: Props) { export default function ChildMenu(props: Props) {
return ( return (
<Text<"a"> <Text<"a">

View File

@ -0,0 +1,3 @@
import ChildMenu from "./ChildMenu";
export default ChildMenu;

View File

@ -1,4 +1,5 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { import {
Box, Box,
Collapse, Collapse,
@ -7,16 +8,24 @@ import {
UnstyledButton, UnstyledButton,
rem, rem,
} from "@mantine/core"; } from "@mantine/core";
import { MenuItem } from "../_data/allMenu";
import { TbChevronRight } from "react-icons/tb"; import { TbChevronRight } from "react-icons/tb";
import { MenuItem } from "../../_data/allMenu";
import ChildMenu from "../ChildMenu/ChildMenu";
import classNames from "./menuItem.module.css"; import classNames from "./menuItem.module.css";
import ChildMenu from "./ChildMenu";
interface Props { interface Props {
menu: MenuItem; menu: MenuItem;
} }
/**
* `MenuItem` is a React functional component that displays an individual menu item.
* It can optionally include a collapsible sub-menu for items with children.
*
* @param props - The component props.
* @param props.menu - The menu item data to display.
* @returns A React element representing an individual menu item.
*/
export default function MenuItem({ menu }: Props) { export default function MenuItem({ menu }: Props) {
const hasChildren = Array.isArray(menu.children); const hasChildren = Array.isArray(menu.children);
@ -26,46 +35,50 @@ export default function MenuItem({ menu }: Props) {
setOpened((prev) => !prev); setOpened((prev) => !prev);
}; };
const subItems = (hasChildren ? menu.children! : []).map((child, i) => ( // Mapping children menu items if available
<ChildMenu key={i} item={child} /> const subItems = (hasChildren ? menu.children! : []).map((child, index) => (
<ChildMenu key={index} item={child} />
)); ));
return ( return (
<> <>
{/* Main Section */} {/* Main Menu Item */}
<UnstyledButton <UnstyledButton
onClick={toggleOpenMenu} onClick={toggleOpenMenu}
className={classNames.control} className={classNames.control}
> >
<Group justify="space-between" gap={0}> <Group justify="space-between" gap={0}>
{/* Left Section */}
{/* Icon and Label */}
<Box style={{ display: "flex", alignItems: "center" }}> <Box style={{ display: "flex", alignItems: "center" }}>
{/* Icon */}
<ThemeIcon variant="light" size={30} color={menu.color}> <ThemeIcon variant="light" size={30} color={menu.color}>
<menu.icon <menu.icon
style={{ width: rem(18), height: rem(18) }} style={{ width: rem(18), height: rem(18) }}
/> />
</ThemeIcon> </ThemeIcon>
{/* Label */}
<Box ml="md">{menu.label}</Box> <Box ml="md">{menu.label}</Box>
</Box> </Box>
{/* Right Section (Chevron if available) */} {/* Chevron Icon for collapsible items */}
{hasChildren && ( {hasChildren && (
<TbChevronRight <TbChevronRight
// stroke="1.5" strokeWidth={1.5}
style={{ style={{
width: rem(16), width: rem(16),
height: rem(16), height: rem(16),
transform: opened ? "rotate(-90deg)" : "rotate(90deg)", transform: opened
? "rotate(-90deg)"
: "rotate(90deg)",
}} }}
className={classNames.chevron} className={classNames.chevron}
/> />
)} )}
</Group> </Group>
</UnstyledButton> </UnstyledButton>
{hasChildren ? <Collapse in={opened}>{subItems}</Collapse> : null}
{/* Collapsible Sub-Menu */}
{hasChildren && <Collapse in={opened}>{subItems}</Collapse>}
</> </>
); );
} }

View File

@ -0,0 +1,3 @@
import MenuItem from "./MenuItem";
export default MenuItem;

View File

@ -1,16 +1,25 @@
"use client"; "use client";
import React from "react"; import React from "react";
import { AppShell, AppShellHeader, Burger } from "@mantine/core"; import { AppShell } from "@mantine/core";
import { useDisclosure } from "@mantine/hooks";
import AppHeader from "../AppHeader"; import AppHeader from "../AppHeader";
import AppNavbar from "../AppNavbar"; import AppNavbar from "../AppNavbar";
import { useDisclosure } from "@mantine/hooks";
interface Props { interface Props {
children: React.ReactNode; children: React.ReactNode;
} }
/**
* `DashboardLayout` is a React functional component that provides a layout structure
* for the dashboard, including a header, navigation bar, and main content area.
*
* @param props - The component props.
* @param props.children - The child components to be rendered inside the layout.
* @returns A React element representing the dashboard layout.
*/
export default function DashboardLayout(props: Props) { export default function DashboardLayout(props: Props) {
// State and toggle function for handling the disclosure of the navigation bar
const [openNavbar, { toggle }] = useDisclosure(false); const [openNavbar, { toggle }] = useDisclosure(false);
return ( return (
@ -29,7 +38,9 @@ export default function DashboardLayout(props: Props) {
{/* Navbar */} {/* Navbar */}
<AppNavbar /> <AppNavbar />
<AppShell.Main>{props.children}</AppShell.Main> <AppShell.Main className="bg-slate-100">
{props.children}
</AppShell.Main>
</AppShell> </AppShell>
); );
} }