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 2 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
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={ { appear: 'appear-animation', appearActive: 'is-appearing' } }
Copy link
Member

Choose a reason for hiding this comment

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

Are we using the appear-animation part of this at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even if we're not using it, it's required to avoid a JS error.

Copy link
Member

Choose a reason for hiding this comment

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

Even if we're not using it, it's required to avoid a JS error.

Could we just use a string, like transitionName="is-appearing". Wouldn't that give us a is-appearing-active modifier? Seems reasonable enough naming to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this would give is-appearing-appear-active

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, maybe a little nasty 😄

Copy link
Member

Choose a reason for hiding this comment

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

Maybe transitionName="is"

Well, in any case, could it at least be an empty string? I think the "appear-animation" could be a little misleading in implying that it's necessary for something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe transitionName="is"

I don't like this option because it's misleading too, it's kind of a hack

Using an empty string is not possible (still a JS error).

What about { appear: 'is-appearing', appearActive: 'is-appearing-active' } and style is-appearing-active?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, that sounds good.

transitionAppear={ true }
transitionAppearTimeout={ 10000 }
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;
}

&.is-appearing {
@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