Skip to content

Commit

Permalink
refactor(core): move ColorSchemeValueContext to singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Apr 29, 2024
1 parent b64d789 commit 23e50fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/sanity/src/_singletons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from './form/studio/ValidationContext'
export * from './i18n/LocaleContext'
export * from './presence/FormFieldPresenceContext'
export * from './store/_legacy/ResourceCacheContext'
export * from './studio/ColorSchemeValueContext'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {createContext} from 'react'
import type {StudioThemeColorSchemeKey} from 'sanity'

/**
* Used to keep track of the internal value, which can be "system" in addition to "light" and "dark"
* @internal
*/
export const ColorSchemeValueContext = createContext<StudioThemeColorSchemeKey | null>(null)
3 changes: 2 additions & 1 deletion packages/sanity/src/core/studio/StudioThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import {LayerProvider, ThemeProvider} from '@sanity/ui'
import {type RootTheme} from '@sanity/ui/theme'
import {type ReactNode} from 'react'
import {ColorSchemeValueContext} from 'sanity/_singletons'

import {defaultTheme, type StudioTheme} from '../theme'
import {useActiveWorkspace} from './activeWorkspaceMatcher'
import {ColorSchemeSetValueContext, ColorSchemeValueContext} from './colorScheme'
import {ColorSchemeSetValueContext} from './colorScheme'

interface StudioThemeProviderProps {
children: ReactNode
Expand Down
7 changes: 1 addition & 6 deletions packages/sanity/src/core/studio/colorScheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ import {
useMemo,
useSyncExternalStore,
} from 'react'
import {ColorSchemeValueContext} from 'sanity/_singletons'

import {type TFunction} from '../i18n'
import {type StudioThemeColorSchemeKey} from '../theme/types'

/**
* Used to keep track of the internal value, which can be "system" in addition to "light" and "dark"
* @internal
*/
export const ColorSchemeValueContext = createContext<StudioThemeColorSchemeKey | null>(null)

/**
* The setter for ColorSchemeValueContext, in a separate context to avoid unnecessary re-renders
* If set to false then the UI should adjust to reflect that the Studio can't change the color scheme
Expand Down

0 comments on commit 23e50fb

Please sign in to comment.