Skip to content

Commit

Permalink
fix: Update to create adensity provider
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel.carrera committed Oct 28, 2024
1 parent 445f80a commit 671e74c
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions modules/react/common/lib/CanvasProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ import {createStyles, getCache} from '@workday/canvas-kit-styling';

export interface CanvasProviderProps {
theme?: PartialEmotionCanvasTheme;
density?: 'low' | 'medium' | 'high' | undefined;
}

export const DensityContext = React.createContext<CanvasProviderProps['density']>('medium');

export const useDensityContext = (): CanvasProviderProps['density'] => {
return React.useContext(DensityContext);
};

// copied from brand/_variables.css
const defaultBranding = createStyles({
[brand.error.darkest]: 'rgba(128,22,14,1)',
Expand Down Expand Up @@ -84,14 +91,15 @@ export const useCanvasThemeToCssVars = (

export const CanvasProvider = ({
children,
theme = {canvas: defaultCanvasTheme, custom: {}},
theme = {canvas: defaultCanvasTheme},

Check failure on line 94 in modules/react/common/lib/CanvasProvider.tsx

View workflow job for this annotation

GitHub Actions / check

Property 'custom' is missing in type '{ canvas: CanvasTheme; }' but required in type 'PartialEmotionCanvasTheme'.
density = 'medium',
...props
}: CanvasProviderProps & React.HTMLAttributes<HTMLElement>) => {
const elemProps = useCanvasThemeToCssVars(theme, props);
const cache = getCache();
return (
<CanvasThemeContext.Provider value={{theme: theme}}>
<CacheProvider value={cache}>
<CacheProvider value={cache}>
<DensityContext.Provider value={density}>
<ThemeProvider theme={theme as Theme}>
<InputProvider />
<div
Expand All @@ -101,18 +109,7 @@ export const CanvasProvider = ({
{children}
</div>
</ThemeProvider>
</CacheProvider>
</CanvasThemeContext.Provider>
</DensityContext.Provider>
</CacheProvider>
);
};

export type CanvasProviderType = {
theme: PartialEmotionCanvasTheme;
};

const CanvasThemeContext = React.createContext<CanvasProviderType>({
theme: {custom: {}},
});
export const useCanvasProvider = () => {
return React.useContext(CanvasThemeContext);
};

0 comments on commit 671e74c

Please sign in to comment.