custom-headless-tags
v0.0.2
Published
Added label and custom class
Downloads
121
Readme
Tags Component
Description
The Tags
component is a customizable input field for adding and deleting tags in a user-friendly manner. It allows users to add tags by pressing the "Enter" key and remove them with a close icon.
Installation
To use the Tags
component in your project, you can install it via npm (or include it as part of your component library):
npm install custom-headless-tags
Usage
Here’s a simple example of how to use the TagInput component in your application:
import React, { useState } from "react";
import Tags from "custom-headless-tags";
const App = () => {
const [tags, setTags] = useState([]);
const handleTagAdd = (tag) => {
setTags([...tags, tag]);
};
const handleTagDelete = (tagToDelete) => {
setTags(tags.filter((tag) => tag !== tagToDelete));
};
return (
<div>
<h1>Tag Input Example</h1>
<Tags
tags={tags}
onTagAdd={handleTagAdd}
onTagDelete={handleTagDelete}
placeholder="Add an option..."
/>
</div>
);
};
export default App;
Props
Tags Props
| Prop | Type | Description |
| ------------- | ----------------- | ------------------------------------------------------------------- |
| tags
| Array<string>
| An array of tags to display in the input field. |
| onTagAdd
| function
| A callback function that is called when a tag is added. |
| onTagDelete
| function
| A callback function that is called when a tag is deleted. |
| placeholder
| string
| Placeholder text for the input field (default: "Add an option..."). |
| label
| React.ReactNode
| Label to assign to the field (optional). |
| className
| string
| Variable that holds the custom class (optional) |
Styles
The Tag component is styled using Tailwind CSS classes. Make sure to include Tailwind CSS in your project to apply the styles correctly.
Example CSS Setup
If you haven’t set up Tailwind CSS yet, here’s a basic example of how to do it:
- Install Tailwind CSS:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
- Configure your tailwind.config.js file:
module.exports = {
content: ["./src/**/*.{js,jsx,ts,tsx}", "./public/index.html"],
theme: {
extend: {},
},
plugins: [],
};
- Include Tailwind in your CSS file: Add the following lines to your main CSS file to include Tailwind’s base, components, and utilities:
@tailwind base;
@tailwind components;
@tailwind utilities;
Customization
Feel free to customize the Tailwind classes used in the Tags
component as needed to fit the design of your application.