2.0.2 • Published 3 years ago

react-plasma-table v2.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

npm.io

React plasma table

  • ✅ Super simple and intuitive API
  • ✅ Semantically opinionated rendered tables
  • ✅ Perfect for small and large projects
  • ✅ Written in Typescript
  • ✅ Sortable out of the box
  • ✅ Searchable (✨ New! ✨)
  • ✅ Now with pagination (✨ New! ✨)
  • ✅ Collapsable (✨ New! ✨)
yarn add react-plasma-table

How to use

This version only provides a semantic and dynamic table component.

import React, { useState } from "react";
import { Table } from "react-plasma-table";
import { format } from "../my-date-formatting-function";

// Define you logic here
const columns = [
  {
    id: 1, // required
    name: "Email", // required
    dataKey: "email", // required
    searchable: true,
  },
  {
    id: 2, // required
    name: "First name", // required
    dataKey: "first_name", // required
    sortable: true,
    searchable: true,
  },
  {
    id: 3, // required
    name: "Last name", // required
    dataKey: "last_name", // required
    sortable: true,
    searchable: true,
  },
  {
    id: 4, // required,
    name: "Birthday", // required
    dataKey: "birthday", // required
    sortable: true,
    component: ({ birthday, ...rest }) => (
      <>{format(new Date(birthday), "dd.MM.yyyy")}</>
    ),
  },
];

// Defile your sorting icons
const sortUp = () => <SortUpIcon />; // Wrong way: const sortUp = <SortUpIcon />
const sortDown = () => <SortUpIcon />;

const onRowClick = (event, row, index) => {
  /* === You'll have access to the event in case you need it
         You'll have access to the entire row object
         You'll have access to the index of the row starting with 0 === */
  // Your row click handling logic here
};

const App = () => {
  const [searchQuery, setSearchQuery] = useState("");

  return (
    <>
      <input type="text" onChange={(e) => setSearchQuery(e.target.value)} />
      <Table
        data={data}
        columns={columns}
        sortDownIcon={sortDown}
        sortUpIcon={sortUp}
        searchQuery={searchQuery}
        onRowClick={(event, row, index) => onRowClick(event, row, index)}
      />
    </>
  );
};

Examples

API

The documentation is still a work in progress.

Table:

props

  • data (required): array of objects
  • columns (required): array of objects => { id: number (required) name: string or number (required) - what you see in the table head dataKey: string or number (required) - the key of the data object to connet to component: JSX element (optional) sortable: boolean (optional) searchable: boolean (optional) }
  • sortUpIcon (optional): JSX element
  • sortDownIcon (optional): JSX element
  • searchQuery (optional): string or undefined
  • onRowClick(optional): function(event, row, index)

  • 💡 You can pass down custom components to your table rows alongside other children

  • 💡 You can get all the individual keys as props in your custom component coming from your api.

Roadmap

  • Search (done)
  • Pagination (done)
  • Collapsable rows (In development)
  • Selection
  • PDF, CSV and Excel exporting
  • Examples
1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.12

3 years ago

1.3.10

3 years ago

1.3.11

3 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.0

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.8.0

4 years ago

0.7.11

4 years ago

0.7.10

4 years ago

0.7.9

4 years ago

0.7.8

4 years ago

0.7.6

4 years ago

0.7.5

4 years ago

0.7.7

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.6.7

4 years ago

0.6.9

4 years ago

0.6.6

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago