addDarkSubscriber((dark) => { console.log("Dark mode changed: ", dark); }); setDark(true); // will trigger the subscriber
Persisting to localStorage
You can persist the dark mode preference to by passing persist: true to initDark.
This will make initDark also load the preference from localStorage.
import { initDark } from"@pistonite/celera";
initDark({ persist:true });
Setting color-scheme CSS property
The color-scheme property handles dark mode for native components like buttons
and scrollbars. By default, initDark will handle setting this property for the :root selector.
You can override this by passing a selector option.
import { initDark } from"@pistonite/celera";
// will set `.my-app { color-scheme: dark }` initDark({ selector:".my-app" });
Initialize the dark mode global state
Detect user preference
User preference is detected with
matchMediaAPI, if available.Global dark mode state
initDarkinitializes the dark mode state.Persisting to localStorage
You can persist the dark mode preference to by passing
persist: truetoinitDark. This will makeinitDarkalso load the preference from localStorage.Setting
color-schemeCSS propertyThe
color-schemeproperty handles dark mode for native components like buttons and scrollbars. By default,initDarkwill handle setting this property for the:rootselector. You can override this by passing aselectoroption.