1.0.4 • Published 7 months ago

flexible-switch-react v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Installation

npm install flexible-switch-react

Usage

A basic implementation looks as follows:

import {Switcher} from 'flexible-switch-react';
const [isActive, setIsActive] = useState(false);
<Switcher isActive={isActive} setIsActive={setIsActive} />

Example of adding an icon:

import { MdDarkMode } from "react-icons/md";
<Switcher 
    isActive={isActive} 
    setIsActive={setIsActive} 

    iconThumbLeft={<MdDarkMode/>}
/>

API

PropTypeDefaultDescription
isActiveboolRequiredIf false, the switch is set to the left. If true, it is set to the right.
setIsActivefuncRequiredInvoked Called when the user clicks the toggle.
sizeSwitchstring100pxThe size of the switch must be entered in pixels in string format.
backgroundSwitchLeftstring'rgba(255, 255, 255, 0.500)'Switch background when thumb is on the left.
backgroundSwitchRightstring'white'Switch background when thumb is on the left.
textColorSwitchLeftstring'black'Text color when thumb is on the left.
textColorSwitchRightstring'black'Text color when thumb is on the right.
BoxShadowSwitcherLeftstring''Allows you to add a shadow from the switch when the thumb is on the left. For example 'box-shadow: 0 0 5px white'
BoxShadowSwitcherRightstring''Allows you to add a shadow from the switch when the thumb is on the right. For example 'box-shadow: 0 0 5px black'
textSwitchLeftstring''Allows you to add text (up to two characters) to the switch on the left.
textSwitchRightstring''Allows you to add text (up to two characters) to the switch on the right.
iconSwitchLeftReact.ReactElementundefinedAllows you to add an icon to the switch as a react component on the left.
iconSwitchRightReact.ReactElementundefinedAllows you to add an icon to the switch as a react component on the right.
backgroundThumbLeftstring'rgb(83, 124, 82)'Adds a background to the thumb when it is on the left. accessibility.
backgroundThumbRightstring'rgb(5, 159, 3)'Adds a background to the thumb when it is on the right.
textColorThumbLeftstring'black'Adds text color when the thumb is on the left.
textColorThumbRightstring'black'Adds text color when the thumb is on the right.
BoxShadowThumbLeftstring''Adds a shadow from the thumb when it is on the left. For example 'box-shadow: 0 0 5px white'
BoxShadowThumbRightstring''Adds a shadow from the thumb when it is on the right. For example 'box-shadow: 0 0 5px black'
textThumbLeftstring''Allows you to add text (up to two characters) to the thumb when it is on the left.
textThumbRightstring''Allows you to add text (up to two characters) to the thumb when it is on the right.
iconThumbLeftReact.ReactElementundefinedAllows you to add an icon to the thumb as a react component when it is on the left.
iconThumbRightReact.ReactElementundefinedAllows you to add an icon to the thumb as a react component when it is on the right.
speedSwitchstring'all 500ms linear'Sets the speed of change for the switch.
speedThumbstring'all 500ms linear'Sets the speed of change for the thumb.