Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

WebAnimations Meta #713

Merged
merged 33 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4685961
add animatable mixin
tomdye Sep 6, 2017
f85b652
startign to add tests
tomdye Oct 3, 2017
71f1b26
starting tests
tomdye Oct 9, 2017
39d41b3
added tests
tomdye Oct 9, 2017
b52717a
coverage
tomdye Oct 11, 2017
787c418
bumped test coverage
tomdye Oct 19, 2017
577f895
reinstated tests
tomdye Oct 19, 2017
17abf43
added typings for animate
tomdye Oct 19, 2017
0842ec8
changed to bdd style
tomdye Oct 20, 2017
8c0d3da
adding animations readme info
tomdye Oct 20, 2017
1a1ab07
fix headings
tomdye Oct 20, 2017
da7d027
add index
tomdye Oct 20, 2017
4ce0f74
add index
tomdye Oct 20, 2017
bfac7b7
auto bind onFinish and onCancel
tomdye Oct 24, 2017
75e2b7b
fix animatable
tomdye Oct 30, 2017
7bf0993
add package lock again
tomdye Oct 30, 2017
d9b3cae
changed to animated
tomdye Oct 31, 2017
2b734c6
fixed test
tomdye Oct 31, 2017
be94fc5
pr comments
tomdye Nov 2, 2017
c0566c5
moved animated to meta
tomdye Nov 2, 2017
24041c8
reinstated tests
tomdye Nov 3, 2017
9197e86
fix readme
tomdye Nov 3, 2017
fdfea28
fix functional test json
tomdye Nov 3, 2017
eb06216
rename add to animate
tomdye Nov 6, 2017
13c5136
adding info test
tomdye Nov 6, 2017
47aac32
added tests for get info
tomdye Nov 6, 2017
e156912
change type
tomdye Nov 6, 2017
97d0e96
update readme, change interface
tomdye Nov 6, 2017
57a721c
remove super call
tomdye Nov 6, 2017
48bef93
updated readme and bind type
tomdye Nov 7, 2017
f28f82b
updated package lock
tomdye Nov 7, 2017
aa37df9
make bind optional
tomdye Nov 7, 2017
3f98375
reinstate type, add instances to tests
tomdye Nov 7, 2017
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
135 changes: 135 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ widget-core is a library to create powerful, composable user interface widgets.
- [Composing Widgets](#composing-widgets)
- [Decomposing Widgets](#decomposing-widgets)
- [Mixins](#mixins)
- [Animation](#animation)
- [Styling & Theming](#styling--theming)
- [Internationalization](#internationalization)
- [Key Principles](#key-principles)
Expand Down Expand Up @@ -302,6 +303,140 @@ function StateMixin<T extends new(...args: any[]) => WidgetBase>(Base: T): T & (

Examples of Dojo 2 mixins can be seen with `ThemedMixin` and `I18nMixin` that are described in [Classes & theming](#classes--theming) and [Internationalization](#internationalization) sections.

### Animation

Dojo 2 widget-core provides a `WebAnimation` meta to apply web animations to VNodes.

To specify the web animations pass an `AnimationProperties` object to the `WebAnimation` meta along with the key of the node you wish to animate. This can be a single animation or an array or animations.

#### Basic Example

```ts
export default class AnimatedWidget extends WidgetBase {
protected render() {
const animate = {
id: 'rootAnimation',
effects: [
{ height: '10px' },
{ height: '100px' }
],
controls: {
play: true
}
};

this.meta(WebAnimation).animate('root', animate);

return v('div', {
key: 'root'
});
}
}
```

`controls` and `timing` are optional properties and are used to setup and control the animation. The `timing` property can only be set once, but the `controls` can be changed to stop / start / reverse etc... the web animation.

#### Changing Animation

Animations can be changed on each widget render in a reactive pattern, for example changing the animation from `slideUp` to `slideDown` on a title pane depending of if the titlepane is open or not.

```ts
export default class AnimatedWidget extends WidgetBase {
private _open = false;

protected render() {
const animate = this._open ? {
id: 'upAnimation',
effects: [
{ height: '100px' },
{ height: '0px' }
],
controls: {
play: true
}
} : {
id: 'downAnimation',
effects: [
{ height: '0px' },
{ height: '100px' }
],
controls: {
play: true
}
};

this.meta(WebAnimation).animate('root', animate);

return v('div', {
key: 'root'
})
}
}
```

#### Passing an effects function

An `effects` function can be passed to the animation and evaluated at render time. This allows you to create programatic effects such as those depending on measurements from the `Dimensions` `Meta`.

```ts
export default class AnimatedWidget extends WidgetBase {
private _getEffect() {
const { scroll } = this.meta(Dimensions).get('content');

return [
{ height: '0px' },
{ height: `${scroll.height}px` }
];
}

protected render() {
const animate = {
id: 'upAnimation',
effects: this._getEffect(),
controls: {
play: true
}
};

this.meta(WebAnimation).animate('root', animate);

return v('div', {
key: 'root'
})
}
}
```

#### Get animation info

The `WebAnimation` meta provides a `get` function that can be used to retrieve information about an animation via it's `id`.
This info contains the currentTime, playState, playbackRate and startTime of the animation. If no animation is found or the animation has been cleared this will return undefined.

```ts
export default class AnimatedWidget extends WidgetBase {
protected render() {
const animate = {
id: 'rootAnimation',
effects: [
{ height: '10px' },
{ height: '100px' }
],
controls: {
play: true
}
};

this.meta(WebAnimation).animate('root', animate);

const info = this.meta(WebAnimation).get('rootAnimation');

return v('div', {
key: 'root'
});
}
}
```

### Styling & Theming

#### Overview
Expand Down
3 changes: 2 additions & 1 deletion intern.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
{ "name": "globalize", "location": "node_modules/globalize", "main": "dist/globalize" },
{ "name": "pepjs", "location": "node_modules/pepjs/dist", "main": "pep" },
{ "name": "intersection-observer", "location": "node_modules/intersection-observer", "main": "intersection-observer" },
{ "name": "sinon", "location": "node_modules/sinon/pkg", "main": "sinon" }
{ "name": "sinon", "location": "node_modules/sinon/pkg", "main": "sinon" },
{ "name": "web-animations-js", "location": "node_modules/web-animations-js" }
],
"map": {
"globalize": {
Expand Down
Loading