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

react-native-toggle-element

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-toggle-element

Switch toggle component for React Native. You can add title, icon, modify component for toggle button.

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.7K
decreased by-37.91%
Maintainers
0
Weekly downloads
 
Created
Source

React-Native-Toggle-Element 2.0 CircleCI

The library has been rewritten with Typescript support in version 2.0.0. This library will work well on both React Native and Expo, please check out the examples folder.

ezgif com-video-to-gif (7)

toggle

Installation

yarn add react-native-toggle-element

# or with npm

npm install react-native-toggle-element

Usage

Init value

import React, { useState } from "react";
import Toggle from "react-native-toggle-element";

const [toggleValue, setToggleValue] = useState(false);

Toggle with default components

toggle-no-content

<Toggle value={toggleValue} onPress={(val) => setToggleValue(val)} />

Toggle with left title

toggle-with-left-content

<Toggle
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  leftTitle="On"
/>

Toggle with right title

toggle-with-right-content

<Toggle
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  leftTitle="Right"
/>

Toggle with left title and right Title

toggle-left-right-title

<Toggle
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  leftTitle="Left"
  rightTitle="Right"
/>

Toggle with custom left component

toggle-left-component

<Toggle
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  leftComponent={<Icon name="credit" width="30" height="30" fill={"#3BD2B5"} />}
/>

Toggle with custom right component

ezgif com-video-to-gif

<Toggle
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  rightComponent={<Icon name="plus" width="30" height="30" fill={"#3BD2B5"} />}
/>

Toggle with mixed left & right components

ezgif com-video-to-gif (1)

<Toggle
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  disabled
  leftComponent={
    <Icon name="credit" width="30" height="30" fill={Colors.tabIconSelected} />
  }
  rightComponent={
    <Icon name="plus" width="30" height="30" fill={Colors.tabIconSelected} />
  }
/>

Toggle with thumb button components

toggle

<Toggle
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  thumbActiveComponent={
    <Icon name="sun" width="40" height="40" fill={"#3BD2B5"} />
  }
  thumbInActiveComponent={
    <Icon name="night" width="40" height="40" fill={"#03452C"} />
  }
  trackBar={{
    activeBackgroundColor: "#9ee3fb",
    inActiveBackgroundColor: "#3c4145",
    borderActiveColor: "#86c3d7",
    borderInActiveColor: "#1c1c1c",
    borderWidth: 5,
    width: 100,
  }}
/>

Disabled Toggle

ezgif com-video-to-gif (3)

<Toggle
  disabled
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  leftTitle="Left"
  rightTitle="Right"
/>

Modify style

Modify TrackBar Size

ezgif com-video-to-gif (5)

<Toggle
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  leftTitle="Left"
  rightTitle="Right"
  trackBar={{
    width: 200,
    height: 50,
    radius: 25,
  }}
/>

Modify TrackBar Style

TrackBarStyle will override Border active color & Border inactive color

ezgif com-video-to-gif (6)

<Toggle
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  trackBarStyle={{
    borderColor: "green",
  }}
  trackBar={{
    borderWidth: 2,
  }}
/>

Modify ThumbButton

ezgif com-video-to-gif (7)

<Toggle
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  leftTitle="Left"
  rightTitle="Right"
  thumbButton={{
    width: 60,
    height: 60,
    radius: 30,
  }}
/>

Modify Disabled Toggle

ezgif com-video-to-gif (8)

<Toggle
  disabled
  disabledTitleStyle={{ color: "red" }}
  disabledStyle={{ backgroundColor: "gray", opacity: 0.3 }}
  value={toggleValue}
  onPress={(newState) => setToggleValue(newState)}
  leftTitle="Left"
  rightTitle="Right"
/>

Props

  • containerStyle
  • disabled
  • disabledStyle
  • disabledTitleStyle
  • leftComponent
  • leftTitle
  • rightComponent
  • rightTitle
  • thumbActiveComponent
  • thumbInActiveComponent
  • thumbStyle
  • thumbButton
  • trackBar
  • trackBarStyle
  • animationDuration

Reference

Untitled_Artwork 2

TypeDefault
React element or componentnone

containerStyle style for main container

TypeDefault
stylenone

disabled disable the Toggle Button component (optional)

TypeDefault
booleanfalse

disabledStyle styling for Toggle Button Component for disabled (optional)

TypeDefault
View style (object)none

disabledTitleStyle styling for leftTitle & right Title(optional) when Toggle Button set with status is disabled(optional). If you want to set disable style for Active & Inactive you should use custom left component or custom right component

TypeDefault
Text style (object))none

leftComponent define your left component here

TypeDefault
React element or componentnone

leftTitle button left title (optional)

TypeDefault
stringnone

rightComponent define your right component here (optional)

TypeDefault
React element or componentnone

rightTitle button right title (optional)

TypeDefault
stringnone

thumbActiveComponent define your thumb button component when status is active (optional)

TypeDefault
React element or componentnone

thumbInActiveComponent define your thumb button component when status is inactive (optional)

TypeDefault
React element or componentnone

thumbStyle thumb button style (optional). Styling will override the value from thumbButton props

TypeDefault
View style (object)none

thumbButton define to change size and radius and color depend on active / inactive status (optional)

TypeDefault
borderWidth0
width50
height50
radius25
activeBackgroundColor#fde2e2
inActiveBackgroundColor#ffb6b6

trackBar define to change size and radius and color depend on active / inactive status (optional)

TypeDefault
borderWidth0
width50
height50
radius25
activeBackgroundColor#fde2e2
inActiveBackgroundColor#ffb6b6
borderActiveColortransparent
borderInActiveColortransparent

trackBarStyle trackbar style (optional). Styling will override the value from trackBar props

TypeDefault
View style (object)none

animationDuration duration of the thumb button animation (optional).

TypeDefault
number350

Keywords

FAQs

Package last updated on 30 Oct 2024

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