
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
day-night-toggle
Advanced tools
A beautiful day/night theme toggle button React component with small, medium, and large sizes
A beautiful day/night mode toggle button React component library.

npm install day-night-toggle
# or
yarn add day-night-toggle
# or
pnpm add day-night-toggle
import { DayNightToggle } from 'day-night-toggle';
import 'day-night-toggle/dist/DayNightToggle.css';
function App() {
return <DayNightToggle />;
}
import { DayNightToggle } from 'day-night-toggle';
import 'day-night-toggle/dist/DayNightToggle.css';
function App() {
return (
<DayNightToggle
syncBody={true}
onChange={(isDark) => {
console.log('Current mode:', isDark ? 'dark' : 'light');
}}
/>
);
}
import { useState } from 'react';
import { DayNightToggle } from 'day-night-toggle';
import 'day-night-toggle/dist/DayNightToggle.css';
function App() {
const [isDark, setIsDark] = useState(false);
return (
<DayNightToggle
defaultDark={isDark}
onChange={setIsDark}
/>
);
}
import { DayNightToggle } from 'day-night-toggle';
import 'day-night-toggle/dist/DayNightToggle.css';
function App() {
return (
<div>
<h3>Small (default)</h3>
<DayNightToggle size="small" />
<h3>Medium</h3>
<DayNightToggle size="medium" />
<h3>Large</h3>
<DayNightToggle size="large" />
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
defaultDark | boolean | false | Initial state for dark mode |
syncBody | boolean | false | Whether to sync to body's data-dark-mode attribute |
onChange | (isDark: boolean) => void | - | Callback function when toggled |
className | string | '' | Custom class name |
style | React.CSSProperties | - | Custom styles |
size | 'small' | 'medium' | 'large' | 'small' | Size of the toggle button |
The component controls state through the aria-pressed attribute:
aria-pressed="false" represents light mode (day)aria-pressed="true" represents dark mode (night)CSS uses the [aria-pressed=true] selector to set --dark: 1, which triggers all animations and style changes.
The component uses CSS variables. You can customize styles by overriding these variables:
.toggle {
--width: 300px; /* Button width */
--speed: 0.6s; /* Animation speed */
--sun: hsl(47, 91%, 58%); /* Sun color */
--moon: hsl(212, 13%, 82%); /* Moon color */
}
import 'day-night-toggle/dist/DayNightToggle.css'syncBody={true}, the component will automatically set the data-dark-mode attribute on bodyMIT
FAQs
A beautiful day/night theme toggle button React component with small, medium, and large sizes
We found that day-night-toggle demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.