diff --git a/packages/frontend/src/components/shared/Table/Table.theme.ts b/packages/frontend/src/components/shared/Table/Table.theme.ts index 664433a6..1cbefd80 100644 --- a/packages/frontend/src/components/shared/Table/Table.theme.ts +++ b/packages/frontend/src/components/shared/Table/Table.theme.ts @@ -1,35 +1,49 @@ -interface ThemeProps { - base: string; - header: string; - row: string; - columnHeaderCell: string; - rowHeaderCell: string; - cell: string; -} +import { tv, VariantProps } from 'tailwind-variants'; -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', -}; +export const tableTheme = tv({ + slots: { + root: ['min-w-full', 'border-collapse'], + header: [ + 'p-2', + 'border-b', + 'border-sky-950/opacity-5', + 'text-sky-950', + 'text-sm', + 'font-medium', + 'leading-tight', + ], + body: [], + 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', + ], + }, + variants: {}, + defaultVariants: { + orientation: 'vertical', + }, +}); -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, -}; +export type TableTheme = VariantProps; diff --git a/packages/frontend/src/components/shared/Table/Table.tsx b/packages/frontend/src/components/shared/Table/Table.tsx index b04128f7..258676cc 100644 --- a/packages/frontend/src/components/shared/Table/Table.tsx +++ b/packages/frontend/src/components/shared/Table/Table.tsx @@ -3,12 +3,8 @@ import { tableTheme } from './Table.theme'; type TableComponentProps = { children: React.ReactNode; - variant?: keyof typeof tableTheme; }; -const useTheme = (variant: 'primary' | 'secondary' = 'primary') => - tableTheme[variant]; - const Table: React.FC & { Header: typeof Header; Body: typeof Body; @@ -16,44 +12,39 @@ const Table: React.FC & { ColumnHeaderCell: typeof ColumnHeaderCell; RowHeaderCell: typeof RowHeaderCell; Cell: typeof Cell; -} = ({ children, variant = 'primary' }) => { - const theme = useTheme(variant); - return {children}
; +} = ({ children }) => { + const theme = tableTheme(); + return {children}
; }; -const Header: React.FC = ({ children, variant }) => { - const theme = useTheme(variant); - return {children}; +const Header: React.FC = ({ children }) => { + const theme = tableTheme(); + return {children}; }; const Body: React.FC = ({ children }) => { - return {children}; + const theme = tableTheme(); + return {children}; }; -const Row: React.FC = ({ children, variant }) => { - const theme = useTheme(variant); - return {children}; +const Row: React.FC = ({ children }) => { + const theme = tableTheme(); + return {children}; }; -const ColumnHeaderCell: React.FC = ({ - children, - variant, -}) => { - const theme = useTheme(variant); - return {children}; +const ColumnHeaderCell: React.FC = ({ children }) => { + const theme = tableTheme(); + return {children}; }; -const RowHeaderCell: React.FC = ({ - children, - variant, -}) => { - const theme = useTheme(variant); - return {children}; +const RowHeaderCell: React.FC = ({ children }) => { + const theme = tableTheme(); + return {children}; }; -const Cell: React.FC = ({ children, variant }) => { - const theme = useTheme(variant); - return {children}; +const Cell: React.FC = ({ children }) => { + const theme = tableTheme(); + return {children}; }; Table.Header = Header;