Skip to content

Commit

Permalink
chore(ui): address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslaw-wlodek committed May 3, 2024
1 parent 2333710 commit c102c41
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ import React, { useState } from 'react';

import { PageContext } from './page.context';

import type { PageContextValue } from './page.context';

interface Props {
children: ReactNode;
}

export const PageProvider = ({
children,
}: Readonly<Props>): React.ReactElement => {
const [state, setState] = useState<{
lightThemePortalContainer?: HTMLElement;
darkThemePortalContainer?: HTMLElement;
}>({});
const [state, setState] = useState<
Pick<
PageContextValue,
'darkThemePortalContainer' | 'lightThemePortalContainer'
>
>({});

return (
<PageContext.Provider
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/design-system/decorators/page.context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext, useContext } from 'react';

interface PageContextValue {
export interface PageContextValue {
darkThemePortalContainer?: HTMLElement;
lightThemePortalContainer?: HTMLElement;
setPortalContainers: ({
Expand Down
21 changes: 13 additions & 8 deletions packages/ui/src/design-system/decorators/page.hooks.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { usePageContext } from './page.context';

interface UsePortalContainerReturnType {
darkThemePortalContainer?: HTMLElement;
lightThemePortalContainer?: HTMLElement;
}
import type { PageContextValue } from './page.context';

/**
* **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,
});
export const usePortalContainer = (): Pick<
PageContextValue,
'darkThemePortalContainer' | 'lightThemePortalContainer'
> => {
const { lightThemePortalContainer, darkThemePortalContainer } =
usePageContext();

return {
darkThemePortalContainer,
lightThemePortalContainer,
};
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { styleVariants } from '@vanilla-extract/css';
import { style, styleVariants } from '@vanilla-extract/css';

import { style, vars } from '../../../design-tokens';
import { vars } from '../../../design-tokens';

const rootBase = style({
display: 'flex',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { styleVariants } from '@vanilla-extract/css';
import { style, styleVariants } from '@vanilla-extract/css';

import { style, sx, vars } from '../../design-tokens';
import { sx, vars } from '../../design-tokens';

const triggerBase = style({
border: 0,
Expand Down

0 comments on commit c102c41

Please sign in to comment.