Giter Site home page Giter Site logo

vovanr / react-multiselect-two-sides Goto Github PK

View Code? Open in Web Editor NEW
15.0 4.0 11.0 687 KB

React multiselect two sides component

Home Page: https://vovanr.github.io/react-multiselect-two-sides

License: MIT License

JavaScript 89.45% HTML 2.72% CSS 7.83%
react react-component

react-multiselect-two-sides's Introduction

react-multiselect-two-sides

Commitizen friendly XO code style

NPM version Build Status

React multiselect two sides component

Demo: vovanr.github.io/react-multiselect-two-sides

Install

npm install --save react-multiselect-two-sides

Usage

See: example

class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      options: [
        {name: 'Foo', value: 0},
        {name: 'Bar', value: 1},
        {name: 'Baz', value: 2, disabled: true},
        {name: 'Qux', value: 3},
        {name: 'Quux', value: 4},
        {name: 'Corge', value: 5},
        {name: 'Grault', value: 6},
        {name: 'Garply', value: 7},
        {name: 'Waldo', value: 8},
        {name: 'Fred', value: 9},
        {name: 'Plugh', value: 10},
        {name: 'Xyzzy', value: 11},
        {name: 'Thud', value: 12}
      ],
      value: [0, 3, 9]
    };
  },

  handleChange = (value) => {
    this.setState({value});
  }

  render() {
    const {options, value} = this.state;
    const selectedCount = value.length;
    const availableCount = options.length - selectedCount;

    return (
      <MultiselectTwoSides
        {...this.state}
        className="msts_theme_example"
        onChange={this.handleChange}
        availableHeader="Available"
        availableFooter={`Available: ${availableCount}`}
        selectedHeader="Selected"
        selectedFooter={`Selected: ${selectedCount}`}
        labelKey="name"
        showControls
        searchable
      />
    );
  }
}

ReactDOM.render(<App/>, document.getElementById('app'));

Api

MultiselectTwoSides.propTypes = {
  availableFooter: PropTypes.node,
  availableHeader: PropTypes.node,
  className: PropTypes.string,
  clearFilterText: PropTypes.string,
  clearable: PropTypes.bool,
  deselectAllText: PropTypes.string,
  disabled: PropTypes.bool,
  filterBy: PropTypes.func,
  filterComponent: PropTypes.func,
  highlight: PropTypes.array,
  labelKey: PropTypes.string,
  limit: PropTypes.number,
  onChange: PropTypes.func,
  options: PropTypes.array,
  placeholder: PropTypes.string,
  searchable: PropTypes.bool,
  selectAllText: PropTypes.string,
  selectedFooter: PropTypes.node,
  selectedHeader: PropTypes.node,
  showControls: PropTypes.bool,
  value: PropTypes.array,
  valueKey: PropTypes.string
};

MultiselectTwoSides.defaultProps = {
  availableFooter: null,
  availableHeader: null,
  className: null,
  clearFilterText: 'Clear',
  clearable: true,
  deselectAllText: 'Deselect all',
  disabled: false,
  // Case-insensitive filter
  filterBy: (option, filter, labelKey) => option[labelKey].toLowerCase().indexOf(filter.toLowerCase()) > -1,
  filterComponent: null,
  highlight: [],
  labelKey: 'label',
  limit: undefined,
  onChange: () => {},
  options: [],
  placeholder: '',
  searchable: false,
  selectAllText: 'Select all',
  selectedFooter: null,
  selectedHeader: null,
  showControls: false,
  value: [],
  valueKey: 'value'
};

License

MIT © Vladimir Rodkin

react-multiselect-two-sides's People

Contributors

ex13 avatar jmferreiratech avatar vovanr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-multiselect-two-sides's Issues

Build Issue while bundling the react-multiselect-two-sides component in create-react-app

Hi,
We need to use this component in one of the react projects. After following the steps in the git repo we could install the component and bring it to the page through npm install. it all works fine during the application local development.

But when we try to create a minified build file of the project using npm run-script build, it throws an error as below
Creating an optimized production build...
Failed to compile.
Failed to minify the code from this file:
./node_modules/react-multiselect-two-sides/lib/index.js:78

So it doesn't generate a normal build. by going through the details of log and possible work around using this link
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify

We uninstalled the component and included all the component files under the src/components folder of the project and updated relevant references in JS files.
After including the component files in the project the Build works fine and I am able to deploy the project.

Can you please suggest if I am missing something here or can you publish the package pre-compiled?

Note - We are using react 16.3.2 on create-react-app boilerplate app and Tomcat for deployment.

Kindly Suggest.

Thanks & Regards,
Vmengh

Select All filtered options

Is it possible to pass over only the filtered options from the available side to the selected side using the select all button.
My current behavior is I have 18 options that display on the available side and I filter down to display only 3, however when I click the select all button, all 18 option move into the selected field.
How can I modify this behavior to only move the filtered options to the selected side?

Add keyboard navigation

Up — Select previous item
Down — Select next item
Left — Focus available list
Right — Focus selected list
Enter or Space — Add or remove selected item

MutiSelect Not Displaying Properly

Attempting to use your Two-Sided MultiSelect by following your example in a react app. The component works functionally, but does not display as in your example.

image

I have included both style.css files as you have, but as you can see from the image, the styling is not working.

I am using the same return statement as you have in the example except for the settings.
<MultiselectTwoSides
className="msts_theme_example"
availableHeader="Available"
availableFooter={Available: ${availableCount}}
selectedHeader="Selected"
selectedFooter={Selected: ${selectedCount}}
placeholder="Filter…"
options={options}
highlight={highlight}
value={value}
onChange={this.handleChange}
/>

Is there something missing? Does this component actually work?

I attempted to clone your repository and run the example, but it does not seem to render at all.

Unexpected token (190:4) You may need an appropriate loader to handle

I am trying to load, but i get this error:

ERROR in ./~/react-multiselect-two-sides/index.jsx
Module parse failed: C:\Users\amaru\ALQUIMIO\my-new-project\node_modules\react-multiselect-two-sides\index.jsx Unexpected token (161:3)
You may need an appropriate loader to handle this file type.

My webpack.config is:

 {
          test: /\.(js|jsx)$/,
          exclude: /node_modules/,
          use: {
            loader: 'babel-loader',
            options: {
              cacheDirectory: true,
              presets: ['es2015', 'react', 'env']
            }
          }
        },

my .babelrc

{
  "presets": [
    "react",
    "es2015",
    "stage-0",
    "env"
  ],
  "plugins": [
    ["transform-class-properties", { "spec": true }],
    ["transform-object-rest-spread"]
  ]
}

and my dependencies:

"devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-preset-env": "^1.6.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "copy-webpack-plugin": "^4.1.0",
    "css-hot-loader": "^1.3.1",
    "css-loader": "^0.28.7",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^0.11.2",
    "html-loader": "^0.5.1",
    "html-webpack-plugin": "^2.30.1",
    "node-sass": "^4.5.3",
    "rimraf": "^2.6.2",
    "sass-loader": "^6.0.6",
    "source-list-map": "^2.0.0",
    "style-loader": "^0.18.2",
    "uglify-js": "^3.1.3",
    "url-loader": "^0.5.9",
    "webpack": "^3.6.0",
    "webpack-dev-server": "^2.9.1"
  },
  "dependencies": {
    "axios": "^0.17.0",
    "bootstrap": "^4.0.0-beta",
    "chart.js": "2.7.0",
    "codemirror": "^5.30.0",
    "font-awesome": "^4.7.0",
    "history": "4.7.2",
    "is-url-external": "^1.0.3",
    "lodash": "^4.17.4",
    "react": "^15.6.2",
    "react-chartjs-2": "2.6.2",
    "react-codemirror2": "^2.0.2",
    "react-dom": "^15.6.2",
    "react-dropzone": "^4.2.1",
    "react-ladda": "5.0.7",
    "react-quill": "^1.1.0",
    "react-redux": "^5.0.6",
    "react-router-dom": "4.2.2",
    "react-select": "1.0.0-rc.10",
    "react-text-mask": "4.1.0",
    "react-transition-group": "^1.2.0",
    "reactstrap": "^4.8.0",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0",
    "simple-line-icons": "^2.4.1",
    "spinkit": "^1.2.5"
  }

I am trying to use the componet like this:
import MultiselectTwoSides from 'react-multiselect-two-sides';

Thank you

Multiselect two sides not working

Hi. I cannot use your component, I'm getting this error whenever I try to use your component:

invariant.js:44 Uncaught Error: Invalid tag: /static/media/index.80a11b5a.jsx

Using
react: 15.6.1

Any idea how to solve it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.