0.0.8 • Published 9 months ago

react-animated-switch v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

A customizable toggle-switch component for React.

  • Customizable - Greatly customizable using props and classes.
  • It Just Works - Sensible default styling. Uses module css file which is automatically inserted to code, so no need to import a separate css file.

Installation

To use this package in your React project, you can install it using npm or yarn:

npm install --save react-animated-switch

or

yarn add react-animated-switch

Usage

import React, { useState } from "react"
import { Switch } from "react-animated-switch"

function App() {
  const [checked, setChecked] = useState<boolean>(false)

  const onChange = (value: boolean) => {
    setChecked(value)
  }

  return (
    <div>
      <Switch checked={checked} onChange={(value: boolean) => onChange(value)} />
    </div>
  )
}

export default App

API

PropTypeDefaultDescription
checkedboolRequiredIf true, the switch is set to checked. If false, it is not checked.
onChange (value:boolean)funcRequiredInvoked when the user clicks the switch. It is passed one argument: value, which is a boolean that describes the presumed future state of the checked .
inActiveTrackColorstring'#D3D3D3'The switch track will take on this color when it is not checked. Only accepts hex-colors.
activeTrackColorstring'#0097EB'The switch track will take on this color when it is checked. Only accepts hex-colors.
inActiveThumbColorstring'#FFFFFF'The switch thumb will take on this color when it is not checked. Only accepts hex-colors.
activeThumbColorstring'#FFFFFF'The switch thumb will take on this color when it is checked. Only accepts hex-colors.
heightnumber28The height of the background of the switch, measured in pixels.
widthnumber56The width of the background of the switch, measured in pixels.
mainClassNamestringundefinedSet as the className of the outer shell of the switch. Useful for positioning the switch.
trackClassNamestringundefinedSet as the className of track of the switch.
thumbClassNamestringundefinedSet as the className of thumb of the switch.

NOTE: When passing className as prop you may have to use !important with css styling to overwrite the default styles

Contributors

License

MIT

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago