1- import React , { Component } from 'react' ;
1+ import React from 'react' ;
22import PropTypes from 'prop-types' ;
33import { compose } from 'redux' ;
44import { DropdownItem } from 'reactstrap' ;
@@ -11,30 +11,31 @@ import AbstractAction from 'components/ElementActions/AbstractAction';
1111 * Element actions is a dropdown menu containing links to inline editing forms for each
1212 * of the element's primary tabs, as well as operations such as save, publish, archive etc
1313 */
14- class ElementActions extends Component {
15- constructor ( props ) {
16- super ( props ) ;
17- this . handleEditTabsClick = this . handleEditTabsClick . bind ( this ) ;
18- }
19-
14+ const ElementActions = ( {
15+ children,
16+ type,
17+ id,
18+ activeTab,
19+ editTabs = [ ] ,
20+ handleEditTabsClick,
21+ expandable = true ,
22+ ActionMenuComponent,
23+ } ) => {
2024 /**
2125 * Set the active tab
2226 *
2327 * @param {Object } event
2428 */
25- handleEditTabsClick ( event ) {
26- const { handleEditTabsClick } = this . props ;
29+ const handleEditTabsClickFn = ( event ) => {
2730 handleEditTabsClick ( event . target . name ) ;
28- }
31+ } ;
2932
3033 /**
3134 * Render buttons for the edit form tabs that will be a part of the edit form (if they exist)
3235 *
3336 * @returns {HTMLElement[]|null }
3437 */
35- renderEditTabs ( ) {
36- const { editTabs, activeTab, type, expandable } = this . props ;
37-
38+ const renderEditTabs = ( ) => {
3839 // Don't render tabs if the block is not expandable or if no tabs are defined
3940 if ( type . broken || ! expandable || ! editTabs || ! editTabs . length ) {
4041 return null ;
@@ -47,59 +48,47 @@ class ElementActions extends Component {
4748 name = { name }
4849 title = { title }
4950 type = { type }
50- onClick = { this . handleEditTabsClick }
51+ onClick = { handleEditTabsClickFn }
5152 active = { name === activeTab }
5253 /> )
5354 ) ;
54- }
55+ } ;
5556
5657 /**
5758 * Renders a divider if there are CMS edit tabs and child actions
5859 *
5960 * @returns {DropdownItem|null }
6061 */
61- renderDivider ( ) {
62- const { children, editTabs, expandable } = this . props ;
63-
62+ const renderDivider = ( ) => {
6463 // Don't render divider if the block is not expandable or if no tabs are defined
6564 // or if there's no actions displayed after the tab list
6665 if ( ! expandable || ! editTabs || ! editTabs . length || React . Children . count ( children ) === 0 ) {
6766 return null ;
6867 }
6968
7069 return < DropdownItem divider role = "separator" /> ;
71- }
70+ } ;
7271
73- /**
74- * If inline editing is enabled, render the "more actions" menu. Injector registrations can
75- * define HOCs that add action components as children of this component.
76- *
77- * @returns {ActionMenuComponent|null }
78- */
79- render ( ) {
80- const { children, id, ActionMenuComponent } = this . props ;
72+ const dropdownToggleClassNames = [
73+ 'element-editor-header__actions-toggle' ,
74+ 'btn' ,
75+ 'btn-sm' ,
76+ 'btn--no-text' ,
77+ ] ;
8178
82- const dropdownToggleClassNames = [
83- 'element-editor-header__actions-toggle' ,
84- 'btn' ,
85- 'btn-sm' ,
86- 'btn--no-text' ,
87- ] ;
88-
89- return (
90- < ActionMenuComponent
91- id = { `element-editor-actions-${ id } ` }
92- className = "element-editor-header__actions-dropdown"
93- dropdownMenuProps = { { right : true } }
94- dropdownToggleClassNames = { dropdownToggleClassNames }
95- >
96- { this . renderEditTabs ( ) }
97- { this . renderDivider ( ) }
98- { children }
99- </ ActionMenuComponent >
100- ) ;
101- }
102- }
79+ return (
80+ < ActionMenuComponent
81+ id = { `element-editor-actions-${ id } ` }
82+ className = "element-editor-header__actions-dropdown"
83+ dropdownMenuProps = { { right : true } }
84+ dropdownToggleClassNames = { dropdownToggleClassNames }
85+ >
86+ { renderEditTabs ( ) }
87+ { renderDivider ( ) }
88+ { children }
89+ </ ActionMenuComponent >
90+ ) ;
91+ } ;
10392
10493// There's some extra prop types in here for registered transformations to consume
10594ElementActions . propTypes = {
@@ -114,12 +103,9 @@ ElementActions.propTypes = {
114103 name : PropTypes . string ,
115104 } ) ) ,
116105 handleEditTabsClick : PropTypes . func . isRequired ,
117- expandable : PropTypes . bool
118- } ;
119-
120- ElementActions . defaultProps = {
121- editTabs : [ ] ,
122- expandable : true
106+ expandable : PropTypes . bool ,
107+ children : PropTypes . node ,
108+ ActionMenuComponent : PropTypes . elementType . isRequired ,
123109} ;
124110
125111export { ElementActions as Component } ;
0 commit comments