@fallsimply/themer
TypeScript icon, indicating that this package has built-in type declarations

2.3.0 • Public • Published

@fallsimply/themer

install with npm i -D @fallsimply/themer or yarn add -D @fallsimply/themer

alternative to prefers-color-scheme media queries that allows using themes besides the native theme

sets an attribute on the body element - either light or dark

breaking changes

version 2 uses the document's html element as the root instead of the body element

before / after

before

CSS

main {
	color: black;
	background: white;
}
@media (prefers-color-scheme: dark) {
	main {
		color: white;
		background: black;
	}
}

CSS Variables

:root {
	--link: #00f;
}
@media (prefers-color-scheme: dark) {
	:root[dark] {
		--link: #f0f;
	}
}

after

CSS

main {
	color: black;
	background: white;
}

[dark] main {
	
	color: white;
	background: black;
}

CSS with Variables

:root {
	--link: #00f;
}

:root[dark] {
	--link: #f0f;
}

JS

import Themer from @fallsimply/themer
window.themer = new Themer()

additional themes shim

place in a .d.ts shim file such as shims-themer.d.ts to add additional themes add a union type under themes

import themer from "@fallsimply/themer";

declare module '@fallsimply/themer' {
	interface Options {
		themes: "sepia" | "amoled"
	}
}

declare global {
	interface Window {
		themer: themer
	}
}
}

Readme

Keywords

none

Package Sidebar

Install

npm i @fallsimply/themer

Weekly Downloads

0

Version

2.3.0

License

MIT

Unpacked Size

7.9 kB

Total Files

8

Last publish

Collaborators

  • fallsimply