Table

The Table is a layout component to display data in a tabular format. It's a great way to display data in a structured way, and it's also a great way to compare data.

Importation

Import the component from pol-ui to use the Table element:

import { Table } from "pol-ui";

Default Table

Default Table

import { Table } from "pol-ui";
const mockUsers = [
  {
    id: 1,
    name: "Albert Arrebola",
    username: "arrebolsillo",
    email: "bolarre@polui.com",
    address: "Calle Eucalipto 66",
  },
  {
    id: 2,
    name: "Cristina Llull",
    username: "cristinallull",
    email: "cristinallull@polui.com",
    address: "Calle 123",
  },
  {
    id: 3,
    name: "Berta Pasamontes",
    username: "donutconchocolate",
    email: "donutconchocolate@polui.com",
    address: "Avenida 123",
  },
  {
    id: 4,
    name: "Pepito Grillo",
    username: "PepeGrillo",
    email: "PepeGrillo@polui.com",
    address: "Pasillo 4",
  },
];
export const TableComponent = (): JSX.Element => {
  const { value, toggle } = useBoolean(false);
  return (
    <Table>
      <Table.Head>
        <Table.HeadCell>Name</Table.HeadCell>
        <Table.HeadCell>Username</Table.HeadCell>
        <Table.HeadCell>Email</Table.HeadCell>
        <Table.HeadCell>Address</Table.HeadCell>
        <Table.HeadCell>
          <span className="sr-only">Edit</span>
        </Table.HeadCell>
      </Table.Head>
 
      <Table.Body className="divide-y">
        {mockUsers.map((user) => (
          <Table.Row key={user.id}>
            <Table.Cell>{user.name}</Table.Cell>
            <Table.Cell>{user.username}</Table.Cell>
            <Table.Cell>{user.email}</Table.Cell>
            <Table.Cell>{user.address}</Table.Cell>
            <Table.Cell>
              <div className="flex gap-1">
                <IconButton title="Edit">
                  <TbEdit />
                </IconButton>
                <IconButton title="Edit" color="info">
                  <TbEye />
                </IconButton>
              </div>
            </Table.Cell>
          </Table.Row>
        ))}
      </Table.Body>
    </Table>
  );
};

Props

Table

Prop nameTypeDefaultDescription
childrenReact.ReactNodeThe content of the Table
classNamestringThe class of the Table
stripedbooleanfalseIf true, the Table will have striped rows
hoverablebooleanfalseIf true, the Table will have hoverable rows
hasShadowbooleantrueIf true, the Table will have a shadow
themeTableThemeThe theme of the Table

TableHead

Prop nameTypeDefaultDescription
themeTableHeadThemeThe theme of the TableHead
💡

You can also provide any prop comming from the HTML thead tag.

TableHeadCell

Prop nameTypeDefaultDescription
TableHeadCellThemeThe theme of the TableHeadCellTheme
💡

You can also provide any prop comming from the HTML th tag.

TableRow

Prop nameTypeDefaultDescription
TableRowThemeThe theme of the TableRowTheme
💡

You can also provide any prop comming from the HTML tr tag.

TableBody

Prop nameTypeDefaultDescription
TableBodyThemeThe theme of the TableBodyTheme
💡

You can also provide any prop comming from the HTML tbody tag.

TableCell

Prop nameTypeDefaultDescription
TableCellThemeThe theme of the TableCellTheme
💡

You can also provide any prop comming from the HTML td tag.

Theme

To learn more about how to customize the appearance of components, please see the Theme docs.

interface TableTheme {
  root: {
    base: string;
    shadow: string;
    wrapper: string;
  };
  head: {
    base: string;
    cell: {
      base: string;
    };
  };
  row: {
    base: string;
    hovered: string;
    striped: string;
  };
  body: {
    base: string;
    cell: {
      base: string;
    };;
  };
}

Since March 1, 2024

Proudly Open Source
  • Npm

  • Github

  • Creator

  • Made with love and Pol-ui by Pol Gubau Amores