Skip to content

Commit

Permalink
fix: Use custom ResetWrapper component
Browse files Browse the repository at this point in the history
#109

The export, components.resetwrapper is unstable between 6.0 versions
and that causes a runtime error. Because it seems almost impossible
to import the component among Storybook 6.x, I simply wrote an imitation
component to eliminate the problem at all.
  • Loading branch information
pocka committed Jul 3, 2021
1 parent 22b1805 commit 61ce68e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/storybook-addon-designs/src/blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { CSSProperties, FC, useContext, useState } from 'react'
import { DocsContext } from '@storybook/addon-docs/blocks'
import { ActionBar, Placeholder } from '@storybook/components'
import * as Html from '@storybook/components/html'
import { jsx, styled } from '@storybook/theming'

import { Figma as FigmaInternal } from './register/components/Figma'
Expand All @@ -14,6 +13,19 @@ import { Wrapper as WrapperInternal } from './register/components/Wrapper'
import * as config from './config'
import { ParameterName } from './addon'

// Since the exports of `@storybook/components` is unstable, I couldn't manage
// to import the `components.resetWrapper` while maintaining version requirements.
// This component does similar to the official one at minimum.
// https://github.com/storybookjs/storybook/blob/4bd2fc9b0677190c59e60fd63841294ab88e80c5/lib/components/src/typography/DocumentFormatting.tsx#L364-L372
// https://github.com/storybookjs/storybook/blob/4bd2fc9b0677190c59e60fd63841294ab88e80c5/lib/components/src/typography/shared.tsx#L42-L51
const ResetWrapper = styled.div(
({ theme }) => `
font-family: ${theme.typography.fonts.base};
font-size: ${theme.typography.size.s3}px;
margin: 0;
`
)

const Wrapper = styled.div<BlocksCommonProps & { collapsed: boolean }>(
({ theme, height = '60%', collapsed }) => `
position: relative;
Expand Down Expand Up @@ -113,7 +125,7 @@ export const DocBlockBase: FC<BlocksCommonProps> = ({
const showOpenInNewTab = showLink && 'url' in rest

return (
<Html.ResetWrapper>
<ResetWrapper>
<Wrapper collapsed={collapsable && collapsed} {...rest}>
{collapsable && collapsed ? (
<CollapsedText>{placeholder}</CollapsedText>
Expand All @@ -133,7 +145,7 @@ export const DocBlockBase: FC<BlocksCommonProps> = ({
].filter(Boolean)}
/>
</Wrapper>
</Html.ResetWrapper>
</ResetWrapper>
)
}

Expand Down

0 comments on commit 61ce68e

Please sign in to comment.