Skip to content

Commit

Permalink
fix: playground context
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 12, 2020
1 parent a01f51e commit 5dfca0b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
7 changes: 5 additions & 2 deletions ui/blocks/src/BlockContainer/story/StoryBlockContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC } from 'react';
import React, { FC, useContext } from 'react';
import {
BlockContainer,
BlockContainerProps,
Expand All @@ -10,6 +10,7 @@ import {
StoryContextProps,
} from '../../context';
import { CURRENT_STORY, getStoryBlockTitle } from '../../utils';
import { PlaygroundContext } from '../../Playground/PlaygroundContext';

export type StoryBlockContainerProps = StoryInputProps & BlockContainerProps;

Expand Down Expand Up @@ -37,14 +38,16 @@ export const StoryBlockContainer: FC<StoryBlockContainerAllProps> = ({
id,
name,
});
const playground = useContext(PlaygroundContext);
const { story } = context;
const title = getStoryBlockTitle({
story,
title: userTitle,
});
const block = children && children(context, rest);
const description =
userDescription || (useStoryDescription ? story?.description : undefined);
(playground === undefined && userDescription) ||
(useStoryDescription ? story?.description : undefined);
return block ? (
<BlockContainer
data-testid={dataTestid}
Expand Down
7 changes: 6 additions & 1 deletion ui/blocks/src/Playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ActionItems,
} from '@component-controls/components';
import { BlockDataContext, useCustomProps } from '../context';
import { PlaygroundContext } from './PlaygroundContext';

import {
StoryBlockContainer,
Expand Down Expand Up @@ -170,7 +171,11 @@ export const Playground: FC<PlaygroundProps> = ({ children, ...props }) => {
background={background}
direction={direction}
>
<Zoom scale={scale || 1}>{children}</Zoom>
<Zoom scale={scale || 1}>
<PlaygroundContext.Provider value={{ useDescription: true }}>
{children}
</PlaygroundContext.Provider>
</Zoom>
</PanelContainer>
)}
</StoryBlockContainer>
Expand Down
8 changes: 8 additions & 0 deletions ui/blocks/src/Playground/PlaygroundContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createContext } from 'react';

export interface PlaygroundContextProps {
useDescription: boolean;
}
export const PlaygroundContext = createContext<PlaygroundContextProps>({
useDescription: false,
});
1 change: 1 addition & 0 deletions ui/blocks/src/Playground/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Playground';
export * from './PlaygroundContext';

0 comments on commit 5dfca0b

Please sign in to comment.