Skip to content

Commit

Permalink
Merge pull request #1373 from lachlanjc/default-color-scheme-true
Browse files Browse the repository at this point in the history
feat(color-modes): Default useColorModeMediaQuery to true
  • Loading branch information
hasparus authored Dec 21, 2020
2 parents b8a093a + 9bf05e4 commit 4d67386
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

## v0.6.0 UNRELEASED

- **BREAKING**: Default `useColorModeMediaQuery` to `true`. Issue #624, PR #1373
- Extract objects with nested variant props. Issue #1357
- Add ability for MDX styling, and fix mdx table align styles. Issue #654
- Remove recursive default values from CSS custom properties. PR #1327
Expand Down
6 changes: 3 additions & 3 deletions packages/color-modes/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const useColorModeState = (theme: Theme = {}) => {
React.useEffect(() => {
const stored = theme.useLocalStorage !== false && storage.get()
document.body.classList.remove('theme-ui-' + stored)
if (!stored && theme.useColorSchemeMediaQuery) {
if (!stored && theme.useColorSchemeMediaQuery !== false) {
const query = getMediaQuery()
setMode(query)
return
Expand Down Expand Up @@ -119,10 +119,10 @@ const applyColorMode = (theme: Theme, mode: string): Theme => {
})
}

const BodyStyles = ({ theme }: { theme: Theme}) =>
const BodyStyles = ({ theme }: { theme: Theme }) =>
jsx(Global, {
styles: () => {
return createColorStyles(theme);
return createColorStyles(theme)
},
})

Expand Down
11 changes: 6 additions & 5 deletions packages/docs/src/pages/color-modes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ npm i gatsby-plugin-theme-ui

This plugin will look for a `src/gatsby-plugin-theme-ui/index.js` file to import and pass to the ThemeProvider.

```js
// gatsby-config.js
```js filename=gatsby-config.js
module.exports = {
plugins: ['gatsby-plugin-theme-ui'],
}
Expand Down Expand Up @@ -120,16 +119,18 @@ This will cause the colors to flash on initial page load.
}
```

### Initialize mode with `prefers-color-scheme` media query
### Responding to the `prefers-color-scheme` media query

To initialize a color mode based on the `prefers-color-scheme` media query, add the `useColorSchemeMediaQuery` flag to your theme.
The `useColorSchemeMediaQuery` configuration option on the theme
initializes a color mode based on the `prefers-color-scheme` media query.
This will set the initial color mode to `dark` when `@media (prefers-color-scheme: dark)` matches,
or `light` when `@media (prefers-color-scheme: light)` matches.
If you do not have a color mode named `dark` or `light`, this will have no effect.
This is enabled by default.

```js
{
useColorSchemeMediaQuery: true,
useColorSchemeMediaQuery: false,
colors: {
text: '#000',
background: '#fff',
Expand Down

1 comment on commit 4d67386

@vercel
Copy link

@vercel vercel bot commented on 4d67386 Dec 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.