Skip to content

Commit

Permalink
Removed deprecated styles and classes inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
devoto13 committed Mar 17, 2024
1 parent 97000bf commit a1342f9
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 98 deletions.
4 changes: 4 additions & 0 deletions docs/upgrading/0.14.0-0.15.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ Dynamic animation can be achieved by binding the `animation` input to `undefined
- <fa-icon [icon]="['fas', 'sync']" [spin]="isSyncAnimated" (click)="isSyncAnimated=!isSyncAnimated"></fa-icon>
+ <fa-icon [icon]="['fas', 'sync']" [animation]="isSyncAnimated ? 'spin' : undefined" (click)="isSyncAnimated=!isSyncAnimated"></fa-icon>
```

## Remove usage of the `styles` and `classes` inputs

Previously deprecated `styles` and `classes` inputs in all components were removed. These inputs don't work the way one would expect and cause a lot of confusion. For the majority of the cases, one should use regular [class and style bindings](https://angular.io/guide/class-binding) provided by Angular. For those rare cases, when it is not enough, there is a guide on how one can style component's internal elements at their own risk - [Styling icon internals](https://github.com/FortAwesome/angular-fontawesome/blob/master/docs/guide/styling-icon-internals.md).
2 changes: 1 addition & 1 deletion projects/demo/e2e/src/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Angular FontAwesome demo', () => {
});

it('should render all icons', async () => {
expect(await appPage.icons.count()).toBe(43);
expect(await appPage.icons.count()).toBe(45);
});

afterEach(async () => {
Expand Down
16 changes: 8 additions & 8 deletions projects/demo/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ <h3>With Mask and Transform</h3>
<h3>Change Size</h3>
<fa-icon [icon]="faAdjust" size="2x"></fa-icon>

<h3>Change color</h3>

<p>Using custom style: <fa-icon [icon]="faAdjust" [style.color]="'red'"></fa-icon></p>
<p>Using custom class: <fa-icon [icon]="faAdjust" class="green-icon"></fa-icon></p>

<h3>Animations</h3>

<button type="button" (click)="isAnimated = !isAnimated">Toggle animations</button>
Expand Down Expand Up @@ -106,12 +111,12 @@ <h3>Layers</h3>
<p>Custom icons created with multiple layers.</p>
<div>
<fa-layers [fixedWidth]="true" size="4x">
<fa-icon [icon]="faCircle" [styles]="{ color: 'Tomato' }"></fa-icon>
<fa-icon [icon]="faCircle" [style.color]="'Tomato'"></fa-icon>
<fa-icon [icon]="faTimes" [inverse]="true" transform="shrink-6"></fa-icon>
</fa-layers>
<fa-layers [fixedWidth]="true" size="4x">
<fa-icon [icon]="faSquare"></fa-icon>
<fa-icon [icon]="faBatteryQuarter" transform="shrink-8" [styles]="{ color: 'Tomato' }"></fa-icon>
<fa-icon [icon]="faBatteryQuarter" transform="shrink-8" [style.color]="'Tomato'"></fa-icon>
</fa-layers>
<fa-layers [fixedWidth]="true" size="4x">
<fa-icon [icon]="faFighterJet"></fa-icon>
Expand All @@ -124,12 +129,7 @@ <h3>Layers</h3>
<div>
<fa-layers [fixedWidth]="true" size="4x">
<fa-icon [icon]="faFlag"></fa-icon>
<fa-layers-text
title="Fort Awesome"
[content]="'Fa'"
transform="up-4"
[styles]="{ 'font-size': '0.3em' }"
></fa-layers-text>
<fa-layers-text title="Fort Awesome" [content]="'Fa'" transform="up-4" [style.font-size]="'0.3em'"></fa-layers-text>
</fa-layers>
</div>

Expand Down
6 changes: 5 additions & 1 deletion projects/demo/src/app/app.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
select {
font-size: 15px;
font-family: Tahoma, Geneva, sans-serif;
}
}

.green-icon {
color: green;
}
16 changes: 13 additions & 3 deletions src/lib/icon/duotone-icon.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input } from '@angular/core';
import { IconDefinition, IconProp } from '@fortawesome/fontawesome-svg-core';
import { IconDefinition, IconParams, IconProp } from '@fortawesome/fontawesome-svg-core';
import { FaIconComponent } from './icon.component';

@Component({
Expand Down Expand Up @@ -64,11 +64,21 @@ export class FaDuotoneIconComponent extends FaIconComponent {
return definition;
}

protected buildParams() {
protected buildParams(): IconParams {
const params = super.buildParams();

if (this.swapOpacity === true || this.swapOpacity === 'true') {
params.classes.push('fa-swap-opacity');
if (Array.isArray(params.classes)) {
params.classes.push('fa-swap-opacity');
} else if (typeof params.classes === 'string') {
params.classes = [params.classes, 'fa-swap-opacity'];
} else {
params.classes = ['fa-swap-opacity'];
}
}

if (params.styles == null) {
params.styles = {};
}
if (this.primaryOpacity != null) {
params.styles['--fa-primary-opacity'] = this.primaryOpacity.toString();
Expand Down
26 changes: 2 additions & 24 deletions src/lib/icon/icon.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
PullProp,
RotateProp,
SizeProp,
Styles,
Transform,
} from '@fortawesome/fontawesome-svg-core';
import { FaConfig } from '../config';
Expand Down Expand Up @@ -53,16 +52,6 @@ export class FaIconComponent implements OnChanges {
@Input() animation?: AnimationProp;

@Input() mask?: IconProp;

/**
* Set `style` attribute on the SVG element rendered by the component.
*
* @deprecated This input breaks view encapsulation and is not recommended.
* For simple cases (like colors), use `style` on the component itself, for
* more complex usages, explicitly opt-in to break the view encapsulation.
* This input is deprecated since 0.12.0 and will be removed in 0.13.0.
*/
@Input() styles?: Styles;
@Input() flip?: FlipProp;
@Input() size?: SizeProp;
@Input() pull?: PullProp;
Expand All @@ -71,16 +60,6 @@ export class FaIconComponent implements OnChanges {
@Input() symbol?: FaSymbol;
@Input() rotate?: RotateProp;
@Input() fixedWidth?: boolean;

/**
* Set `class` attribute on the SVG element rendered by the component.
*
* @deprecated This input breaks view encapsulation and is not recommended.
* For simple cases (like colors), use `class` on the component itself, for
* more complex usages, explicitly opt-in to break the view encapsulation.
* This input is deprecated since 0.12.0 and will be removed in 0.13.0.
*/
@Input() classes?: string[] = [];
@Input() transform?: string | Transform;

/**
Expand Down Expand Up @@ -149,7 +128,7 @@ export class FaIconComponent implements OnChanges {
return null;
}

protected buildParams() {
protected buildParams(): IconParams {
const classOpts: FaProps = {
flip: this.flip,
animation: this.animation,
Expand All @@ -167,9 +146,8 @@ export class FaIconComponent implements OnChanges {
return {
title: this.title,
transform: parsedTransform,
classes: [...faClassList(classOpts), ...this.classes],
classes: faClassList(classOpts),
mask: this.mask != null ? this.findIconDefinition(this.mask) : null,
styles: this.styles != null ? this.styles : {},
symbol: this.symbol,
attributes: {
role: this.a11yRole,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/layers/layers-counter.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('FaLayersCounterComponent', () => {
selector: 'fa-host',
template: `
<fa-layers>
<fa-layers-counter [content]="'Test'" [styles]="{ color: 'Tomato' }"></fa-layers-counter>
<fa-layers-counter [content]="'Test'"></fa-layers-counter>
</fa-layers>
`,
})
Expand Down
32 changes: 2 additions & 30 deletions src/lib/layers/layers-counter.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, HostBinding, Input, OnChanges, Optional, SimpleChanges } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { counter, CounterParams, Styles } from '@fortawesome/fontawesome-svg-core';
import { counter, CounterParams } from '@fortawesome/fontawesome-svg-core';
import { faWarnIfParentNotExist } from '../shared/errors/warn-if-parent-not-exist';
import { FaLayersComponent } from './layers.component';

Expand All @@ -15,26 +15,6 @@ import { FaLayersComponent } from './layers.component';
export class FaLayersCounterComponent implements OnChanges {
@Input() content: string;
@Input() title?: string;

/**
* Set `style` attribute on the SVG element rendered by the component.
*
* @deprecated This input breaks view encapsulation and is not recommended.
* For simple cases (like colors), use `style` on the component itself, for
* more complex usages, explicitly opt-in to break the view encapsulation.
* This input is deprecated since 0.12.0 and will be removed in 0.13.0.
*/
@Input() styles?: Styles;

/**
* Set `class` attribute on the SVG element rendered by the component.
*
* @deprecated This input breaks view encapsulation and is not recommended.
* For simple cases (like colors), use `class` on the component itself, for
* more complex usages, explicitly opt-in to break the view encapsulation.
* This input is deprecated since 0.12.0 and will be removed in 0.13.0.
*/
@Input() classes?: string[] = [];
@Input() position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';

@HostBinding('innerHTML') renderedHTML: SafeHtml;
Expand All @@ -54,17 +34,9 @@ export class FaLayersCounterComponent implements OnChanges {
}

protected buildParams(): CounterParams {
const classes = [];
if (this.classes != null) {
classes.push(...this.classes);
}
if (this.position != null) {
classes.push(`fa-layers-${this.position}`);
}
return {
title: this.title,
classes,
styles: this.styles,
classes: this.position != null ? [`fa-layers-${this.position}`] : undefined,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/layers/layers-text.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('FaLayersTextComponent', () => {
selector: 'fa-host',
template: `
<fa-layers>
<fa-layers-text [content]="'Test'" [styles]="{ color: 'Tomato' }"></fa-layers-text>
<fa-layers-text [content]="'Test'"></fa-layers-text>
</fa-layers>
`,
})
Expand Down
25 changes: 1 addition & 24 deletions src/lib/layers/layers-text.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
PullProp,
RotateProp,
SizeProp,
Styles,
text,
TextParams,
Transform,
Expand All @@ -27,27 +26,6 @@ import { FaLayersComponent } from './layers.component';
export class FaLayersTextComponent implements OnChanges {
@Input() content: string;
@Input() title?: string;

/**
* Set `style` attribute on the SVG element rendered by the component.
*
* @deprecated This input breaks view encapsulation and is not recommended.
* For simple cases (like colors), use `style` on the component itself, for
* more complex usages, explicitly opt-in to break the view encapsulation.
* This input is deprecated since 0.12.0 and will be removed in 0.13.0.
*/
@Input() styles?: Styles;

/**
* Set `class` attribute on the SVG element rendered by the component.
*
* @deprecated This input breaks view encapsulation and is not recommended.
* For simple cases (like colors), use `class` on the component itself, for
* more complex usages, explicitly opt-in to break the view encapsulation.
* This input is deprecated since 0.12.0 and will be removed in 0.13.0.
*/
@Input() classes?: string[] = [];

@Input() flip?: FlipProp;
@Input() size?: SizeProp;
@Input() pull?: PullProp;
Expand Down Expand Up @@ -94,9 +72,8 @@ export class FaLayersTextComponent implements OnChanges {

return {
transform: parsedTransform,
classes: [...faClassList(classOpts), ...this.classes],
classes: faClassList(classOpts),
title: this.title,
styles: this.styles,
};
}

Expand Down
10 changes: 5 additions & 5 deletions src/lib/layers/layers.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('FaLayersComponent', () => {
<fa-layers>
<fa-icon [icon]="faUser"></fa-icon>
<fa-icon [icon]="faCoffee"></fa-icon>
<fa-layers-text [content]="'User with coffee'" [styles]="{ color: 'Tomato' }"></fa-layers-text>
<fa-layers-text [content]="'User with coffee'"></fa-layers-text>
</fa-layers>
`,
})
Expand All @@ -35,7 +35,7 @@ describe('FaLayersComponent', () => {
<fa-layers size="2x">
<fa-icon [icon]="faUser"></fa-icon>
<fa-icon [icon]="faCoffee"></fa-icon>
<fa-layers-text [content]="'User with coffee'" [styles]="{ color: 'Tomato' }"></fa-layers-text>
<fa-layers-text [content]="'User with coffee'"></fa-layers-text>
</fa-layers>
`,
})
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('FaLayersComponent', () => {
<fa-layers [fixedWidth]="false">
<fa-icon [icon]="faUser"></fa-icon>
<fa-icon [icon]="faCoffee"></fa-icon>
<fa-layers-text [content]="'User with coffee'" [styles]="{ color: 'Tomato' }"></fa-layers-text>
<fa-layers-text [content]="'User with coffee'"></fa-layers-text>
</fa-layers>
`,
})
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('FaLayersComponent', () => {
template: `
<fa-layers>
<fa-duotone-icon [icon]="faDummy"></fa-duotone-icon>
<fa-layers-text [content]="'Dummy'" [styles]="{ color: 'Tomato' }"></fa-layers-text>
<fa-layers-text [content]="'Dummy'"></fa-layers-text>
</fa-layers>
`,
})
Expand All @@ -155,7 +155,7 @@ describe('FaLayersComponent', () => {
<fa-layers>
<ng-container>
<fa-icon [icon]="faUser"></fa-icon>
<fa-layers-text [content]="'Dummy'" [styles]="{ color: 'Tomato' }"></fa-layers-text>
<fa-layers-text [content]="'Dummy'"></fa-layers-text>
</ng-container>
</fa-layers>
`,
Expand Down

0 comments on commit a1342f9

Please sign in to comment.