refactor: Literal delegates to Value

This commit is contained in:
cha0s 2020-06-26 02:24:39 -05:00
parent 995e7a0f11
commit ef817def93

View File

@ -3,7 +3,7 @@ import {compose} from '@avocado/core';
import contempo from 'contempo';
import React from 'react';
import useTypeRenderers from '~/client/hooks/useTypeRenderers';
import Value from '~/client/value';
import propTypes from './prop-types';
import {defaultOps, opsOptions} from './typing';
@ -19,9 +19,7 @@ const Literal = ({
type,
value: {value},
}) => {
const typeRenderers = useTypeRenderers();
const actualType = 'any' === type ? fromLiteral(value) : type.split('|').map(description).find((desc) => desc.type !== 'undefined').type;
const Component = typeRenderers[actualType];
const [options] = opsOptions(context, [], actualType);
options.push('<literal>');
return (
@ -43,18 +41,12 @@ const Literal = ({
.map((option) => <option key={option}>{option}</option>)
}
</select>
{
Component
? (
<Component
onChange={onChange}
options={componentOptions}
type={actualType}
value={value}
/>
)
: null
}
<Value.Component
onChange={onChange}
options={componentOptions}
type={actualType}
value={value}
/>
</div>
);
};