0.2.0 • Published 3 years ago

material-crud-component v0.2.0

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
3 years ago

Material Crud Component

Material Crud Component is a simple package that allows you to scaffold CRUD pages data in minutes.

Installation

yarn install material-crud-component
#OR
npm install --save material-crud-component

Usage

import Crud from 'material-crud-component';

Example

...    
        const data = [{ cost: 1000, gluten: 'NO'} ...];
...
        return ( 
           <Crud
                title="Nutrition"
                columns={[
                    {
                        key: 'cost',
                        label: 'Cost',
                        name: 'cost',
                        align: 'right',
                        format: (val: any) => numeral(val).format('$0,0[.]0')
                    }
                ]}
                data={data.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)}
                idExtractor={(val: any) => val.id}
                pagination={{
                    totalElements: data.length,
                    page,
                    rowsPerPage,
                    rowsPerPageOptions: [10, 25, 50],
                    onPageChange: (p: number) => {
                        setPage(p)
                    },
                    onRowsPerPageChange: (s: number) => {
                        setRowsPerPage(s);
                    }
                }}
                onDelete={(item: any) => {
                    const d = data.filter(i => item.id !== i.id);
                    setData(d);
                }}
                addItem={{
                    form: {
                        required: ['cost', 'gluten'],
                        properties: {
                            cost: {type: 'number', title: 'Cost'},
                            gluten: {type: 'string', title: 'Gluten Free', enum: ['Yes', 'No']},
                        }
                    },
                    onSubmit: (item: any) => {
                        setData([...data, {...item, id: Date.now().toString()}])
                    }
                }}
                editItem={{
                    form: {
                        required: ['cost', 'gluten'], 
                        properties: {
                            cost: {type: 'number', title: 'Cost'},
                            gluten: {type: 'string', title: 'Gluten Free', enum: ['Yes', 'No']},
                        }
                    },
                    onSubmit: (item: any) => {
                        const i = data.findIndex(i => item.id === i.id);
                        data[i] = item;
                        setData([...data]);
                    }
                }}
            />);

A detailed example can be found in the examples directory

Properties

NameRequiredDescription
titlestring or React component to display at the head of the table
columnsYeslist of fields to display from the item. See column definition for further details
dataYeslist tor records

TODO

complete documentation

0.0.1

3 years ago

0.2.0

3 years ago

1.0.0

3 years ago