Skip to content

Commit

Permalink
Fix mode switcher (#3427)
Browse files Browse the repository at this point in the history
* fix mode

* rm unused
  • Loading branch information
lukasoppermann committed Jun 20, 2023
1 parent d71d32b commit baf907d
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/BaseStyles.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import styled, {createGlobalStyle} from 'styled-components'
import {COMMON, SystemCommonProps, SystemTypographyProps, TYPOGRAPHY} from './constants'
import {useTheme, defaultColorMode, ColorModeWithAuto} from './ThemeProvider'
import {useTheme} from './ThemeProvider'
import {ComponentProps} from './utils/types'

// load polyfill for :focus-visible
Expand Down Expand Up @@ -38,21 +38,13 @@ export type BaseStylesProps = ComponentProps<typeof Base>
function BaseStyles(props: BaseStylesProps) {
const {children, color = 'fg.default', fontFamily = 'normal', lineHeight = 'default', ...rest} = props

const {colorScheme, colorMode, dayScheme, nightScheme} = useTheme()
const {colorScheme, dayScheme, nightScheme} = useTheme()

/**
* We need to map valid primer/react color modes onto valid color modes for primer/primitives
* valid color modes for primer/primitives: auto | light | dark
* valid color modes for primer/primer: auto | day | night | light | dark
*/
type colorModesForPrimitives = 'auto' | 'light' | 'dark'
const primerColorModeToPrimitiveColorMode: {[key in ColorModeWithAuto]: colorModesForPrimitives} = {
auto: 'auto',
light: 'light',
dark: 'dark',
day: 'light',
night: 'dark',
}

return (
<Base
Expand All @@ -61,7 +53,7 @@ function BaseStyles(props: BaseStylesProps) {
fontFamily={fontFamily}
lineHeight={lineHeight}
data-portal-root
data-color-mode={primerColorModeToPrimitiveColorMode[colorMode || defaultColorMode]}
data-color-mode={colorScheme?.includes('dark') ? 'dark' : 'light'}
data-light-theme={dayScheme}
data-dark-theme={nightScheme}
>
Expand Down

0 comments on commit baf907d

Please sign in to comment.