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

darco-dark-mode

v0.0.9

Published

a customizable component to switch between dark and light theme

Downloads

7

Readme

Dark mode switch theme

Customizable Dark Mode Component

The "Customizable Dark Mode Component" is a versatile React component designed to effortlessly integrate dark mode functionality into your web applications. With this component, you can easily switch between light and dark themes while allowing customization through various props.

darkmode

Features

  • Dark Mode Switching: Seamlessly switch between light and dark themes with a straightforward user interface.

  • Custom Icons: Customize icons for both light and dark modes using the icons prop. Easily set different icons based on the chosen theme.

  • Custom Styles: Tailor the appearance of the dark mode switch and other interface elements with the styles prop. You can define specific styles for the main container, switch container, and icons container.

  • CSS Variables Control: Use the switchStyles prop to dynamically adjust CSS variables when switching between themes. This feature enables you to fine-tune the look and feel of your application in different themes.

  • Switch Mode: Choose between "dynamic" and "static" dark mode switching modes, allowing you to determine the behavior of the dark mode transition.

  • Hover Effects: Enable or disable hover effects in dark mode with the hover prop, granting you control over how user interactions are presented in different themes.

Installation

   npm i darco-dark-mode

Prop Types

CustomStyles

  • mainContainer?: CSSProperties: Optional custom styles for the main container.
  • switchContainer?: CSSProperties: Optional custom styles for the switch container.
  • iconsContainer?: CSSProperties: Optional custom styles for the icons container.

switchMod

  • "dinamic": Dynamic dark mode switching.
  • "static": Static dark mode switching.

darkmodeProps

  • switchStyles?: SwitchStyles : An array of two objects specifying styles for different themes.
  • icons?:: An array of objects specifying icons for different themes.
  • SwitchMode?: : The mode of dark mode switching ("dynamic" or "static").
  • styles?: : Custom CSS.Properties styles for the switch component.
  • hover?: : Specifies whether hover effects should be applied in dark mode.

themeType

  • "Light": Light theme.
  • "Dark": Dark theme.

SwitchStyles

An array of two objects specifying styles for different themes:

  • theme: The theme type ("Light" or "Dark").
  • variables: An array of CSS variable names to change.
  • values: An array of corresponding values to set for the CSS variables.

Icons

An array of two objects specifying icons for different themes:

  • theme: The theme type ("Light" or "Dark").
  • icon: The icon to display as a JSX element.

isDark

  • a callback funtion to handle the current state

Usage

You can use these types in your React application to ensure type safety when dealing with custom styles and dark mode configurations.

Example usage in a component:

icons: (Type: Icons | boolean):

  • Customize icons for light and dark themes.

Example of icons use:

import { Icons } from "darco-dark-mode/types";
import Darkmode from "darco-dark-mode";

const customIcons: Icons = [
  {
    theme: "Light",
    icon: <LightIcon />, // or a svg icon
  },
  {
    theme: "Dark",
    icon: <DarkIcon />, // or a svg icon
  }
]

const App = () => {
  return (
    <Darkmode icons={customIcons}/>
     // or
    <Darkmode icons /> // to use the default icons
  )
}

Example to switch styles:

switchStyles: (Type: SwitchStyles):

Adjust CSS variables dynamically when switching themes. Example:

/* your CSS styles */
:root {
  --bg-color: red;
  --color: blue;
}
body {
  background-color: var(--bg-color);
  color: var(--color);
}
  • This will change your CSS variables when switching between light and dark themes
import Darkmode, { SwitchStyles } from "darco-dark-mode";

const switchStylesVariables: SwitchStyles = [
  {
    theme: "Light",
    variables: ["--bg-color", "--color"],
    values: ["white", "black"],
  },
  {
    theme: "Dark",
    variables: ["--bg-color", "--color"],
    values: ["black", "white"],
  },
];

const App = () => {
  return <Darkmode switchStyles={switchStylesVariables} />;
};

Example to customize the switch button:

Styles: (Type: CSSProperties):

  • Custom styles for the main container.
  • Custom styles for the switch container.
  • Custom styles for the icons container.

you can customize the styles for the main container, switch container, and icons container, passing an object with CssProperties to the styles prop.

import Darkmode, { CustomStyles } from "darco-dark-mode";

const customStyles: CustomStyles = {
      mainContainer: {
        background: "red",
        border: "none"
        /* more custom styles for the main container*/
      },
      switchContainer: {
        background: "purple",
        borderRadius: "10px"
        /* more custom styles for the switch container */

      },
      iconsContainer: {
        color: "red",
        justifyContent: "center",
        alignItems: "center"
        /* more custom styles for the icon container */
      }
    },

const App = () => {
  return (
    <Darkmode styles={customStyles}/>
  )
}

Example of use of the isDark prop

import { useState } from "react";
import Darkmode from "./components/Darkmode";

function App() {
  const [theme, setTheme] = useState("");

  const myCurrentTheme = (e: string) => {
    setTheme(e);
  };

  return (
    <div className="App">
      <Darkmode isDark={myCurrentTheme} />
      <h1>DarkMode working on it ...</h1>
      <h2>my theme is {theme}</h2>
    </div>
  );
}