Documentation Index
Fetch the complete documentation index at: https://mintlify.com/kokonut-labs/kokonutui/llms.txt
Use this file to discover all available pages before exploring further.
A React hook that manages a collection of tags with automatic color assignment, maximum tag limits, and easy add/remove functionality.
Installation
Manually copy the hook from/hooks/use-tags.ts into your project.
Usage
API Reference
Parameters
The hook accepts a configuration object:| Parameter | Type | Default | Description |
|---|---|---|---|
onChange | (tags: Tag[]) => void | undefined | Callback fired when tags change |
defaultTags | Tag[] | [] | Initial tags |
maxTags | number | 10 | Maximum number of tags allowed |
defaultColors | string[] | See below | Array of Tailwind classes for tag colors |
Tag Type
Default Colors
The hook includes 5 default color schemes:- Blue:
bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300 - Purple:
bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300 - Green:
bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-300 - Yellow:
bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-300 - Red:
bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-900
Return Value
Returns an object with:| Property | Type | Description |
|---|---|---|
tags | Tag[] | Current array of tags |
setTags | (tags: Tag[]) => void | Set tags directly |
addTag | (tag: Tag) => Tag[] | undefined | Add a new tag, returns updated array or undefined if max reached |
removeTag | (tagId: string) => Tag[] | Remove tag by ID, returns updated array |
removeLastTag | () => Tag[] | undefined | Remove the last tag |
hasReachedMax | boolean | Whether max tag limit has been reached |
Features
- Automatic color cycling - Colors automatically assigned from default palette
- Max tag limit - Prevents adding more tags than allowed
- Change callbacks - Get notified when tags change
- Keyboard support -
removeLastTagfor backspace handling - Dark mode support - Default colors include dark mode variants
Example: Tag Input with Keyboard
Example: Custom Colors
Example: Controlled Tags
Use Cases
- Tag input components for forms
- Category selection interfaces
- Skill or technology selectors
- Email recipient chips (like Gmail)
- Filter tag management
- Multi-select with visual feedback
Color Assignment
Colors are assigned automatically in a round-robin fashion:- Tag 1: First color
- Tag 2: Second color
- Tag 6: First color again (cycles)
color property when adding a tag.
Notes
- All functions return the updated tags array for chaining
addTagreturnsundefinedif max tags reachedremoveLastTagreturnsundefinedif no tags exist- Default colors include dark mode support with Tailwind dark: prefix
- IDs must be unique strings