@fortawesome/vue-fontawesome 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,821 +2,33 @@
2
2
  <img align="right" width="100" height="100" alt="Official Javascript Component" src="https://img.fortawesome.com/349cfdf6/official-javascript-component.svg">
3
3
  </a>
4
4
 
5
- # vue-fontawesome
5
+ # vue-fontawesome (with Vue 3)
6
6
 
7
7
  [![npm](https://img.shields.io/npm/v/@fortawesome/vue-fontawesome.svg?style=flat-square)](https://www.npmjs.com/package/@fortawesome/vue-fontawesome)
8
8
  [![GitHub Actions Status](https://github.com/FortAwesome/vue-fontawesome/workflows/CI/badge.svg)](https://github.com/FortAwesome/vue-fontawesome/actions)
9
9
 
10
- > Font Awesome 5 Vue component using SVG with JS
11
-
12
- ---
13
-
14
- **Vue 3 is just around the corner!**
15
-
16
- **If you have been using 0.1.x of vue-fontawesome, you can safely upgrade to
17
- 2.x. We have some upgrading information in the [CHANGELOG](./CHANGELOG.md)**
10
+ > Font Awesome Vue 3 component using SVG with JS
18
11
 
19
12
  ---
20
13
 
21
14
  <!-- toc -->
22
15
 
23
- - [Introduction](#introduction)
24
- * [Upgrading Font Awesome?](#upgrading-font-awesome)
25
- * [Get started](#get-started)
26
- * [Learn about our new SVG implementation](#learn-about-our-new-svg-implementation)
27
- - [Installation](#installation)
28
- - [Add more styles or Pro icons](#add-more-styles-or-pro-icons)
29
- - [Usage](#usage)
30
- * [Recommended](#recommended)
31
- + [Using Solid icons](#using-solid-icons)
32
- + [Using Brand icons](#using-brand-icons)
33
- + [Using Regular icons](#using-regular-icons)
34
- + [Using Light icons](#using-light-icons)
35
- + [Using Duotone icons](#using-duotone-icons)
36
- + [Quick warning about self-closing tags](#quick-warning-about-self-closing-tags)
37
- + [Processing i tags into svg using Font Awesome](#processing-i-tags-into-svg-using-font-awesome)
38
- * [The icon property](#the-icon-property)
39
- + [Shorthand that assumes a prefix of "fas"](#shorthand-that-assumes-a-prefix-of-fas)
40
- + [Explicit prefix (note the Vue bind shorthand because this uses an array)](#explicit-prefix-note-the-vue-bind-shorthand-because-this-uses-an-array)
41
- + [Explicit icon definition through something like a computed property](#explicit-icon-definition-through-something-like-a-computed-property)
42
- * [Alternative using component property](#alternative-using-component-property)
43
- * [Why use the concept of a library?](#why-use-the-concept-of-a-library)
44
- + [Import the specific icons that you need](#import-the-specific-icons-that-you-need)
45
- + [Import the same icon from different styles](#import-the-same-icon-from-different-styles)
46
- + [Import entire styles](#import-entire-styles)
47
- * [Tree shaking alternative](#tree-shaking-alternative)
48
- - [Features](#features)
49
- * [Register your components first](#register-your-components-first)
50
- * [Basic](#basic)
51
- * [Advanced](#advanced)
52
- - [Integrating with other tools and frameworks](#integrating-with-other-tools-and-frameworks)
53
- * [Nuxt.js](#nuxtjs)
54
- * [PurgeCSS](#purgecss)
55
- * [Web Components with vue-web-component-wrapper](#web-components-with-vue-web-component-wrapper)
56
- - [FAQ](#faq)
57
- * [Why so explicit (the :icon="['far', 'coffee']" syntax)?](#why-so-explicit-the-iconfar-coffee-syntax)
58
- + [How about a separate property for the prefix?](#how-about-a-separate-property-for-the-prefix)
59
- + [Bindings become boilerplate and verbose](#bindings-become-boilerplate-and-verbose)
60
- + [Properties can disagree with each other](#properties-can-disagree-with-each-other)
16
+ - [Documentation](#documentation)
61
17
  - [How to Help](#how-to-help)
62
18
  - [Contributors](#contributors)
63
- - [Releasing this project](#releasing-this-project)
19
+ - [Releasing this project (only project owners can do this)](#releasing-this-project-only-project-owners-can-do-this)
64
20
 
65
21
  <!-- tocstop -->
66
22
 
67
- ## Introduction
68
-
69
- Hey there! We're glad you're here...
70
-
71
- ### Upgrading Font Awesome?
72
-
73
- If you've used Font Awesome in the past (version 4 or older) there are some
74
- things that you should learn before you dive in.
75
-
76
- > https://fontawesome.com/how-to-use/on-the-web/setup/upgrading-from-version-4
77
-
78
- ### Get started
79
-
80
- This package is for integrating with Vue.js. If you aren't using Vue then it's
81
- not going to help you. Head over to our "Get Started" page for some guidance.
82
-
83
- > https://fontawesome.com/how-to-use/on-the-web/setup/getting-started
84
-
85
- ### Learn about our new SVG implementation
86
-
87
- This package, under the hood, uses SVG with JS and the `@fortawesome/fontawesome-svg-core` library. This implementation differs drastically from
88
- the web fonts implementation that was used in version 4 and older of Font Awesome. You might head over there to learn about how it works.
89
-
90
- > https://fontawesome.com/how-to-use/on-the-web/advanced/svg-javascript-core
91
-
92
- ## Installation
93
-
94
- Install the core package and icon content.
95
-
96
- ```
97
- $ npm i --save @fortawesome/fontawesome-svg-core
98
- $ npm i --save @fortawesome/free-solid-svg-icons
99
- ```
100
-
101
- Or with Yarn:
102
- ```
103
- $ yarn add @fortawesome/fontawesome-svg-core
104
- $ yarn add @fortawesome/free-solid-svg-icons
105
- ```
106
-
107
- **Install this Vue component**
108
-
109
- ```
110
- $ npm i --save @fortawesome/vue-fontawesome@prerelease
111
- ```
112
-
113
- The `prerelease` tag is compatible with Vue 3 but not Vue 2.
114
-
115
- If you are still using Vue 2.x you can [read about usage here](https://github.com/FortAwesome/vue-fontawesome/tree/2.x).
116
-
117
- ## Add more styles or Pro icons
118
-
119
- Brands are separated into their own style and for customers upgrading from
120
- version 4 to 5 we have a limited number of Regular icons available.
121
-
122
- **Visit [fontawesome.com/icons](https://fontawesome.com/icons) to search for free and Pro icons**
123
-
124
- ```
125
- $ npm i --save @fortawesome/free-brands-svg-icons
126
- $ npm i --save @fortawesome/free-regular-svg-icons
127
- ```
128
-
129
- If you are a [Font Awesome Pro](https://fontawesome.com/pro) subscriber you can install Pro packages after these [additional configuration](https://fontawesome.com/how-to-use/on-the-web/setup/using-package-managers) are made.
130
-
131
- ```
132
- $ npm i --save @fortawesome/pro-solid-svg-icons
133
- $ npm i --save @fortawesome/pro-regular-svg-icons
134
- $ npm i --save @fortawesome/pro-light-svg-icons
135
- $ npm i --save @fortawesome/pro-duotone-svg-icons
136
- ```
137
-
138
- ## Usage
139
-
140
- ### Recommended
141
-
142
- The following examples are based on a project configured with [vue-cli](https://github.com/vuejs/vue-cli).
143
-
144
- **Registering the component**
145
-
146
- `src/main.js`
147
-
148
- ```javascript
149
- import { createApp } from 'vue'
150
- import App from './App.vue'
151
- import { library } from '@fortawesome/fontawesome-svg-core'
152
- import { faUserSecret } from '@fortawesome/free-solid-svg-icons'
153
- import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
154
-
155
- library.add(faUserSecret)
156
-
157
-
158
- createApp(App)
159
- .component('font-awesome-icon', FontAwesomeIcon)
160
- .mount('#app')
161
- ```
162
-
163
- `src/App.vue`
164
-
165
- ```vue
166
- <template>
167
- <div id="app">
168
- <font-awesome-icon icon="user-secret" />
169
- </div>
170
- </template>
171
-
172
- <script>
173
- export default {
174
- name: 'App'
175
- }
176
- </script>
177
- ```
178
-
179
- #### Using Solid icons
180
-
181
- ```javascript
182
- import { library } from '@fortawesome/fontawesome-svg-core'
183
- import { faUserSecret } from '@fortawesome/free-solid-svg-icons'
184
-
185
- library.add(faUserSecret)
186
- ```
187
-
188
- ```html
189
- <!-- The solid style is implicit -->
190
- <font-awesome-icon icon="user-secret" />
191
-
192
- <!-- It's better to be explicit -->
193
- <!-- Don't forget to bind the property with ":" (we forget all the time!) -->
194
- <font-awesome-icon :icon="['fas', 'user-secret']" />
195
- ```
196
-
197
- #### Using Brand icons
198
-
199
- ```javascript
200
- import { library } from '@fortawesome/fontawesome-svg-core'
201
- import { faFontAwesome } from '@fortawesome/free-brands-svg-icons'
202
-
203
- library.add(faFontAwesome)
204
- ```
205
-
206
- ```html
207
- <!-- Don't forget to bind the property with ":" (we forget all the time!) -->
208
- <font-awesome-icon :icon="['fab', 'font-awesome']" />
209
- ```
210
-
211
- #### Using Regular icons
212
-
213
- Using the Pro packages requires [additional configuration](https://fontawesome.com/how-to-use/on-the-web/setup/using-package-managers).
214
-
215
- ```javascript
216
- import { library } from '@fortawesome/fontawesome-svg-core'
217
- // Note we are using the Pro style here
218
- import { faUserSecret } from '@fortawesome/pro-regular-svg-icons'
219
-
220
- library.add(faUserSecret)
221
- ```
222
-
223
- ```html
224
- <font-awesome-icon :icon="['far', 'user-secret']" />
225
- ```
226
-
227
- #### Using Light icons
228
-
229
- ```javascript
230
- import { library } from '@fortawesome/fontawesome-svg-core'
231
- // Note we are using the Pro style here
232
- import { faUserSecret } from '@fortawesome/pro-light-svg-icons'
233
-
234
- library.add(faUserSecret)
235
- ```
236
-
237
- ```html
238
- <font-awesome-icon :icon="['fal', 'user-secret']" />
239
- ```
240
-
241
- #### Using Duotone icons
242
-
243
- ```javascript
244
- import { library } from '@fortawesome/fontawesome-svg-core'
245
- // Note we are using the Pro style here
246
- import { faUserSecret } from '@fortawesome/pro-duotone-svg-icons'
247
-
248
- library.add(faUserSecret)
249
- ```
250
-
251
- ```html
252
- <font-awesome-icon :icon="['fad', 'user-secret']" />
253
- ```
254
-
255
- You can also [import the same icon from different
256
- styles](#import-the-same-icon-from-different-styles) with some help from ES
257
- `import`.
258
-
259
- #### Quick warning about self-closing tags
260
-
261
- If you are using inline templates or HTML as templates you need to be careful to avoid self-closing tags.
262
-
263
- See [this issue on the Vue.js project](https://github.com/vuejs/vue/issues/1036)
264
-
265
- If you are writing these types of templates make sure and use valid HTML syntax:
266
-
267
- ```html
268
- <font-awesome-icon icon="coffee"></font-awesome-icon>
269
- ```
270
-
271
- #### Processing i tags into svg using Font Awesome
272
-
273
- A basic installation of [Font Awesome](https://fontawesome.com/how-to-use/on-the-web/setup/getting-started?using=svg-with-js) has
274
- the ability to automatically transform `<i class="fas fa-coffee"></i>` into
275
- `<svg class="...">...</svg>` icons. This technology works with the browser's
276
- DOM, [`requestAnimationFrame`][raf], and [`MutationObserver`][mo].
277
-
278
- When using the `@fortawesome/fontawesome-svg-core` package this **behavior is
279
- disabled by default**. This project uses that package so you will have to
280
- explicitly enable it like this:
281
-
282
- ```javascript
283
- import { dom } from '@fortawesome/fontawesome-svg-core'
284
-
285
- dom.watch() // This will kick of the initial replacement of i to svg tags and configure a MutationObserver
286
- ```
287
-
288
- [raf]: https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
289
- [mo]: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
290
-
291
- ### The icon property
292
-
293
- The `icon` property of the `FontAwesomeIcon` component can be used in the following way:
294
-
295
- #### Shorthand that assumes a prefix of "fas"
296
-
297
- ```javascript
298
- <font-awesome-icon icon="spinner" />
299
- <font-awesome-icon icon="align-left" />
300
-
301
- <font-awesome-icon :icon="['fas', 'spinner']" /> // Same as above
302
- <font-awesome-icon :icon="['fas', 'align-left']" /> // Same as above
303
- ```
304
-
305
- For the above to work you must add the `spinner` and `align-left` icon to the library.
306
-
307
- ```javascript
308
- import { library } from '@fortawesome/fontawesome-svg-core'
309
- import { faSpinner, faAlignLeft } from '@fortawesome/free-solid-svg-icons'
310
-
311
- library.add(faSpinner, faAlignLeft)
312
- ```
313
-
314
- In the event that you are using an icon with a multi-word name please note that
315
- you would need to pass in the icon name using _kebab-case_ as opposed to _camelCase_.
316
-
317
- ```javascript
318
- <font-awesome-icon icon="address-card" /> // import { faAddressCard } from '@fortawesome/free-solid-svg-icons'
319
- ```
320
-
321
- #### Explicit prefix (note the Vue bind shorthand because this uses an array)
322
-
323
- ```javascript
324
- <font-awesome-icon :icon="['far', 'spinner']" />
325
- ```
326
-
327
- For the above to work you must add the regular `spinner` icon (Pro only) to the library.
328
-
329
- ```javascript
330
- import { library } from '@fortawesome/fontawesome-svg-core'
331
- import { faSpinner } from '@fortawesome/pro-regular-svg-icons'
332
-
333
- library.add(faSpinner)
334
- ```
335
-
336
- #### Explicit icon definition through something like a computed property
337
-
338
- ```javascript
339
- <template>
340
- <div id="app">
341
- <font-awesome-icon :icon="appIcon" />
342
- </div>
343
- </template>
344
-
345
- <script>
346
- import { faChessQueen } from '@fortawesome/free-solid-svg-icons'
347
-
348
- export default {
349
- name: 'App',
350
-
351
- computed: {
352
- appIcon () {
353
- return faChessQueen
354
- }
355
- }
356
- }
357
- </script>
358
- ```
359
-
360
- ### Alternative using component property
361
-
362
- With Vue you can tell your component to resolve other component explicitly.
363
-
364
- ```javascript
365
- <template>
366
- <div>
367
- <font-awesome-icon :icon="myIcon" />
368
- </div>
369
- </template>
370
-
371
- <script>
372
- import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
373
- import { faSpinner } from '@fortawesome/free-solid-svg-icons'
374
-
375
- export default {
376
- name: 'MyComponent',
377
-
378
- data () {
379
- return {
380
- myIcon: faSpinner
381
- }
382
- },
383
-
384
- components: {
385
- FontAwesomeIcon
386
- }
387
- }
388
- </script>
389
- ```
390
-
391
- ### Why use the concept of a library?
392
-
393
- Explicitly selecting icons offer the advantage of only bundling the icons that you
394
- use in your final bundled file. This allows us to subset Font Awesome's
395
- thousands of icons to just the small number that are normally used.
396
-
397
- #### Import the specific icons that you need
398
-
399
- ```javascript
400
- import { library } from '@fortawesome/fontawesome-svg-core'
401
- import { faCoffee } from '@fortawesome/free-solid-svg-icons'
402
- import { faSpinner } from '@fortawesome/pro-light-svg-icons'
403
-
404
- library.add(faCoffee, faSpinner)
405
- ```
406
-
407
- #### Import the same icon from different styles
408
-
409
- ```javascript
410
- import { library } from '@fortawesome/fontawesome-svg-core'
411
- import { faCoffee as fasCoffee } from '@fortawesome/pro-solid-svg-icons'
412
- import { faCoffee as farCoffee } from '@fortawesome/pro-regular-svg-icons'
413
- import { faCoffee as falCoffee } from '@fortawesome/pro-light-svg-icons'
414
- import { faCoffee as fadCoffee } from '@fortawesome/pro-duotone-svg-icons'
415
-
416
- library.add(fasCoffee, farCoffee, falCoffee, fadCoffee)
417
- ```
418
-
419
- ```html
420
- <font-awesome-icon :icon="['fas', 'coffee']"/>
421
- <font-awesome-icon :icon="['far', 'coffee']"/>
422
- <font-awesome-icon :icon="['fal', 'coffee']"/>
423
- <font-awesome-icon :icon="['fad', 'coffee']"/>
424
- ```
425
-
426
- #### Import entire styles
427
-
428
- ```javascript
429
- import { fab } from '@fortawesome/free-brands-svg-icons'
430
-
431
- library.add(fab)
432
- ```
433
-
434
- This will add the _entire brands style to your library_. Be careful with this
435
- approach as it may be convenient in the beginning but your bundle size will be
436
- large. We **highly** recommend that you take advantage of subsetting through tree shaking.
437
-
438
- ### Tree shaking alternative
439
-
440
- Keeping the bundles small when using `import { faCoffee }` relies on
441
- [tree-shaking](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking).
442
- If you are not using a tool that supports tree shaking **you may end up bundling more
443
- icons than you intend**. Here are some alternative import syntaxes:
444
-
445
- ```javascript
446
- import { library } from '@fortawesome/fontawesome-svg-core'
447
- import { faCoffee } from '@fortawesome/free-solid-svg-icons/faCoffee'
448
- import { faSpinner } from '@fortawesome/pro-light-svg-icons/faSpinner'
449
-
450
- library.add(faCoffee, faSpinner)
451
- ```
452
-
453
- How does this work? We have individual icon files like
454
- `node_modules/@fortawesome/free-solid-svg-icons/faCoffee.js` that contain just
455
- that specific icon.
456
-
457
- ## Features
458
-
459
- The following features are available as part of Font Awesome. Note that the syntax is different from our general web-use documentation.
460
-
461
- ### Register your components first
462
-
463
- To use the following examples you must first register your component so Vue is aware of it.
464
-
465
- A good place to do this is in `main.js` or in the module you are calling `new
466
- Vue()`. **Make sure you register the component** and **have added icons to your
467
- library** before you bootstrap your Vue application.
468
-
469
- ```javascript
470
- import Vue from 'vue'
471
- import { FontAwesomeIcon, FontAwesomeLayers, FontAwesomeLayersText } from '@fortawesome/vue-fontawesome'
472
-
473
- Vue.component('font-awesome-icon', FontAwesomeIcon)
474
- Vue.component('font-awesome-layers', FontAwesomeLayers)
475
- Vue.component('font-awesome-layers-text', FontAwesomeLayersText)
476
- ```
477
-
478
- ### Basic
479
-
480
- [Size](https://fontawesome.com/how-to-use/on-the-web/styling/sizing-icons):
481
-
482
- ```html
483
- <font-awesome-icon icon="spinner" size="xs" />
484
- <font-awesome-icon icon="spinner" size="lg" />
485
- <font-awesome-icon icon="spinner" size="6x" />
486
- ```
487
-
488
- [Fixed width](https://fontawesome.com/how-to-use/on-the-web/styling/fixed-width-icons):
489
-
490
- ```html
491
- <font-awesome-icon icon="spinner" fixed-width />
492
- ```
493
-
494
- [Rotate](https://fontawesome.com/how-to-use/on-the-web/styling/rotating-icons):
495
-
496
- ```html
497
- <font-awesome-icon icon="spinner" rotation="90" />
498
- <font-awesome-icon icon="spinner" rotation="180" />
499
- <font-awesome-icon icon="spinner" rotation="270" />
500
- ```
501
-
502
- Flip horizontally, vertically, or both:
503
-
504
- ```html
505
- <font-awesome-icon icon="spinner" flip="horizontal" />
506
- <font-awesome-icon icon="spinner" flip="vertical" />
507
- <font-awesome-icon icon="spinner" flip="both" />
508
- ```
509
-
510
- Spin and pulse [animation](https://fontawesome.com/how-to-use/on-the-web/styling/animating-icons):
511
-
512
- ```html
513
- <font-awesome-icon icon="spinner" spin />
514
- <font-awesome-icon icon="spinner" pulse />
515
- ```
516
-
517
- [Border](https://fontawesome.com/how-to-use/on-the-web/styling/bordered-pulled-icons):
518
-
519
- ```html
520
- <font-awesome-icon icon="spinner" border />
521
- ```
522
-
523
- [Pull left or right](https://fontawesome.com/how-to-use/on-the-web/styling/bordered-pulled-icons):
524
-
525
- ```html
526
- <font-awesome-icon icon="spinner" pull="left" />
527
- <font-awesome-icon icon="spinner" pull="right" />
528
- ```
529
-
530
- [Inverse](https://fontawesome.com/how-to-use/on-the-web/styling/stacking-icons):
531
-
532
- ```html
533
- <font-awesome-icon icon="spinner" inverse />
534
- ```
535
-
536
- [Swap opacity](https://fontawesome.com/how-to-use/on-the-web/styling/duotone-icons#swapping-layers):
537
-
538
- ```html
539
- <font-awesome-icon :icon="['fad', 'spinner']" swap-opacity />
540
- ```
541
-
542
- ### Advanced
543
-
544
- [Power Transforms](https://fontawesome.com/how-to-use/on-the-web/styling/power-transforms):
545
-
546
- ```html
547
- <font-awesome-icon icon="spinner" transform="shrink-6 left-4" />
548
- <font-awesome-icon icon="spinner" :transform="{ rotate: 42 }" />
549
- ```
550
-
551
- [Masking](https://fontawesome.com/how-to-use/on-the-web/styling/masking):
552
-
553
- ```html
554
- <font-awesome-icon icon="coffee" :mask="['far', 'circle']" />
555
- ```
556
-
557
- [Symbols](https://fontawesome.com/how-to-use/on-the-web/advanced/svg-symbols):
558
-
559
- ```html
560
- <font-awesome-icon icon="edit" symbol />
561
- <font-awesome-icon icon="edit" symbol="edit-icon" />
562
- ```
563
-
564
- [Layers](https://fontawesome.com/how-to-use/on-the-web/styling/layering):
565
-
566
- ```html
567
- <font-awesome-layers class="fa-lg">
568
- <font-awesome-icon icon="circle" />
569
- <font-awesome-icon icon="check" transform="shrink-6" :style="{ color: 'white' }" />
570
- </font-awesome-layers>
571
- ```
572
-
573
- [Layers text](https://fontawesome.com/how-to-use/on-the-web/styling/layering):
574
-
575
- ```html
576
- <font-awesome-layers full-width class="fa-4x">
577
- <font-awesome-icon icon="queen"/>
578
- <font-awesome-layers-text class="gray8" transform="down-2 shrink-8" value="Q" />
579
- </font-awesome-layers>
580
- ```
581
-
582
- [Counters](https://fontawesome.com/how-to-use/on-the-web/styling/layering):
583
-
584
- ```html
585
- <font-awesome-layers full-width class="fa-4x">
586
- <font-awesome-icon icon="envelope"/>
587
- <font-awesome-layers-text counter value="1" position="top-right" />
588
- </font-awesome-layers>
589
- ```
590
-
591
- ## Integrating with other tools and frameworks
592
-
593
- ### Nuxt.js
594
-
595
- Install `@fortawesome/vue-fontawesome` and `@fortawesome/fontawesome-svg-core` and any icon packages.
596
-
597
- ```
598
- npm install --save @fortawesome/vue-fontawesome @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons
599
- ```
600
-
601
- Inside your Nuxt.js project add a `plugins/fontawesome.js` file.
602
-
603
- ```javascript
604
- import Vue from 'vue'
605
- import { library, config } from '@fortawesome/fontawesome-svg-core'
606
- import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
607
- import { fas } from '@fortawesome/free-solid-svg-icons'
608
-
609
- // This is important, we are going to let Nuxt.js worry about the CSS
610
- config.autoAddCss = false
611
-
612
- // You can add your icons directly in this plugin. See other examples for how you
613
- // can add other styles or just individual icons.
614
- library.add(fas)
615
-
616
- // Register the component globally
617
- Vue.component('font-awesome-icon', FontAwesomeIcon)
618
- ```
619
-
620
- Modify `nuxt.config.js` adding to the `css` and `plugins` sections.
621
-
622
- ```javascript
623
- css: [
624
- '@fortawesome/fontawesome-svg-core/styles.css'
625
- ]
626
- ```
627
-
628
- ```javascript
629
- plugins: [
630
- '~/plugins/fontawesome.js'
631
- ]
632
- ```
633
-
634
- ### PurgeCSS
635
-
636
- If you use PurgeCSS, or use the nuxt.js tailwindcss module which comes with PurgeCSS prebundled, you need to add fontawesome css classes to the whitelist, as the classes only gets inserted on rendering, and PurgeCSS will treat them as unused and remove them otherwise.
637
-
638
- In your `nuxt.config.js`, add a purgeCSS config object. You may adjust the regex to your liking:
639
-
640
- ```javascript
641
- purgeCSS: {
642
- whitelistPatterns: [/svg.*/, /fa.*/]
643
- },
644
- ```
645
-
646
- ### Web Components with vue-web-component-wrapper
647
-
648
- The Vue [project provides a wrapper](https://github.com/vuejs/vue-web-component-wrapper)
649
- that will register your Vue components as [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components).
650
-
651
- This project and all Font Awesome SVG icons will work just fine in these
652
- components but we need to take an additional step to add the CSS correctly.
653
-
654
- To take advantage of encapsulation that the Shadow DOM provides and to keep
655
- other areas of the DOM clean we need to add the Font Awesome CSS to the root of
656
- the Shadow DOM.
657
-
658
- Here is an example that leverages the `mounted()` lifecycle hook to insert the CSS.
659
-
660
- ```javascript
661
- <script>
662
- import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
663
- import { config, dom } from '@fortawesome/fontawesome-svg-core'
664
- import { faCoffee, faStroopwafel, faDragon } from '@fortawesome/free-solid-svg-icons'
665
-
666
- // Make sure you tell Font Awesome to skip auto-inserting CSS into the <head>
667
- config.autoAddCss = false
668
-
669
- const component = {
670
- name: 'MyCustomElement',
671
-
672
- template: `<font-awesome-icon :icon="icon" />`,
673
-
674
- components: {
675
- FontAwesomeIcon
676
- },
677
-
678
- mounted () {
679
- // This will only work on your root Vue component since it's using $parent
680
- const { shadowRoot } = this.$parent.$options
681
- const id = 'fa-styles'
682
-
683
- if (!shadowRoot.getElementById(`${id}`)) {
684
- const faStyles = document.createElement('style')
685
- faStyles.setAttribute('id', id)
686
- faStyles.textContent = dom.css()
687
- shadowRoot.appendChild(faStyles)
688
- }
689
- },
690
-
691
- computed: {
692
- icon () {
693
- const icons = [faCoffee, faStroopwafel, faDragon]
694
-
695
- return icons[Math.floor(Math.random() * 3)]
696
- }
697
- }
698
- }
699
-
700
- export default component
701
- </script>
702
- ```
703
-
704
- ## FAQ
705
-
706
- ### Why so explicit (the :icon="['far', 'coffee']" syntax)?
707
-
708
- It's been brought up a few times that the array syntax used for specifying an
709
- icon from the library is a bit cumbersome. Initially, this does seem to
710
- be the case but we do have good reasons.
711
-
712
- #### How about a separate property for the prefix?
713
-
714
- ```html
715
- <font-awesome-icon far icon="spinner" />
716
- ```
717
-
718
- or
719
-
720
- ```html
721
- <font-awesome-icon prefix="far" icon="spinner" />
722
- ```
723
-
724
- The problem with this is that it does not provide a consistent or concise way to specify the mask.
725
-
726
- ```html
727
- <font-awesome-icon far icon="spinner" mask="circle" />
728
- ```
729
-
730
- Does the `far` apply to the icon or the mask? What is the prefix for the property it does not apply to?
731
-
732
- Whereas this is consistent and concise:
733
-
734
- ```html
735
- <font-awesome-icon :icon="['far', 'spinner']" :mask="['fas', 'circle']" />
736
- ```
737
-
738
- #### Bindings become boilerplate and verbose
739
-
740
- Since icons are not always static but can change based on Vue component
741
- `methods` or `computed` values we have to take that into consideration.
742
-
743
- Icon properties end up being more verbose:
744
-
745
- ```html
746
- <font-awesome-icon :far="style === 'far'" :fal="style === 'fal'" :icon="icon" />
747
- ```
748
-
749
- vs.
750
-
751
- ```html
752
- <font-awesome-icon :icon="[style, icon]" />
753
- ```
754
-
755
- Or if you are using a `prefix` property it smells of needless boilerplate:
756
-
757
- ```html
758
- <template>
759
- <font-awesome-icon :prefix="iconPrefix" :icon="iconName" />
760
- </template>
761
-
762
- <script>
763
- export default {
764
- computed: {
765
- iconPrefix() {
766
- return 'fas'
767
- },
768
- iconName() {
769
- return 'coffee'
770
- }
771
- }
772
- }
773
- </script>
774
- ```
775
-
776
- vs.
777
-
778
- ```html
779
- <template>
780
- <font-awesome-icon :icon="icon" />
781
- </template>
782
-
783
- <script>
784
- export default {
785
- computed: {
786
- icon() {
787
- return ['fas', 'coffee']
788
- }
789
- }
790
- }
791
- </script>
792
- ```
793
-
794
- #### Properties can disagree with each other
795
-
796
- If we allow prefix definition through a property and we also allow an icon to
797
- be specified as an object through direct import these two have a chance to
798
- argue with eachother. This could lead to some head-scratching when an icon
799
- doesn't appear in the expected style.
800
-
801
- In the following case which style should be used (light from the icon definition or regular from the far boolean):
23
+ ## Documentation
802
24
 
803
- ```html
804
- import { faSpinner } from `@fortawesome/pro-light-svg-icons`
25
+ Official documentation is hosted at fontawesome.com
805
26
 
806
- <template>
807
- <font-awesome-icon far :icon="faSpinner" />
808
- </template>
27
+ Helpful Vue links:
28
+ - [Add Icons with Vue](https://fontawesome.com/docs/web/use-with/vue/add-icons)
29
+ - [Adding Icon Styling with Vue](https://fontawesome.com/docs/web/use-with/vue/style)
809
30
 
810
- <script>
811
- export default {
812
- data() {
813
- return {
814
- faSpinner
815
- }
816
- }
817
- }
818
- </script>
819
- ```
31
+ To find the Vue setup, go to our [Web docs](https://fontawesome.com/docs/web) and click the ***"Set Up with Vue"*** (left hand side menu).
820
32
 
821
33
  ## How to Help
822
34
 
@@ -827,11 +39,11 @@ Review the following docs before diving in:
827
39
 
828
40
  And then:
829
41
 
830
- 1. Check the existing issue and see if you can help!
42
+ * Check the existing [issues](https://github.com/FortAwesome/vue-fontawesome/issues) and see if you can help!
831
43
 
832
44
  ## Contributors
833
45
 
834
- The following contributors have either hepled to start this project, have contributed
46
+ The following contributors have either helped to start this project, have contributed
835
47
  code, are actively maintaining it (including documentation), or in other ways
836
48
  being awesome contributors to this project. **We'd like to take a moment to recognize them.**
837
49
 
@@ -847,6 +59,7 @@ being awesome contributors to this project. **We'd like to take a moment to reco
847
59
  | <img src="https://github.com/rigma.png?size=72" /> | Romain Failla | [@rigma](https://github.com/rigma) |
848
60
  | <img src="https://github.com/viniciuslrangel.png?size=72" /> | Vinicius Rangel | [@viniciuslrangel](https://github.com/viniciuslrangel) |
849
61
  | <img src="https://github.com/otijhuis.png?size=72" /> | Okke Tijhuis | [@otijhuis](https://github.com/otijhuis) |
62
+ | <img src="https://github.com/parkeyparker.png?size=72" /> | Aaron Parker | [@parkeyparker](https://github.com/parkeyparker) |
850
63
 
851
64
  If we've missed someone (which is quite likely) submit a Pull Request to us and we'll get it resolved.
852
65
 
@@ -858,7 +71,8 @@ The Font Awesome team:
858
71
  | <img src="https://github.com/robmadole.png?size=72" /> | Rob Madole | [@robmadole](https://github.com/robmadole) |
859
72
  | <img src="https://github.com/mlwilkerson.png?size=72" /> | Mike Wilkerson | [@mlwilkerson](https://github.com/mlwilkerson) |
860
73
  | <img src="https://github.com/talbs.png?size=72" /> | Brian Talbot | [@talbs](https://github.com/talbs) |
74
+ | <img src="https://github.com/jasonlundien.png?size=72" /> | Jason Lundien | [@jasonlundien](https://github.com/jasonlundien) |
861
75
 
862
- ## Releasing this project
76
+ ## Releasing this project (only project owners can do this)
863
77
 
864
78
  See [DEVELOPMENT.md](DEVELOPMENT.md#release)