@intility/bifrost-react
Version:
React library for Intility's design system, Bifrost.
37 lines (36 loc) • 937 B
JavaScript
"use client";
import { c as _c } from "react-compiler-runtime";
import { useLayoutEffect } from "react";
/**
* React single-page-application helper to apply a Bifrost color mode to the
* root document element.
*
* Avoid for Next.js or other Server-Side frameworks where you can control the
* `<html>` element directly.
*
* @param mode Can be one of "light", "dark", or "system".
*
* @see https://bifrost.intility.com/react/useApplyColorMode
*
* @example
* useApplyColorMode("dark");
*/
export default function useApplyColorMode(mode) {
const $ = _c(3);
let t0;
let t1;
if ($[0] !== mode) {
t0 = () => {
document.documentElement.classList.toggle("bf-lightmode", mode === "light");
document.documentElement.classList.toggle("bf-darkmode", mode === "dark");
};
t1 = [mode];
$[0] = mode;
$[1] = t0;
$[2] = t1;
} else {
t0 = $[1];
t1 = $[2];
}
useLayoutEffect(t0, t1);
}