1.0.9 • Published 4 years ago

@feizheng/react-interactive-list v1.0.9

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

react-interactive-list

An interactive, dynamic list of components with add / remove actions.

version license size download

installation

npm install -S @feizheng/react-interactive-list

update

npm update @feizheng/react-interactive-list

properties

NameTypeRequiredDefaultDescription
classNamestringfalse-The extended className for component.
minnumberfalse1The minimum size.
maxnumberfalse10The max size.
itemsarrayfalse[]The data source.
templatefuncfalsenoopThe data item template.
templateDeletefuncfalsenoopThe action of delete component.
templateCreatefuncfalsenoopThe action of create component.
templateDefaultfuncfalsenoopThe empty create template.
onChangefuncfalsenoopThe change handler.
onValidatefuncfalsenoopWhen trigger max/min boundary.

usage

  1. import css

    @import "~@feizheng/react-interactive-list/dist/style.scss";
    
    // customize your styles:
    $react-interactive-list-options: ()
  2. import js

    import NxOfflineSw from '@feizheng/next-offline-sw';
    import ReactGithubCorner from '@feizheng/react-github-corner';
    import ReactSwUpdateTips from '@feizheng/react-sw-update-tips';
    import React from 'react';
    import ReactDOM from 'react-dom';
    import ReactInteractiveList from '@feizheng/react-interactive-list';
    import './assets/style.scss';
    
    class App extends React.Component {
      state = { hasUpdate: false, items: ['value1', 'value2', 'value3', 'value4'] };
    
      componentDidMount() {
        NxOfflineSw.install({
          onUpdateReady: () => {
            this.setState({ hasUpdate: true });
          }
        });
      }
    
      template = ({ item, index }, cb) => {
        return (
          <div className="is-item" key={index}>
            {index + 1}:{item} <button onClick={cb}>Remove</button>
          </div>
        );
      };
    
      templateCreate = ({ items }, cb) => {
        return (
          <button className="button" onClick={cb}>
            Add
          </button>
        );
      };
    
      templateDefault = () => {
        return 'A new template';
      };
    
      onChange = (inEvent) => {
        console.log('change:', inEvent.target.value);
      };
    
      onValidate = (inEvent) => {
        console.log('validate:', inEvent.target.value);
      };
    
      onClickRadom = (inEvent) => {
        const random = Math.floor(Math.random() * 8);
        this.setState({ items: [1, 2, 3, 4, 5, 6, 7, 8].slice(0, random) });
      };
    
      render() {
        const { items } = this.state;
    
        return (
          <div className="p-3 app-container">
            {/* Core components usage start */}
            <button className="button" onClick={this.onClickRadom}>
              Set Random Items
            </button>
            <ReactInteractiveList
              items={items}
              template={this.template}
              templateDefault={this.templateDefault}
              templateCreate={this.templateCreate}
              onChange={this.onChange}
              onValidate={this.onValidate}
            />
            {/* Core components usage end */}
            <ReactSwUpdateTips value={this.state.hasUpdate} />
            <ReactGithubCorner value="https://github.com/afeiship/react-interactive-list" />
          </div>
        );
      }
    }
    
    ReactDOM.render(<App />, document.getElementById('app'));

documentation

license

Code released under the MIT license.

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago