Skip to content

Commit

Permalink
fix: fix Playground box area
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Apr 1, 2020
1 parent 69443e4 commit 69408aa
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 27 deletions.
9 changes: 6 additions & 3 deletions ui/blocks/src/BlockContainer/story/StoryBlockContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
StoryInputProps,
StoryContextProps,
} from '../../context';
import { CURRENT_STORY, getStoryTitle } from '../../utils';
import { CURRENT_STORY, getStoryBlockTitle } from '../../utils';

export type StoryBlockContainerProps = {
children: (
Expand All @@ -32,8 +32,11 @@ export const StoryBlockContainer: FC<StoryBlockContainerProps> = ({
name,
});
const { component, kind, story } = context;
const title =
userTitle == CURRENT_STORY ? getStoryTitle(kind, component) : userTitle;
const title = getStoryBlockTitle({
kind,
component,
title: userTitle,
});
const block = children(context, rest);
return (
<BlockContainer
Expand Down
20 changes: 19 additions & 1 deletion ui/blocks/src/Playground/Playground.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const customTitle = () => (
);
export const notCollapsible = () => (
<MockContext storyId="blocks-core-story-plain--controls">
<Playground title="." collapsible={false}>
<Playground title="." collapsible={false} id=".">
<Story id="." />
</Playground>
</MockContext>
Expand All @@ -83,3 +83,21 @@ export const extraPanel = () => (
</Playground>
</MockContext>
);

export const child = () => (
<MockContext storyId="blocks-core-story-plain--controls">
<Playground title="My donut example ">
<Donut value={1 / 2} />
</Playground>
</MockContext>
);

export const multiChild = () => (
<MockContext storyId="blocks-core-story-plain--controls">
<Playground title="Multiple donuts">
<Donut value={1 / 2} />
<Donut value={1 / 2} />
<Donut value={1 / 2} />
</Playground>
</MockContext>
);
53 changes: 39 additions & 14 deletions ui/blocks/src/Playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import {
Tabs,
TabList,
TabPanel,
} from '@component-controls/components';

import { Button } from 'theme-ui';
import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch';
import {
getSortedPanels,
ActionItems,
ActionItem,
ActionContainer,
ActionContainerProps,
} from '@component-controls/components';

import { Button } from 'theme-ui';
import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch';
import {
StoryBlockContainer,
StoryBlockContainerProps,
} from '../BlockContainer';
import { StorySource } from '../StorySource';

export interface TransformOptions {
Expand Down Expand Up @@ -72,9 +74,14 @@ export interface PlaygroundOwnProps {
openTab?: React.ReactNode;
}
export type PlaygroundProps = PlaygroundOwnProps &
Omit<StoryBlockContainerProps, 'children'> &
Omit<ActionContainerProps, 'paddingTop'>;

export const Playground: FC<PlaygroundProps> = ({
title,
id,
name,
collapsible,
transform,
actions: userActions = [],
children,
Expand Down Expand Up @@ -165,12 +172,21 @@ export const Playground: FC<PlaygroundProps> = ({
</Collapsible>
);
return !zoomEnabled ? (
<ActionContainer actions={panelActions}>
{children}
{panelsElement}
</ActionContainer>
<StoryBlockContainer
name={name}
title={title}
id={id}
collapsible={collapsible}
>
{() => (
<ActionContainer actions={panelActions}>
{children}
{panelsElement}
</ActionContainer>
)}
</StoryBlockContainer>
) : (
<ActionContainer>
<div>
<Global
styles={css`
.react-transform-component,
Expand Down Expand Up @@ -221,14 +237,23 @@ export const Playground: FC<PlaygroundProps> = ({
? [...zoomActions, ...actions]
: actions;
return (
<ActionContainer plain={true} actions={actionsItems}>
<TransformComponent>{childStories}</TransformComponent>
</ActionContainer>
<StoryBlockContainer
name={name}
title={title}
id={id}
collapsible={collapsible}
>
{() => (
<ActionContainer plain={true} actions={actionsItems}>
<TransformComponent>{childStories}</TransformComponent>
</ActionContainer>
)}
</StoryBlockContainer>
);
}}
</TransformWrapper>
{panelsElement}
</ActionContainer>
</div>
);
};

Expand Down
8 changes: 3 additions & 5 deletions ui/blocks/src/Stories/Stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ export const Stories: FC<StoriesProps> = props => (
disabled: true,
},
}}
title={storyTitle}
collapsible={false}
key={`playground-${story.id}`}
{...rest}
>
<StoryComponent
id={story.id}
title={storyTitle}
collapsible={false}
/>
<StoryComponent id={story.id} />
</Playground>
);
})}
Expand Down
11 changes: 11 additions & 0 deletions ui/blocks/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ export const getStoryTitle = (
}
return undefined;
};

export const getStoryBlockTitle = ({
kind,
component,
title,
}: {
kind?: StoriesKind;
component?: StoryComponent;
title?: string;
}): string | undefined =>
title == CURRENT_STORY ? getStoryTitle(kind, component) : title;
12 changes: 8 additions & 4 deletions ui/components/src/BlockContainer/BlockContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export const BlockContainer: FC<BlockContainerProps> = ({
const [isOpen, setIsOpen] = React.useState(true);
const blockId =
id || (title ? title.toLowerCase().replace(/\s/g, '-') : undefined);
const BlockTitle: FC = () => (
<Subtitle color="text" css={{ fontWeight: 400, paddingRight: 10 }}>
{title}
</Subtitle>
);
//workaround for storybook iframe url
const url =
(window.location != window.parent.location
Expand Down Expand Up @@ -85,7 +90,7 @@ export const BlockContainer: FC<BlockContainerProps> = ({
<Octicon icon={LinkIcon} />
</Link>
)}
{title && collapsible ? (
{title && collapsible && (
<Link
aria-label={isOpen ? 'Collapse this block' : 'Expand this block'}
css={{
Expand All @@ -94,13 +99,12 @@ export const BlockContainer: FC<BlockContainerProps> = ({
onClick={() => setIsOpen(!isOpen)}
>
<Flex sx={{ flexDirection: 'row', alignItems: 'center' }}>
<Subtitle css={{ paddingRight: 10 }}>{title}</Subtitle>
<BlockTitle />
<Octicon icon={isOpen ? ChevronDown : ChevronRight} />
</Flex>
</Link>
) : (
<Subtitle css={{ paddingRight: 10 }}>{title}</Subtitle>
)}
{title && !collapsible && <BlockTitle />}
</Flex>
)}
{collapsible && children ? (
Expand Down

0 comments on commit 69408aa

Please sign in to comment.