JSPM

  • Created
  • Published
  • Downloads 263
  • Score
    100M100P100Q67923F
  • License MIT

React interactive-list.

Package Exports

  • @jswork/react-interactive-list
  • @jswork/react-interactive-list/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@jswork/react-interactive-list) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-interactive-list

React interactive-list.

version license size download

installation

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

usage

  1. import css
@import "~@jswork/react-interactive-list/dist/style.css";

// or use sass
@import "~@jswork/react-interactive-list/dist/style.scss";

// customize your styles:
$react-interactive-list-options: ()
  1. import js
import React, { useState } from 'react';
import ReactInteractiveList from '../../src/main';
import styled from 'styled-components';

const Container = styled.div`
  width: 80%;
  margin: 30px auto 0;

  .message {
    border-radius: 1em;
    margin: 0.5em;
    line-height: 1.1em;
    background-color: lightblue;
  }
`;

export default () => {
  const [items, setItems] = useState([
    'I wondered why the baseball was getting bigger. Then it hit me.',
    'Police were called to a day care, where a three-year-old was resisting a rest.',
    'Did you hear about the guy whose whole left side was cut off? He’s all right now.',
    'The roundest knight at King Arthur’s round table was Sir Cumference.',
    'To write with a broken pencil is pointless.',
    'When fish are in schools they sometimes take debate.',
    'The short fortune teller who escaped from prison was a small medium at large.',
    'A thief who stole a calendar… got twelve months.',
    'A thief fell and broke his leg in wet cement. He became a hardened criminal.'
  ]);

  const template = ({ item, index }, cb) => {
    const idx = index + 1;
    return (
      <div className="message" key={index}>
        <p>
          <span>
            {idx}.{item}
          </span>
          <button onClick={cb}>DELETE</button>
        </p>
      </div>
    );
  };

  const templateCreate = (_, cb) => {
    return <button onClick={cb}>Create</button>;
  };

  const templateDefault = () => {
    return 'New Item';
  };

  const handleChange = (e) => {
    const { value } = e.target;
    setItems(value);
  };

  console.log('render...');

  return (
    <Container>
      <ReactInteractiveList
        items={items}
        template={template}
        templateCreate={templateCreate}
        templateDefault={templateDefault}
        onChange={handleChange}
      />
    </Container>
  );
};

preview

license

Code released under the MIT license.