feat(widget-object): add "summary" #4291 (#4398)

This commit is contained in:
KoljaTM
2020-10-15 16:55:06 +02:00
committed by GitHub
parent 9e0b8ac4b8
commit 963e775897
2 changed files with 14 additions and 3 deletions

View File

@ -2,8 +2,9 @@ import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { ClassNames } from '@emotion/core';
import { Map, List } from 'immutable';
import { ObjectWidgetTopBar, lengths, colors } from 'netlify-cms-ui-default';
import { List, Map } from 'immutable';
import { colors, lengths, ObjectWidgetTopBar } from 'netlify-cms-ui-default';
import { stringTemplate } from 'netlify-cms-lib-widgets';
const styleStrings = {
nestedObjectControl: `
@ -126,6 +127,13 @@ export default class ObjectControl extends React.Component {
return this.controlFor(singleField);
};
objectLabel = () => {
const { value, field } = this.props;
const label = field.get('label', field.get('name'));
const summary = field.get('summary');
return summary ? stringTemplate.compileStringTemplate(summary, null, '', value) : label;
};
render() {
const { field, forID, classNameWrapper, forList, hasError } = this.props;
const collapsed = forList ? this.props.collapsed : this.state.collapsed;
@ -159,6 +167,7 @@ export default class ObjectControl extends React.Component {
<ObjectWidgetTopBar
collapsed={collapsed}
onCollapseToggle={this.handleCollapseToggle}
heading={collapsed && this.objectLabel()}
/>
)}
<div