Skip to content

Commit

Permalink
Merge pull request #1103 from primer/storybook-themeprovider
Browse files Browse the repository at this point in the history
Wrap Storybook stories in ThemeProvider
  • Loading branch information
T-Hugs authored Mar 4, 2021
2 parents a253410 + 591193b commit 268a298
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/stories/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import React from 'react'
import {Meta} from '@storybook/react'
import {ThemeProvider} from 'styled-components'

import {
BaseStyles,
Expand All @@ -11,7 +12,8 @@ import {
ButtonInvisible,
ButtonOutline,
ButtonPrimary,
ButtonTableList
ButtonTableList,
theme
} from '..'
import {ButtonStyleProps} from 'styled-system'
import {ButtonBaseProps} from '../Button/ButtonBase'
Expand All @@ -23,9 +25,11 @@ export default {
decorators: [
Story => {
return (
<BaseStyles>
<Story />
</BaseStyles>
<ThemeProvider theme={theme}>
<BaseStyles>
<Story />
</BaseStyles>
</ThemeProvider>
)
}
],
Expand Down
11 changes: 7 additions & 4 deletions src/stories/Portal.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import React from 'react'
import {Meta} from '@storybook/react'
import {ThemeProvider} from 'styled-components'

import {BaseStyles, Box} from '..'
import {BaseStyles, Box, theme} from '..'
import Portal, {registerPortalRoot} from '../Portal'

export default {
Expand All @@ -14,9 +15,11 @@ export default {
// story works in isolation.
registerPortalRoot(undefined)
return (
<BaseStyles>
<Story />
</BaseStyles>
<ThemeProvider theme={theme}>
<BaseStyles>
<Story />
</BaseStyles>
</ThemeProvider>
)
}
]
Expand Down
16 changes: 11 additions & 5 deletions src/stories/useAnchoredPosition.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import React from 'react'
import {Meta} from '@storybook/react'

import {BaseStyles, Box, ButtonPrimary, Position} from '..'
import {BaseStyles, Box, ButtonPrimary, Position, theme} from '..'
import {useAnchoredPosition} from '../hooks/useAnchoredPosition'
import styled from 'styled-components'
import styled, {ThemeProvider} from 'styled-components'
import {get} from '../constants'
import {AnchorSide} from '../behaviors/anchoredPosition'
import Portal, {registerPortalRoot} from '../Portal'
Expand All @@ -15,7 +15,11 @@ export default {
// Note: For some reason, if you use <BaseStyles><Story /></BaseStyles>,
// the component gets unmounted from the root every time a control changes!
Story => {
return <BaseStyles>{Story()}</BaseStyles>
return (
<ThemeProvider theme={theme}>
<BaseStyles>{Story()}</BaseStyles>
</ThemeProvider>
)
}
],
argTypes: {
Expand Down Expand Up @@ -229,7 +233,7 @@ export const WithPortal = () => {
left={position?.left ?? 0}
width={250}
height={400}
sx={{visibility: position ? "visible" : "hidden"}}
sx={{visibility: position ? 'visible' : 'hidden'}}
>
An un-constrained overlay!
</Float>
Expand All @@ -239,7 +243,9 @@ export const WithPortal = () => {
</Nav>
<Box sx={{flexGrow: 1}} p={3}>
<h1>The body!</h1>
<p><em>Note: The controls below have no effect in this story.</em></p>
<p>
<em>Note: The controls below have no effect in this story.</em>
</p>
</Box>
</Main>
)
Expand Down

1 comment on commit 268a298

@vercel
Copy link

@vercel vercel bot commented on 268a298 Mar 4, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.