0.2.1 • Published 5 years ago

react-apollo-flexi-table v0.2.1

Weekly downloads
12
License
MIT
Repository
github
Last release
5 years ago

React Apollo Flexi Table

A flexible table with frozen header for React and well combined with react-apollo. By using this table, You can easily sharing flex ratio on both table header and table items, and all components are written in hooks.

Demo GIF

Usage

import React from 'react';
import { Mutation } from 'react-apollo';
import {
  Table,
  TableField,
} from 'react-apollo-flexi-table';

function Example() {
   return (
     <Table
       dataSource={[{
         id: 1,
         name: 'John',
         nickname: 'J',
       }, {
         id: 2,
         name: 'Ben',
         nickname: 'B',
       }]}
       fetchMoreHeight={150}
       fetchMore={() => { /* do your fetchMore here */ }}>
       <TableField
         name="User Name"
         fieldKey="name"
         flex={1}
         isCenter />
      <TableField
         name="Nickname"
         fieldKey="nickname"
         flex={1.2}
         Component={props => (
           <Mutation mutation={YOUR_MUTATION}>
             {mutate => (
               <YourComponent
                 {...props}
                 mutate={mutate} />
             )}
           </Mutation>
         )}
     </Table>
   );
}

Please check my examples folder and you will see more details. https://github.com/travor20814/react-apollo-flexi-table/blob/master/examples/table/FlexiTable.jsx

Options

Table Props

nametypedefaultValuerequired
childrenArray<React.Node>nullv
dataSourceArray<Object>[]v
actionTitlesArray<string>[]
getActionsFunction() => []
fetchMoreFunctionundefined
fetchMoreHeightnumber150
showPlaceholderbooleanfalse
placeholderstringnull
placeholderColorstring#9b9b9b
placeholderWrapperStyleObjectnull
placeholderStyleObjectnull
headerBackgroundColorstringtransparent
headerTextColorstring#000
headerBorderstring0px solid #000
headerBorderRadiusnumber0
headerFontSizenumber18
headerWrapperStyleObjectnull
itemWrapperStyleObjectnull
wrapperStyleObjectnull

TableField Props

nametypedefaultValuerequired
namestringundefinedv
fieldKeystringundefinedv
flexnumber1
minWidthnumberauto
colorstring#9b9b9b
isCenterbooleanfalse
isImagebooleanfalse
styleObjectundefined
ComponentReact.Nodenull

Descriptions

Table

  • children - You should use our TableField for clearly defining what Table child is.

  • dataSource - The data list you want to map to the table. You must be careful about the key you use. TableField's prop fieldKey will find value base on the object key. (Hint: Each object should have an id for unique key)

  • actionTitles - actions will place on the right-hand side of the table. Here you can assign these action fields title.

  • getActions - You can pass any components you want in a function that return an array of components.

  • fetchMore - It makes you easily work with react-apollo fetchMore, and it will trigger this function when table's remain scroll height is less than fetchMoreHeight, which default is 150px.

  • fetchMoreHeight - Define when should the fetchMore function been triggered when table remain scroll height is less than fetchMoreHeight

TableField

  • name - Define field name you want to show on the header.

  • fieldKey - Define what dataSource key you want to take.

  • flex - Define field flex in the table. It will helps you synchronize header flex and item field flex.

  • style - If you want customizing your field style, you can pass any css style you want to override it.

  • Component - You can pass your custom component here, and it will replace the origin one. Also, some table useful props will pass into your custom component.

0.2.1

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago