Table

Tables are used to display data in a structured way.

Source
Theme Source

Dream exports a set of Table components:

  • Table - The main container for the Table.
  • TableHeader - The header for the Table.
  • TableBody - The body for the Table.
  • TableCaption - The caption for the Table.
  • TableCell - The cell for the Table.
  • TableColumnHeader - The column header for the Table.
  • TableRow - The row for the Table.
import {
    Table,
    TableBody,
    TableCaption,
    TableCell,
    TableColumnHeader,
    TableHeader,
    TableRow
} from "@dreamy-ui/react";
NameAgeGender
Name 120Male
Name 222Female
Name 325Male
<Table>
  <TableHeader>
    <TableRow>
      <TableColumnHeader>Name</TableColumnHeader>
      <TableColumnHeader>Age</TableColumnHeader>
      <TableColumnHeader>Gender</TableColumnHeader>
    </TableRow>
  </TableHeader>
  <TableBody>
    {[20, 22, 25].map((item, index) => (
      <TableRow key={index}>
        <TableCell>Name {index + 1}</TableCell>
        <TableCell>{item}</TableCell>
        <TableCell>{item % 5 === 0 ? "Male" : "Female"}</TableCell>
      </TableRow>
    ))}
  </TableBody>
</Table>

simple

NameAgeGender
Name 120Male
Name 222Female
Name 325Male

line

NameAgeGender
Name 120Male
Name 222Female
Name 325Male
{["simple", "line"].map((variant) => (
  <>
    <Text size={"lg"}>{variant}</Text>
    <Table variant={variant}>
      <TableHeader>
        <TableRow>
          <TableColumnHeader>Name</TableColumnHeader>
          <TableColumnHeader>Age</TableColumnHeader>
          <TableColumnHeader>Gender</TableColumnHeader>
        </TableRow>
      </TableHeader>
      <TableBody>
        {[20, 22, 25].map((item, index) => (
          <TableRow key={index}>
            <TableCell>Name {index + 1}</TableCell>
            <TableCell>{item}</TableCell>
            <TableCell>{item % 5 === 0 ? "Male" : "Female"}</TableCell>
          </TableRow>
        ))}
        </TableBody>
    </Table>
  </>
))}

simple

NameAgeGender
Name 120Male
Name 222Female
Name 325Male

line

NameAgeGender
Name 120Male
Name 222Female
Name 325Male
{["simple", "line"].map((variant) => (
    <>
      <Text size={"lg"}>{variant}</Text>
      <Table variant={variant} withBackground>
        <TableHeader>
          <TableRow>
            <TableColumnHeader>Name</TableColumnHeader>
            <TableColumnHeader>Age</TableColumnHeader>
            <TableColumnHeader>Gender</TableColumnHeader>
          </TableRow>
        </TableHeader>
        <TableBody>
          {[20, 22, 25].map((item, index) => (
            <TableRow key={index}>
              <TableCell>Name {index + 1}</TableCell>
              <TableCell>{item}</TableCell>
              <TableCell>{item % 5 === 0 ? "Male" : "Female"}</TableCell>
            </TableRow>
          ))}
          </TableBody>
      </Table>
    </>
  ))}
NameAgeGender
Name 120Male
Name 222Female
Name 325Male
<Table interactive>
  <TableHeader>
    <TableRow>
      <TableColumnHeader>Name</TableColumnHeader>
      <TableColumnHeader>Age</TableColumnHeader>
      <TableColumnHeader>Gender</TableColumnHeader>
    </TableRow>
  </TableHeader>
  <TableBody>
    {[20, 22, 25].map((item, index) => (
      <TableRow key={index}>
        <TableCell>Name {index + 1}</TableCell>
        <TableCell>{item}</TableCell>
        <TableCell>{item % 5 === 0 ? "Male" : "Female"}</TableCell>
      </TableRow>
    ))}
  </TableBody>
</Table>
NameAgeGender
Name 120Male
Name 222Female
Name 325Male
Name 428Female
Name 531Female
Name 635Male
<Table striped>
  <TableHeader>
    <TableRow>
      <TableColumnHeader>Name</TableColumnHeader>
      <TableColumnHeader>Age</TableColumnHeader>
      <TableColumnHeader>Gender</TableColumnHeader>
    </TableRow>
  </TableHeader>
  <TableBody>
    {[20, 22, 25, 28, 31, 35].map((item, index) => (
      <TableRow key={index}>
        <TableCell>Name {index + 1}</TableCell>
        <TableCell>{item}</TableCell>
        <TableCell>{item % 5 === 0 ? "Male" : "Female"}</TableCell>
      </TableRow>
    ))}
  </TableBody>
</Table>

sm

NameAgeGender
Name 120Male
Name 222Female
Name 325Male

md

NameAgeGender
Name 120Male
Name 222Female
Name 325Male

lg

NameAgeGender
Name 120Male
Name 222Female
Name 325Male
{["sm", "md", "lg"].map((size) => (
  <>
    <Text size={"lg"}>{size}</Text>
    <Table size={size}>
      <TableHeader>
        <TableRow>
          <TableColumnHeader>Name</TableColumnHeader>
          <TableColumnHeader>Age</TableColumnHeader>
          <TableColumnHeader>Gender</TableColumnHeader>
        </TableRow>
      </TableHeader>
      <TableBody>
        {[20, 22, 25].map((item, index) => (
          <TableRow key={index}>
            <TableCell>Name {index + 1}</TableCell>
            <TableCell>{item}</TableCell>
            <TableCell>{item % 5 === 0 ? "Male" : "Female"}</TableCell>
          </TableRow>
        ))}
        </TableBody>
    </Table>
  </>
))}