1.1.1 • Published 7 years ago

material-ui-repeatable v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

material-ui-repeatable

Repeat any component as many times as you like on the page.

Single TextField

Single

Multiple TextField's

Multi

Installation

yarn add material-ui-repeatable

Or with npm

npm i --save material-ui-repeatable

Usage example

import React, { Component } from 'react';
import Repeatable from 'material-ui-repeatable';

class MyComponent extends Component {
    contructor() {
        super();
        this.state = {
            copies: 1
        };
    }

    repeat = (index) => (
        <div key={`replicant-${index}`}>hello, I am replicant {index}</div>
    )

    onAdd = (index) => {
        console.log('added replicant', index);
        this.setState({ copies: this.state.copies + 1 });
    }

    onRemove = (index) => {
        console.log('removed replicant', index);
        this.setState({ copies: this.state.copies - 1 });
    }

    render() {
        return (
            <Repeatable
              initialCopies={this.state.copies}
              childrenRenderer={this.repeat}
              onAdd={this.onAdd}
              onRemove={this.onRemove}
              />
        );
    }
}

Properties

For snackbar props please see material-ui docs.

NameTypeDefaultDescription
initialCopiesnumber1Number of the replicants to be generated at the render time.
requiredCopiesnumber1Number of the replicants that should be persist(remove control will hide when this value is reached).
childrenRendererfunction(index) => []A function that returns a new replicant.
onAddfunction(index) => undefinedFunction that will be invoked after some replicant added.
onRemovefunction(index) => undefinedFunction that will be invoked after some replicant removed.
styleobject{}Style of the component container.

License

MIT