1.0.2 • Published 4 years ago

react-dark-mode-switch v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

react-dark-mode-switch

fancy checkbox to do whatever but styles as dark mode switch

NPM JavaScript Style Guide

Install

npm install --save react-dark-mode-switch

Default look

Farmers Market Finder Demo

Usage

import React, { Component } from 'react'
import DarkModeToggle from 'react-dark-mode-switch'
const darkModeClass="darkMode"

export default class App extends Component {
    state = {
    darkMode: false
  }

  toggleChecked = (event) => {
    this.setState({ darkMode: event.target.checked });
  }
  render() {
    return (
      <div className={`App ${this.state.darkMode? darkModeClass: ""}`}>
        DARK MODE TEST
        <DarkModeToggle
          /* required */
          toggleChecked={this.toggleChecked}
          isChecked={this.state.darkMode} 
          /* optional working default values are provided */
          darkLabel="dark" 
          lightLabel="light" 
          activeClass="darkActive"
          id="darkModeToggle" 
        />
      </div>
    )
  }
}

Props

PropTypeRequiredDescription
isCheckedBooleanValue of checkbox
toggleCheckedFunctionFunction to change isChecked. Does actually get you the event value event.target.checked
idStringPass your own id to the container. Preferably use this to apply your own styles since it overwrites the intern styles without !important
classNameStringPass your own className to the wrapper
activeClassStringClassName that gets added to the container when isChecked is true (default "DMT_Active")
classNameStringCan be used to add your own className to parent component
darkLabelStringString that gets displayed in the left half of the container (default "dark")
lightLabelStringString that gets displayed in the right half of the container (default "light")

License

MIT © https://github.com/kantimam