Theme switcher for websites
-
Install package:
npm install @anmiles/theme-switcher
-
Import component:
import { ThemeSwitcher } from '@anmiles/theme-switcher';
-
Use component:
<ThemeSwitcher float="right" />
where
float(optional) - position of icon and dropdown box
-
Install package:
npm install @anmiles/theme-switcher
-
Copy all files from
distinto the target website. -
Create HTML container for theme switcher:
<div class="my-selector"></div>
-
Include React library and theme switcher:
<script type="text/javascript" src="https://unpkg.com/react@18.3.1/umd/react.development.js"></script> <script type="text/javascript" src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.development.js"></script> <script type="text/javascript" src="./theme-switcher-1.0.2.js"></script>
<script type="text/javascript" src="https://unpkg.com/react@18.3.1/umd/react.production.min.js"></script> <script type="text/javascript" src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js"></script> <script type="text/javascript" src="./theme-switcher-1.0.2.min.js"></script>
-
Place theme switcher into container:
<script type="text/javascript"> new ThemeSwitcher({ float: 'right' }) .render(document.querySelector('.my-selector')); </script>
where
float(optional) - position of icon and dropdown box
Use selectors to write theme-specific styles:
body[data-theme="light"] .selector {
/* css rules */
} body[data-theme="dark"] .selector {
/* css rules */
}Or you can just write default styles for light theme and override them for dark theme using body[data-theme="dark"].