
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.
@hdoc-react/toggle-theme
Advanced tools
Simple button component for toggle between light and dark theme in your
React app.
localStorage with the key theme.localStorage, the default is the user's preferred
theme.npm install @hdoc-react/toggle-theme
First, import load-theme.js in your index.html:
<script
type="module"
src="/path/to/@hdoc-react/toggle-theme/dist/load-theme.js"
></script>
Then, in your App.jsx or another file:
import { ThemeButton } from "@hdoc-react/toggle-theme";
function App() {
return (
<>
<ThemeButton
lightElement={<span>Light</span>}
darkElement={<span>Dark</span>}
fullRounded
/>
</>
);
}
Finally, you will need to add your styles manually:
body {
background-color: var(--color-bg, #fff);
color: var(--color-text, #000);
}
.my-class {
color: var(--my-color-text, #000);
}
/* FOR LIGHT THEME: */
/* This is usually unnecessary. */
[data-theme="light"] {
--color-bg: #fff;
--color-text: #000;
--my-color-text: #000;
}
[data-theme="light"] .my-class {
--my-color-text: #000;
/* or */
color: #000;
}
/* FOR DARK THEME: */
[data-theme="dark"] {
--color-bg: #242424;
--color-text: #fff;
--my-color-text: #fff;
}
[data-theme="dark"] .my-class {
--my-color-text: #fff;
/* or */
color: #fff;
}
lightElement
Element to render when the theme is light.
Type: ReactNode
darkElement
Element to render when the theme is dark.
Type: ReactNode
fullRounded
Whether to render the button with rounded corners as a circle.
Type: boolean
theme-button
Default class name
theme-button--full-rounded
Styles the button as a circle when fullRounded=true
You can customize the background color of the button with the following CSS custom properties:
.theme-button {
--button-bg: #fff;
--button-bg-hover: #eee;
--button-bg-active: #ddd;
}
/* The same custom properties applies for dark theme. */
[data-theme="dark"] .theme-button {
--button-bg: #333;
--button-bg-hover: #444;
--button-bg-active: #555;
}
FAQs
A react button component for toggle the theme
We found that @hdoc-react/toggle-theme 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
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.