Skip to content

Commit

Permalink
Merge pull request #4 from JamesRArroyo/banner-animation
Browse files Browse the repository at this point in the history
Banner now cycles through each body value with fade in/out animation.
  • Loading branch information
hipsterreed authored Nov 9, 2017
2 parents 8346185 + f3da5a8 commit 72ae4d3
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bower_components
.DS_Store
47 changes: 30 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
# \<ab-animated-banner\>

A Polymer web component.

The `ab-animated-banner` is a polymer element which displays a simple banner that cycles through an array of strings.

## Install the Polymer-CLI
## Installation

First, make sure you have the [Polymer CLI](https://www.npmjs.com/package/polymer-cli) installed. Then run `polymer serve` to serve your application locally.
```sh
$ bower install -S ab-animated-banner
```

## Viewing Your Application
## Getting Started

```
$ polymer serve
```
Include the [webcomponents.js](http://webcomponents.org/polyfills/) "lite" polyfill (for browsers who don't natively support web components), then import `ab-animated-banner.html`:

## Building Your Application

```
$ polymer build
```html
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="/bower_components/ab-animated-banner/ab-animated-banner.html">
```

This will create builds of your application in the `build/` directory, optimized to be served in production. You can then serve the built versions by giving `polymer serve` a folder to serve from:
Add the element.

```
$ polymer serve build/default
```html
<ab-animated-banner> </ab-animated-banner>
```

## Running Tests
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

```
$ polymer test
```
## License

The MIT License (MIT)

Copyright (c) 2017 Jimmy Arroyo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Your application is already set up to be tested via [web-component-tester](https://github.com/Polymer/web-component-tester). Run `polymer test` to run your application's test suite locally.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
129 changes: 120 additions & 9 deletions ab-animated-banner.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,48 @@

}

.banner .innerLeft{
.banner .header{
height: 100%;
width: 20%;
float: left;
background: rgba(253,202,0,1);
}

.innerLeft h4{
.header h4{
font-size: 20px;
text-align: center;
}

.banner .body{
height: 100%;
display: flex;
flex-wrap: wrap;
justify-content:flex-start;
}

.body span{
height: 40px;
margin: 13px 15px 0 0;
}

.body .text{
width: 200px;
padding-top: 11px;
font-size: 14px;
font-weight: 800;
color: #525252;
margin-left: 10px;
}

</style>

<div class="banner-container">
<div class="banner">
<div class="innerLeft">
<h4>[[title]]</h4>
<div class="header">
<h4>[[headerTitle]]</h4>
</div>
<div id="bannerAnimation" class="body">
<span class="text">[[_body]]</span>
</div>
</div>
</div>
Expand All @@ -53,19 +75,108 @@ <h4>[[title]]</h4>
* @polymer
*/
class AbAnimatedBanner extends Polymer.Element {
static get is() { return 'ab-animated-banner'; }

static get is() {
return 'ab-animated-banner';
}

static get properties() {
return {
title: {
/**
* Holds all attributes that can be passed to the banner.
*/
bannerOptions: {
type: Object,
value: {}
},
/**
* The title displayed in the left side of the banner.
*/
headerTitle: {
type: String,
value: 'Title'
value: ''
},
dataSet: {

/**
* Set the array of strings to be displayed in the body of the banner.
*/
bodyArray: {
type: Array,
value: ['Jimmy Arroyo', 'John Doe', 'Bob Smith']
value: []
},

/**
* The body text of the banner.
*/
_body: {
type: String,
value: ''
},

/**
* The dataSet's position in which the banner's body is displaying.
*/
_dataSetPosition: {
type: Number,
value: -1
}
};
}

/**
* Cycles through an array of strings displaying them one by one
* with an animation
*
*/
_cycleAnimation() {
// increment array and get remainder so loop is never ending.
this._dataSetPosition = (this._dataSetPosition + 1) % this.bodyArray.length;

// update banner body with new value;
this._body = this.bodyArray[this._dataSetPosition];

let bannerAnimation = this.$.bannerAnimation.animate([
{transform: 'translateY(0)', opacity: 1, easing: 'ease-in'},
{transform: 'translateY(0)', opacity: 1},
{transform: 'translateY(0)', opacity: 1}, // Hack: added duplicate keyframe since web animations api doesnt allow a delay or duration on a specific keyframe in the sequence
{transform: 'translateY(0)', opacity: 0, easing: 'ease-out'}
], {
duration: 4000,
iterations: 1,
direction: 'alternate',
fill: 'forwards'
});

var element = this;

// Continue cylcing banner.
bannerAnimation.onfinish = function() {
element._cycleAnimation();
};

};

/**
* Deconstructs the bannerOptions and assigns them to the element.
*
* @param {Object} bannerOptions Options used to customize the animatedBanner element.
*/
assignProperties(bannerOptions) {
// TODO: Check that values are of correct type and handle errors
this.bodyArray = bannerOptions.bodyArray;
this.headerTitle = bannerOptions.headerTitle;
};

ready() {
super.ready();

// Bind bannerOptions to bannerElement
this.assignProperties(this.bannerOptions);

// Start animation cycle
this._cycleAnimation();
}

}

window.customElements.define(AbAnimatedBanner.is, AbAnimatedBanner);
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</head>

<body style="background-color: #efefef">
<ab-animated-banner></ab-animated-banner>
<ab-animated-banner banner-options='{"bodyArray": ["Jimmy", "Jane", "John"], "headerTitle": "Names"}'></ab-animated-banner>
</body>

</html>

0 comments on commit 72ae4d3

Please sign in to comment.