diff --git a/docs/app/components/server/table/description.md b/docs/app/components/server/table/description.md new file mode 100644 index 0000000000..6354b455bf --- /dev/null +++ b/docs/app/components/server/table/description.md @@ -0,0 +1 @@ +A component for displaying large amounts of data in rows and columns. diff --git a/docs/app/components/server/table/examples/Default.tsx b/docs/app/components/server/table/examples/Default.tsx new file mode 100644 index 0000000000..e83fd6225e --- /dev/null +++ b/docs/app/components/server/table/examples/Default.tsx @@ -0,0 +1,25 @@ +import Table from '@heathmont/moon-base-tw/lib/table/Table'; + +export const Default = () => ( + + + + Header 1 + Header 2 + Header 3 + + + + + Cell 1 + Cell 2 + Cell 3 + + + Cell 1 + Cell 2 + Cell 3 + + +
+); diff --git a/docs/app/components/server/table/page.tsx b/docs/app/components/server/table/page.tsx new file mode 100644 index 0000000000..a53d5609ed --- /dev/null +++ b/docs/app/components/server/table/page.tsx @@ -0,0 +1,22 @@ +import { Default } from '@/app/components/server/table/examples/Default'; +import ExampleSection from '@/app/components/shared/ExampleSection'; +import QuickNav from '@/app/components/shared/QuickNav'; +import { getExamples } from '@/app/utils/getExamples'; +import { MDX } from '@/components/MDX'; + +export default async function Table() { + const { server } = await getExamples(); + const examplesList = Object.keys(server.table.examples); + return ( +
+

Table

+ + + } + code={server.table.examples.Default} + /> +
+ ); +} diff --git a/docs/app/components/shared/CodePreview.tsx b/docs/app/components/shared/CodePreview.tsx index 2e5d83169f..93ada9ecff 100644 --- a/docs/app/components/shared/CodePreview.tsx +++ b/docs/app/components/shared/CodePreview.tsx @@ -1,5 +1,5 @@ const CodePreview = ({ code }: { code: string }) => ( -
+  
     {code}
   
); diff --git a/docs/app/components/types.ts b/docs/app/components/types.ts index ec466cf036..2e26dc47ab 100644 --- a/docs/app/components/types.ts +++ b/docs/app/components/types.ts @@ -72,6 +72,12 @@ export interface Examples { Default: 'string'; }; }; + table: { + description: 'string'; + examples: { + Default: 'string'; + }; + }; tag: { description: 'string'; examples: { diff --git a/workspaces/base/src/table/Table.tsx b/workspaces/base/src/table/Table.tsx index cf87fd0ff8..17cecad638 100644 --- a/workspaces/base/src/table/Table.tsx +++ b/workspaces/base/src/table/Table.tsx @@ -1,31 +1,9 @@ import React from 'react'; +import type Props from './private/types/Props'; +import type TableProps from './private/types/TableProps'; +import getSize from './private/utils/getSize'; import mergeClassnames from '../mergeClassnames/mergeClassnames'; -type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'; -type TableProps = { - className?: string; - children?: React.ReactNode; - size?: Size; -}; - -const getSize = (size?: Size) => { - switch (size) { - case 'xs': - return '[&_td]:px-2 [&_td]:py-1 [&_td]:text-moon-12 [&_th]:px-2 [&_th]:py-1 [&_th]:text-moon-12'; - case 'sm': - return '[&_td]:px-3 [&_td]:py-1 [&_td]:text-moon-14 [&_th]:px-3 [&_th]:py-1 [&_th]:text-moon-14'; - case 'lg': - return '[&_td]:px-3 [&_td]:py-3 [&_td]:text-moon-14 [&_th]:px-3 [&_th]:py-3 [&_th]:text-moon-14'; - case 'xl': - return '[&_td]:px-3 [&_td]:py-4 [&_td]:text-moon-14 [&_th]:px-3 [&_th]:py-4 [&_th]:text-moon-14'; - case '2xl': - return '[&_td]:px-3 [&_td]:py-5 [&_td]:text-moon-14 [&_th]:px-3 [&_th]:py-5 [&_th]:text-moon-14'; - case 'md': - default: - return '[&_td]:px-3 [&_td]:py-2 [&_td]:text-moon-14 [&_th]:px-3 [&_th]:py-2 [&_th]:text-moon-14'; - } -}; - const TableRoot = ({ children, className, size, ...props }: TableProps) => ( (
); -type BodyProps = { - className?: string; - children?: React.ReactNode; -}; - -const Body = ({ children, className, ...props }: BodyProps) => ( +const Body = ({ children, className, ...props }: Props) => ( {children} ); -type HeadProps = { - className?: string; - children?: React.ReactNode; -}; - -const Head = ({ children, className, ...props }: HeadProps) => ( +const Head = ({ children, className, ...props }: Props) => ( {children} ); -type RowProps = { - className?: string; - children?: React.ReactNode; -}; - -const Row = ({ children, className, ...props }: RowProps) => ( +const Row = ({ children, className, ...props }: Props) => ( {children} ); -type HeaderProps = { - className?: string; - children?: React.ReactNode; -}; - -const Header = ({ children, className, ...props }: HeaderProps) => ( +const Header = ({ children, className, ...props }: Props) => ( ( ); -type CellProps = { - className?: string; - children?: React.ReactNode; -}; - -const Cell = ({ children, className, ...props }: CellProps) => ( +const Cell = ({ children, className, ...props }: Props) => ( diff --git a/workspaces/base/src/table/private/types/Props.ts b/workspaces/base/src/table/private/types/Props.ts new file mode 100644 index 0000000000..d916a547cb --- /dev/null +++ b/workspaces/base/src/table/private/types/Props.ts @@ -0,0 +1,6 @@ +type Props = { + className?: string; + children?: React.ReactNode; +}; + +export default Props; diff --git a/workspaces/base/src/table/private/types/Size.ts b/workspaces/base/src/table/private/types/Size.ts new file mode 100644 index 0000000000..484d7c3b3b --- /dev/null +++ b/workspaces/base/src/table/private/types/Size.ts @@ -0,0 +1,3 @@ +type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'; + +export default Size; diff --git a/workspaces/base/src/table/private/types/TableProps.ts b/workspaces/base/src/table/private/types/TableProps.ts new file mode 100644 index 0000000000..557aab10a4 --- /dev/null +++ b/workspaces/base/src/table/private/types/TableProps.ts @@ -0,0 +1,8 @@ +import type Props from './Props'; +import type Size from './Size'; + +type TableProps = Props & { + size?: Size; +}; + +export default TableProps; diff --git a/workspaces/base/src/table/private/utils/getSize.ts b/workspaces/base/src/table/private/utils/getSize.ts new file mode 100644 index 0000000000..769c3aea67 --- /dev/null +++ b/workspaces/base/src/table/private/utils/getSize.ts @@ -0,0 +1,21 @@ +import type Size from '../types/Size'; + +const getSize = (size?: Size) => { + switch (size) { + case 'xs': + return '[&_td]:px-2 [&_td]:py-1 [&_td]:text-moon-12 [&_th]:px-2 [&_th]:py-1 [&_th]:text-moon-12'; + case 'sm': + return '[&_td]:px-3 [&_td]:py-1 [&_td]:text-moon-14 [&_th]:px-3 [&_th]:py-1 [&_th]:text-moon-14'; + case 'lg': + return '[&_td]:px-3 [&_td]:py-3 [&_td]:text-moon-14 [&_th]:px-3 [&_th]:py-3 [&_th]:text-moon-14'; + case 'xl': + return '[&_td]:px-3 [&_td]:py-4 [&_td]:text-moon-14 [&_th]:px-3 [&_th]:py-4 [&_th]:text-moon-14'; + case '2xl': + return '[&_td]:px-3 [&_td]:py-5 [&_td]:text-moon-14 [&_th]:px-3 [&_th]:py-5 [&_th]:text-moon-14'; + case 'md': + default: + return '[&_td]:px-3 [&_td]:py-2 [&_td]:text-moon-14 [&_th]:px-3 [&_th]:py-2 [&_th]:text-moon-14'; + } +}; + +export default getSize;