SIMPLE TAILWIND TABLE FOR REACT
It's easy to make an table with tailwind styles

Live demo here
Feature planing
Usage
1. Install
npm install react-simple-tailwind-table
OR
yarn add react-simple-tailwind-table
2.Import library into to your source
Edit tailwind.config.js and add into content
module.exports = {
content: [
'./node_modules/react-simple-tailwind-table/**/*.{html,js,ts,css,scss}',
],
safelist: [{ pattern: /rounded-./ }],
};
Add it into components
import 'react-simple-tailwind-table/build/style.css';
import { useTableConfiguration, TailwindTable } from 'react-simple-tailwind-table';
3.Declare your configuration with hook
const temp = [
{ name: 'CRIS', status: 'DONE', score: 1000 },
{ name: 'NIDA', status: 'DONE', score: 200 },
{ name: 'TEEL', status: 'DOING', score: 450 },
{ name: 'LOUS', status: 'DOING', score: 800 },
{ name: 'JAN', status: 'PENDING', score: 0 },
];
const { tableData, tableColumns } = useTableConfiguration(temp, [
{
label: 'Username',
accessor: 'name',
body: { className: 'font-bold text-gray-600' },
header: { background: '#345543', className: 'text-white' },
align: 'left',
},
{
label: 'Status',
accessor: 'status',
body: { className: 'px-2' },
renderData: (data) => {
const color = {
DONE: 'text-green-500',
DOING: 'text-orange-600',
PENDING: 'text-gray-500',
};
return <span className={color[data.status]}>{data.status}</span>;
},
},
{ label: 'Score', accessor: 'score', sort: (a, b) => a.score - b.score },
]);
4. Render your table
<TailwindTable data={tableData} columns={tableColumns} />

Difference (OPTIONAL)
<TailwindTable data={tableData} columns={tableColumns} differnce={{ enable: false }} />

Columns configuration
interface ITableColumn<T = undefined> {
label: string;
accessor?: Partial<keyof T>;
width?: CSSProperties['width'];
align?: CSSProperties['textAlign'];
renderData?: (data: T, tableState?: ITableState<T>) => ReactNode;
renderHeader?: (tableState?: ITableState<T>) => ReactNode;
sort?: TTableSortFn<T>;
body?: {
className?: string;
background?: CSSProperties['background'];
};
header?: {
className?: string;
background?: CSSProperties['background'];
buttonClass?: string;
};
filter?: {
show?: boolean;
dotColor?: string;
render?: (tableState: ITableState<T>) => ReactNode;
};
}
Technologies
- Typescript
- SCSS
- React
- Jest
- Rollup
- Storybook
Maintainer
@saintno