npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-toggle-element

v2.1.1

Published

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

Downloads

27,998

Readme

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

| Type | Default | | -------------------------- | :-----: | | React element or component | none |

containerStyle style for main container

| Type | Default | | ----- | :-----: | | style | none |

disabled disable the Toggle Button component (optional)

| Type | Default | | ------- | :-----: | | boolean | false |

disabledStyle styling for Toggle Button Component for disabled (optional)

| Type | Default | | ------------------- | :-----: | | 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

| Type | Default | | -------------------- | :-----: | | Text style (object)) | none |

leftComponent define your left component here

| Type | Default | | -------------------------- | :-----: | | React element or component | none |

leftTitle button left title (optional)

| Type | Default | | ------ | :-----: | | string | none |

rightComponent define your right component here (optional)

| Type | Default | | -------------------------- | :-----: | | React element or component | none |

rightTitle button right title (optional)

| Type | Default | | ------ | :-----: | | string | none |

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

| Type | Default | | -------------------------- | :-----: | | React element or component | none |

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

| Type | Default | | -------------------------- | :-----: | | React element or component | none |

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

| Type | Default | | ------------------- | :-----: | | View style (object) | none |

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

| Type | Default | | ----------------------- | :-----: | | borderWidth | 0 | | width | 50 | | height | 50 | | radius | 25 | | activeBackgroundColor | #fde2e2 | | inActiveBackgroundColor | #ffb6b6 |

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

| Type | Default | | ----------------------- | :---------: | | borderWidth | 0 | | width | 50 | | height | 50 | | radius | 25 | | activeBackgroundColor | #fde2e2 | | inActiveBackgroundColor | #ffb6b6 | | borderActiveColor | transparent | | borderInActiveColor | transparent |

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

| Type | Default | | ------------------- | :-----: | | View style (object) | none |

animationDuration duration of the thumb button animation (optional).

| Type | Default | | ------ | :-----: | | number | 350 |