@@ -21,7 +21,7 @@ export class Fold extends Component {
2121 if ( ! this . foldVisible && ! this . props . messageIfEmpty ) {
2222 return null ;
2323 }
24- const { deleteContainer} = this . context ;
24+ const { deleteContainer, moveContainer } = this . context ;
2525 const {
2626 canDelete,
2727 children,
@@ -33,6 +33,8 @@ export class Fold extends Component {
3333 icon : Icon ,
3434 messageIfEmpty,
3535 name,
36+ canMoveUp,
37+ canMoveDown,
3638 } = this . props ;
3739
3840 const contentClass = classnames ( 'fold__content' , {
@@ -47,7 +49,7 @@ export class Fold extends Component {
4749 'fold__top__arrow--open' : ! folded ,
4850 } ) ;
4951
50- const arrowIcon = (
52+ const arrowDownIcon = (
5153 < div className = { arrowClass } >
5254 < div className = "fold__top__arrow__wrapper" >
5355 < AngleDownIcon />
@@ -70,13 +72,50 @@ export class Fold extends Component {
7072 </ div >
7173 ) : null ;
7274
75+ const movingControls = ( canMoveDown || canMoveUp ) && (
76+ < div className = "fold__top__moving-controls" >
77+ < span
78+ className = { `fold__top__moving-controls--up${ canMoveUp ? '' : '--disabled' } ` }
79+ onClick = { e => {
80+ // prevents fold toggle to happen when clicking on moving arrow controls
81+ e . stopPropagation ( ) ;
82+
83+ if ( canMoveUp ) {
84+ if ( ! moveContainer || typeof moveContainer !== 'function' ) {
85+ throw new Error ( 'moveContainer must be a function' ) ;
86+ }
87+ moveContainer ( 'up' ) ;
88+ }
89+ } }
90+ >
91+ < AngleDownIcon />
92+ </ span >
93+ < span
94+ className = { `fold__top__moving-controls--down${ canMoveDown ? '' : '--disabled' } ` }
95+ onClick = { e => {
96+ // prevents fold toggle to happen when clicking on moving arrow controls
97+ e . stopPropagation ( ) ;
98+ if ( canMoveDown ) {
99+ if ( ! moveContainer || typeof moveContainer !== 'function' ) {
100+ throw new Error ( 'moveContainer must be a function' ) ;
101+ }
102+ moveContainer ( 'down' ) ;
103+ }
104+ } }
105+ >
106+ < AngleDownIcon />
107+ </ span >
108+ </ div >
109+ ) ;
110+
73111 const foldHeader = ! hideHeader && (
74112 < div className = { headerClass } onClick = { toggleFold } >
75113 < div className = "fold__top__arrow-title" >
76- { arrowIcon }
114+ { arrowDownIcon }
77115 { icon }
78116 < div className = "fold__top__title" > { striptags ( name ) } </ div >
79117 </ div >
118+ { movingControls }
80119 { deleteButton }
81120 </ div >
82121 ) ;
@@ -118,6 +157,8 @@ Fold.propTypes = {
118157 icon : PropTypes . oneOfType ( [ PropTypes . node , PropTypes . func ] ) ,
119158 messageIfEmpty : PropTypes . string ,
120159 name : PropTypes . string ,
160+ canMoveUp : PropTypes . bool ,
161+ canMoveDown : PropTypes . bool ,
121162} ;
122163
123164Fold . contextTypes = {
@@ -175,6 +216,7 @@ PlotlyFold.plotly_editor_traits = {
175216PlotlyFold . contextTypes = Object . assign (
176217 {
177218 deleteContainer : PropTypes . func ,
219+ moveContainer : PropTypes . func ,
178220 } ,
179221 containerConnectedContextTypes
180222) ;
0 commit comments