Skip to content

Commit

Permalink
feat(alpha-app-provider): apply WindowProvider and add window prop
Browse files Browse the repository at this point in the history
  • Loading branch information
sungik-choi committed Nov 29, 2023
1 parent 6d0aacb commit fb310b3
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions packages/bezier-react/src/providers/AlphaAppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {
type ThemeName,
TokenProvider,
} from '~/src/hooks/useToken'
import { document } from '~/src/utils/dom'
import { window as defaultWindow } from '~/src/utils/dom'

import { TooltipProvider } from '~/src/components/Tooltip'

import WindowProvider from './WindowProvider'

export interface AlphaAppProviderProps {
children: React.ReactNode
/**
Expand All @@ -25,8 +27,13 @@ export interface AlphaAppProviderProps {
*/
features?: Feature[]
/**
* Root element to apply theme data attribute to.
* @default document.body
* Window object to use for the app.
* @default window
*/
window?: Window
/**
* Root element to apply theme data attribute to. window of default value is a window object passed by `window` prop
* @default window.document.body
*/
rootElement?: HTMLElement
}
Expand Down Expand Up @@ -55,7 +62,8 @@ export function AlphaAppProvider({
children,
themeName = 'light',
features = [],
rootElement = document.body,
window = defaultWindow,
rootElement = window.document.body,
}: AlphaAppProviderProps) {
useEffect(function updateThemeDataAttribute() {
// TODO: Change data attribute constant to import from bezier-tokens
Expand All @@ -69,12 +77,14 @@ export function AlphaAppProvider({
])

return (
<TokenProvider themeName={themeName}>
<FeatureProvider features={features}>
<TooltipProvider>
{ children }
</TooltipProvider>
</FeatureProvider>
</TokenProvider>
<WindowProvider window={window}>
<TokenProvider themeName={themeName}>
<FeatureProvider features={features}>
<TooltipProvider>
{ children }
</TooltipProvider>
</FeatureProvider>
</TokenProvider>
</WindowProvider>
)
}

0 comments on commit fb310b3

Please sign in to comment.