Skip to content

Commit 1634af7

Browse files
authored
Merge pull request #561 from system-ui/next-raw-colors
Keep raw color values in theme-ui context
2 parents 464b5c7 + 9d19ef8 commit 1634af7

File tree

6 files changed

+5
-19
lines changed

6 files changed

+5
-19
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
- Adds separate `ColorModeProvider` component
1010
- Removes support for `theme.initialColorMode` - use `initialColorModeName` instead
1111
- Removes layout components (`Layout`, `Header`, `Main`, `Footer`) - use `Box` and `Flex` instead
12-
- Raw color values are now available as `theme.rawColors` in context when custom properties are enabled
1312
- Updates CSS custom properties implementation for color modes
1413
- When using `useColorSchemeMediaQuery` flag, it will initialize the mode to `light` when `@media (prefers-color-scheme: light)` is enabled
1514
- Global color mode styles are automatically added to the body without needing to render the `ColorMode` component

packages/color-modes/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ export const ColorModeProvider = ({
101101
const outer = useThemeUI()
102102
const [colorMode, setColorMode] = useColorModeState(outer.theme)
103103
const theme = applyColorMode(outer.theme || {}, colorMode)
104+
const emotionTheme = {...theme}
104105

105106
if (theme.useCustomProperties !== false) {
106-
theme.rawColors = {...theme.colors}
107-
theme.colors = toCustomProperties(theme.colors, 'colors')
107+
emotionTheme.colors = toCustomProperties(emotionTheme.colors, 'colors')
108108
}
109109

110110
const context = {
@@ -114,7 +114,7 @@ export const ColorModeProvider = ({
114114
setColorMode,
115115
}
116116

117-
return jsx(EmotionContext.Provider, { value: theme },
117+
return jsx(EmotionContext.Provider, { value: emotionTheme },
118118
jsx(Context.Provider, { value: context },
119119
jsx(BodyStyles, { key: 'color-mode' }),
120120
children

packages/color-modes/test/index.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,6 @@ test('does not initialize mode from prefers-color-scheme media query when useCol
332332
expect(mode).toBe('default')
333333
})
334334

335-
test.skip('ColorMode component renders null', () => {
336-
const json = renderer
337-
.create(
338-
<ThemeProvider>
339-
<ColorMode />
340-
</ThemeProvider>
341-
)
342-
.toJSON()
343-
expect(json).toBe(null)
344-
})
345-
346335
test('ColorModeProvider renders with global colors', () => {
347336
const root = render(
348337
<ThemeProvider
@@ -557,7 +546,7 @@ test('raw color values are passed to theme-ui context when custom properties are
557546
let color
558547
const Grabber = props => {
559548
const context = useThemeUI()
560-
color = context.theme.rawColors.primary
549+
color = context.theme.colors.primary
561550
return false
562551
}
563552
const root = render(

packages/docs/src/pages/migrating.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ title: Migrating
1111
- Default color mode name
1212
- Manually enable `useColorSchemeMediaQuery`
1313
- Removes layout components (`Layout`, `Header`, `Main`, `Footer`). Use the `Box` and `Flex` layout primitives instead.
14-
- When CSS custom properties are enabled, raw color values are available in the `theme.rawColors` object
1514
- Theme context is now stateless. If you've made use of `context.setTheme`, this no longer works. An alternative approach will be introduced later.
1615
- Global typographic styles
1716

packages/gatsby-plugin-theme-ui/test/provider.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ test('renders with theme context', () => {
2323
const root = render(wrapRootElement({ element: <Consumer /> }, {}))
2424
expect(context.theme).toEqual({
2525
colors: {},
26-
rawColors: {},
2726
})
2827
})
2928

packages/theme-ui/test/color-modes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ test('raw color values are passed to theme-ui context when custom properties are
464464
let color
465465
const Grabber = props => {
466466
const context = useThemeUI()
467-
color = context.theme.rawColors.primary
467+
color = context.theme.colors.primary
468468
return false
469469
}
470470
const root = render(

0 commit comments

Comments
 (0)