shine-and-bright

0.2.0 • Public • Published

shine-and-bright

Dark and Light Theme Switch CSS

NPM version

Installation

npm i shine-and-bright

Usage

Include shine-and-bright/index.css in your application.
Below is an example of including it in the root CSS.

@import url("./node_modules/shine-and-bright/index.css");

Markup

Switch:

<button class="snb-shine-and-bright-switch">
  <span class="snb-shine-and-bright"></span>
</button>

It changes to a moon icon when an ancestor element has dark class.
e.g.:

<button id="foo" class="snb-shine-and-bright-switch">
  <span class="snb-shine-and-bright"></span>
</button>
<script>
  document.querySelector("#foo").addEventListener("click", () => {
    document.documentElement.classList.toggle("dark");
  });
</script>

bright <-> shine

Icon only:

<button class="snb-shine-and-bright"></button>

It changes to a moon icon when an ancestor element has dark class.

Moon only:

<button class="snb-shine"></button>

Sun only:

<button class="snb-bright"></button>

Customization

You can customize some styles using CSS properties.

:root {
  --snb-icon-size: 18px; /* default 18px */
  --snb-animation-duration: 300ms; /* default 300ms */
  --snb-switch-width: 40px; /* default 40px (when 18px) */
  --snb-switch-padding: 1px; /* default 1px (when 18px) */
  --snb-switch-border-width: 1px; /* default 1px (when 18px) */
  --snb-switch-border-color: #888; /* default #888 */
  --snb-bright-color: orange; /* default orange */
  --snb-bright-color-second: gold; /* default gold */
  --snb-shine-color: yellow; /* default yellow */
}

Readme

Keywords

Package Sidebar

Install

npm i shine-and-bright

Weekly Downloads

4

Version

0.2.0

License

MIT

Unpacked Size

8.96 kB

Total Files

4

Last publish

Collaborators

  • ota-meshi