tickle/modules/utils/documentMode.mjs
2023-05-09 04:00:53 +02:00

15 lines
431 B
JavaScript

//@ts-check
/**
* Creates a helper to add or remove global classes that begin with `is-`
* @param {string} name
*/
export const documentMode = (name) => ({
on: () => document.body.classList.add(`is-${name}`),
off: () => document.body.classList.remove(`is-${name}`),
toggle: () => document.body.classList.toggle(`is-${name}`),
has: () => document.body.classList.contains(`is-${name}`),
});
export default documentMode;