content editable tag input
Installation
To use TagInput in your React project, simply install it via NPM:
npm install @pradeepmishra/taginput
Then, import it into your project:
import TagInput from '@pradeepmishra/taginput'; Peer Dependencies
TagInput has peer dependencies of the following npm libraries
react slate slate-reactmake sure you have them all in your project's dependencies.
UsageTagInput can be used like any other React component, with props for customization:
<TagInput removeTagButton={false} initValue='Initial {{tag}} value' onValueChange={(value) => console.log(`New value: ${value}`)} addImageElement={(tagContent) => ( <img src={`https://example.com/${tagContent}`} /> )} transformInputText={(tagContent) => tagContent.toUpperCase()} transformInputElement={(tagContent) => ( <span style={{ color: 'blue' }}>{tagContent}</span> )} /> Props
removeTagButton
: Boolean (optional) - hide the delete button in all tags (default: false).
initValue
: String (optional) - provides an initial value for the input field (default: "").
onValueChange
: Function (optional) - called when the value of the input field changes. The new value is passed as an argument to the function.
addImageElement
: Function (optional) - called when a new tag is added. The content of the tag is passed as an argument to the function, and the function should return a valid HTML element to be displayed in the tag.
transformInputText
: Function (optional) - called when a new tag is added. The content of the tag is passed as an argument to the function, and the function should return a transformed string to be displayed in the tag.
transformInputElement
: Function (optional) - called when a new tag is added. The content of the tag is passed as an argument to the function, and the function should return a transformed HTML element to be displayed in the tag.
capturePattern
: RegExp (optional) - Provide a regex pattern to capture text to identify a tag.
TagInput is released under the MIT License. Feel free to use it in your personal or commercial projects. If you have any questions or issues, please feel free to open an issue on the Github repository.
AuthorPradeep Mishra Github Twitter Linkedin
Demo sitehttps://ce-taginput.netlify.app/
Rendered view版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。