UNPKG

attributes-kit

Version:
92 lines (76 loc) 1.89 kB
import React from 'react'; import PropTypes from 'prop-types'; import merge from 'lodash/merge'; import Row from '../Row/Row'; import Type from '../Type/Type'; import Column from '../Column/Column'; import { Value } from '../Value/Value'; import Description from '../Description/Description'; import { hasDescription, hasValue, } from '../../Modules/ElementUtils/ElementUtils'; class Primitive extends React.Component { static propTypes = { element: PropTypes.object, style: PropTypes.object, collapseByDefault: PropTypes.bool, }; static contextTypes = { theme: PropTypes.object, }; get style() { const { BORDER_COLOR } = this.context.theme; const style = { base: { }, typeHeader: { borderBottom: `1px solid ${BORDER_COLOR}`, paddingBottom: '8px', paddingLeft: '0px', paddingTop: '4px', }, type: { root: { fontSize: '12px', }, }, }; return merge(style, this.props.style || {}); }; get type() { const element = this.props.element; if (element.meta && element.meta.id) { return element.meta.id; } return element.element; }; render() { return ( <Column style={this.style.base}> <Row style={this.style.typeHeader}> <Type type={this.type} style={this.style.type} /> </Row> { hasDescription(this.props.element) && <Row> <Description element={this.props.element} /> </Row> } { hasValue(this.props.element) && <Row> <Value element={this.props.element} collapseByDefault={this.props.collapseByDefault} /> </Row> } </Column> ); }; } export default Primitive;