Skip to content

Commit

Permalink
Update README.md with theme mode usage instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Mar 2, 2024
1 parent aa15ee3 commit 53246c1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ Vanilla, Next, React, Vue, and Master CSS are available:
* 💫 Access theme preferences and modes through context
* 🧩 Built-in `"use client"` directive

## Why should I use this?
CSS's `prefers-color-scheme` feature query cannot force override to the specified color mode. Once you want to switch themes, you cannot use `@media (prefers-color-scheme: dark)`.

https://stackoverflow.com/questions/56300132/how-to-override-css-prefers-color-scheme-setting

## How does this work?
This package automatically switches themes using `class=""` and `color-scheme:`; that's it.
```html
Expand Down Expand Up @@ -124,7 +129,7 @@ import ThemeModeProvider from '@master/theme-mode.vue'

## Basic usage
### Default to light or dark mode
You can set the default theme mode when the user has not set a theme preference, such as common `light` or `dark` mode:,
You can set the default theme mode when the user has not set a theme preference, such as common `light` or `dark` mode.
```tsx
<ThemeModeProvider preference="dark">...</ThemeModeProvider>
```
Expand All @@ -147,7 +152,7 @@ Rendered as:
> Note: CSS only supports light and dark modes for system preferences.
### Sync the user's preference to `localStorage`
By default `options.store` is set to `theme-preference`, which uses this key to perform local storage when the preference is changed.
By default `options.store` is set to `'theme-preference'`, which uses this key to set local storage when the preference is changed.

In this way, the theme preference set last time will be applied when the user visits or refreshes the website again.

Expand Down

0 comments on commit 53246c1

Please sign in to comment.