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