-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an Animate component and menu appear animation for popovers & sta…
…rt work on handbook (#13617)
- Loading branch information
1 parent
dafd700
commit 3f0ef0b
Showing
28 changed files
with
293 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Animation | ||
|
||
Animation can help reinforce a sense of hierarchy and spatial orientation. This document goes into principles you should follow when you add animation. | ||
|
||
## Principles | ||
|
||
### Point of Origin | ||
|
||
- Animation can help anchor an interface element. For example a menu can scale up from the button that opened it. | ||
- Animation can help give a sense of place; for example a sidebar can animate in from the side, implying it was always hidden off-screen. | ||
- Design your animations as if you're working with real-world materials. Imagine your user interface elements are made of real materials — when not on screen, where are they? Use animation to help express that. | ||
|
||
### Speed | ||
|
||
- Animations should never block a user interaction. They should be fast, almost always complete in less than 0.2 seconds. | ||
- A user should not have to wait for an animation to finish before they can interact. | ||
- Animations should be performant. Use `transform` CSS properties when you can, these render elements on the GPU, making them smooth. | ||
- If an animation can't be made fast & performant, leave it out. | ||
|
||
### Simple | ||
|
||
- Don't bounce if the material isn't made of rubber. | ||
- Don't rotate, fold, or animate on a curved path. Keep it simple. | ||
|
||
### Consistency | ||
|
||
In creating consistent animations, we have to establish physical rules for how elements behave when animated. When all animations follow these rules, they feel consistent, related, and predictable. An animation should match user expectations, if it doesn't, it's probably not the right animation for the job. | ||
|
||
Reuse animations if one already exists for your task. | ||
|
||
## Inventory of Reused Animations | ||
|
||
The generic `Animate` component is used to animate different parts of the interface. See [the component documentation](/packages/components/src/animate/README.md) for more details about the available animations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Animate | ||
|
||
Simple interface to introduce animations to components. | ||
|
||
## Usage | ||
|
||
```jsx | ||
import { Animate } from '@wordpress/components'; | ||
|
||
const MyAnimatedNotice = () => ( | ||
<Animate todo="Add missing props"> | ||
{ ( { className } ) => ( | ||
<Notice className={ className } status="success"> | ||
<p>Animation finished.</p> | ||
</Notice> | ||
) } | ||
</Animate> | ||
); | ||
``` | ||
|
||
## Props | ||
|
||
Name | Type | Default | Description | ||
--- | --- | --- | --- | ||
`type` | `string` | `undefined` | Type of the animation to use. | ||
`options` | `object` | `{}` | Options of the chosen animation. | ||
`children` | `function` | `undefined` | A callback receiving a list of props ( `className` ) to apply to the DOM element to animate. | ||
|
||
## Available Animation Types | ||
|
||
### appear | ||
|
||
This animation is meant for popover/modal content, such as menus appearing. It shows the height and width of the animated element scaling from 0 to full size, from its point of origin. | ||
|
||
#### Options | ||
|
||
Name | Type | Default | Description | ||
--- | --- | --- | --- | ||
`origin` | `string` | `top center` | Point of origin (`top`, `bottom`,` middle right`, `left`, `center`). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
function Animate( { type, options = {}, children } ) { | ||
if ( type === 'appear' ) { | ||
const { origin = 'top' } = options; | ||
const [ yAxis, xAxis = 'center' ] = origin.split( ' ' ); | ||
|
||
return children( { | ||
className: classnames( | ||
'components-animate__appear', | ||
{ | ||
[ 'is-from-' + xAxis ]: xAxis !== 'center', | ||
[ 'is-from-' + yAxis ]: yAxis !== 'middle', | ||
}, | ||
), | ||
} ); | ||
} | ||
|
||
return children( {} ); | ||
} | ||
|
||
export default Animate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.components-animate__appear { | ||
animation: components-animate__appear-animation 0.1s cubic-bezier(0, 0, 0.2, 1) 0s; | ||
animation-fill-mode: forwards; | ||
|
||
&.is-from-top, | ||
&.is-from-top.is-from-left { | ||
transform-origin: top left; | ||
} | ||
&.is-from-top.is-from-right { | ||
transform-origin: top right; | ||
} | ||
&.is-from-bottom, | ||
&.is-from-bottom.is-from-left { | ||
transform-origin: bottom left; | ||
} | ||
&.is-from-bottom.is-from-right { | ||
transform-origin: bottom right; | ||
} | ||
} | ||
|
||
@keyframes components-animate__appear-animation { | ||
from { | ||
transform: translateY(-2em) scaleY(0) scaleX(0); | ||
} | ||
to { | ||
transform: translateY(0%) scaleY(1) scaleX(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.