Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse object widgets #927

Merged
merged 2 commits into from
Dec 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/EditorWidgets/List/ListControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export default class ListControl extends Component {
onAddAsset={onAddAsset}
onRemoveInsertedMedia={onRemoveInsertedMedia}
classNameWrapper={`${classNameWrapper} nc-listControl-objectControl`}
forList
/>
</SortableListItem>);
};
Expand Down
11 changes: 10 additions & 1 deletion src/components/EditorWidgets/Object/Object.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
.nc-objectControl-root {
padding: 14px;
padding: 0 14px;
}

.nc-objectControl-topBar {
align-items: center;
background-color: #dfdfe3;
display: flex;
justify-content: space-between;
margin: 0 -14px;
padding: 13px;
}
33 changes: 22 additions & 11 deletions src/components/EditorWidgets/Object/ObjectControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import { Map } from 'immutable';
import { partial } from 'lodash';
import c from 'classnames';
import { resolveWidget } from 'Lib/registry';
import { Icon } from 'UI';
import EditorControl from 'Editor/EditorControlPane/EditorControl';

const TopBar = ({ collapsed, onCollapseToggle }) =>
<div className="nc-listControl-topBar">
<div className="nc-listControl-listCollapseToggle" onClick={onCollapseToggle}>
<Icon type="chevron" direction={collapsed ? 'up' : 'down'} size="small"/>
{itemsCount} {listLabel}
const TopBar = ({ collapsed, onCollapseToggle }) => (
<div className="nc-objectControl-topBar">
<div className="nc-objectControl-objectCollapseToggle">
<button className="nc-listControl-listCollapseToggleButton" onClick={onCollapseToggle}>
<Icon type="chevron" direction={collapsed ? 'up' : 'down'} size="small" />
</button>
</div>
</div>;

</div>
);

export default class ObjectControl extends Component {
static propTypes = {
Expand All @@ -32,6 +34,7 @@ export default class ObjectControl extends Component {
field: PropTypes.object,
forID: PropTypes.string,
classNameWrapper: PropTypes.string.isRequired,
forList: PropTypes.bool,
};

constructor(props) {
Expand Down Expand Up @@ -85,15 +88,23 @@ export default class ObjectControl extends Component {
);
}

handleCollapseToggle = () => {
this.setState({ collapsed: !this.state.collapsed });
}

render() {
const { field, forID, classNameWrapper } = this.props;
const { field, forID, classNameWrapper, forList } = this.props;
const { collapsed } = this.state;
const multiFields = field.get('fields');
const singleField = field.get('field');

if (multiFields) {
return (<div id={forID} className={c(classNameWrapper, 'nc-objectControl-root')}>
{multiFields.map((f, idx) => this.controlFor(f, idx))}
</div>);
return (
<div id={forID} className={c(classNameWrapper, 'nc-objectControl-root')}>
{ forList ? null : <TopBar collapsed={collapsed} onCollapseToggle={this.handleCollapseToggle} /> }
{ collapsed ? null : multiFields.map((f, idx) => this.controlFor(f, idx)) }
</div>
);
} else if (singleField) {
return this.controlFor(singleField);
}
Expand Down