-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
848feb3
commit 6f69648
Showing
6 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React from 'react'; | ||
import { ActionItem } from '@component-controls/components'; | ||
import { PrismTheme } from 'prism-react-renderer'; | ||
import dracula from 'prism-react-renderer/themes/dracula'; | ||
import duotoneDark from 'prism-react-renderer/themes/duotoneDark'; | ||
import duotoneLight from 'prism-react-renderer/themes/duotoneLight'; | ||
import github from 'prism-react-renderer/themes/github'; | ||
import nightOwl from 'prism-react-renderer/themes/nightOwl'; | ||
import nightOwlLight from 'prism-react-renderer/themes/nightOwlLight'; | ||
import oceanicNext from 'prism-react-renderer/themes/oceanicNext'; | ||
import palenight from 'prism-react-renderer/themes/palenight'; | ||
import shadesOfPurple from 'prism-react-renderer/themes/shadesOfPurple'; | ||
|
||
import { StoryConfig } from './StoryConfig'; | ||
import { MockContext } from '../test/MockContext'; | ||
export default { | ||
title: 'Blocks/StoryConfig', | ||
component: StoryConfig, | ||
}; | ||
|
||
export const overview = () => ( | ||
<MockContext storyId="id-of-story"> | ||
<StoryConfig id="." /> | ||
</MockContext> | ||
); | ||
|
||
export const theme = () => ( | ||
<MockContext storyId="blocks-core-story-plain--controls"> | ||
<StoryConfig id="." theme={shadesOfPurple} /> | ||
</MockContext> | ||
); | ||
|
||
const themes: { | ||
[key: string]: PrismTheme; | ||
} = { | ||
dracula, | ||
duotoneDark, | ||
duotoneLight, | ||
github, | ||
nightOwl, | ||
nightOwlLight, | ||
oceanicNext, | ||
palenight, | ||
shadesOfPurple, | ||
}; | ||
export const themeSelector = () => { | ||
const [theme, setTheme] = React.useState('dracula'); | ||
const themeAction: ActionItem = { | ||
title: theme, | ||
onClick: () => { | ||
const themeNames = Object.keys(themes); | ||
const selected = themeNames.indexOf(theme); | ||
const nextTheme = selected < themeNames.length - 1 ? selected + 1 : 0; | ||
setTheme(themeNames[nextTheme]); | ||
}, | ||
}; | ||
return ( | ||
<MockContext storyId="blocks-core-story-plain--controls"> | ||
<StoryConfig id="." actions={[themeAction]} theme={themes[theme]} /> | ||
</MockContext> | ||
); | ||
}; | ||
|
||
export const customTitle = () => ( | ||
<MockContext storyId="id-of-story"> | ||
<StoryConfig title="Story configuration" /> | ||
</MockContext> | ||
); | ||
|
||
export const notCollapsible = () => ( | ||
<MockContext> | ||
<StoryConfig title="." collapsible={false} /> | ||
</MockContext> | ||
); | ||
|
||
export const noMargin = () => ( | ||
<MockContext storyId="id-of-story"> | ||
<StoryConfig sxStyle={{ mt: 0, mb: 0 }} /> | ||
</MockContext> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/** @jsx jsx */ | ||
/* eslint react/jsx-key: 0 */ | ||
import { jsx } from 'theme-ui'; | ||
import { FC, useState, useContext } from 'react'; | ||
import { | ||
ThemeContext, | ||
Source, | ||
SourceProps, | ||
ActionItem, | ||
} from '@component-controls/components'; | ||
import { repositoryActions } from '../utils/repositoryActions'; | ||
import { | ||
StoryBlockContainer, | ||
StoryBlockContainerProps, | ||
} from '../BlockContainer/story'; | ||
|
||
export type StoryConfigProps = StoryBlockContainerProps & SourceProps; | ||
|
||
/** | ||
* Displays the configuration object of a story. | ||
*/ | ||
export const StoryConfig: FC<StoryConfigProps> = props => { | ||
const [showFileSource, setShowFileSource] = useState<boolean>(false); | ||
|
||
return ( | ||
<StoryBlockContainer {...props}> | ||
{(context, sourceProps: SourceProps) => { | ||
const onShowFileSource = () => setShowFileSource(!showFileSource); | ||
|
||
const { story, kind, kindPackage } = context; | ||
const { dark } = useContext(ThemeContext); | ||
const allActions: ActionItem[] = []; | ||
const repositoryItems = repositoryActions(kindPackage); | ||
if (repositoryItems) { | ||
allActions.push.apply(allActions, repositoryItems); | ||
} | ||
if (kind?.source) { | ||
allActions.push({ | ||
title: showFileSource ? 'story code' : 'file code', | ||
onClick: onShowFileSource, | ||
}); | ||
} | ||
const { loc, renderFn, source, arguments: storyArgs, ...other } = | ||
story || {}; | ||
return Object.keys(other).length ? ( | ||
<Source | ||
dark={dark} | ||
language="json" | ||
{...sourceProps} | ||
actions={allActions} | ||
> | ||
{JSON.stringify(other, null, 2)} | ||
</Source> | ||
) : null; | ||
}} | ||
</StoryBlockContainer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './StoryConfig'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters