ce-theme-switcher

0.0.3 • Public • Published

Yet another dark/light mode switcher

Working with the code

  • Clone the repo git clone ...
  • Install dependencies npm install
  • Mesh with the code npm run server

Using the code

  • In the HTML insert the custom element:
<dark-light-switch
    default=true 
    text-on=on
    text-off=off
    text-legend="dark theme:">
</dark-light-switch>
  • Include the javascript and the stylesheet as well
<link href=index.css rel=stylesheet>
<script type=module src=index.js></script>

Attributes

You can control aspects of the switcher through attributes:

  • default: Indicates a prefered default theme. If the browser supports prefers-color-scheme then this value will be ignored and will get the one from the system. Also since the switcher is using the browser's localstate to preserve the state this will be effective only the first time a user visits a page with the switcher (consecutive requests will take the value directly from the localstate)
  • text-on: Allows for I8n of the default string on, can be ommited for English sites
  • text-off: Allows for I8n of the default string off, can be ommited for English sites
  • text-legend: Allows for I8n of the default string dark theme:, can be ommited for English sites

Events

  • Every time the state is changed a change event is ommited from the dark-light-switch

Note

  • The switcher will also synchronise to the system events for prefers-color-scheme

Icons from the Font Awesome icon set:

Readme

Keywords

none

Package Sidebar

Install

npm i ce-theme-switcher

Weekly Downloads

19

Version

0.0.3

License

MIT

Unpacked Size

12.4 kB

Total Files

7

Last publish

Collaborators

  • dgrammatiko