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

Feature: Progress Linear/Circular Component #134

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
32 changes: 32 additions & 0 deletions addon/components/paper-progress-circular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Ember from 'ember';

var BASE_DIAMETER = 48;

export default Ember.Component.extend({
browserCompatibility: Ember.inject.service('browser-compatibility'),

classNames: ['md-default-theme'],

tagName: 'md-progress-circular',

attributeBindings: ['value', 'md-mode'],

mdDiameter: 48,

scale: Ember.computed('mdDiameter', function() {
return this.get('mdDiameter') / BASE_DIAMETER;
}),

clampedValue: Ember.computed('value', function() {

var value = this.get('value');

return Math.max(0, Math.min(value || 0, 100));

}),

circleStyle: Ember.computed('scale', function() {
return Ember.String.htmlSafe(this.get('browserCompatibility.CSS.TRANSFORM') + ': ' + 'scale(' + this.get('scale').toString() + ')');
})

});
81 changes: 81 additions & 0 deletions addon/components/paper-progress-linear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import Ember from 'ember';

function makeTransform(value) {
var scale = value / 100;
var translateX = (value - 100) / 2;
return 'translateX(' + translateX.toString() + '%) scale(' + scale.toString() + ', 1)';
}

export default Ember.Component.extend({
tagName: 'md-progress-linear',

classNames: ['md-default-theme'],

isInserted: false,

browserCompatibility: Ember.inject.service('browser-compatibility'),

init() {
this._super(...arguments);
this.setupTransforms();
},

didInsertElement() {
this._super(...arguments);

this.set('isInserted', true);
this.$('.md-container').addClass('md-ready');
},


attributeBindings: ['md-mode', 'md-buffer-value'],

transforms: new Array(101),

setupTransforms() {
for (var i = 0; i < 101; i++) {
this.transforms[i] = makeTransform(i);
}
},

bar1Style: Ember.computed('clampedBufferValue', function() {
return new Ember.Handlebars.SafeString(this.get('browserCompatibility.CSS.TRANSFORM') + ': ' + this.transforms[this.get('clampedBufferValue')]);
}),

bar2Style: Ember.computed('clampedValue', function() {

if (this.get('md-mode') === 'query') {
return new Ember.Handlebars.SafeString('');
}

return new Ember.Handlebars.SafeString(this.get('browserCompatibility.CSS.TRANSFORM') + ': ' + this.transforms[this.get('clampedValue')]);
}),

clampedValue: Ember.computed('value', function() {

var value = this.get('value');
if (value > 100) {
return 100;
}

if (value < 0) {
return 0;
}

return Math.ceil(value || 0);
}),

clampedBufferValue: Ember.computed('md-buffer-value', function() {
var value = this.get('md-buffer-value');
if (value > 100) {
return 100;
}

if (value < 0) {
return 0;
}

return Math.ceil(value || 0);
})

});
1 change: 1 addition & 0 deletions app/components/paper-progress-circular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-paper/components/paper-progress-circular';
1 change: 1 addition & 0 deletions app/components/paper-progress-linear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-paper/components/paper-progress-linear';
34 changes: 34 additions & 0 deletions app/services/browser-compatibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Ember from 'ember';

export default Ember.Service.extend({

snifferService: Ember.inject.service('sniffer'),

webkit: Ember.computed('', function() {
return /webkit/i.test(this.get('snifferService.vendorPrefix'));
}),

vendorProperty(name) {
var prefix = this.get('snifferService.vendorPrefix').toLowerCase();
return this.get('webkit') ? `-webkit-${name.charAt(0)}${name.substring(1)}` : name;
},

CSS: Ember.computed('webkit', function() {
var webkit = this.get('webkit');
return {
/* Constants */
TRANSITIONEND: 'transitionend' + (webkit ? ' webkitTransitionEnd' : ''),
ANIMATIONEND: 'animationend' + (webkit ? ' webkitAnimationEnd' : ''),

TRANSFORM: this.vendorProperty('transform'),
TRANSFORM_ORIGIN: this.vendorProperty('transformOrigin'),
TRANSITION: this.vendorProperty('transition'),
TRANSITION_DURATION: this.vendorProperty('transitionDuration'),
ANIMATION_PLAY_STATE: this.vendorProperty('animationPlayState'),
ANIMATION_DURATION: this.vendorProperty('animationDuration'),
ANIMATION_NAME: this.vendorProperty('animationName'),
ANIMATION_TIMING: this.vendorProperty('animationTimingFunction'),
ANIMATION_DIRECTION: this.vendorProperty('animationDirection')
};
})
});
68 changes: 68 additions & 0 deletions app/services/sniffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import Ember from 'ember';

const isString = value => {
return typeof value === 'string';
};

var lowercase = (string) => {
return isString(string) ? string.toLowerCase() : string;
};

function toInt(str) {
return parseInt(str, 10);
}


export default Ember.Service.extend({
vendorPrefix: '',
transitions: false,
animations: false,
document: document,
window: window,

android: Ember.computed('', function() {
return toInt((/android (\d+)/.exec(lowercase((this.get('window').navigator || {}).userAgent)) || [])[1]);
}),

init() {
this._super(...arguments);

var bodyStyle = this.get('document').body && this.get('document').body.style;
var vendorPrefix;
var vendorRegex = /^(Moz|webkit|ms)(?=[A-Z])/;

var transitions = false;
var animations = false;
var match;

if (bodyStyle) {
for (var prop in bodyStyle) {
if (match = vendorRegex.exec(prop)) {
vendorPrefix = match[0];
vendorPrefix = vendorPrefix.substr(0, 1).toUpperCase() + vendorPrefix.substr(1);
break;
}
}

if (!vendorPrefix) {
vendorPrefix = ('WebkitOpacity' in bodyStyle) && 'webkit';
}

transitions = !!(('transition' in bodyStyle) || (vendorPrefix + 'Transition' in bodyStyle));
animations = !!(('animation' in bodyStyle) || (vendorPrefix + 'Animation' in bodyStyle));

if (this.get('android') && (!transitions || !animations)) {
transitions = isString(bodyStyle.webkitTransition);
animations = isString(bodyStyle.webkitAnimation);
}


}

this.set('transitions', transitions);
this.set('animations', animations);

this.set('vendorPrefix', vendorPrefix);
}

});
2 changes: 2 additions & 0 deletions app/styles/ember-paper.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
@import 'paper-icon';
@import 'paper-slider';
@import 'paper-subheader';
@import 'paper-progress-linear';
@import 'paper-progress-circular';

@import 'paper-sidenav';
@import 'paper-backdrop';
Loading