Skip to content

Commit

Permalink
NEW Add content for 'Add Block' popover widget
Browse files Browse the repository at this point in the history
  • Loading branch information
raissanorth committed Sep 4, 2018
1 parent a048cb1 commit 202ab8a
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions client/src/boot/registerComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Header from 'components/ElementEditor/Header';
import Content from 'components/ElementEditor/Content';
import Summary from 'components/ElementEditor/Summary';
import FormBuilder from 'components/ElementEditor/FormBuilder';
import AddElementPopoverContent from 'components/ElementEditor/AddElementPopoverContent';

export default () => {
Injector.component.registerMany({
Expand All @@ -20,5 +21,6 @@ export default () => {
ElementContent: Content,
ElementSummary: Summary,
ElementFormBuilder: FormBuilder,
AddElementPopoverContent,
});
};
60 changes: 60 additions & 0 deletions client/src/components/ElementEditor/AddElementPopoverContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* global window */

import React, { Component, PropTypes } from 'react';
import { Button } from 'reactstrap';
import classNames from 'classnames';

/**
* The AddElementPopoverContent component used in the context of an ElementEditor shows the
* available elements that can be added to an ElementalArea.
*/
class AddElementPopoverContent extends Component {
constructor(props) {
super(props);

this.renderElementButtons = this.renderElementButtons.bind(this);
}

renderElementButtons() {
const { elementTypes } = this.props;

return elementTypes.map((elementType) =>
(
<Button
className={
classNames(
elementType.icon,
'btn--icon-xl',
'element-editor-add-element-content__button'
)
}
key={elementType.ID}
>
{elementType.title}
</Button>
)
);
}

render() {
return (
<div className="element-editor-add-element-content">
<div className="element-editor-add-element-content__button-container">
{this.renderElementButtons()}
</div>
</div>
);
}
}
AddElementPopoverContent.propTypes = {
elementTypes: PropTypes.arrayOf(PropTypes.shape({
title: PropTypes.string,
icon: PropTypes.string,
})),
};

AddElementPopoverContent.defaultProps = {

};

export default AddElementPopoverContent;
43 changes: 43 additions & 0 deletions client/src/components/ElementEditor/AddElementPopoverContent.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.element-editor-add-element-content {
display: flex;
flex-direction: column;
max-width: 300px;
padding: 16px 20px 20px 20px;
box-shadow: $z-depth-1;
border-radius: $border-radius-sm;
max-height: 500px; // Placeholder, value TBC
overflow-y: scroll;

&__button-container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;

:nth-child(odd) {
margin-right: 10px;
}
:nth-child(even) {
margin-right: 0;
}
}

&__button {
min-width: calc(100% * (1 / 2) - 5px);
padding: 7px 0 7px 2px;
text-align: start;
margin-bottom: 10px;

&::before {
margin-right: 12px;
font-size: 2.3rem;

}
}

// Adds necessary specificity to override default font-size
& &__button::before {
font-size: 2.3rem;
}
}


2 changes: 1 addition & 1 deletion client/src/components/ElementEditor/ElementEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ElementEditor extends PureComponent {
return (
<div className="element-editor">
<ToolbarComponent elementTypes={elementTypes} baseAddHref={baseAddHref} />
<ListComponent pageId={pageId} />
<ListComponent elementTypes={elementTypes} pageId={pageId} />
</div>
);
}
Expand Down
4 changes: 4 additions & 0 deletions client/src/components/ElementEditor/ElementList.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component, PropTypes } from 'react';
import { elementType } from 'types/elementType';
import { inject } from 'lib/Injector';
import AddElementPopoverContent from 'components/ElementEditor/AddElementPopoverContent';

class ElementList extends Component {
/**
Expand Down Expand Up @@ -39,10 +40,12 @@ class ElementList extends Component {
}

render() {
const { elementTypes } = this.props;
return (
<div className="elemental-editor__list">
{this.renderLoading()}
{this.renderBlocks()}
<AddElementPopoverContent elementTypes={elementTypes} />
</div>
);
}
Expand All @@ -51,6 +54,7 @@ class ElementList extends Component {
ElementList.propTypes = {
// @todo support either ElementList or Element children in an array (or both)
blocks: PropTypes.arrayOf(elementType),
elementTypes: PropTypes.array.isRequired,
loading: PropTypes.bool,
};

Expand Down
1 change: 1 addition & 0 deletions client/src/styles/bundle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
@import "../components/ElementEditor/ElementList";
@import "../components/ElementEditor/AddNewButton";
@import "../components/ElementEditor/Toolbar";
@import "../components/ElementEditor/AddElementPopoverContent";
2 changes: 2 additions & 0 deletions src/Forms/ElementalAreaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\Models\ElementalArea;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\FieldGroup;
Expand Down Expand Up @@ -118,6 +119,7 @@ public function getSchemaDataDefaults()
$blockTypes[] = [
'value' => str_replace('\\', '-', $className),
'title' => $blockTitle,
'icon' => Config::inst()->get($className, 'icon'),
];
}

Expand Down

0 comments on commit 202ab8a

Please sign in to comment.