-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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: Support for iframeWidth parameter on stories #9149
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Object.keys(docsComponents).forEach(key => { | |
|
||
interface CommonProps { | ||
height?: string; | ||
width?: string; | ||
inline?: boolean; | ||
} | ||
|
||
|
@@ -47,7 +48,7 @@ export const getStoryProps = ( | |
const inputId = id === CURRENT_SELECTION ? currentId : id; | ||
const previewId = inputId || mdxStoryNameToId[name]; | ||
|
||
const { height, inline } = props; | ||
const { height, width, inline } = props; | ||
const data = storyStore.fromId(previewId); | ||
const { framework = null } = (data && data.parameters) || {}; | ||
|
||
|
@@ -61,6 +62,7 @@ export const getStoryProps = ( | |
const { | ||
inlineStories = inferInlineStories(framework), | ||
iframeHeight = undefined, | ||
iframeWidth = undefined, | ||
prepareForInline = undefined, | ||
} = docsParam; | ||
const { storyFn = undefined, name: storyName = undefined } = data || {}; | ||
|
@@ -71,14 +73,15 @@ export const getStoryProps = ( | |
`Story '${storyName}' is set to render inline, but no 'prepareForInline' function is implemented in your docs configuration!` | ||
); | ||
} | ||
|
||
return { | ||
const newVar = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
inline: storyIsInline, | ||
id: previewId, | ||
storyFn: prepareForInline && storyFn ? () => prepareForInline(storyFn) : storyFn, | ||
height: height || (storyIsInline ? undefined : iframeHeight), | ||
width: width || (storyIsInline ? undefined : iframeWidth), | ||
title: storyName, | ||
}; | ||
return newVar; | ||
}; | ||
|
||
const StoryContainer: FunctionComponent<StoryProps> = props => ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ const PreviewContainer = styled.div<PreviewProps>( | |
position: 'relative', | ||
overflow: 'hidden', | ||
margin: '25px 0 40px', | ||
display: 'inline-block', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using flexbox for this is a little more robust I think. |
||
...getBlockBackgroundStyle(theme), | ||
borderBottomLeftRadius: withSource && isExpanded && 0, | ||
borderBottomRightRadius: withSource && isExpanded && 0, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ const MISSING_STORY = (id?: string) => (id ? `Story "${id}" doesn't exist.` : St | |
interface CommonProps { | ||
title: string; | ||
height?: string; | ||
width?: string; | ||
id: string; | ||
} | ||
|
||
|
@@ -53,8 +54,8 @@ const InlineZoomWrapper: FunctionComponent<{ scale: number }> = ({ scale, childr | |
); | ||
}; | ||
|
||
const InlineStory: FunctionComponent<InlineStoryProps> = ({ storyFn, height, id }) => ( | ||
<div style={{ height }}> | ||
const InlineStory: FunctionComponent<InlineStoryProps> = ({ storyFn, height, id, width }) => ( | ||
<div style={{ height, width }}> | ||
<ZoomContext.Consumer> | ||
{({ scale }) => ( | ||
<InlineZoomWrapper scale={scale}> | ||
|
@@ -65,8 +66,13 @@ const InlineStory: FunctionComponent<InlineStoryProps> = ({ storyFn, height, id | |
</div> | ||
); | ||
|
||
const IFrameStory: FunctionComponent<IFrameStoryProps> = ({ id, title, height = '500px' }) => ( | ||
<div style={{ width: '100%', height }}> | ||
const IFrameStory: FunctionComponent<IFrameStoryProps> = ({ | ||
id, | ||
title, | ||
height = '500px', | ||
width = '950px', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this completely optional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's actually just a default height and width. In case the IFrameStory component does not receive those parameters, it would just set it to 950x500 px... Could you explain a little bit more about how this could be optional? |
||
}) => ( | ||
<div style={{ width, height }}> | ||
<ZoomContext.Consumer> | ||
{({ scale }) => { | ||
return ( | ||
|
@@ -96,15 +102,15 @@ const IFrameStory: FunctionComponent<IFrameStoryProps> = ({ id, title, height = | |
const Story: FunctionComponent<StoryProps> = props => { | ||
const { error } = props as ErrorProps; | ||
const { storyFn } = props as InlineStoryProps; | ||
const { id, inline, title, height } = props; | ||
const { id, inline, title, height, width } = props; | ||
|
||
if (error) { | ||
return <EmptyBlock>{error}</EmptyBlock>; | ||
} | ||
return inline ? ( | ||
<InlineStory id={id} storyFn={storyFn} title={title} height={height} /> | ||
<InlineStory id={id} storyFn={storyFn} title={title} height={height} width={width} /> | ||
) : ( | ||
<IFrameStory id={id} title={title} height={height} /> | ||
<IFrameStory id={id} title={title} height={height} width={width} /> | ||
); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why text-align center?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this so no matter what size the iFrame has, the component will always be centered on the Docs Page...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it:
With it:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that visual outcome looks ok to me (I'm no designer), but this shouldn't be done with inline styles IMHO, I'm wondering if centering should be done with flexbox rather then text-align.
@shilman @domyen does the centering of the iframe seem like the right thing to do to you?