Skip to content

Commit 5962a75

Browse files
authored
feat(config): Add prefix to plugin configuration
Default to `fas` as the library does now. When changed, the icon needs to be recompiled related #18
1 parent 44d868d commit 5962a75

12 files changed

+1799
-1670
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Inspired by:
1212
- [Installation](#installation)
1313
- [Usage](#usage)
1414
* [Zero Configuration](#zero-configuration)
15-
* [Global Configuration](#global-configuration)
15+
* [Default Configuration](#default-configuration)
1616
* [Explicit Import](#explicit-import)
1717
* [Non FAS Icons](#non-fas-icons)
1818
* [Binding Variations](#binding-variations)
@@ -59,7 +59,7 @@ export function configure(aurelia) {
5959
}
6060
```
6161

62-
### Global Configuration
62+
### Default Configuration
6363
```javascript
6464
import { PLATFORM } from 'aurelia-framework';
6565

@@ -128,6 +128,8 @@ _foobar.html_
128128
- The icon can be a string, like `icon="coffee"`.
129129
- The icon can be an `Array` of strings, where the first element is a prefix,
130130
and the second element is the icon name: `icon.bind="['fab', 'apple']"`
131+
- The prefix can be bound, the default is `fas`: `prefix="fab" icon="apple"`
132+
- A default prefix can be setup in the plugin configuration: `{ prefix="fab" }`
131133

132134
## Dependencies
133135

dev-app/app.html

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ <h2 class="subtitle has-text-centered">(Most examples use the size attribute for
3636
</div>
3737
<div class="card-content">
3838
<p class="title is-4">HTML Attributes</p>
39+
<div class="content">
40+
The bulma class value "has-text-danger" is passed to the icon
41+
to make it red
42+
</div>
3943
</div>
4044
</div>
4145
<div class="card column">
4246
<div class="card-header is-centered">
43-
<font-awesome-icon size="2x" icon="spinner" spin.bind="true"></font-awesome-icon>
44-
<font-awesome-icon size="2x" icon="spinner" pulse.bind="true"></font-awesome-icon>
47+
<font-awesome-icon icon="spinner" spin.bind="true"></font-awesome-icon>
48+
<font-awesome-icon icon="spinner" pulse.bind="true"></font-awesome-icon>
4549
</div>
4650
<div class="card-content">
4751
<p class="title is-4">Animations</p>
@@ -56,7 +60,7 @@ <h2 class="subtitle has-text-centered">(Most examples use the size attribute for
5660
<div class="columns">
5761
<div class="column card">
5862
<div class="card-header is-centered">
59-
<font-awesome-icon size="2x" icon="home" mask="circle" size="3x"></font-awesome-icon>
63+
<font-awesome-icon icon="home" mask="circle"></font-awesome-icon>
6064
</div>
6165
<div class="card-content">
6266
<p class="title is-4">Masking</p>
@@ -69,38 +73,51 @@ <h2 class="subtitle has-text-centered">(Most examples use the size attribute for
6973
</div>
7074
<div class="column card">
7175
<div class="card-header is-centered">
72-
<font-awesome-icon size="2x" icon.bind="icon"></font-awesome-icon>
76+
<font-awesome-icon icon.bind="icon"></font-awesome-icon>
7377
</div>
7478
<div class="card-content">
7579
<p class="title is-4">Reactive</p>
7680
<div class="content">
81+
<p>
82+
The icon will be recreated when a bindable property is changes.
83+
</p>
7784
<button
7885
class="button"
7986
click.delegate="icon=(icon==='coffee' ? 'mug-hot' : 'coffee')">
80-
Brew
87+
Change bound icon
8188
</button>
8289
</div>
8390
</div>
8491
</div>
8592
<div class="column card">
8693
<div class="card-header is-centered">
87-
<font-awesome-icon size="2x" icon.bind="[ 'fab', 'microsoft' ]"></font-awesome-icon>
88-
+
89-
<font-awesome-icon size="2x" icon.bind="[ 'fab', 'github' ]"></font-awesome-icon>
94+
<font-awesome-icon if.bind="!rotated" prefix="fas" icon="coffee"></font-awesome-icon>
95+
<font-awesome-icon if.bind="rotated" prefix="fas" icon="coffee"></font-awesome-icon>
9096
</div>
9197
<div class="card-content">
92-
<p class="title is-4">Brand Icons</p>
98+
<p class="title is-4">Plugin Configuration</p>
99+
<div class="content">
100+
<p>
101+
The icon rotation will change for the new icon because the configuration
102+
object "rotation" property is being reset
103+
</p>
104+
<button class="button" click.delegate="changeRotation()">Change default rotation</button>
105+
</div>
93106
</div>
94107
</div>
95108
<div class="column card">
96109
<div class="card-header is-centered">
97-
<font-awesome-icon size="2x" if.bind="!coffeeSpilled" icon="coffee"></font-awesome-icon>
98-
<font-awesome-icon size="2x" if.bind="coffeeSpilled" icon="mug-hot"></font-awesome-icon>
110+
<font-awesome-icon if.bind="prefix" prefix="${prefix}" icon="thumbs-up"></font-awesome-icon>
111+
<font-awesome-icon if.bind="!prefix" icon="thumbs-up"></font-awesome-icon>
99112
</div>
100113
<div class="card-content">
101-
<p class="title is-4">Global Configuration</p>
114+
<p class="title is-4">Icon prefix</p>
102115
<div class="content">
103-
<button class="button" click.delegate="spillGlobal()">Spill</button>
116+
<p>
117+
You can override the default "fas" icon prefix by binding
118+
to another prefix in your view or the icon configuration
119+
</p>
120+
<button class="button" click.delegate="changePrefix()">Change default prefix</button>
104121
</div>
105122
</div>
106123
</div>

dev-app/app.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import { inject } from 'aurelia-framework';
22

3-
@inject('globalOptions')
3+
@inject('defaultOptions')
44
export class App {
55
message = 'Aurelia Font Awesome 5 Examples';
66
icon = 'coffee'
7-
coffeeSpilled = false;
7+
rotated = false;
8+
prefix = 'fas';
89

910
constructor(private _options) {
1011
}
1112

12-
spillGlobal() {
13+
attached() {
14+
this._options.prefix = 'far'
15+
}
16+
17+
changeRotation() {
1318
this._options.rotation = !this._options.rotation ? 270 : 0;
14-
this.coffeeSpilled = !this.coffeeSpilled;
19+
this.rotated = !this.rotated;
20+
}
21+
22+
changePrefix() {
23+
this.prefix = !this.prefix ? 'fas' : null;
1524
}
1625
}

dev-app/main.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@ import {
55
faHome,
66
faSpinner,
77
faCoffee,
8-
faMugHot
8+
faMugHot,
9+
faThumbsUp as fasThumbsUp
910
} from '@fortawesome/free-solid-svg-icons';
1011
import { fab } from '@fortawesome/free-brands-svg-icons'
12+
import { faThumbsUp } from '@fortawesome/free-regular-svg-icons'
1113

1214
export function configure(aurelia: Aurelia) {
1315
const options = {
14-
rotation: 0
16+
rotation: 0,
17+
size: '2x'
1518
};
1619

17-
aurelia.container.registerInstance('globalOptions', options);
20+
aurelia.container.registerInstance('defaultOptions', options);
1821

1922
aurelia.use
2023
.standardConfiguration()
2124
// load the plugin ../src
2225
// The "resources" is mapped to "../src" in aurelia.json "paths"
2326
.feature('resources', {
2427
iconOptions: options,
25-
icons: [ fab, faCircle, faHome, faSpinner, faCoffee, faMugHot ]
28+
icons: [ fab, faCircle, faHome, faSpinner, faCoffee, faMugHot, faThumbsUp, fasThumbsUp ]
2629
});
2730

2831
aurelia.use.developmentLogging(environment.debug ? 'debug' : 'warn');

0 commit comments

Comments
 (0)