0.0.30 • Published 22 days ago

ait_reusable_table_react v0.0.30

Weekly downloads
-
License
-
Repository
github
Last release
22 days ago

AIT Reusable Table React

A fully-fledged Table module created for React apps. Provides table component, search field, paging mode and more!

Overview

Introduction

AIT Reusable Table React provide You to use components that adapted to AIT standards. Its fully customizeable, realabel, integrated with Tailwind CSS.

Demo

Installation

Install The Module

With NPM

npm add ait_reusable_table_react

With Yarn

yarn add ait_reusable_table_react

Install Tailwind CSS

This project uses Tailwind CSS for UI Framework. You can refer this link to install Tailwind CSS

System Requirements

ModuleVersion
Node.js^18.19.1
React^18.2.0
Tailwind CSS^3.4.1
react-router-dom^6.22.3

Components

Table

import { Table } from 'ait_reusable_table_react'
ParameterTypeDescriptionDefault ValueRequired
childrenReactNodeChildren ComponentundefinedNo
classNamesTableClassNamesClass name that apply to Table componentundefinedNo
onUpdateParams(params: TableContextValueParams) => voidFired when TableCell with order props was clickedundefinedNo
paramsx: string: anyvalue that apply to TableCell with order propsundefinedNo

All common table props can be apply to this component

TableClassNames

NameTypeRequired
containerstringNo
tablestringNo

TableContextValueParams

NameTypeRequired
x: stringanyNo

TableRow

import { TableRow } from 'ait_reusable_table_react'

All common tr props can be apply to this component


TableHead

import { TableHead } from 'ait_reusable_table_react'

All common thead props can be apply to this component


TableBody

import { TableBody } from 'ait_reusable_table_react'

All common tbody props can be apply to this component


TableCell

Table > TableHead > TableRow > TableCell

ParameterTypeDescriptionDefault ValueRequired
childrenReactNodeChildren ComponentundefinedNo
classNamesTableCellClassNamesClass name that apply to TableCell componentundefinedNo
indexbooleanSet TableCell behavior as indexfalseNo
orderstringCan be used to provide sort-order functionundefinedNo
orderPrefixstringapply prefix to order value, useful if you want to apply multiple sort-orderundefinedNo
actionbooleanSet TableCell behavior as actionfalseNo

Table > TableBody > TableRow > TableCell

ParameterTypeDescriptionDefault ValueRequired
childrenReactNodeChildren ComponentundefinedNo
classNamesTableCellClassNamesClass name that apply to TableCell componentundefinedNo
indexnumberSet TableCell indexundefinedNo
valueanySet TableCell children with validation. If validation is fail, placeholder will appear insteadundefinedNo
validate(value: T) => booleancustom validationundefinedNo
placeholderstringappear while return validate is false-No
renderValue(value: T) => ReactNodeRender custom value. Useful if you want to mapping value of Array or ObjectundefinedNo
actionbooleanSet TableCell behavior as actionfalseNo

All common tbody props can be apply to this component

TableCellClassNames

NameTypeRequired
actionDividerstringNo
actionWrapperstringNo
cellstringNo
ascIconstringNo
descIconstringNo
iconstringNo

ActionButton

import { ActionButton } from 'ait_reusable_table_react'

Used for TableCell action

ParameterTypeDescriptionDefault ValueRequired
variantReactNodeSet behavior of ActionButtonundefinedNo
loadingbooleanSet loading stateundefinedNo
tostringroute to destination page. make sure react-router-dom v6 was installedundefinedNo

All common button props can be apply to this component


Typography

import { Typography } from 'ait_reusable_table_react'
ParameterTypeDescriptionDefault ValueRequired
childrenReactNodeChildren ComponentundefinedNo
variant'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'body1' | 'body2' | 'subtitle1' | 'subtitle2' | 'caption'Set behavior of Typographybody1No
type'light' | 'normal' | 'medium' | 'semibold' | 'bold'Set type of TypographynormalNo

All common HTMLAttributes can be apply to this component


TextField

import { TextField } from 'ait_reusable_table_react'
ParameterTypeDescriptionDefault ValueRequired
labelstringlabel that apply to TextFieldundefinedNo
classNamesTextFieldClassNamesClass name that apply to TableCell componentundefinedNo
helperTextstringTextField helper textundefinedNo
startIconComponentType<SVGProps>prefix TextField iconundefinedNo
endIconComponentType<SVGProps>suffix TextField iconundefinedNo
onClickEndIconMouseEventHandlerFired when end icon was clickedundefinedNo
prefixstring | numberprefix TextFieldundefinedNo
suffixstring | numbersuffix TextFieldundefinedNo
sizing'sm' | 'md' | 'lg'size of TextField'md'No
errorbooleanTell to TextField that style behavior must be danger styleundefinedNo

All common input props can be apply to this component

TextFieldClassNames

NameTypeRequired
containerstringNo
helperTextstringNo
startIconWrapperstringNo
startIconstringNo
endIconWrapperstringNo
endIconstringNo
wrapperstringNo
inputstringNo

Paging

import { Paging } from 'ait_reusable_table_react'
ParameterTypeDescriptionDefault ValueRequired
onChangePage(data: PagingParams) => voidFired when paging was changedundefinedYes
pagenumberCurrent page1No
limitnumberTotal data to display per page10No
totalnumberTotal data0No
loadingbooleanProps to temporary disable paging while data on loadfalseNo

PagingParams

NameTypeRequired
pagenumberYes
limitnumberYes

Search

import { InputSearch } from 'ait_reusable_table_react'
ParameterTypeDescriptionDefault ValueRequired
onChangeText(value: string) => voidFired while value is changedundefinedNo
valuestringset controlled value for this componentundefinedNo

All common input props can be apply to this component

Example

How to use it

Common Usage

import {
  useState
} from "react";

import {
  ActionButton,
  Content,
  ContentBody,
  ContentHeader,
  InputSearch,
  Paging,
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableRow,
  ToggleDarkMode
} from "ait_reusable_table_react";
import {
  Wrapper
} from "../../components";

export function ExamplePage() {

  const [params, setParams] = useState({
    total: 1000,
    size: 10,
    page: 1
  });

  const updateParams = (value: typeof params) => {
    setParams((_) => ({ ..._, ...value }));
  };

  const renderTableItem = (_: any, index: number) => {
    return (
      <TableRow key={index}>
        <TableCell {...{ index }} />
        <TableCell>First Name</TableCell>
        <TableCell>Last Name</TableCell>
        <TableCell>Username</TableCell>
        <TableCell>Email</TableCell>
        <TableCell action={true}>
          <ActionButton variant="detail" />
          <ActionButton variant="edit" />
          <ActionButton variant="delete" />
        </TableCell>
      </TableRow>
    );
  };

  return (
    <Wrapper>
      <Content>
        <ContentHeader title="Table Example">
          <ToggleDarkMode />
        </ContentHeader>
        <ContentBody>
          <InputSearch />
          <Table onUpdateParams={(_: any) => updateParams(_)} {...{ params }}>
            <TableHead>
              <TableRow>
                <TableCell index={true} />
                <TableCell order="first_name">First Name</TableCell>
                <TableCell order="last_name">Last Name</TableCell>
                <TableCell order="username">Username</TableCell>
                <TableCell orderPrefix="example" order="email">Email</TableCell>
                <TableCell className="w-[160px]" action={true}></TableCell>
              </TableRow>
            </TableHead>
            <TableBody>
              {Array.from({ length: params.size }, renderTableItem)}
            </TableBody>
          </Table>
          <Paging
            onChangePage={(_: any) => updateParams(_)}
            total={params.total}
            size={params.size}
            page={params.page}
          />
        </ContentBody>
      </Content>
    </Wrapper>
  );
}

Integrating with Query Params

See src/examples/modules/ExampleWithQueryParams

Integrating with Query Params and React Query

Make sure your Backend was following AIT standard.

See src/examples/modules/ExampleWithReactQuery

Developers

muhammad-f-huda-ait

0.0.23

22 days ago

0.0.25

22 days ago

0.0.30

22 days ago

0.0.26

22 days ago

0.0.27

22 days ago

0.0.29

22 days ago

0.0.20

23 days ago

0.0.21

23 days ago

0.0.10

23 days ago

0.0.22

23 days ago

0.0.11

23 days ago

0.0.12

23 days ago

0.0.14

23 days ago

0.0.3

23 days ago

0.0.2

23 days ago

0.0.15

23 days ago

0.0.9

23 days ago

0.0.16

23 days ago

0.0.8

23 days ago

0.0.17

23 days ago

0.0.19

23 days ago

0.0.5

23 days ago

0.0.7

23 days ago

0.0.6

23 days ago

0.0.1

1 month ago