Skip to content

Commit

Permalink
fix(spinner): add color input property to spinner, fix class clobbering
Browse files Browse the repository at this point in the history
fixes #7087 fixes #7401
  • Loading branch information
brandyscarney committed Aug 19, 2016
1 parent 7fba099 commit 048b086
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components.ios.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"components/searchbar/searchbar.ios",
"components/segment/segment.ios",
"components/select/select.ios",
"components/spinner/spinner.ios",
"components/tabs/tabs.ios",
"components/toggle/toggle.ios",
"components/toast/toast.ios",
Expand Down
1 change: 1 addition & 0 deletions src/components.md.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"components/searchbar/searchbar.md",
"components/segment/segment.md",
"components/select/select.md",
"components/spinner/spinner.md",
"components/tabs/tabs.md",
"components/toggle/toggle.md",
"components/toast/toast.md",
Expand Down
1 change: 1 addition & 0 deletions src/components.wp.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"components/searchbar/searchbar.wp",
"components/segment/segment.wp",
"components/select/select.wp",
"components/spinner/spinner.wp",
"components/tabs/tabs.wp",
"components/toggle/toggle.wp",
"components/toast/toast.wp",
Expand Down
24 changes: 24 additions & 0 deletions src/components/spinner/spinner.ios.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import "./spinner";

// iOS Spinner
// --------------------------------------------------

@each $color-name, $color-base, $color-contrast in get-colors($colors-ios) {

.spinner-#{$color-name} {

&.spinner-ios line,
&.spinner-ios-small line,
&.spinner-crescent circle {
stroke: $color-base;
}

&.spinner-bubbles circle,
&.spinner-circles circle,
&.spinner-dots circle {
fill: $color-base;
}

}

}
24 changes: 24 additions & 0 deletions src/components/spinner/spinner.md.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import "./spinner";

// Material Design Spinner
// --------------------------------------------------

@each $color-name, $color-base, $color-contrast in get-colors($colors-md) {

.spinner-#{$color-name} {

&.spinner-ios line,
&.spinner-ios-small line,
&.spinner-crescent circle {
stroke: $color-base;
}

&.spinner-bubbles circle,
&.spinner-circles circle,
&.spinner-dots circle {
fill: $color-base;
}

}

}
43 changes: 40 additions & 3 deletions src/components/spinner/spinner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Input, ViewEncapsulation } from '@angular/core';
import { ChangeDetectionStrategy, Component, ElementRef, Input, Renderer, ViewEncapsulation } from '@angular/core';
import { NgFor, NgStyle } from '@angular/common';

import { Config } from '../../config/config';
Expand Down Expand Up @@ -108,7 +108,6 @@ import { Config } from '../../config/config';
`,
directives: [NgFor, NgStyle],
host: {
'[class]': '_applied',
'[class.spinner-paused]': 'paused'
},
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -122,6 +121,21 @@ export class Spinner {
private _init: boolean;
private _applied: string;

/** @internal */
_color: string;

/**
* @input {string} The predefined color to use. For example: `"primary"`, `"secondary"`, `"danger"`.
*/
@Input()
get color(): string {
return this._color;
}

set color(value: string) {
this._updateColor(value);
}

/**
* @input {string} SVG spinner name.
*/
Expand Down Expand Up @@ -153,7 +167,11 @@ export class Spinner {
*/
@Input() paused: boolean = false;

constructor(private _config: Config) {}
constructor(
private _config: Config,
private _elementRef: ElementRef,
private _renderer: Renderer
) {}

/**
* @private
Expand Down Expand Up @@ -188,6 +206,7 @@ export class Spinner {
}
}

this._renderer.setElementClass(this._elementRef.nativeElement, this._applied, true);
}
}
}
Expand All @@ -199,6 +218,24 @@ export class Spinner {
return data;
}

/**
* @internal
*/
_updateColor(newColor: string) {
this._setElementColor(this._color, false);
this._setElementColor(newColor, true);
this._color = newColor;
}

/**
* @internal
*/
_setElementColor(color: string, isAdd: boolean) {
if (color !== null && color !== '') {
this._renderer.setElementClass(this._elementRef.nativeElement, `spinner-${color}`, isAdd);
}
}

}

const SPINNERS: any = {
Expand Down
24 changes: 24 additions & 0 deletions src/components/spinner/spinner.wp.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import "./spinner";

// Windows Spinner
// --------------------------------------------------

@each $color-name, $color-base, $color-contrast in get-colors($colors-wp) {

.spinner-#{$color-name} {

&.spinner-ios line,
&.spinner-ios-small line,
&.spinner-crescent circle {
stroke: $color-base;
}

&.spinner-bubbles circle,
&.spinner-circles circle,
&.spinner-dots circle {
fill: $color-base;
}

}

}
24 changes: 24 additions & 0 deletions src/components/spinner/test/colors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component } from '@angular/core';
import { ionicBootstrap } from '../../../../../src';


@Component({
templateUrl: 'main.html'
})
class E2EPage {
paused: boolean = false;

toggleState() {
this.paused = !this.paused;
}
}


@Component({
template: '<ion-nav [root]="root"></ion-nav>'
})
class E2EApp {
root = E2EPage;
}

ionicBootstrap(E2EApp);
59 changes: 59 additions & 0 deletions src/components/spinner/test/colors/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<ion-header>

<ion-toolbar>
<ion-title>Spinners</ion-title>
</ion-toolbar>

</ion-header>


<ion-content padding>

<table style="border-collapse:initial; border-spacing: 20px">
<tr>
<td>Platform Default</td>
<td>
<ion-spinner color="primary" [paused]="paused"></ion-spinner>
</td>
</tr>
<tr>
<td>ios</td>
<td>
<ion-spinner color="secondary" name="ios" duration="1000" [paused]="paused"></ion-spinner>
</td>
</tr>
<tr>
<td>ios-small</td>
<td>
<ion-spinner color="danger" name="ios-small" duration="1000" [paused]="paused"></ion-spinner>
</td>
</tr>
<tr>
<td>bubbles</td>
<td>
<ion-spinner color="light" name="bubbles" [paused]="paused"></ion-spinner>
</td>
</tr>
<tr>
<td>circles</td>
<td>
<ion-spinner color="secondary" name="circles" [paused]="paused"></ion-spinner>
</td>
</tr>
<tr>
<td>crescent</td>
<td>
<ion-spinner color="primary" name="crescent" [paused]="paused"></ion-spinner>
</td>
</tr>
<tr>
<td>dots</td>
<td>
<ion-spinner color="danger" name="dots" [paused]="paused"></ion-spinner>
</td>
</tr>
</table>

<button ion-button (click)="toggleState()">Toggle Paused</button>

</ion-content>

0 comments on commit 048b086

Please sign in to comment.