simple react component for a theme changer button
npm install simple-theme-changerA simple React component to toggle between light and dark themes.
To use this component in your React project, follow these steps:
1. Install the package via npm:
``bash`
npm install simple-theme-changer
2. In your .jsx or .js file, import the ThemeChanger component:
`js`
import ThemeChanger from 'simple-theme-changer';
Once installed and imported, you can use the ThemeChanger component in your JSX like this:
`jsx`
By default, the theme is set to light. If you want to change the default theme to dark, you can pass the defaultTheme prop like this:
`jsx`
To apply the styles based on the current theme, you can use the following class names:
- .light for light theme styles.
- .dark for dark theme styles.
For example, if you want to apply different styles to an element based on the theme, you can do something like this:
`css
/ For light theme /
.light .my-element {
background-color: white;
color: black;
}
/ For dark theme /
.dark .my-element {
background-color: black;
color: white;
}
`
Here is a simple example of how to use the ThemeChanger component:
`jsx
import React from 'react';
import ThemeChanger from 'simple-theme-changer';
const App = () => {
return (
export default App;
`
| Prop Name | Type | Default | Description |
|----------------|--------|----------|--------------------------------------------------------|
| defaultTheme | string | "light" | The default theme to use ("light" or "dark"`). |
MIT License. See the LICENSE.txt file for details.