custom-headless-toggle
v0.0.2
Published
Updated README
Downloads
136
Readme
Toggle Component
Description
The Toggle
component is a customizable toggle component. It allows the user to slide a toggle on / off.
Installation
To use the Toggle
component in your project, you can install it via npm (or include it as part of your component library):
npm install custom-headless-toggle
Usage
Here’s a simple example of how to use the Toggle
component in your application:
import React, { useState } from "react";
import { Toggle } from "custom-headless-toggle";
const App = () => {
const [showToggle, setShowToggle] = useState("");
const handleToggle = (selectedValue) => {
setShowToggle(selectedValue);
};
return (
<div>
<Toggle enabled={showToggle} setEnabled={handleToggle} />
</div>
);
};
export default App;
Props
Checkbox Props
| Prop | Type | Description |
| ------------ | ---------- | --------------------------------------------------------------------- |
| enabled
| boolean
| Value of the toggle, determining whether it is on or off. |
| setEnabled
| function
| A callback function that is called to update the value of the toggle. |
Styles
The Toggle
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 Toggle
component as needed to fit the design of your application.