Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/gamut-styles/src/GamutProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export interface GamutProviderProps {
* Pass a nonce to the cache to prevent CSP errors
*/
nonce?: string;
/**
* Whether to use logical properties for the theme
*/
useLogicalProperties?: boolean;
}

export const GamutContext = React.createContext<{
Expand Down Expand Up @@ -56,6 +60,7 @@ export const GamutProvider: React.FC<GamutProviderProps> = ({
useGlobals = true,
useCache = true,
nonce,
useLogicalProperties = true,
}) => {
const { hasGlobals, hasCache } = useContext(GamutContext);
const shouldCreateCache = useCache && !hasCache;
Expand All @@ -76,6 +81,7 @@ export const GamutProvider: React.FC<GamutProviderProps> = ({
const contextValue = {
hasGlobals: shouldInsertGlobals,
hasCache: shouldCreateCache,
useLogicalProperties,
nonce,
};

Expand All @@ -88,8 +94,13 @@ export const GamutProvider: React.FC<GamutProviderProps> = ({
</>
);

// Merge useLogicalProperties into theme so variance can access it via props.theme
const themeWithLogicalProperties = {
...theme,
useLogicalProperties,
};
const content = (
<ThemeProvider theme={theme}>
<ThemeProvider theme={themeWithLogicalProperties}>
Comment on lines +97 to +103
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if you should memoize this, ThemeProivider is kindof an expensive operation and we want to make sure it doesn't rerender for unrelated reasons

{nonce ? <MotionConfig nonce={nonce}>{children}</MotionConfig> : children}
</ThemeProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe(GamutProvider, () => {
),
});

screen.getByText(JSON.stringify(theme));
screen.getByText(JSON.stringify({ ...theme, useLogicalProperties: true }));
});
it('it can have another GamutProvider as a child with creating multiple caches or globals', () => {
renderView({
Expand Down
Loading