Skip to content

Commit

Permalink
feat: handle objects in source merge values
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Feb 24, 2020
1 parent f455cd8 commit 89d7266
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions blocks/core/src/Source/argument-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
StoryArguments,
ArgUsageLocation,
ControlTypes,
ComponentControl,
} from '@component-controls/specification';
import {
LoadedComponentControl,
Expand Down Expand Up @@ -33,10 +34,22 @@ const stringifyValue = (type: string, value: any): string => {
switch (type) {
case ControlTypes.TEXT:
return `"${jsStringEscape(value)}"`;
case ControlTypes.OPTIONS:
return `[${stringifyValue(ControlTypes.TEXT, value)}]`;
case ControlTypes.OBJECT:
if (value) {
return `{ ${Object.keys(value)
.map((key: string) => {
const obj: ComponentControl = value[key];
return `${key}: ${stringifyValue(obj.type, obj.value)}`;
})
.join(', ')} }`;
}
return '';

default:
return value;
if (Array.isArray(value)) {
return `[${stringifyValue(ControlTypes.OPTIONS, value.join(', '))}]`;
}
return typeof value === 'string' ? `"${jsStringEscape(value)}"` : value;
}
};
const replaceString = (
Expand Down

0 comments on commit 89d7266

Please sign in to comment.