Skip to content

Commit

Permalink
feat: back to the root element
Browse files Browse the repository at this point in the history
  • Loading branch information
sungik-choi committed Nov 30, 2023
1 parent f8befb7 commit f2faf6b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
12 changes: 11 additions & 1 deletion packages/bezier-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ import '~/src/styles/index.scss'
export { default as BezierProvider } from '~/src/providers/BezierProvider'
export * from '~/src/providers/WindowProvider'
export * from '~/src/providers/AlphaAppProvider'
export * from '~/src/providers/ThemeProvider'
export {
useThemeName,
useToken,
ThemeProvider,
LightTheme,
DarkTheme,
InvertedTheme,
type ThemeName,
type ThemeProviderProps,
type FixedThemeProviderProps,
} from '~/src/providers/ThemeProvider'

/* Foundation */
export * from '~/src/foundation'
Expand Down
28 changes: 19 additions & 9 deletions packages/bezier-react/src/providers/AlphaAppProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'

import {
type Feature,
Expand All @@ -10,7 +10,7 @@ import { TooltipProvider } from '~/src/components/Tooltip'

import {
type ThemeName,
ThemeProvider,
TokenProvider,
} from './ThemeProvider'
import { WindowProvider } from './WindowProvider'

Expand Down Expand Up @@ -59,16 +59,26 @@ export function AlphaAppProvider({
features = [],
window = defaultWindow,
}: AlphaAppProviderProps) {
useEffect(function updateThemeDataAttribute() {
const rootElement = window.document.documentElement
// TODO: Change data attribute constant to import from bezier-tokens
rootElement.setAttribute('data-bezier-theme', themeName)
return function cleanup() {
rootElement.removeAttribute('data-bezier-theme')
}
}, [
window,
themeName,
])

return (
<WindowProvider window={window}>
<FeatureProvider features={features}>
<TooltipProvider>
<ThemeProvider themeName={themeName}>
<div data-bezier-root>
{ children }
</div>
</ThemeProvider>
</TooltipProvider>
<TokenProvider themeName={themeName}>
<TooltipProvider>
{ children }
</TooltipProvider>
</TokenProvider>
</FeatureProvider>
</WindowProvider>
)
Expand Down
7 changes: 5 additions & 2 deletions packages/bezier-react/src/providers/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ interface TokenProviderProps {
children: React.ReactNode
}

function TokenProvider({
/**
* @private For internal use only.
*/
export function TokenProvider({
themeName,
children,
}: TokenProviderProps) {
Expand Down Expand Up @@ -120,7 +123,7 @@ export const DarkTheme = forwardRef<HTMLElement, FixedThemeProviderProps>(functi
return (
<ThemeProvider
ref={forwardedRef}
themeName="light"
themeName="dark"
>
{ children }
</ThemeProvider>
Expand Down
1 change: 1 addition & 0 deletions packages/bezier-react/src/styles/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
font-size: 62.5%; // 10/16 = 0.625. Make REM calculations easier.
font-family: var(--font-family-sans-kr);
color: var(--txt-black-darkest);
color-scheme: light;
}

// TODO: Change data attribute constant to import from bezier-tokens
Expand Down

0 comments on commit f2faf6b

Please sign in to comment.