React TokenInput
Live Demo: https://seawind543.github.io/react-token-input/
React TokenInput (react-customize-token-input)
A react token (tag) controlled
input component, which support:
- Accept customize data structure.
- Customize token (tag) Look & Feel on the
label
Demo, delete button
Demo, or even override the whole Token component
Demo. - Customize separate characters for separate end-user input string. Demo
- Inline editing on exist token.
- Paste values. Demo
- Preprocessing function for normalized user input value.
It could be helpful to reproduce a single value into multiple values too. Demo
- Validate function.
Installation
- Install the latest version of react and react-customize-token-input:
yarn add react react-customize-token-input
- At this point you can import
react-token-input
and its styles in your application by:
import TokenInput from 'react-customize-token-input';
import 'react-customize-token-input/dist/react-customize-token-input.css';
Dev
- Run
yarn install
to install required packages. - Run
yarn dev
to launch webpack-dev-server
. - After step 2, you will see following message output in command console.
「wds」: Project is running at http://0.0.0.0:8000/
「wds」: webpack output is served from /
「wds」: Content not from webpack is served from ../docs
Note: To stop the program, just type ctrl + c
in command console.
- After step 3 complete, you could access
http://localhost:8000/
to see result.
Usage
See Live Examples: https://seawind543.github.io/react-token-input/
Note: Sources code of Examples in the folder examples
Props
style: PropTypes.object,
className: PropTypes.string,
readOnly: PropTypes.bool,
autoFocus: PropTypes.bool,
placeholder: PropTypes.string,
tokenValues: PropTypes.array.isRequired,
onTokenValuesChange: PropTypes.func,
separators: PropTypes.array,
onPreprocess: PropTypes.func,
onBuildTokenValue: PropTypes.func,
onInputValueChange: PropTypes.func,
onTokenValueValidate: PropTypes.func,
onGetTokenClassName: PropTypes.func,
onGetTokenDisplayLabel: PropTypes.func,
onRenderTokenDeleteButtonContent: PropTypes.func,
onGetTokenEditableValue: PropTypes.func,
onGetTokenErrorMessage: PropTypes.func,
customizeTokenComponent: PropTypes.func,
Default value of optional Props
className: '',
readOnly: false,
autoFocus: false,
placeholder: '',
separators: [
',',
';',
'\n',
'\r',
'\r\n',
];
onBuildTokenValue: buildDefaultTokenValue,
onInputValueChange: () => {},
onTokenValueValidate: () => undefined,
onGetTokenClassName: () => '',
onGetTokenDisplayLabel: getDefaultTokenEditableValue,
onGetTokenEditableValue: getDefaultTokenEditableValue,
onGetTokenErrorMessage: getDefaultTokenErrorMessage,
Props of customizeTokenComponent
Could also reference this Example Demo and its source code ExampleCustomizeToken
from the folder examples
.
readOnly: PropTypes.bool.isRequired,
tokenValue: PropTypes.any.isRequired,
tokenMeta: PropTypes.object.isRequired,
onGetClassName: PropTypes.func.isRequired,
onGetDisplayLabel: PropTypes.func.isRequired,
onRenderDeleteButtonContent: PropTypes.func,
onGetEditableValue: PropTypes.func.isRequired,
onGetErrorMessage: PropTypes.func.isRequired,
onBuildTokenValue: PropTypes.func.isRequired,
onEditStart: PropTypes.func.isRequired,
onEditEnd: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
License
MIT