JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q37418F
  • License MIT

React 'dark mode' component

Package Exports

  • dark-mode-react
  • dark-mode-react/dist/index.cjs.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dark-mode-react) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dark-mode-react

NOTE: react dark mode based on "react": "^18.2.0" and "react-dom": "^18.2.0". The user setting persists to localStorage.

Don't forget about ⭐ GitHub

import React from 'react';
import {Theme} from "dark-mode-react";
import yourDarkImage from './path/to/your/DarkImage.png'
import yourLightImage from './path/to/your/LightImage.png'

const NameYourComponent = () => {
  return (
    <div>
      <Theme
        darkIcon={yourDarkImage}
        lightIcon={yourLightImage}
        altDark='dark icon'
        altLight="light icon"
        width={50}
        height={50}
        className="your-class_name"
      />
    </div>
  )
};

A React theme component accepts the following props:

Key Description
darkIcon Image with .png, .jpg, .svg* extensions.
lightIcon Image with .png, .jpg, .svg* extensions.
altDark Type string, required.
altLight Type string, required.
width Type number. Width for your icon.
height Type number. Height for your icon.
myClass Type String. If you want to have background or add hover effect for icon wrapper.

* - Don't forget, svg has width and height by default.

Add your global styles. Example:

:root {
  --background-color: #007aff;
  --color-text: white;
}

[data-theme='light'] {
  --background: #227d2c;
  --color-text: black
}

body {
  background: var(--background-color);
  color: var(--color-text);
}

Installation

$ npm i dark-mode-react