Skip to content

Commit

Permalink
Add retrocompatible overload for createBentoProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
gabro committed Sep 21, 2023
1 parent 7922fe3 commit b1fb2ee
Showing 1 changed file with 23 additions and 2 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

0 comments on commit b1fb2ee

Please sign in to comment.