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

Blocks: Animate the controls on appear only #905

Merged
merged 4 commits into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 28 additions & 12 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { connect } from 'react-redux';
import classnames from 'classnames';
import { Slot } from 'react-slot-fill';
import { partial } from 'lodash';
import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';

/**
* WordPress dependencies
*/
import { Children } from 'element';
import Toolbar from 'components/toolbar';

/**
Expand All @@ -33,6 +35,11 @@ import {
isTypingInBlock,
} from '../../selectors';

function FirstChild( { children } ) {
const childrenArray = Children.toArray( children );
return childrenArray[ 0 ] || null;
}

class VisualEditorBlock extends wp.element.Component {
constructor() {
super( ...arguments );
Expand Down Expand Up @@ -200,18 +207,27 @@ class VisualEditorBlock extends wp.element.Component {
>
{ ( showUI || isHovered ) && <BlockMover uid={ block.uid } /> }
{ showUI &&
<div className="editor-visual-editor__block-controls">
<BlockSwitcher uid={ block.uid } />
{ !! settings.controls && (
<Toolbar
controls={ settings.controls.map( ( control ) => ( {
...control,
onClick: () => control.onClick( block.attributes, this.setAttributes ),
isActive: control.isActive ? control.isActive( block.attributes ) : false,
} ) ) } />
) }
<Slot name="Formatting.Toolbar" />
</div>
<CSSTransitionGroup
transitionName="controls"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we still use our is- modifier convention here as a prefix, e.g. is-appearing?

transitionAppear={ true }
transitionAppearTimeout={ 100 }
transitionEnter={ false }
transitionLeave={ false }
component={ FirstChild }
>
<div className="editor-visual-editor__block-controls">
<BlockSwitcher uid={ block.uid } />
{ !! settings.controls && (
<Toolbar
controls={ settings.controls.map( ( control ) => ( {
...control,
onClick: () => control.onClick( block.attributes, this.setAttributes ),
isActive: control.isActive ? control.isActive( block.attributes ) : false,
} ) ) } />
) }
<Slot name="Formatting.Toolbar" />
</div>
</CSSTransitionGroup>
}
<div onKeyPress={ this.maybeStartTyping }>
<BlockEdit
Expand Down
5 changes: 4 additions & 1 deletion editor/modes/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
}

.editor-visual-editor__block-controls {
@include animate_fade;
display: flex;
position: sticky;
z-index: z-index( '.editor-visual-editor__block-controls' );
Expand All @@ -87,6 +86,10 @@
@include break-medium() {
top: $header-height + $admin-bar-height + $item-spacing;
}

&.controls-appear.controls-appear-active {
@include animate_fade;
}
}

.editor-visual-editor__block-controls + div {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"react-dom": "^15.5.4",
"react-redux": "^5.0.4",
"react-slot-fill": "^1.0.0-alpha.11",
"react-transition-group": "^1.1.3",
"redux": "^3.6.0",
"uuid": "^3.0.1"
}
Expand Down