attributes-kit
Version:
React component for MSON rendering
61 lines (50 loc) • 1.19 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import Radium from 'radium';
import merge from 'lodash/merge';
import Sample from '../Sample/Sample';
import Row from '../Row/Row';
import Column from '../Column/Column';
import {
hasDefault,
} from '../../Modules/ElementUtils/ElementUtils';
class ArrayItemDefaults extends React.Component {
static propTypes = {
element: PropTypes.object,
style: PropTypes.object,
collapseByDefault: PropTypes.bool,
};
get style() {
const style = {
sample: {
row: {
marginTop: '6px',
},
},
};
return merge(style, this.props.style || {});
}
render() {
if (!this.props.element) {
return false;
}
if (!hasDefault(this.props.element)) {
return false;
}
const defaultValue = this.props.element.attributes.default;
return (
<Row>
<Column>
<Sample
title="Default"
sample={defaultValue}
style={this.style.sample}
collapseByDefault={this.props.collapseByDefault}
/>
</Column>
</Row>
);
}
}
export default ArrayItemDefaults;