New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@agney/react-dark-mode-toggle

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agney/react-dark-mode-toggle

An updated, cute dark mode toggle button for React.

latest
Source
npmnpm
Version
2.0.4
Version published
Maintainers
1
Created
Source

@agney/react-dark-mode-toggle

Rewrite of a cute dark mode toggle 🦉

Original library react-dark-mode-toggle was created by Alex Thoma. Credit goes out to those who helped build that library to what it is today. Let's see if we can take it even further.

latest release latest release code language: typescript vitejs code style: prettier

  • Switches out emotion for goober from the original repository.

This rewrite:

  • Adds native TS support
  • Adds Rollup bundling support (ESM/CJS output targets)
  • Adds CSS vendor prefixing via Emotion
  • Resolves issue where prop checked is true but the toggle initially renders in light-mode then snaps to dark-mode
  • Updates react-lottie-player to latest for TS support & to fix the above flickering problem
  • Project infrastructure (e.g. prettier, husky, lint-staged, etc.)

How it works

react-lottie-player is used to render a Lottie file (i.e. a JSON payload) in a React component we call DarkModeToggle. This underlying library is a peer dependency of the project which is why you'll see it in the installation instructions below.

🚀 Installation

npm:
npm i react-dark-mode-toggle-2
yarn:
yarn add react-dark-mode-toggle-2

✨ Usage

import React from "react";
import { DarkModeToggle } from "react-dark-mode-toggle-2";

export const YourComponent = () => {
  const [isDarkMode, setIsDarkMode] = React.useState(false);
  
  return (
    <DarkModeToggle 
      onChange={setIsDarkMode}
      isDarkMode={isDarkMode} 
      size={85} 
    />
  );
};

📌 Props

PropTypeDefaultRequired
onChangefuncN/AYes
isDarkModebooleanN/AYes
sizenumber (defaults to px) or a string containing a number+unit (e.g "10px", "2em", "4.5rem", "100%", etc). These units may also have a space between them (e.g. "10 px", "2 em", etc).85pxNo
speednumber1.3No
classNamestring''No

Note, this is not a dark mode theme implementation; it's just a button! You'll need to mix this with a management solution such as use-dark-mode.

📝 Notes

In Chrome, you may experience a blue outline around the toggle button after clicking it. If this behavior concerns you see this issue for more information and available workarounds.

✌️ License

MIT

Keywords

react

FAQs

Package last updated on 04 May 2023

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