Skip to content

Commit

Permalink
feat: initial display object props in code
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed May 3, 2020
1 parent 37fa1fb commit f3a0529
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions ui/blocks/src/StorySource/StorySource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint react/jsx-key: 0 */
import { jsx } from 'theme-ui';
import { FC, useState, useContext } from 'react';
import { getControlValue } from '@component-controls/core';
import { getControlValue, getControlValues } from '@component-controls/core';
import { Styled } from 'theme-ui';
import {
ThemeContext,
Expand Down Expand Up @@ -74,11 +74,17 @@ export const StorySource: FC<StorySourceProps> = ({
}
const args = story?.arguments;
const tags = getArgumentsLocations(args);
if (args && args.length && !showFileSource) {
allActions.push({
title: ViewStyleNext[viewStyle],
onClick: onMergeValues,
});
// if the props are not deconstructed, single variable
let propsArgs: string | undefined;
if (args && args.length) {
propsArgs =
typeof args[0].value === 'string' ? args[0].value : undefined;
if (!showFileSource) {
allActions.push({
title: ViewStyleNext[viewStyle],
onClick: onMergeValues,
});
}
}
if (actions) {
allActions.push.apply(allActions, actions);
Expand Down Expand Up @@ -130,7 +136,13 @@ export const StorySource: FC<StorySourceProps> = ({
{controls &&
viewStyle === 'values' &&
param.type === 'usage'
? getControlValue(controls, s) || s
? propsArgs === s
? JSON.stringify(
getControlValues(controls),
null,
2,
)
: getControlValue(controls, s) || s
: s}
</Tag>
) : (
Expand Down

0 comments on commit f3a0529

Please sign in to comment.