SveltePress / sveltepress

A content centered site build tool, build on top of Sveltekit.
https://sveltepress.site
MIT License
370 stars 20 forks source link

Access current light/dark mode state via context store #243

Closed gka closed 9 months ago

gka commented 9 months ago

Describe the problem

For some of the examples in my SveltePress page I would love to know if the page is currently in dark or light mode.

Describe the proposed solution

it would be great if from my Svelte pages and live components I could just access a global isDark store, perhaps like this

import { getContext } from 'svelte';
const { isDark } = getContext('sveltepress');

Alternatives considered

The alternative would be to somehow track if there's a .dark class set on the <html> element, which doesn't really work reactively without a lot of hazzle.

Importance

nice to have

Blackman99 commented 9 months ago

Thanks for your feedback! This feature would be considered to add in the next release.

Blackman99 commented 9 months ago

New docs: https://sveltepress.site/reference/default-theme/#Global-context