Skip to content

Commit

Permalink
Added component for working with Duotone icons
Browse files Browse the repository at this point in the history
  • Loading branch information
devoto13 committed Aug 8, 2019
1 parent ecfa4f1 commit bf95641
Show file tree
Hide file tree
Showing 18 changed files with 414 additions and 74 deletions.
9 changes: 9 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Take advantage of the other FontAwesome icon styles.
* [Brand](./usage/using-other-styles.md#brand-icons)
* [Regular](./usage/using-other-styles.md#regular-icons)
* [Light (Pro Only)](./usage/using-other-styles.md#pro-only-light-icons)
* [Duotone (Pro Only)](./usage/using-other-styles.md#pro-only-duotone-icons)

## Features
Utilize core FontAwesome features
Expand All @@ -28,6 +29,14 @@ Utilize core FontAwesome features
* [Custom Classes](./usage/features.md#custom-classes)
* [Default Style](./usage/features.md#default-style)

## Features specific for Duotone icons
Additional features available for Duotone icons

* [Basic use](./usage/features.md#basic-use)
* [Swap layers opacity](./usage/features.md#swap-layers-opacity)
* [Customize layers opacity](./usage/features.md#customize-layers-opacity)
* [Customize layers color](./usage/features.md#customize-layers-color)

## Advanced Features
Take your icons to the next level with these advanced features.

Expand Down
36 changes: 36 additions & 0 deletions docs/usage/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@ The following features are available as part of Font Awesome. Note that the synt
<fa-icon [icon]="['fas', 'coffee']" [styles]="{'stroke': 'red', 'color': 'red'}"></fa-icon>
```

## Duotone icons

### Basic use

[FontAwesome Spec](https://fontawesome.com/how-to-use/on-the-web/styling/duotone-icons#basic-use):

```html
<fa-duotone-icon [icon]="['fad', 'coffee']"></fa-duotone-icon>
```

### Swap layers opacity

[FontAwesome Spec](https://fontawesome.com/how-to-use/on-the-web/styling/duotone-icons#swapping-layers):

```html
<fa-duotone-icon [icon]="['fad', 'coffee']" swapOpacity="true"></fa-duotone-icon>
```

### Customize layers opacity

[FontAwesome Spec](https://fontawesome.com/how-to-use/on-the-web/styling/duotone-icons#changing-opacity):

```html
<fa-duotone-icon [icon]="['fad', 'coffee']" primaryOpacity="0.9"></fa-duotone-icon>
<fa-duotone-icon [icon]="['fad', 'coffee']" secondaryOpacity="0.1"></fa-duotone-icon>
```

### Customize layers color

[FontAwesome Spec](https://fontawesome.com/how-to-use/on-the-web/styling/duotone-icons#coloring):

```html
<fa-duotone-icon [icon]="['fad', 'coffee']" primaryColor="red"></fa-duotone-icon>
<fa-duotone-icon [icon]="['fad', 'coffee']" secondaryColor="blue"></fa-duotone-icon>
```

## Advanced Usage

### Mask
Expand Down
17 changes: 15 additions & 2 deletions docs/usage/using-other-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,22 @@ library.add(faArrowAltRight);
<fa-icon [icon]="['fal', 'calendar']"></fa-icon>
```

## Duotone icons
## Pro-only Duotone Icons

Duotone icons are currently in pre-release and are coming soon to this component.
```bash
$ yarn add @fortawesome/pro-duotone-svg-icons
```

```javascript
import { faCamera } from '@fortawesome/pro-duotone-svg-icons';

// Add an icon to the library for convenient access in other components
library.add(faCamera);
```

```html
<fa-duotone-icon [icon]="['fad', 'camera']"></fa-duotone-icon>
```

## Same Icon from Multiple Styles

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@
"svg"
],
"peerDependencies": {
"@angular/common": "^8.0.0-rc.5",
"@angular/core": "^8.0.0-rc.5",
"@fortawesome/fontawesome-svg-core": "^1.2.0"
"@fortawesome/fontawesome-svg-core": "^1.2.21"
},
"ngPackage": {
"lib": {
Expand Down
18 changes: 18 additions & 0 deletions projects/demo/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
<h1>Font Awesome examples</h1>

<h3>Icon as Object (with title attribute—inspect the DOM to see it)</h3>
<fa-icon [icon]="faCoffee" title="Coffee: Best Drink Ever"></fa-icon>

<h3>Icon looked up in library by name</h3>
<p>Possible after adding the <code>faUser</code> icon from the <code>free-solid-svg-icons</code> package to the library.</p>
<p>The default prefix of <code>fas</code> is assumed. Also, add a border.</p>
<fa-icon icon='user' [border]="true"></fa-icon>

<h3>Duotone icons</h3>
<fa-duotone-icon [icon]="faDummy"></fa-duotone-icon>
<p>Swap layer opacity.</p>
<fa-duotone-icon [icon]="faDummy" swapOpacity="true"></fa-duotone-icon>
<p>Custom primary or secondary layer opacity.</p>
<fa-duotone-icon [icon]="faDummy" primaryOpacity="0.7" secondaryOpacity="0.1"></fa-duotone-icon>
<p>Custom primary or secondary layer color.</p>
<fa-duotone-icon [icon]="faDummy" primaryColor="red" secondaryColor="blue"></fa-duotone-icon>

<h3>Icon with Non-default Style Prefix Using [prefix, iconName]</h3>
<p><code>icon</code> should be set equal to an array object with two string elements: the prefix and the icon name.</p>
<p>Using a string for an icon name also requires that this icon has been added to the library with <code>library.add()</code></p>
<fa-icon [icon]="['far','user']"></fa-icon>

<h3>Icon as Object with non-Default Prefix</h3>
<p>The icon object knows its own prefix, so the prefix is not specified in this case.</p>
<fa-icon [icon]="regularUser"></fa-icon>

<h3>With Mask and Transform</h3>
<fa-icon [icon]="faCircle" transform="shrink-9 right-4" [mask]="faSquare"></fa-icon>

<h3>Change Size</h3>
<fa-icon [icon]="faAdjust" size="2x"></fa-icon>

<h3>Animation</h3>
<p>Click to toggle animation.</p>
<fa-icon [icon]="faSync" [spin]="isSyncAnimated" (click)="isSyncAnimated =! isSyncAnimated"></fa-icon>
Expand Down Expand Up @@ -70,11 +86,13 @@ <h3>Layers</h3>

<app-alternate-prefix></app-alternate-prefix>


<h3>When using text layer outside layers component</h3>
<p>Expect to see an error on the JavaScript console, and nothing shown between these bars:
|<fa-layers-counter [content]="notificationsCounter | number"></fa-layers-counter>|
</p>


<h3>Intentionally Missing Icon</h3>
<p>Expect to see an error on the JavaScript console, and nothing shown between these bars: |<fa-icon [icon]="undefined"></fa-icon>|</p>

Expand Down
16 changes: 15 additions & 1 deletion projects/demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { library } from '@fortawesome/fontawesome-svg-core';
import { IconDefinition, IconName, library } from '@fortawesome/fontawesome-svg-core';
import { faFlag, faUser as regularUser } from '@fortawesome/free-regular-svg-icons';
import {
faAdjust,
Expand Down Expand Up @@ -39,6 +39,20 @@ export class AppComponent {
faEllipsisH = faEllipsisH;
faFighterJet = faFighterJet;
faBatteryQuarter = faBatteryQuarter;
faDummy: IconDefinition = {
prefix: 'fad',
iconName: 'dummy' as IconName,
icon: [
512,
512,
[],
'f030',
[
'M50 50 H412 V250 H50 Z',
'M50 262 H412 V462 H50 Z'
]
]
};

notificationsCounter = 1000;
isSyncAnimated = true;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/fontawesome.module.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { FaDuotoneIconComponent } from './icon/duotone-icon.component';
import { FaIconComponent } from './icon/icon.component';
import { FaLayersComponent } from './layers/layers.component';
import { FaLayersTextComponent } from './layers/layers-text.component';
import { FaLayersCounterComponent } from './layers/layers-counter.component';
import { FaLayersTextComponent } from './layers/layers-text.component';
import { FaLayersComponent } from './layers/layers.component';
import { FaStackItemSizeDirective } from './stack/stack-item-size.directive';
import { FaStackComponent } from './stack/stack.component';

@NgModule({
imports: [CommonModule],
declarations: [
FaIconComponent,
FaDuotoneIconComponent,
FaLayersComponent,
FaLayersTextComponent,
FaLayersCounterComponent,
Expand All @@ -20,6 +19,7 @@ import { FaStackComponent } from './stack/stack.component';
],
exports: [
FaIconComponent,
FaDuotoneIconComponent,
FaLayersComponent,
FaLayersTextComponent,
FaLayersCounterComponent,
Expand Down
107 changes: 107 additions & 0 deletions src/lib/icon/duotone-icon.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { Component } from '@angular/core';
import { faUser } from '@fortawesome/free-solid-svg-icons';
import { faDummy, initTest, queryByCss } from '../../testing/helpers';
import { FaDuotoneIconComponent } from './duotone-icon.component';

describe('FaDuotoneIconComponent', () => {
it('should render the duotone icon', () => {
@Component({
selector: 'fa-host',
template: '<fa-duotone-icon [icon]="faDummy"></fa-duotone-icon>'
})
class HostComponent {
faDummy = faDummy;
}

const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg')).toBeTruthy();
});

it('should allow to swap opacity of the layers', () => {
@Component({
selector: 'fa-host',
template: '<fa-duotone-icon [icon]="faDummy" [swapOpacity]="true"></fa-duotone-icon>'
})
class HostComponent {
faDummy = faDummy;
}

const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg').classList.contains('fa-swap-opacity')).toBeTruthy();
});

it('should allow to customize opacity of the primary layer', () => {
@Component({
selector: 'fa-host',
template: '<fa-duotone-icon [icon]="faDummy" [primaryOpacity]="0.1"></fa-duotone-icon>'
})
class HostComponent {
faDummy = faDummy;
}

const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg').style.getPropertyValue('--fa-primary-opacity')).toBe(' 0.1');
});

it('should allow to customize opacity of the secondary layer', () => {
@Component({
selector: 'fa-host',
template: '<fa-duotone-icon [icon]="faDummy" [secondaryOpacity]="0.9"></fa-duotone-icon>'
})
class HostComponent {
faDummy = faDummy;
}

const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg').style.getPropertyValue('--fa-secondary-opacity')).toBe(' 0.9');
});

it('should allow to customize color of the primary layer', () => {
@Component({
selector: 'fa-host',
template: '<fa-duotone-icon [icon]="faDummy" primaryColor="red"></fa-duotone-icon>'
})
class HostComponent {
faDummy = faDummy;
}

const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg').style.getPropertyValue('--fa-primary-color')).toBe(' red');
});

it('should allow to customize color of the secondary layer', () => {
@Component({
selector: 'fa-host',
template: '<fa-duotone-icon [icon]="faDummy" secondaryColor="red"></fa-duotone-icon>'
})
class HostComponent {
faDummy = faDummy;
}

const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg').style.getPropertyValue('--fa-secondary-color')).toBe(' red');
});

it('should throw if specified icon is not a Duotone icon', () => {
@Component({
selector: 'fa-host',
template: '<fa-duotone-icon [icon]="faUser"></fa-duotone-icon>'
})
class HostComponent {
faUser = faUser;
}

const fixture = initTest(HostComponent);
expect(() => fixture.detectChanges()).toThrow(new Error(
'The specified icon does not appear to be a Duotone icon. ' +
'Check that you specified the correct style: <fa-duotone-icon [icon]="[\'fab\', \'user\']"></fa-duotone-icon> ' +
'or use: <fa-icon icon="user"></fa-icon> instead.'
));
});
});
Loading

0 comments on commit bf95641

Please sign in to comment.