Skip to content

Commit

Permalink
feat: add className to MarigoldProvider (#3893)
Browse files Browse the repository at this point in the history
* feat: add className to MarigoldProvider

* add test for it

* docs

* Create strong-kiwis-check.md
  • Loading branch information
sarahgm committed May 2, 2024
1 parent 908baaa commit f57caec
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changeset/strong-kiwis-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@marigold/storybook-config": patch
"@marigold/docs": patch
"@marigold/components": patch
---

feat: add className to MarigoldProvider
15 changes: 12 additions & 3 deletions config/storybook/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export const decorators: any = [
{Object.keys(THEME).map(key => (
<OverlayContainerProvider value={`portalContainer-${key}`}>
<Frame key={key} id={key} title={`Theme "${key}"`}>
<MarigoldProvider theme={THEME[key as ThemeNames]}>
<MarigoldProvider
theme={THEME[key as ThemeNames]}
className="bg-bg-surface"
>
<div className="p-4" data-theme={key}>
{Story()}
</div>
Expand All @@ -72,7 +75,10 @@ export const decorators: any = [
}
case 'core': {
return (
<MarigoldProvider theme={THEME[theme as ThemeNames]}>
<MarigoldProvider
theme={THEME[theme as ThemeNames]}
className="bg-bg-surface"
>
<div className="h-screen p-6">
<FieldGroup labelWidth="200px">{Story()}</FieldGroup>
</div>
Expand All @@ -81,7 +87,10 @@ export const decorators: any = [
}
default: {
return (
<MarigoldProvider theme={THEME[theme as ThemeNames]}>
<MarigoldProvider
theme={THEME[theme as ThemeNames]}
className="bg-bg-surface"
>
<div className="h-screen p-6">{Story()}</div>
</MarigoldProvider>
);
Expand Down
6 changes: 6 additions & 0 deletions docs/content/components/application/provider/provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ import { MarigoldProvider } from '@marigold/components';
default: 'none',
description: 'The use that should be used within the provider context.',
},
{
property: 'className',
type: 'string',
default: 'none',
description: 'Set a className to the outer div from your app.',
},

]}
/>
Expand Down
7 changes: 5 additions & 2 deletions docs/ui/ComponentDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ export const ComponentDemo = ({ name, children }: ComponentDemoProps) => {
>
<div id="portalContainer" className="not-prose" />
<OverlayContainerProvider value="portalContainer">
<MarigoldProvider theme={(current && themes[current]) as Theme}>
<div className="not-prose w-full overflow-x-auto p-4">
<MarigoldProvider
theme={(current && themes[current]) as Theme}
className="bg-bg-surface"
>
<div className="not-prose size-full overflow-x-auto p-4">
<Wrapper>
<Demo />
</Wrapper>
Expand Down
22 changes: 22 additions & 0 deletions packages/components/src/Provider/MarigoldProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,25 @@ test('cascading without a selector is allowed when inner theme has not root styl
)
).not.toThrowError();
});

test('using classname prop', () => {
const outerTheme = {
name: 'outer',
colors: {
primary: 'coral',
},
components: {
Button: cva(),
},
};

render(
<MarigoldProvider theme={outerTheme} className="bg-slate-400">
child
</MarigoldProvider>
);
const theme = screen.getByText('child');

console.log(theme?.className);
expect(theme?.className).toMatchInlineSnapshot(`"bg-slate-400"`);
});
7 changes: 6 additions & 1 deletion packages/components/src/Provider/MarigoldProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export interface MarigoldProviderProps<T extends Theme>
// ---------------
export function MarigoldProvider<T extends Theme>({
children,
className,
theme,
}: MarigoldProviderProps<T>) {
return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
return (
<ThemeProvider theme={theme} className={className}>
{children}
</ThemeProvider>
);
}

0 comments on commit f57caec

Please sign in to comment.