-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): add light theme portal container for storybook + use with Se…
…lect
- Loading branch information
1 parent
820bfe5
commit 5a79d30
Showing
6 changed files
with
59 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export { page } from './page.decorator'; | ||
export * as Variants from './variants-table'; | ||
export { Section } from './page-section.component'; | ||
export { useDarkThemePortalContainer } from './page.hooks'; | ||
export { usePortalContainer } from './page.hooks'; | ||
export { UIStateTable } from './ui-state-table.component'; | ||
export { ColorSchemaTable } from './color-schema-table.component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import { createContext, useContext } from 'react'; | ||
|
||
interface PageContextValue { | ||
portalContainer?: HTMLElement; | ||
setPortalContainer: (container: Readonly<HTMLElement>) => void; | ||
darkThemePortalContainer?: HTMLElement; | ||
lightThemePortalContainer?: HTMLElement; | ||
setPortalContainers: ({ | ||
lightTheme, | ||
darkTheme, | ||
}: Readonly<{ lightTheme: HTMLElement; darkTheme: HTMLElement }>) => void; | ||
} | ||
|
||
export const PageContext = createContext<PageContextValue>({ | ||
portalContainer: undefined, | ||
setPortalContainer: () => false, | ||
darkThemePortalContainer: undefined, | ||
lightThemePortalContainer: undefined, | ||
setPortalContainers: () => void 0, | ||
}); | ||
|
||
export const usePageContext = (): PageContextValue => { | ||
const context = useContext(PageContext); | ||
return context; | ||
}; | ||
export const usePageContext = (): PageContextValue => useContext(PageContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
import { usePageContext } from './page.context'; | ||
|
||
export const useDarkThemePortalContainer = (): HTMLElement | undefined => | ||
usePageContext().portalContainer; | ||
interface UsePortalContainerReturnType { | ||
darkThemePortalContainer?: HTMLElement; | ||
lightThemePortalContainer?: HTMLElement; | ||
} | ||
|
||
/** | ||
* **Important**: This is for Storybook use only. In real app everything will be placed in context of a single | ||
* ThemeProvider. It should be used with all components that create portals to fix LocalThemeProvider with dark theme | ||
* and Interaction tests (without this approach your component may not be accessible using `canvas.getByTestId()`). | ||
*/ | ||
export const usePortalContainer = (): UsePortalContainerReturnType => ({ | ||
darkThemePortalContainer: usePageContext().darkThemePortalContainer, | ||
lightThemePortalContainer: usePageContext().lightThemePortalContainer, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters