import * as React from 'react'; import * as _ from 'lodash'; import { Link } from 'react-router-dom'; import { ComponentProp, ComponentPropType } from '../../../types'; import componentInfoContext from '../../../utils/componentInfoContext'; import ComponentPropName from '../ComponentProp/ComponentPropName'; import { getComponentGroup } from '../../../utils'; const InlineMarkdown = React.lazy(() => import('../InlineMarkdown')); type ComponentPropsRowProps = ComponentProp; const ComponentPropValue: React.FunctionComponent = props => { const { name, parameters } = props; if (name === 'literal') return enum; if (name === 'ShorthandValue' || name === 'ShorthandCollection') { const componentName = parameters[0].name.replace('Props', ''); const parentInfo = componentInfoContext.byDisplayName[componentName]; const linkName = _.kebabCase(parentInfo.parentDisplayName || componentName); const kindParam = parameters[1] && parameters[1].name !== 'never'; const kindIsVisible = name === 'ShorthandCollection' && kindParam; const showHash = parentInfo.parentDisplayName || _.size(getComponentGroup(componentName)) > 1; const propsSection = showHash ? `#${_.kebabCase(componentName)}` : ''; return ( {name} {`<`} {parameters[0].name} {kindIsVisible && , {parameters[1].name}} {`>`} ); } return {name}; }; const ComponentPropsRow: React.FunctionComponent = props => { const { defaultValue, description, name, required, types } = props; const shorthand = types.some(type => type.name === 'ShorthandValue' || type.name === 'ShorthandCollection'); const typeValues = _.uniqBy(types, type => type.name); const enumValues = _.filter(types, type => type.name === 'literal'); return ( {_.isNil(defaultValue) ? null : {JSON.stringify(defaultValue)}} {typeValues.map((type, index) => ( {index < typeValues.length - 1 && | } ))} {enumValues.length > 0 && Values:} {enumValues.map(type => ( {type.value} ))} {/* TODO make this work with typescript types */} {/* */} ); }; export default React.memo(ComponentPropsRow);