Skip to content

Commit

Permalink
fix: storybook addon
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Dec 5, 2023
1 parent 6e2b976 commit 5ec0be6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-carrots-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chakra-ui/storybook-addon": patch
---

Fix issue in storybook addon where theme could be undefined.
13 changes: 7 additions & 6 deletions tooling/storybook-addon/src/ChakraProviderDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ export const ChakraProviderDecorator = makeDecorator({
parameterName: "chakra",
skipIfNoParametersOrOptions: false,
wrapper: (getStory, context, { parameters }) => {
const chakraTheme = parameters?.theme
const chakraTheme: Record<string, any> | undefined = parameters?.theme

const direction = useDirection(
context.globals[DIRECTION_TOOL_ID] || chakraTheme.direction,
context.globals[DIRECTION_TOOL_ID] || chakraTheme?.direction,
)

const themeWithDirectionOverride = React.useMemo(
() => extendTheme({ direction }, chakraTheme),
[chakraTheme, direction],
)
const themeWithDirectionOverride = React.useMemo(() => {
return chakraTheme
? extendTheme({ direction }, chakraTheme)
: extendTheme({ direction })
}, [chakraTheme, direction])

return (
<ChakraBaseProvider {...parameters} theme={themeWithDirectionOverride}>
Expand Down

0 comments on commit 5ec0be6

Please sign in to comment.