@dirk-bester/dark-light
v1.0.3
Published
A SvelteKit skeleton tailwindcss dark mode component with dark|light|OS settings.
Downloads
4
Maintainers
Readme
Install
$ npm install --save @dirk-bester/dark-light
Usage
import { osDarkLightWatcher } from '@dirk-bester/dark-light/dist';
<svelte:head>{@html `<script>${osDarkLightWatcher.toString()} osDarkLightWatcher();</script>`}</svelte:head>
<Darklight>
<!-- 🌚🌑 🌓 🌔🌕🌛🌞 -->
<button slot="dark" class="btn-icon"><h1>🌑</h1></button>
<button slot="os" class="btn-icon"><h1>🌓</h1></button>
<button slot="light" class="btn-icon"><h1>🌕</h1></button>
</Darklight>
You can pass in any controls you want. Buttons preserve a11y navigation.
Why
- Devices have a dark mode setting.
- User's want the simplicity of coming to your website and immediately getting their setting.
- Some users even want the OS to switch between dark and light based on time of day.
- An inferior approach is to have a mishmash of custom settings that ignore the OS setting.
- Why force users to twiddle on your site? Do the right thing.
Building
To build your library:
npm run package
To create a production version of your showcase app:
npm run build
You can preview the production build with npm run preview
.
To deploy your app, you may need to install an adapter for your target environment.
Publishing
Go into the package.json
and give your package the desired name through the "name"
option. Also consider adding a "license"
field and point it to a LICENSE
file which you can create from a template (one popular option is the MIT license).
To publish your library to npm:
npm publish