import {createComponent} from '@workday/canvas-kit-react/common';
import {FlexProps, GridProps, mergeStyles} from '@workday/canvas-kit-react/layout';
import {createStencil, px2rem} from '@workday/canvas-kit-styling';
import {system} from '@workday/canvas-tokens-web';
import {baseTableStencil} from './BaseTable';
import {baseTableBodyStencil} from './parts/BaseTableBody';
import {baseTableCaptionStencil} from './parts/BaseTableCaption';
import {baseTableCellStencil} from './parts/BaseTableCell';
import {baseTableHeadStencil} from './parts/BaseTableHead';
import {baseTableHeaderStencil} from './parts/BaseTableHeader';
import {TableRow} from './parts/css-grid-table/TableRow';
export interface TableProps extends GridProps {}
export const tableStencil = createStencil({
extends: baseTableStencil,
base: {
display: 'grid',
},
});
export const tableBodyStencil = createStencil({
extends: baseTableBodyStencil,
base: {
display: 'grid',
},
});
export const tableCaptionStencil = createStencil({
extends: baseTableCaptionStencil,
base: {
display: 'flex',
borderBlockEnd: `${px2rem(1)} solid ${system.legacy.color.border.default}`,
},
});
export const tableCellStencil = createStencil({
extends: baseTableCellStencil,
base: {
display: 'grid',
},
});
export const tableFooterStencil = createStencil({
base: {
display: 'grid',
},
});
export const tableHeadStencil = createStencil({
extends: baseTableHeadStencil,
base: {
display: 'grid',
},
});
export const tableHeaderStencil = createStencil({
extends: baseTableHeaderStencil,
base: {
display: 'grid',
alignItems: 'center',
},
});
export const TableBody = createComponent('tbody')({
displayName: 'Table.Body',
Component: ({children, ...elemProps}: GridProps, ref, Element) => {
return (
{children}
);
},
});
export const TableCaption = createComponent('caption')({
displayName: 'Table.Caption',
Component: ({children, ...elemProps}: FlexProps, ref, Element) => {
return (
{children}
);
},
});
export const TableCell = createComponent('td')({
displayName: 'Table.Cell',
Component: ({children, ...elemProps}: GridProps, ref, Element) => {
return (
{children}
);
},
});
export const TableFooter = createComponent('tfoot')({
displayName: 'Table.Footer',
Component: ({children, ...elemProps}: GridProps, ref, Element) => {
return (
{children}
);
},
});
export const TableHead = createComponent('thead')({
displayName: 'Table.Head',
Component: ({children, ...elemProps}: GridProps, ref, Element) => {
return (
{children}
);
},
});
export const TableHeader = createComponent('th')({
displayName: 'Table.Header',
Component: ({children, ...elemProps}: GridProps, ref, Element) => {
return (
{children}
);
},
});
/**
* `Table` is a simple styled compound component that renders a [table](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) element. It is used to present information in a two-dimensional table comprised of rows and columns of cells containing data.
* `Table` is built off of `BaseTable` and is using [CSS Grid](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout) features.
*
*
* ```tsx
import {Table} from '@workday/canvas-kit-react/table';
export default function App() {
return (
Table Caption
Table Header
Table Header
Table Header
Table Header
Table Header
Table Data Cell
Table Header
Table Data Cell
Table Header
Table Data Cell
);
}
```
*/
export const Table = createComponent('table')({
displayName: 'Table',
Component: ({children, ...elemProps}: TableProps, ref, Element) => {
return (
{children}
);
},
subComponents: {
/**
* `Table.Caption` renders a [caption](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption) element.
*
*
* ```tsx
import {Table} from '@workday/canvas-kit-react/table';
export default function App() {
return (
Table Caption
Table Header
Table Cell
);
}
```
*/
Caption: TableCaption,
/**
* `Table.Head` renders a [thead](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/thead) element.
*
*
* ```tsx
import {Table} from '@workday/canvas-kit-react/table';
export default function App() {
return (
);
}
```
*/
Head: TableHead,
/**
* `Table.Body` renders a [tbody](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody) element.
*
*
* ```tsx
import {Table} from '@workday/canvas-kit-react/table';
export default function App() {
return (
);
}
```
*/
Body: TableBody,
/**
* `Table.Row` renders a [tr](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr) element.
*
* **Note**: `Table.Row` is built on [Grid](/docs/components-layout-grid--basic). It will look for
* how many children are there and if those children are valid React Elements. This will adjust the
* amount of columns automatically using the `gridTemplateColumns` style prop and the width of the
* columns is also set using a `minmax` function in the `gridTemplateColumns` style prop. If a user
* would like to adjust this, it can be overwritten on `Table.Row`. See the example below for how to
* overwrite `gridTemplateColumns`.
*
*
* ```tsx
import {Table} from '@workday/canvas-kit-react/table';
export default function App() {
return (
);
}
```
*/
Row: TableRow,
/**
* `Table.Header` renders a [th](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th) element.
*
*
* ```tsx
import {Table} from '@workday/canvas-kit-react/table';
export default function App() {
return (
);
}
```
*/
Header: TableHeader,
/**
* `Table.Cell` renders a [td](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td) element.
*
*
* ```tsx
import {Table} from '@workday/canvas-kit-react/table';
export default function App() {
return (
);
}
```
*/
Cell: TableCell,
/**
* `Table.Footer` renders a [tfoot](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tfoot) element.
*
*
* ```tsx
import {Table} from '@workday/canvas-kit-react/table';
export default function App() {
return (
);
}
```
*/
Footer: TableFooter,
},
});