@busshi/react-switch
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

publish

React-Switch

A custom React switch component reusable without extra dependency (only React dependencies).

Installation

yarn add @busshi/react-switch or npm install @busshi/react-switch

Custom properties

Props Type Default value Required / Optional
checked boolean required
onChange function required
width string 40px optional
height string 20px optional
borderRadius string 20px optional
backgroundColor string #ddd optional
thumbSize string 20px optional
thumbColor string white optional
checkedBackgroundColor string #306FDB optional

Note

Colors can be passed as prop as hex (#FFF), rgb (rgb(255, 255, 255)) or as noun (white).

Usage

import Switch from "@busshi/react-switch";
import { useState } from "react";

function App() {
  const [isChecked, setIsChecked] = useState(false);

  return (
    <div>
      <Switch
        checked={isChecked}
        onChange={() => {
          setIsChecked(!isChecked);
        }}
        width="40px"
        height="20px"
        borderRadius="20px"
        backgroundColor="#ddd"
        thumbSize="20px"
        thumbColor="white"
        checkedBackgroundColor="#306FDB"
      />
    </div>
  );
}

export default App;

Readme

Keywords

Package Sidebar

Install

npm i @busshi/react-switch

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

9.01 kB

Total Files

13

Last publish

Collaborators

  • busshi