Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-switch-selector

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-switch-selector

Data switch/toggle component for React️ ⚛

  • 1.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.1K
increased by5.75%
Maintainers
1
Weekly downloads
 
Created
Source

react-switch-selector · downloads version code style: prettier

Examples

Default

ReactSwitchSelector

Custom colors

ReactSwitchSelector

Installation

npm install react-switch-selector --save

or

yarn add react-switch-selector

Usage

SwitchSelector will stretch to fill it's parent size (both width and height), so it's required create dedicated div container.

import SwitchSelector from "react-switch-selector";
const options = [
   {
       label: <span>Foo</span>,
       value: {
            foo: true
       },
       selectedBackgroundColor: "#0097e6",
   },
   {
       label: "Bar",
       value: "bar",
       selectedBackgroundColor: "#fbc531"
   }
];

const onChange = (newValue) => {
    console.log(newValue);
};

const initialSelectedIndex = options.findIndex(({value}) => value === "bar");

return (
    <div className="your-required-wrapper" style={{width: 100, height: 30}}>
        <SwitchSelector
            onChange={onChange}
            options={options}
            initialSelectedIndex={initialSelectedIndex}
            backgroundColor={"#353b48"}
            fontColor={"#f5f6fa"}
        />
    </div>
);

Props

Prop nameTypeDefaultRequiredNote
optionsArray of OptionType[]trueOptions array to render. Each item has a label, value and optional styling props
onChangeFunction(v) => (console.log(v))trueonChange callback that returns selected Option's value
initialSelectedIndexnumber0falseInitially selected index of options array
forcedSelectedIndexnumberundefinedfalseForce selectedIndex with this prop
borderstring/number0falseBorder of wrapping div
backgroundColorstring#ecf0f1falseBackground color of wrapping div
selectedBackgroundColorstring#2ecc71falseBackground of selected Option
wrapperBorderRadiusnumber20falseBorder radius of wrapping div
optionBorderRadiusnumber18falseBorder radius of Option component
fontSizenumber14falseFont size of Option's label
fontColorstring#000falseFont color of Option's label
selectedFontColorstring#ffffalseFont color of selected Option's label
selectionIndicatorMarginnumber2falseInner px margin of selected option indicator
OptionType
Property nameTypeDefaultRequiredNote
labelstring/number/ReactElement/HTMLElementundefinedtrueOption's label
valueanyundefinedtrueOption's value that is returned by onChange callback
selectedBackgroundColorstringundefinedfalseBackground of this selected Option
fontColorstringundefinedfalseFont color of this Option's label
selectedFontColorstringundefinedfalseFont color of this selected Option's label
Overriding styles by pure css classes is available with react-switch-selector prefix:
  • react-switch-selector-wrapper - component root div
  • react-switch-selector-option - each option
  • react-switch-selector-option-label - each option item's label

Keywords

FAQs

Package last updated on 06 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc