React TokenInput
A react token input component, which allow:
- Apply customize data structure.
- Customize render functions for
token label part
or the complete token
. - Customize separate characters for separate user input.
- Pre-processs function for normalized user input value .
It could be helpful to reproduce a single value into multiple values too.
- Validate function.
Demo: https://seawind543.github.io/react-token-input/
Installation
- Install the latest version of react and react-customize-token-input:
npm install --save react react-customize-token-input
- At this point you can import
react-token-input
and its styles in your application as follows:
import TokenInput from 'react-customize-token-input';
import 'react-customize-token-input/dist/react-customize-token-input.css';
Dev
- Run
npm install
to install required packages. - Run
npm run dev
to launch webpack-dev-server
. - After step 2, you will see following message output in command console.
Project is running at http://0.0.0.0:8000/
webpack output is served from /
- It might take some time for webpack to compiled. Please wait for message below output in the command console.
webpack: Compiled with warnings.
Note: To stop the program, just type ctrl + c
in command console.
Usage
<TokenInput />
<TokenInput readOnly={true} />
<TokenInput
defaultData={this.state.cData}
buildDataFromValue={this.actions.cData.buildDataFromValue}
dataValue={this.actions.cData.dataValue}
tokenLabelRender={this.actions.cData.tokenLabelRender}
validator={this.actions.cData.validator}
tokenErrorMessage={this.actions.cData.tokenErrorMessage}
onTokensUpdate={this.actions.cData.handleTokensUpdate}
/>
<TokenInput
reproduceValue={this.actions.urls.reproduceValue}
onTokensUpdate={this.actions.urls.handleTokensUpdate}
/>
Props
className: PropTypes.string,
readOnly: PropTypes.bool,
placeholder: PropTypes.string,
autoFocus: PropTypes.bool,
defaultData: PropTypes.array,
separators: PropTypes.array,
preprocessor: PropTypes.func,
buildDataFromValue: PropTypes.func,
dataValue: PropTypes.func,
tokenClassName: PropTypes.func,
tokenLabelRender: PropTypes.func,
tokenErrorMessage: PropTypes.func,
tokenRender: PropTypes.func,
validator: PropTypes.func,
onInputValueChange: PropTypes.func,
onTokensUpdate: PropTypes.func
Priority of props
When tokenRender
is provide, following props will be ignored.
buildDataFromValue
dataValue
tokenClassName
tokenLabelRender
tokenErrorMessage
License
MIT