@zenequityui/tags-input
v0.9.6
Published
zenequityui: Basic Tags Input Component
Downloads
17
Readme
Installation
To install a component run
$ npm install @zenequityui/tags-input --save
Please import CSS styles via
@import '/path__to__node_modules/@zenequityui/tags-input/dist/index.min.css
Usage
Tags Input
import { TagsInput } from '@zenequityui/tags-input';
const suggestions = [
{title: 'Argentina', value: 'argentina'},
{title: 'Australia', value: 'australia'},
{title: 'Belgium', value: 'belgium'},
{title: 'Bhutan', value: 'bhutan' },
{title: 'Brazil', value: 'brazil' },
{title: 'Canada', value: 'canada' },
{title: 'China', value: 'china' },
{title: 'Colombia', value: 'colombia' },
{title: 'Egypt', value: 'egypt' },
{title: 'Finland', value: 'finland' },
{title: 'Georgia', value: 'georgia' },
{title: 'Germany', value: 'germany' },
{title: 'India', value: 'india' },
{title: 'Indonesia', value: 'indonesia' },
];
initialState = {
suggestionContent: suggestions,
selectedItem: [],
searchValue: '',
};
<TagsInput
suggestions={state.suggestionContent}
placeholder="Select anyone"
searchValue={state.searchValue}
onChange={(event) => {
setState({
searchValue: event,
})
}}
searchContent={['title']}
renderSuggestion={(suggestion) => suggestion.title}
messageIfEmpty="No Item Found"
onAddTag={(item, meta) => {
if (meta.isSuggestion) {
setState(prevState => ({
selectedItem: [...prevState.selectedItem, item.value],
searchValue: '',
}));
} else {
setState(prevState => ({
selectedItem: [...prevState.selectedItem, item],
searchValue: '',
}));
}
}}
onRemoveTag={(item, index, meta) => {
setState({
selectedItem: state.selectedItem.filter((item, i) => i !== index),
});
}}
tags={state.selectedItem}
renderTag={tag => tag}
/>
Expanded Tags Input
import { TagsInput } from '@zenequityui/tags-input';
const suggestions = [
{title: 'Argentina', value: 'argentina'},
{title: 'Australia', value: 'australia'},
{title: 'Belgium', value: 'belgium'},
{title: 'Bhutan', value: 'bhutan' },
{title: 'Brazil', value: 'brazil' },
{title: 'Canada', value: 'canada' },
{title: 'China', value: 'china' },
{title: 'Colombia', value: 'colombia' },
{title: 'Egypt', value: 'egypt' },
{title: 'Finland', value: 'finland' },
{title: 'Georgia', value: 'georgia' },
{title: 'Germany', value: 'germany' },
{title: 'India', value: 'india' },
{title: 'Indonesia', value: 'indonesia' },
];
initialState = {
suggestionContent: suggestions,
selectedItem: [],
searchValue: '',
};
<TagsInput
isExpanded
suggestions={state.suggestionContent}
placeholder="Select anyone"
searchValue={state.searchValue}
onChange={(event) => {
setState({
searchValue: event,
})
}}
searchContent={['title']}
renderSuggestion={(suggestion) => suggestion.title}
messageIfEmpty="No Item Found"
onAddTag={(item, meta) => {
if (meta.isSuggestion) {
setState(prevState => ({
selectedItem: [...prevState.selectedItem, item.value],
searchValue: '',
}));
} else {
setState(prevState => ({
selectedItem: [...prevState.selectedItem, item],
searchValue: '',
}));
}
}}
onRemoveTag={(item, index, meta) => {
setState({
selectedItem: state.selectedItem.filter((item, i) => i !== index),
});
}}
tags={state.selectedItem}
renderTag={tag => tag}
/>