UnpopularTable Documentation

The UnpopularTable component provides a flexible and responsive table with various customization options. Below are examples of how to use the component in different scenarios.

Props

The UnpopularTable component has the following props:

PropDescriptionType
columnsAn array of objects, each containing a header and an accessorArray
dataAn array of objects where each object represents a row in the tableArray
borderedA boolean indicating whether the table should be borderedBoolean
hoverA boolean indicating whether the table should be hoverableBoolean
stripedA boolean indicating whether the table should be stripedBoolean
headerStyleAn object containing style properties for the table headerObject
rowStytleAn object containing style properties for the table rowObject
tableStyleAn object containing style properties for the tableObject
responsiveA boolean indicating whether the table should be responsiveBoolean
itemsPerPageThe number of items to display per pageNumber

Basic Usage

1. Basic Table

To create a basic table, you need to provide the columns and data props. The columns prop is an array of objects, each containing a header and an accessor. The data prop is an array of objects where each object represents a row in the table.

const columns = [
  { header: "Name", accessor: "name" },
  { header: "Age", accessor: "age" },
  { header: "Email", accessor: "email" },
];

const data = [
  { name: "John Doe", age: 28, email: "john.doe@example.com" },
  { name: "Jane Smith", age: 34, email: "jane.smith@example.com" },
  { name: "Sam Johnson", age: 23, email: "sam.johnson@example.com" },
];

// Usage
<UnpopularTable columns={columns} data={data} />
NameAgeEmailCustom Cell
John Doe28john.doe@example.com Custom Cell
Jane Smith34jane.smith@example.com Custom Cell
Sam Johnson23sam.johnson@example.com Custom Cell
Chris Lee45chris.lee@example.com Custom Cell
Patricia Brown31patricia.brown@example.com Custom Cell
Michael Davis27michael.davis@example.com Custom Cell
Jessica Garcia29jessica.garcia@example.com Custom Cell
Daniel Martinez33daniel.martinez@example.com Custom Cell
Laura Hernandez38laura.hernandez@example.com Custom Cell
David Wilson41david.wilson@example.com Custom Cell

2. Striped Table

You can create a striped table by setting the striped prop to true. This will alternate the background color of the rows for better readability.

<UnpopularTable columns={columns} data={data} striped />
NameAgeEmailCustom Cell
John Doe28john.doe@example.com Custom Cell
Jane Smith34jane.smith@example.com Custom Cell
Sam Johnson23sam.johnson@example.com Custom Cell
Chris Lee45chris.lee@example.com Custom Cell
Patricia Brown31patricia.brown@example.com Custom Cell
Michael Davis27michael.davis@example.com Custom Cell
Jessica Garcia29jessica.garcia@example.com Custom Cell
Daniel Martinez33daniel.martinez@example.com Custom Cell
Laura Hernandez38laura.hernandez@example.com Custom Cell
David Wilson41david.wilson@example.com Custom Cell

3. Bordered Table

To add borders to your table, use the bordered prop.

<UnpopularTable columns={columns} data={data} bordered />
NameAgeEmailCustom Cell
John Doe28john.doe@example.com Custom Cell
Jane Smith34jane.smith@example.com Custom Cell
Sam Johnson23sam.johnson@example.com Custom Cell
Chris Lee45chris.lee@example.com Custom Cell
Patricia Brown31patricia.brown@example.com Custom Cell
Michael Davis27michael.davis@example.com Custom Cell
Jessica Garcia29jessica.garcia@example.com Custom Cell
Daniel Martinez33daniel.martinez@example.com Custom Cell
Laura Hernandez38laura.hernandez@example.com Custom Cell
David Wilson41david.wilson@example.com Custom Cell

4. Hoverable Table

To highlight rows when hovered over, set the hover prop to true.

<UnpopularTable columns={columns} data={data} hover />
NameAgeEmailCustom Cell
John Doe28john.doe@example.com Custom Cell
Jane Smith34jane.smith@example.com Custom Cell
Sam Johnson23sam.johnson@example.com Custom Cell
Chris Lee45chris.lee@example.com Custom Cell
Patricia Brown31patricia.brown@example.com Custom Cell
Michael Davis27michael.davis@example.com Custom Cell
Jessica Garcia29jessica.garcia@example.com Custom Cell
Daniel Martinez33daniel.martinez@example.com Custom Cell
Laura Hernandez38laura.hernandez@example.com Custom Cell
David Wilson41david.wilson@example.com Custom Cell

5. Responsive Table

For a responsive table that scrolls horizontally on smaller screens, use the responsive prop.

<UnpopularTable columns={columns} data={data} responsive />
NameAgeEmailCustom Cell
John Doe28john.doe@example.com Custom Cell
Jane Smith34jane.smith@example.com Custom Cell
Sam Johnson23sam.johnson@example.com Custom Cell
Chris Lee45chris.lee@example.com Custom Cell
Patricia Brown31patricia.brown@example.com Custom Cell
Michael Davis27michael.davis@example.com Custom Cell
Jessica Garcia29jessica.garcia@example.com Custom Cell
Daniel Martinez33daniel.martinez@example.com Custom Cell
Laura Hernandez38laura.hernandez@example.com Custom Cell
David Wilson41david.wilson@example.com Custom Cell

6. Custom Styles

You can apply custom styles to the table, headers, and rows by using the tableStyle, headerStyle, and rowStyle props.

const tableStyle = {
  backgroundColor: '#fff',
  color: '#333',
};

const headerStyle = {
  backgroundColor: '#007bff',
  color: '#fff',
};

const rowStyle = {
  backgroundColor: '#f9f9f9',
};

// Usage
<UnpopularTable
  columns={columns}
  data={data}
  tableStyle={tableStyle}
  headerStyle={headerStyle}
  rowStyle={rowStyle}
/>
NameAgeEmailCustom Cell
John Doe28john.doe@example.com Custom Cell
Jane Smith34jane.smith@example.com Custom Cell
Sam Johnson23sam.johnson@example.com Custom Cell
Chris Lee45chris.lee@example.com Custom Cell
Patricia Brown31patricia.brown@example.com Custom Cell
Michael Davis27michael.davis@example.com Custom Cell
Jessica Garcia29jessica.garcia@example.com Custom Cell
Daniel Martinez33daniel.martinez@example.com Custom Cell
Laura Hernandez38laura.hernandez@example.com Custom Cell
David Wilson41david.wilson@example.com Custom Cell

7. Pagination

To add pagination to your table, use the itemsPerPage prop to specify the number of items per page.

<UnpopularTable columns={columns} data={data} itemsPerPage={5} />
NameAgeEmailCustom Cell
John Doe28john.doe@example.com Custom Cell
Jane Smith34jane.smith@example.com Custom Cell
Sam Johnson23sam.johnson@example.com Custom Cell
Chris Lee45chris.lee@example.com Custom Cell
Patricia Brown31patricia.brown@example.com Custom Cell

8. Combining Props

You can combine multiple props to achieve the desired table appearance.

<UnpopularTable
  columns={columns}
  data={data}
  striped
  bordered
  hover
  responsive
  itemsPerPage={5}
  tableStyle={{ backgroundColor: '#fff', color: '#333' }}
  headerStyle={{ backgroundColor: '#007bff', color: '#fff' }}
  rowStyle={{ backgroundColor: '#f9f9f9' }}
/>
NameAgeEmailCustom Cell
John Doe28john.doe@example.com Custom Cell
Jane Smith34jane.smith@example.com Custom Cell
Sam Johnson23sam.johnson@example.com Custom Cell
Chris Lee45chris.lee@example.com Custom Cell
Patricia Brown31patricia.brown@example.com Custom Cell

Conclusion

The UnpopularTable component provides a versatile and stylish solution for building responsive tables. Utilize its customization options to enhance user experience with elegant and functional toast messages in your React applications.