1.0.6 • Published 1 year ago

@busshi/react-switch v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

PropsTypeDefault valueRequired / Optional
checkedbooleanrequired
onChangefunctionrequired
widthstring40pxoptional
heightstring20pxoptional
borderRadiusstring20pxoptional
backgroundColorstring#dddoptional
thumbSizestring20pxoptional
thumbColorstringwhiteoptional
checkedBackgroundColorstring#306FDBoptional

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;
1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago