Skip to content

Commit

Permalink
fix(components): add a mode agnostic css class (#9133)
Browse files Browse the repository at this point in the history
Fixes #8545
  • Loading branch information
alan-agius4 authored and brandyscarney committed Nov 14, 2016
1 parent d3ef28d commit 025c5cc
Show file tree
Hide file tree
Showing 30 changed files with 148 additions and 186 deletions.
32 changes: 16 additions & 16 deletions src/components/app/test/ion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ describe('Ion', () => {
describe('color', () => {

it('should set color when it hasnt been set yet', () => {
ion._setMode('icon', 'md');
ion._setColor('icon', 'primary');
expect(className(ion)).toEqual('icon-md icon-md-primary');
ion._setMode('md');
ion._setColor('primary');
expect(className(ion)).toEqual('icon icon-md icon-md-primary');
});

it('should remove color when it has already been set', () => {
ion._setMode('icon', 'md');
ion._setColor('icon', 'primary');
ion._setColor('icon', null);
expect(className(ion)).toEqual('icon-md');
ion._setMode('md');
ion._setColor('primary');
ion._setColor(null);
expect(className(ion)).toEqual('icon icon-md');
});

it('should update color when it has already been set', () => {
ion._setMode('icon', 'md');
ion._setColor('icon', 'primary');
ion._setColor('icon', 'secondary');
expect(className(ion)).toEqual('icon-md icon-md-secondary');
ion._setMode('md');
ion._setColor('primary');
ion._setColor('secondary');
expect(className(ion)).toEqual('icon icon-md icon-md-secondary');
});

it('should not setElementClass if its the same value', () => {
ion._setMode('icon', 'ios');
ion._setColor('icon', 'primary');
ion._setMode('ios');
ion._setColor('primary');
spyOn(ion, 'setElementClass');

expect(ion.setElementClass).not.toHaveBeenCalled();
ion._setColor('icon', 'primary');
ion._setColor('primary');

expect(className(ion)).toEqual('icon-ios icon-ios-primary');
expect(className(ion)).toEqual('icon icon-ios icon-ios-primary');
});

});

var ion: Ion;

beforeEach(() => {
ion = new Ion(mockConfig(), mockElementRef(), mockRenderer());
ion = new Ion(mockConfig(), mockElementRef(), mockRenderer(), 'icon');
});

function className(ion: Ion) {
Expand Down
8 changes: 3 additions & 5 deletions src/components/badge/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,19 @@ export class Badge extends Ion {
*/
@Input()
set color(val: string) {
this._setColor('badge', val);
this._setColor(val);
}

/**
* @input {string} The mode to apply to this component.
*/
@Input()
set mode(val: string) {
this._setMode('badge', val);
this._setMode(val);
}

constructor(config: Config, elementRef: ElementRef, renderer: Renderer) {
super(config, elementRef, renderer);

this.mode = config.get('mode');
super(config, elementRef, renderer, 'badge');
}

}
32 changes: 12 additions & 20 deletions src/components/card/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@ export class Card extends Ion {
*/
@Input()
set color(val: string) {
this._setColor('card', val);
this._setColor(val);
}

/**
* @input {string} The mode to apply to this component.
*/
@Input()
set mode(val: string) {
this._setMode('card', val);
this._setMode(val);
}

constructor(config: Config, elementRef: ElementRef, renderer: Renderer) {
super(config, elementRef, renderer);

this.mode = config.get('mode');
super(config, elementRef, renderer, 'card');
}

}
Expand All @@ -50,21 +48,19 @@ export class CardContent extends Ion {
*/
@Input()
set color(val: string) {
this._setColor('card-content', val);
this._setColor(val);
}

/**
* @input {string} The mode to apply to this component.
*/
@Input()
set mode(val: string) {
this._setMode('card-content', val);
this._setMode(val);
}

constructor(config: Config, elementRef: ElementRef, renderer: Renderer) {
super(config, elementRef, renderer);

this.mode = config.get('mode');
super(config, elementRef, renderer, 'card-content');
}

}
Expand All @@ -83,21 +79,19 @@ export class CardHeader extends Ion {
*/
@Input()
set color(val: string) {
this._setColor('card-header', val);
this._setColor(val);
}

/**
* @input {string} The mode to apply to this component.
*/
@Input()
set mode(val: string) {
this._setMode('card-header', val);
this._setMode(val);
}

constructor(config: Config, elementRef: ElementRef, renderer: Renderer) {
super(config, elementRef, renderer);

this.mode = config.get('mode');
super(config, elementRef, renderer, 'card-header');
}

}
Expand All @@ -115,21 +109,19 @@ export class CardTitle extends Ion {
*/
@Input()
set color(val: string) {
this._setColor('card-title', val);
this._setColor(val);
}

/**
* @input {string} The mode to apply to this component.
*/
@Input()
set mode(val: string) {
this._setMode('card-title', val);
this._setMode(val);
}

constructor(config: Config, elementRef: ElementRef, renderer: Renderer) {
super(config, elementRef, renderer);

this.mode = config.get('mode');
super(config, elementRef, renderer, 'card-title');
}

}
12 changes: 5 additions & 7 deletions src/components/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ export class Checkbox extends Ion implements AfterContentInit, ControlValueAcces
*/
@Input()
set color(val: string) {
this._setColor('checkbox', val);
this._setColor(val);
}

/**
* @input {string} The mode to apply to this component.
*/
@Input()
set mode(val: string) {
this._setMode('checkbox', val);
this._setMode(val);
}

/**
Expand All @@ -114,9 +114,7 @@ export class Checkbox extends Ion implements AfterContentInit, ControlValueAcces
elementRef: ElementRef,
renderer: Renderer
) {
super(config, elementRef, renderer);

this.mode = config.get('mode');
super(config, elementRef, renderer, 'checkbox');

_form.register(this);

Expand Down Expand Up @@ -168,7 +166,7 @@ export class Checkbox extends Ion implements AfterContentInit, ControlValueAcces
* @private
*/
writeValue(val: any) {
this._setChecked( isTrueProperty(val) );
this._setChecked(isTrueProperty(val));
}

/**
Expand Down Expand Up @@ -215,7 +213,7 @@ export class Checkbox extends Ion implements AfterContentInit, ControlValueAcces
/**
* @private
*/
onTouched() {}
onTouched() { }

/**
* @private
Expand Down
8 changes: 3 additions & 5 deletions src/components/chip/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,19 @@ export class Chip extends Ion {
*/
@Input()
set color(val: string) {
this._setColor('chip', val);
this._setColor(val);
}

/**
* @input {string} The mode to apply to this component.
*/
@Input()
set mode(val: string) {
this._setMode('chip', val);
this._setMode(val);
}

constructor(config: Config, elementRef: ElementRef, renderer: Renderer) {
super(config, elementRef, renderer);

this.mode = config.get('mode');
super(config, elementRef, renderer, 'chip');
}

}
4 changes: 1 addition & 3 deletions src/components/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ export class Content extends Ion {
@Optional() viewCtrl: ViewController,
@Optional() public _tabs: Tabs
) {
super(config, elementRef, renderer);

this._setMode('content', config.get('mode'));
super(config, elementRef, renderer, 'content');

this._sbPadding = config.getBoolean('statusbarPadding', false);

Expand Down
11 changes: 5 additions & 6 deletions src/components/datetime/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export class DateTime extends Ion implements AfterContentInit, ControlValueAcces
*/
@Input()
set mode(val: string) {
this._setMode('datetime', val);
this._setMode(val);
}

/**
Expand All @@ -433,9 +433,8 @@ export class DateTime extends Ion implements AfterContentInit, ControlValueAcces
@Optional() private _item: Item,
@Optional() private _pickerCtrl: PickerController
) {
super(config, elementRef, renderer);
super(config, elementRef, renderer, 'datetime');

this.mode = config.get('mode');
_form.register(this);

if (_item) {
Expand Down Expand Up @@ -632,7 +631,7 @@ export class DateTime extends Ion implements AfterContentInit, ControlValueAcces
// loop through each month and see if it
// is within the min/max date range
monthOpt.disabled = (dateSortValue(selectedYear, monthOpt.value, 31) < minCompareVal ||
dateSortValue(selectedYear, monthOpt.value, 1) > maxCompareVal);
dateSortValue(selectedYear, monthOpt.value, 1) > maxCompareVal);
}
}

Expand All @@ -648,8 +647,8 @@ export class DateTime extends Ion implements AfterContentInit, ControlValueAcces
var compareVal = dateSortValue(selectedYear, selectedMonth, dayOpt.value);

dayOpt.disabled = (compareVal < minCompareVal ||
compareVal > maxCompareVal ||
numDaysInMonth <= i);
compareVal > maxCompareVal ||
numDaysInMonth <= i);
}

} else {
Expand Down
12 changes: 5 additions & 7 deletions src/components/fab/fab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,30 @@ import { nativeTimeout } from '../../util/dom';
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
})
export class FabButton extends Ion {
export class FabButton extends Ion {

/**
* @input {string} The predefined color to use. For example: `"primary"`, `"secondary"`, `"danger"`.
*/
@Input()
set color(val: string) {
this._setColor('fab', val);
this._setColor(val);
}

/**
* @input {string} The mode to apply to this component.
*/
@Input()
set mode(val: string) {
this._setMode('fab', val);
this._setMode(val);
}

constructor(
config: Config,
elementRef: ElementRef,
renderer: Renderer,
) {
super(config, elementRef, renderer);
this.setElementClass('fab', true); // set role
this.mode = config.get('mode');
super(config, elementRef, renderer, 'fab');
}


Expand Down Expand Up @@ -324,7 +322,7 @@ export class FabContainer {
return;
}
let lists = this._fabLists.toArray();
for (let list of lists) {
for (let list of lists) {
list.setVisible(isActive);
}
this._mainButton.setActiveClose(isActive);
Expand Down
8 changes: 3 additions & 5 deletions src/components/icon/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,23 @@ export class Icon extends Ion {
return this._color;
}
set color(value: string) {
this._setColor('icon', value);
this._setColor(value);
}

/**
* @input {string} The mode to apply to this component.
*/
@Input()
set mode(val: string) {
this._setMode('icon', val);
this._setMode(val);
}

constructor(
config: Config,
elementRef: ElementRef,
renderer: Renderer
) {
super(config, elementRef, renderer);

this.mode = config.get('mode');
super(config, elementRef, renderer, 'icon');
this._iconMode = config.get('iconMode');
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/input/input-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class InputBase extends Ion {
nav: NavController,
ngControl: NgControl
) {
super(config, elementRef, renderer);
super(config, elementRef, renderer, 'input');

this._nav = <NavControllerBase>nav;
this._useAssist = config.getBoolean('scrollAssist', false);
Expand Down
Loading

0 comments on commit 025c5cc

Please sign in to comment.