Skip to content

Commit

Permalink
feat(sanity): render global font and background color
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard committed Oct 5, 2022
1 parent 6d3c53a commit 27d5085
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
15 changes: 15 additions & 0 deletions packages/sanity/src/core/studio/GlobalStyle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {createGlobalStyle} from 'styled-components'

export const GlobalStyle = createGlobalStyle(({theme}) => {
const {color, fonts} = theme.sanity

return {
html: {
backgroundColor: color.base.bg,
},

'#sanity': {
fontFamily: fonts.text.family,
},
}
})
10 changes: 9 additions & 1 deletion packages/sanity/src/core/studio/Studio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {ThemeColorSchemeKey} from '@sanity/ui'
import {History} from 'history'
import React, {ReactElement} from 'react'
import {Config} from '../config'
import {GlobalStyle} from './GlobalStyle'
import {StudioProvider} from './StudioProvider'
import {useWorkspace} from './workspace'

Expand All @@ -10,7 +11,11 @@ export interface StudioProps {
config: Config
onSchemeChange?: (nextScheme: ThemeColorSchemeKey) => void
scheme?: ThemeColorSchemeKey
/** @beta */
unstable_history?: History
/** @beta */
unstable_globalStyles?: boolean
/** @beta */
unstable_noAuthBoundary?: boolean
}

Expand All @@ -22,8 +27,11 @@ function StudioLayout() {

/** @beta */
export function Studio(props: StudioProps): ReactElement {
const {unstable_globalStyles: globalStyles, ...restProps} = props

return (
<StudioProvider {...props}>
<StudioProvider {...restProps}>
{globalStyles && <GlobalStyle />}
<StudioLayout />
</StudioProvider>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/core/studio/StudioThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function StudioThemeProvider({children}: StudioThemeProviderProps) {
const {scheme} = useColorScheme()

return (
<ThemeProvider scheme={scheme} theme={theme}>
<ThemeProvider scheme={scheme} theme={theme} tone="transparent">
<LayerProvider>{children}</LayerProvider>
</ThemeProvider>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/core/studio/colorScheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function ColorSchemeProvider({
{/* that may render before the StudioThemeProvider renders. this is */}
{/* required because the StudioThemeProvider has a dependence on the */}
{/* active workspace provided via the ActiveWorkspaceMatcher */}
<ThemeProvider scheme={scheme} theme={studioTheme}>
<ThemeProvider scheme={scheme} theme={studioTheme} tone="transparent">
{children}
</ThemeProvider>
</ColorSchemeContext.Provider>
Expand Down
8 changes: 5 additions & 3 deletions packages/sanity/src/core/studio/renderStudio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ export function renderStudio(
rootElement: HTMLElement | null,
config: Config,
reactStrictMode = false
) {
): () => void {
if (!rootElement) {
throw new Error('Missing root element to mount application into')
}

const root = createRoot(rootElement)

root.render(
reactStrictMode ? (
<StrictMode>
<Studio config={config} />
<Studio config={config} unstable_globalStyles />
</StrictMode>
) : (
<Studio config={config} />
<Studio config={config} unstable_globalStyles />
)
)

return () => root.unmount()
}

0 comments on commit 27d5085

Please sign in to comment.