Skip to content

Commit

Permalink
fix: storysource plain/values labels switch
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 3, 2020
1 parent 6c3516d commit 8283975
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions ui/block-components/src/StorySource/StorySource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ export type StorySourceProps = TaggedSourceProps & {
fileSource?: string;
};

type ViewStyle = 'plain' | 'tags' | 'values';
type ViewStyle = 'tags' | 'values';

const ViewStyleNext: {
[key in ViewStyle]: ViewStyle;
} = {
values: 'tags',
tags: 'values',
};
export const StorySource: FC<StorySourceProps> = ({
controls,
fileSource,
Expand All @@ -68,14 +74,7 @@ export const StorySource: FC<StorySourceProps> = ({
const [viewStyle, setViewStyle] = React.useState<ViewStyle>('tags');
const [showFileSource, setShowFileSource] = React.useState<boolean>(false);

const onMergeValues = () =>
setViewStyle(
viewStyle === 'plain'
? 'tags'
: viewStyle === 'tags' && !!controls && !!args
? 'values'
: 'plain',
);
const onMergeValues = () => setViewStyle(ViewStyleNext[viewStyle]);
const onShowFileSource = () => setShowFileSource(!showFileSource);

const allActions = [...actions];
Expand All @@ -86,7 +85,10 @@ export const StorySource: FC<StorySourceProps> = ({
});
}
if (args && args.length) {
allActions.push({ title: viewStyle, onClick: onMergeValues });
allActions.push({
title: ViewStyleNext[viewStyle],
onClick: onMergeValues,
});
}

let source: string;
Expand Down

0 comments on commit 8283975

Please sign in to comment.