UNPKG

simple-theme-changer

Version:

simple react component for a theme changer button

89 lines (59 loc) 1.88 kB
# Simple Theme Changer A simple React component to toggle between light and dark themes. ## Installation 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'; ``` ## Usage Once installed and imported, you can use the ThemeChanger component in your JSX like this: ```jsx <ThemeChanger /> ``` 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 <ThemeChanger defaultTheme="dark" /> ``` ## Theme Styling 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; } ``` ## Example 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 ( <div> <h1>Welcome to My App</h1> <ThemeChanger /> </div> ); }; export default App; ``` ## Props | Prop Name | Type | Default | Description | |----------------|--------|----------|--------------------------------------------------------| | `defaultTheme` | string | `"light"` | The default theme to use (`"light"` or `"dark"`). | ## License MIT License. See the LICENSE.txt file for details.