3.0.0 • Published 1 year ago

@shannqa/light-dark-theme v3.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

light-dark-theme

Work in progress

Keep in mind that this is my first attempt at creating a npm module, more of a learning excercise than a legitimate tool :)

It's a very simple module for adding a switch to toggle the page's light/dark theme in javascript.

  1. Import the module into your js file: import setTheme from "@shannqa/light-dark-theme";

  2. Create or select an element which is going to be your toggle, for example: const themeSetter = document.createElement("button");

  3. Run the function from the module, using the above element as an argument: setTheme(themeSetter);

  4. (Optional) Add styling and append the element to the DOM:

themeSetter.classList.add("theme-toggle");
header.appendChild(themeSetter);
  1. In your CSS file, add following selectors:
:root,
:root.light {
}
:root.dark {
}
  1. Add your preferred styling to the light and dark root classes using variables, for example:
--bg-color: white;
--font-color: black;
--secondary-color: rgb(82, 12, 90);
  1. Use the variable colors in your regular CSS selectors, for example:
body {
background-color: var(--bg-color);
color: var(--font-color);
}
3.0.0

1 year ago

2.3.1

1 year ago

2.3.0

1 year ago

2.2.5

1 year ago

2.2.4

1 year ago

2.2.3

1 year ago

2.2.2

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.1.5

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago