From 947337acb1b898d800cb1cc9aef05b85dda216b5 Mon Sep 17 00:00:00 2001 From: Vivian Phung Date: Mon, 13 May 2024 15:28:24 -0400 Subject: [PATCH] table basic component --- .../components/shared/Table/Table.theme.ts | 35 ++++++++ .../src/components/shared/Table/Table.tsx | 81 +++++++++++-------- 2 files changed, 83 insertions(+), 33 deletions(-) create mode 100644 packages/frontend/src/components/shared/Table/Table.theme.ts diff --git a/packages/frontend/src/components/shared/Table/Table.theme.ts b/packages/frontend/src/components/shared/Table/Table.theme.ts new file mode 100644 index 0000000..664433a --- /dev/null +++ b/packages/frontend/src/components/shared/Table/Table.theme.ts @@ -0,0 +1,35 @@ +interface ThemeProps { + base: string; + header: string; + row: string; + columnHeaderCell: string; + rowHeaderCell: string; + cell: string; +} + +const primaryTheme: ThemeProps = { + base: 'min-w-full border-collapse', + header: 'border-b border-sky-950/opacity-5 font-medium leading-tight', + row: 'border-b border-sky-950/opacity-5', + columnHeaderCell: + 'p-4 text-sky-950 text-sm font-medium uppercase tracking-wider text-left', + rowHeaderCell: + 'p-4 text-slate-600 text-sm font-normal leading-tight text-left', + cell: 'p-4 whitespace-nowrap text-sm text-slate-600 font-normal text-left', +}; + +const secondaryTheme: ThemeProps = { + base: 'min-w-full border-collapse', + header: + 'p-2 border-b border-sky-950/5 text-sky-950 text-sm font-medium leading-tight', + row: 'text-left border-b border-gray-300/50', + columnHeaderCell: + 'px-6 py-3 text-xs font-medium uppercase tracking-wider text-gray-800', + rowHeaderCell: 'px-6 py-4 font-medium whitespace-nowrap text-gray-800', + cell: 'px-6 py-4 whitespace-nowrap text-sm text-gray-600', +}; + +export const tableTheme = { + primary: primaryTheme, + secondary: secondaryTheme, +}; diff --git a/packages/frontend/src/components/shared/Table/Table.tsx b/packages/frontend/src/components/shared/Table/Table.tsx index 7f5fd5b..b04128f 100644 --- a/packages/frontend/src/components/shared/Table/Table.tsx +++ b/packages/frontend/src/components/shared/Table/Table.tsx @@ -1,45 +1,60 @@ import React from 'react'; +import { tableTheme } from './Table.theme'; -const Header: React.FC<{ children: React.ReactNode }> = ({ children }) => ( - {children} -); -const Body: React.FC<{ children: React.ReactNode }> = ({ children }) => ( - {children} -); -const Row: React.FC<{ children: React.ReactNode }> = ({ children }) => ( - {children} -); -const ColumnHeaderCell: React.FC<{ children: React.ReactNode }> = ({ - children, -}) => ( - - {children} - -); -const RowHeaderCell: React.FC<{ children: React.ReactNode }> = ({ - children, -}) => ( - - {children} - -); -const Cell: React.FC<{ children: React.ReactNode }> = ({ children }) => ( - - {children} - -); +type TableComponentProps = { + children: React.ReactNode; + variant?: keyof typeof tableTheme; +}; -const Table: React.FC<{ children: React.ReactNode }> & { +const useTheme = (variant: 'primary' | 'secondary' = 'primary') => + tableTheme[variant]; + +const Table: React.FC & { Header: typeof Header; Body: typeof Body; Row: typeof Row; ColumnHeaderCell: typeof ColumnHeaderCell; RowHeaderCell: typeof RowHeaderCell; Cell: typeof Cell; -} = ({ children }) => {children}
; +} = ({ children, variant = 'primary' }) => { + const theme = useTheme(variant); + return {children}
; +}; + +const Header: React.FC = ({ children, variant }) => { + const theme = useTheme(variant); + return {children}; +}; + +const Body: React.FC = ({ children }) => { + return {children}; +}; + +const Row: React.FC = ({ children, variant }) => { + const theme = useTheme(variant); + return {children}; +}; + +const ColumnHeaderCell: React.FC = ({ + children, + variant, +}) => { + const theme = useTheme(variant); + return {children}; +}; + +const RowHeaderCell: React.FC = ({ + children, + variant, +}) => { + const theme = useTheme(variant); + return {children}; +}; + +const Cell: React.FC = ({ children, variant }) => { + const theme = useTheme(variant); + return {children}; +}; Table.Header = Header; Table.Body = Body;