Skip to content

Commit

Permalink
Merge pull request #775 from buildo/retrocompat-createBentoProvider
Browse files Browse the repository at this point in the history
Add retrocompatible overload for createBentoProvider
  • Loading branch information
federico-ercoles authored Sep 22, 2023
2 parents cd50d90 + ab63f4e commit 0a49b42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
25 changes: 23 additions & 2 deletions packages/bento-design-system/src/BentoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,31 @@ type Props = {
} & DefaultMessages;

export function createBentoProvider(
config: PartialBentoConfig = {},
config?: PartialBentoConfig,
sprinkles?: SprinklesFn
): (props: Props) => JSX.Element;

export function createBentoProvider(
config?: PartialBentoConfig,
theme?: BentoTheme,
sprinkles: SprinklesFn = bentoSprinkles
sprinkles?: SprinklesFn
): (props: Props) => JSX.Element;

export function createBentoProvider(
config: PartialBentoConfig = {},
themeOrSprinkles?: BentoTheme | SprinklesFn,
sprinkles_?: SprinklesFn
) {
let sprinkles: SprinklesFn = bentoSprinkles;
let theme: BentoTheme | undefined = undefined;
if (typeof themeOrSprinkles === "function") {
sprinkles = themeOrSprinkles;
}
if (typeof themeOrSprinkles === "object") {
theme = themeOrSprinkles;
sprinkles = sprinkles_ ?? bentoSprinkles;
}

function OptionalThemeWrapper(props: { children: Children; theme?: BentoTheme }) {
if (!props.theme) return <>{props.children}</>;
return <BentoThemeProvider theme={props.theme}>{props.children}</BentoThemeProvider>;
Expand Down
1 change: 0 additions & 1 deletion packages/bento-design-system/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const BentoProvider = createBentoProvider(
itemsPerPageOptions: [5, 10, 20, 50],
},
},
undefined,
sprinkles
);

Expand Down

0 comments on commit 0a49b42

Please sign in to comment.