Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
dark-mode-context
Advanced tools
A simple context provider for dark mode. It can be used in combination with Tailwind CSS to apply dark mode class with support for respecting the user's system preferences.
It also includes a few components that Utilise Headless UI to make a accesable menu to control the dark mode. Note: this not tested yet.
A Demo can be found here, and the source code can be found here.
npm install --save dark-mode-context
yarn add dark-mode-context
import React, { Component } from 'react'
import { DarkModeProvider,DarkModeMenu } from 'dark-mode-context'
const App = () => (
<DarkModeProvider injectDarkClass>
<div>
<h1>Hello World</h1>
<DarkModeMenu />
</div>
</DarkModeProvider>
)
import React, { Component } from 'react'
import { useDarkModeContext, DarkModeProvider } from 'dark-mode-context'
const MyButton = () => {
const {isDark, toggleDarkMode} = useDarkModeContext()
return (
<button onClick={toggleDarkMode}>
{isDark ? 'Dark Mode' : 'Light Mode'}
</button>
)
}
const App = () => (
<DarkModeProvider injectDarkClass>
<div>
<h1>Hello World</h1>
<MyButton />
</div>
</DarkModeProvider>
)
injectDarkClass
: boolean
- Whether the DarkModeProvider should start in dark mode or not. Defaults to false
wrapAs
: React.ElementType | undefined
- The element to wrap the children in. Defaults to undefined
darkClassName
: string
- The class name to be used for dark mode. Defaults to dark
lightClassName
: string
- The class name to be used for light mode. Defaults to ''
children
: React.ReactNode
- The children of the DarkModeProviderNote: when
wrapAs
is not set, andinjectDarkClass
is set totrue
, the dark class will be added to the root element<html>
.
as
: React.ElementType - The element to be used for the menu. Defaults to React.Fragment
className
: string | undefined
- The class name to be used for the menu. Defaults to undefined
darkBtn
: React.ReactNode
- The button to be used for dark mode. Defaults to DarkBtn
lightBtn
: React.ReactNode
- The button to be used for light mode. Defaults to LightBtn
systemBtn
: React.ReactNode
- The button to be used for system mode. Defaults to SystemBtn
menuToggleBtn
: React.ReactNode
- The button to be used for toggling the menu. Defaults to MenuToggleBtn
Note: This component requires HeadlessUI to be installed, which can be done by running
npm install --save headlessui
.
onClick
: () => void
- The function to be called when the button is clicked. Defaults to undefined
className
: string | undefined
- The class name to be used for the button. Defaults to undefined
Note: These components uses Tailwind CSS to style the button. they can be styled by passing a class name to the
className
prop.
MIT © NatoNathan
FAQs
A simple context provider for dark mode
The npm package dark-mode-context receives a total of 4 weekly downloads. As such, dark-mode-context popularity was classified as not popular.
We found that dark-mode-context demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.