Skip to content

Commit

Permalink
feat: support for union type
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Nov 24, 2020
1 parent bfcde64 commit 67ef09f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions core/core/src/controls-smart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ export const controlFromProps = (
value,
};
}
case 'union': {
const value =
typeof defaultValue === 'string'
? cleanQuotes(defaultValue)
: undefined;
if (typeof propDef.type !== 'object') {
return null;
}
const options = Array.isArray(propDef.type.value)
? propDef.type.value.map((v: { name: string }) => v.name)
: typeof propDef.type.raw === 'string' &&
propDef.type.raw.split('|').map(v => v.trim());

if (!Array.isArray(options)) {
return null;
}

return {
type: ControlTypes.OPTIONS,
options: options.map((v: any) => {
return cleanQuotes(v.value ?? v);
}),
value,
};
}
// typescript callback function signature
case '(() => void)':
case 'func': {
Expand Down

0 comments on commit 67ef09f

Please sign in to comment.