generated from Luis/nextjs-python-web-template
added custom table component
This commit is contained in:
@@ -47,9 +47,9 @@ export default function RootLayout({
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Clan.lol</title>
|
||||
<title>Service-Aware Networks</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="description" content="Clan.lol - build your own network" />
|
||||
<meta name="description" content="Service-Aware Networks" />
|
||||
<link rel="icon" href="favicon.ico" sizes="any" />
|
||||
</head>
|
||||
<StyledEngineProvider injectFirst>
|
||||
@@ -72,8 +72,7 @@ export default function RootLayout({
|
||||
onClose={() => setShowSidebar(false)}
|
||||
/>
|
||||
<div
|
||||
className={tw`${
|
||||
!showSidebarDerived && translate
|
||||
className={tw`${!showSidebarDerived && translate
|
||||
} flex h-full w-full flex-col overflow-y-scroll transition-[margin] duration-150 ease-in-out`}
|
||||
>
|
||||
<div className="static top-0 mb-2 py-2">
|
||||
@@ -89,7 +88,7 @@ export default function RootLayout({
|
||||
<div className="col-span-1 block w-full bg-fixed text-center font-semibold dark:invert lg:hidden">
|
||||
<Image
|
||||
src="/favicon.png"
|
||||
alt="Clan Logo"
|
||||
alt="TUB Logo"
|
||||
width={58}
|
||||
height={58}
|
||||
priority
|
||||
|
||||
@@ -10,7 +10,7 @@ export default function Dashboard() {
|
||||
<div className="grid h-full place-items-center">
|
||||
<div className="mt-8 w-full max-w-xl">
|
||||
<LoadingOverlay
|
||||
title="Clan Experience"
|
||||
title="Service-Aware Networks"
|
||||
subtitle="Loading"
|
||||
variant="circle"
|
||||
/>
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
createTheme,
|
||||
} from "@mui/material/styles";
|
||||
|
||||
import colors from "@clan/colors/colors.json";
|
||||
import colors from "../../../../theme/src/colors.json";
|
||||
const { palette, common } = colors.ref;
|
||||
|
||||
const commonOptions: Partial<ThemeOptions> = {
|
||||
@@ -46,8 +46,8 @@ export const darkTheme = createTheme({
|
||||
mode: "dark",
|
||||
...commonPalette,
|
||||
background: {
|
||||
default: palette.neutral2.value,
|
||||
paper: palette.neutral5.value,
|
||||
default: palette.neutral20.value,
|
||||
paper: palette.neutral50.value,
|
||||
},
|
||||
common: {
|
||||
black: common.black.value,
|
||||
|
||||
@@ -8,13 +8,17 @@ import {
|
||||
ListItemText,
|
||||
} from "@mui/material";
|
||||
import Image from "next/image";
|
||||
import { ReactNode } from "react";
|
||||
import React, { ReactNode } from "react";
|
||||
|
||||
import { tw } from "@/utils/tailwind";
|
||||
import AssignmentIndIcon from "@mui/icons-material/AssignmentInd";
|
||||
|
||||
import Link from "next/link";
|
||||
import WysiwygIcon from "@mui/icons-material/Wysiwyg";
|
||||
import ChevronLeftIcon from "@mui/icons-material/ChevronLeft";
|
||||
import HomeIcon from '@mui/icons-material/Home';
|
||||
import HubIcon from '@mui/icons-material/Hub';
|
||||
import PersonIcon from '@mui/icons-material/Person';
|
||||
import RouterIcon from '@mui/icons-material/Router';
|
||||
import StorageIcon from '@mui/icons-material/Storage';
|
||||
|
||||
type MenuEntry = {
|
||||
icon: ReactNode;
|
||||
@@ -27,17 +31,41 @@ type MenuEntry = {
|
||||
|
||||
const menuEntries: MenuEntry[] = [
|
||||
{
|
||||
icon: <AssignmentIndIcon />,
|
||||
label: "Freelance",
|
||||
icon: <HomeIcon />,
|
||||
label: "Home",
|
||||
to: "/",
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
icon: <WysiwygIcon />,
|
||||
label: "Blog",
|
||||
to: "/blog",
|
||||
icon: <HubIcon />,
|
||||
label: "Entities",
|
||||
to: "/entities",
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
icon: <PersonIcon />,
|
||||
label: "C1",
|
||||
to: "/client-1",
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
icon: <PersonIcon />,
|
||||
label: "C2",
|
||||
to: "/client-2",
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
icon: <RouterIcon />,
|
||||
label: "AP",
|
||||
to: "/access-point",
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
icon: <StorageIcon />,
|
||||
label: "DLG",
|
||||
to: "/distributed-ledger-gateway",
|
||||
disabled: false,
|
||||
}
|
||||
];
|
||||
|
||||
const hideSidebar = tw`-translate-x-14 lg:-translate-x-64`;
|
||||
@@ -50,17 +78,22 @@ interface SidebarProps {
|
||||
export function Sidebar(props: SidebarProps) {
|
||||
const { show, onClose } = props;
|
||||
|
||||
const [activeMenuItem, setActiveMenuItem] = React.useState('/');
|
||||
|
||||
const handleMenuItemClick = (path: string) => {
|
||||
setActiveMenuItem(path);
|
||||
};
|
||||
|
||||
return (
|
||||
<aside
|
||||
className={tw`${
|
||||
show ? showSidebar : hideSidebar
|
||||
className={tw`${show ? showSidebar : hideSidebar
|
||||
} z-9999 static left-0 top-0 flex h-screen w-14 flex-col overflow-x-hidden overflow-y-hidden bg-neutral-10 transition duration-150 ease-in-out dark:bg-neutral-2 lg:w-64`}
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2 overflow-hidden px-0 py-5 lg:p-6">
|
||||
<div className="mt-8 hidden w-full text-center font-semibold text-white lg:block">
|
||||
<Image
|
||||
src="/logo.png"
|
||||
alt="Clan Logo"
|
||||
alt="TUB Logo"
|
||||
width={75}
|
||||
height={75}
|
||||
priority
|
||||
@@ -90,6 +123,8 @@ export function Sidebar(props: SidebarProps) {
|
||||
LinkComponent={Link}
|
||||
href={menuEntry.to}
|
||||
disabled={menuEntry.disabled}
|
||||
selected={activeMenuItem === menuEntry.to}
|
||||
onClick={() => handleMenuItemClick(menuEntry.to)}
|
||||
>
|
||||
<ListItemIcon
|
||||
color="inherit"
|
||||
|
||||
66
pkgs/ui/src/components/table/index.tsx
Normal file
66
pkgs/ui/src/components/table/index.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
import React from "react";
|
||||
import Table from '@mui/material/Table';
|
||||
import TableBody from '@mui/material/TableBody';
|
||||
import TableContainer from '@mui/material/TableContainer';
|
||||
import TableHead from '@mui/material/TableHead';
|
||||
import TableRow from '@mui/material/TableRow';
|
||||
import Paper from '@mui/material/Paper';
|
||||
|
||||
import { NoDataOverlay } from "@/components/noDataOverlay";
|
||||
import { StyledTableCell, StyledTableRow } from "./style";
|
||||
import { CustomTableConfiguration, ICustomTable } from "@/types";
|
||||
|
||||
const CustomTable = ({ configuration, data }: ICustomTable) => {
|
||||
|
||||
// display empty icon in case there is no data
|
||||
if (!data || data.length === 0)
|
||||
return <NoDataOverlay label="No Activity yet" />
|
||||
|
||||
const renderTableCell = (value: any, cellKey: string, render?: (param: any) => void | undefined) => {
|
||||
|
||||
let renderedValue = value;
|
||||
|
||||
// cover use case if the data is an array
|
||||
if (Array.isArray(value)) renderedValue = value.join(', ')
|
||||
|
||||
// cover use case if we want to render a component
|
||||
if (render) renderedValue = render(value);
|
||||
|
||||
return (
|
||||
<StyledTableCell key={cellKey} align="left">
|
||||
{renderedValue}
|
||||
</StyledTableCell>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
<TableContainer component={Paper}>
|
||||
<Table sx={{ minWidth: 700 }} aria-label="customized table">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
{configuration.map((header: CustomTableConfiguration) => (
|
||||
<StyledTableCell key={header.key}>
|
||||
{header.label}
|
||||
</StyledTableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{data.map((data: any, rowIndex: number) => (
|
||||
<StyledTableRow key={rowIndex}>
|
||||
{configuration.map((column: CustomTableConfiguration) => {
|
||||
const cellValue: any = data[column.key];
|
||||
const cellKey = column.key;
|
||||
const renderComponent = column?.render;
|
||||
return renderTableCell(cellValue, cellKey, renderComponent);
|
||||
})}
|
||||
</StyledTableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
)
|
||||
}
|
||||
|
||||
export default CustomTable;
|
||||
23
pkgs/ui/src/components/table/style.tsx
Normal file
23
pkgs/ui/src/components/table/style.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import { styled } from '@mui/material/styles';
|
||||
import TableCell, { tableCellClasses } from '@mui/material/TableCell';
|
||||
import TableRow from '@mui/material/TableRow';
|
||||
|
||||
export const StyledTableCell = styled(TableCell)(({ theme }) => ({
|
||||
[`&.${tableCellClasses.head}`]: {
|
||||
backgroundColor: theme.palette.common.black,
|
||||
color: theme.palette.common.white,
|
||||
},
|
||||
[`&.${tableCellClasses.body}`]: {
|
||||
fontSize: 14,
|
||||
},
|
||||
}));
|
||||
|
||||
export const StyledTableRow = styled(TableRow)(({ theme }) => ({
|
||||
'&:nth-of-type(odd)': {
|
||||
backgroundColor: theme.palette.action.hover,
|
||||
},
|
||||
// hide last border
|
||||
'&:last-child td, &:last-child th': {
|
||||
border: 0,
|
||||
},
|
||||
}));
|
||||
10
pkgs/ui/src/types/index.ts
Normal file
10
pkgs/ui/src/types/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface CustomTableConfiguration {
|
||||
key: string;
|
||||
label: string;
|
||||
render?: (param: any) => void;
|
||||
}
|
||||
|
||||
export interface ICustomTable {
|
||||
configuration: CustomTableConfiguration[],
|
||||
data: any
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
import colors from "@clan/colors/colors.json";
|
||||
// import colors from "../theme/src/colors.json";
|
||||
|
||||
const {
|
||||
ref: { palette, common },
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
@@ -21,10 +25,21 @@
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./src/*"],
|
||||
"@API/*": ["./src/api/*"]
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
],
|
||||
"@API/*": [
|
||||
"./src/api/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user