Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon-docs: Fix fixed-position inline stories #11350

Merged
merged 13 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/docs/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ basic.parameters = {
}
```

And for `MDX` you can modify it as an attribute on the `Story` element:
And for `MDX` you can modify it, especially if you work with some components using fixed or sticky positions, as an attribute on the `Story` element:

```md
<Story name='basic' height='400px'>{...}</Story>
Expand Down
1 change: 0 additions & 1 deletion lib/components/src/blocks/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const StyledSource = styled(Source)<{}>(({ theme }) => ({
const PreviewContainer = styled.div<PreviewProps>(
({ theme, withSource, isExpanded }) => ({
position: 'relative',
overflow: 'hidden',
margin: '25px 0 40px',
...getBlockBackgroundStyle(theme),
borderBottomLeftRadius: withSource && isExpanded && 0,
Expand Down
42 changes: 42 additions & 0 deletions lib/components/src/blocks/Story.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react';
import { styled } from '@storybook/theming';
import { Story, StoryError } from './Story';
import { Button } from '../Button/Button';

Expand All @@ -23,3 +24,44 @@ export const Inline = () => <Story inline storyFn={buttonFn} title="hello button
export const Error = () => <Story error={StoryError.NO_STORY} />;

export const ReactHook = () => <Story inline storyFn={buttonHookFn} title="hello button" />;

const FixedLayoutExample = styled.div(({ theme }) => ({
'&, header, aside, main': {
position: 'fixed',
top: 0,
right: 0,
bottom: 0,
left: 0,
},
header: {
height: '3rem',
background: theme.background.positive,
},
'aside, main': {
top: '3rem',
},
aside: {
width: '10rem',
background: theme.background.warning,
},
main: {
left: '10rem',
background: theme.background.negative,
},
}));

export const CustomHeight = () => (
<Story
inline
id="custom-height"
storyFn={() => (
<FixedLayoutExample>
<header />
<aside />
<main />
</FixedLayoutExample>
)}
height="15rem"
title="Define a custom story height for fixed position context for example"
/>
);
4 changes: 3 additions & 1 deletion lib/components/src/blocks/Story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ type StoryProps = InlineStoryProps | IFrameStoryProps;

const InlineStory: FunctionComponent<InlineStoryProps> = ({ storyFn, height, id }) => (
<Fragment>
{height ? <style>{`#story--${id} { min-height: ${height} }`}</style> : null}
{height ? (
<style>{`#story--${id} { min-height: ${height}; transform: 'translateZ(0)'; overflow: 'auto' }`}</style>
) : null}
<Fragment>
{storyFn ? createElement(storyFn) : <EmptyBlock>{MISSING_STORY(id)}</EmptyBlock>}
</Fragment>
Expand Down