@fortawesome/vue-fontawesome 3.0.0-1 → 3.0.0-5

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fortawesome/vue-fontawesome",
3
3
  "description": "Official Vue component for Font Awesome 5",
4
- "version": "3.0.0-1",
4
+ "version": "3.0.0-5",
5
5
  "main": "index.js",
6
6
  "module": "index.es.js",
7
7
  "jsnext:main": "index.es.js",
@@ -20,7 +20,9 @@
20
20
  "Yannick Ihmels <github.com/ihmels>",
21
21
  "btaens <github.com/btaens>",
22
22
  "David Driscoll <github.com/david-driscoll>",
23
- "Tyranteon <github.com/tyranteon>"
23
+ "Tyranteon <github.com/tyranteon>",
24
+ "Vinicius Rangel <github.com/viniciuslrangel>",
25
+ "Okke Tijhuis <github.com/otijhuis>"
24
26
  ],
25
27
  "license": "MIT",
26
28
  "scripts": {
@@ -36,8 +38,8 @@
36
38
  ]
37
39
  },
38
40
  "peerDependencies": {
39
- "@fortawesome/fontawesome-svg-core": ">= 1.2.0 < 1.3",
40
- "vue": "3.0.0-rc.6"
41
+ "@fortawesome/fontawesome-svg-core": "~1 || >=1.3.0-beta1",
42
+ "vue": ">= 3.0.0 < 4"
41
43
  },
42
44
  "devDependencies": {
43
45
  "@fortawesome/fontawesome-svg-core": "^1.2.0",
@@ -58,7 +60,7 @@
58
60
  "rollup-plugin-babel": "^3.0.2",
59
61
  "rollup-plugin-commonjs": "^9.1.0",
60
62
  "rollup-plugin-node-resolve": "^3.0.0",
61
- "vue": "3.0.0-rc.6"
63
+ "vue": "3.0.0"
62
64
  },
63
65
  "dependencies": {},
64
66
  "husky": {
package/rollup.config.js CHANGED
@@ -9,7 +9,8 @@ const globals = {
9
9
 
10
10
  export default {
11
11
  external: [
12
- '@fortawesome/fontawesome-svg-core'
12
+ '@fortawesome/fontawesome-svg-core',
13
+ 'vue',
13
14
  ],
14
15
  input: 'src/index.js',
15
16
  output: [
@@ -1,5 +1,5 @@
1
1
  import { parse as faParse, icon as faIcon } from '@fortawesome/fontawesome-svg-core'
2
- import { defineComponent } from 'vue'
2
+ import { defineComponent, computed, watch } from 'vue'
3
3
  import convert from '../converter'
4
4
  import log from '../logger'
5
5
  import { objectWithKey, classList } from '../utils'
@@ -97,30 +97,31 @@ export default defineComponent({
97
97
  },
98
98
 
99
99
  setup (props, { attrs }) {
100
- const { symbol, title } = props
101
- const icon = normalizeIconArgs(props.icon)
102
- const classes = objectWithKey('classes', classList(props))
103
- const transform = objectWithKey(
100
+ const icon = computed(() => normalizeIconArgs(props.icon))
101
+ const classes = computed(() => objectWithKey('classes', classList(props)))
102
+ const transform = computed(() => objectWithKey(
104
103
  'transform',
105
104
  (typeof props.transform === 'string')
106
105
  ? faParse.transform(props.transform)
107
106
  : props.transform
108
- )
109
- const mask = objectWithKey('mask', normalizeIconArgs(props.mask))
107
+ ))
108
+ const mask = computed(() => objectWithKey('mask', normalizeIconArgs(props.mask)))
110
109
 
111
- const renderedIcon = faIcon(icon, {
112
- ...classes,
113
- ...transform,
114
- ...mask,
115
- symbol,
116
- title
117
- })
110
+ const renderedIcon = computed(() => faIcon(icon.value, {
111
+ ...classes.value,
112
+ ...transform.value,
113
+ ...mask.value,
114
+ symbol: props.symbol,
115
+ title: props.title
116
+ }))
118
117
 
119
- if (!renderedIcon) {
120
- return log('Could not find one or more icon(s)', icon, mask)
121
- }
118
+ watch(renderedIcon, (value) => {
119
+ if (!value) {
120
+ return log('Could not find one or more icon(s)', icon.value, mask.value)
121
+ }
122
+ }, { immediate: true })
122
123
 
123
- const abstractElement = renderedIcon.abstract[0]
124
- return convert(abstractElement, {}, attrs)
124
+ const vnode = computed(() => renderedIcon.value ? convert(renderedIcon.value.abstract[0], {}, attrs) : null)
125
+ return () => vnode.value
125
126
  }
126
127
  })
@@ -1,5 +1,5 @@
1
1
  import { config } from '@fortawesome/fontawesome-svg-core'
2
- import { defineComponent, h } from 'vue'
2
+ import { defineComponent, h, computed } from 'vue'
3
3
 
4
4
  export default defineComponent({
5
5
  name: 'FontAwesomeLayers',
@@ -14,11 +14,11 @@ export default defineComponent({
14
14
  setup (props, { slots }) {
15
15
  const { familyPrefix } = config
16
16
 
17
- const className = [
17
+ const className = computed(() => [
18
18
  `${familyPrefix}-layers`,
19
19
  ...(props.fixedWidth ? [`${familyPrefix}-fw`] : [])
20
- ]
20
+ ])
21
21
 
22
- return () => h('div', { class: className }, slots.default ? slots.default() : [])
22
+ return () => h('div', { class: className.value }, slots.default ? slots.default() : [])
23
23
  }
24
24
  })
@@ -1,5 +1,5 @@
1
1
  import { config, parse, text } from '@fortawesome/fontawesome-svg-core'
2
- import { defineComponent } from 'vue'
2
+ import { defineComponent, computed } from 'vue'
3
3
  import convert from '../converter'
4
4
  import { objectWithKey } from '../utils'
5
5
 
@@ -29,18 +29,21 @@ export default defineComponent({
29
29
  setup (props, { attrs }) {
30
30
  const { familyPrefix } = config
31
31
 
32
- const classes = objectWithKey('classes', [
32
+ const classes = computed(() => objectWithKey('classes', [
33
33
  ...(props.counter ? [`${familyPrefix}-layers-counter`] : []),
34
34
  ...(props.position ? [`${familyPrefix}-layers-${props.position}`] : [])
35
- ])
36
- const transform = objectWithKey('transform', typeof props.transform === 'string' ? parse.transform(props.transform) : props.transform)
37
- const renderedText = text(props.value.toString(), { ...transform, ...classes })
35
+ ]))
36
+ const transform = computed(() => objectWithKey('transform',
37
+ typeof props.transform === 'string' ? parse.transform(props.transform) : props.transform))
38
+ const abstractElement = computed(() => {
39
+ const { abstract } = text(props.value.toString(), { ...transform.value, ...classes.value })
40
+ if (props.counter) {
41
+ abstract[0].attributes.class = abstract[0].attributes.class.replace('fa-layers-text', '')
42
+ }
43
+ return abstract[0]
44
+ })
38
45
 
39
- const { abstract } = renderedText
40
- if (props.counter) {
41
- abstract[0].attributes.class = abstract[0].attributes.class.replace('fa-layers-text', '')
42
- }
43
-
44
- return convert(abstract[0], {}, attrs)
46
+ const vnode = computed(() => convert(abstractElement.value, {}, attrs))
47
+ return () => vnode.value
45
48
  }
46
49
  })
@@ -283,3 +283,17 @@ describe('title', () => {
283
283
  expect(wrapper.element.getElementsByTagName('title').length).toBe(0)
284
284
  })
285
285
  })
286
+
287
+ describe('reactivity', () => {
288
+ test('changing props should update the element', async () => {
289
+ const wrapper = mountFromProps({ icon: faCoffee, title: 'Coffee' })
290
+
291
+ expect(wrapper.element.classList.contains('fa-coffee')).toBeTruthy()
292
+ expect(wrapper.element.getElementsByTagName('title')[0].innerHTML).toBe('Coffee')
293
+
294
+ await wrapper.setProps({ icon: faCircle, title: 'Circle' })
295
+
296
+ expect(wrapper.element.classList.contains('fa-circle')).toBeTruthy()
297
+ expect(wrapper.element.getElementsByTagName('title')[0].innerHTML).toBe('Circle')
298
+ })
299
+ })
@@ -64,3 +64,20 @@ describe('class handling', () => {
64
64
  expect(wrapper.element.getAttribute('class')).toBe('fa-layers fa-fw')
65
65
  })
66
66
  })
67
+
68
+ describe('reactivity', () => {
69
+ test('changing props should update the element', async () => {
70
+ const wrapper = compileAndMount({
71
+ template: '<font-awesome-layers fixed-width />',
72
+ components: {
73
+ FontAwesomeLayers
74
+ }
75
+ })
76
+
77
+ expect(wrapper.element.getAttribute('class')).toBe('fa-layers fa-fw')
78
+
79
+ await wrapper.setProps({ fixedWidth: false })
80
+
81
+ expect(wrapper.element.getAttribute('class')).toBe('fa-layers')
82
+ })
83
+ })
@@ -75,3 +75,20 @@ describe('counter', () => {
75
75
  expect(wrapper.element.getAttribute('class')).toBe('fa-layers-counter fa-layers-bottom-right')
76
76
  })
77
77
  })
78
+
79
+ describe('reactivity', () => {
80
+ test('changing props should update the element', async () => {
81
+ const wrapper = compileAndMount({
82
+ template: '<font-awesome-layers-text :value="42" :counter="true" />',
83
+ components: {
84
+ FontAwesomeLayersText
85
+ }
86
+ })
87
+
88
+ expect(wrapper.element.innerHTML).toBe('42')
89
+
90
+ await wrapper.setProps({ value: 43 })
91
+
92
+ expect(wrapper.element.innerHTML).toBe('43')
93
+ })
94
+ })
package/src/converter.js CHANGED
@@ -59,11 +59,11 @@ function combineClassObjects (...collections) {
59
59
  }
60
60
 
61
61
  /**
62
- * Converts a FontAwesome abstract element of an icon into a Vue render function.
62
+ * Converts a FontAwesome abstract element of an icon into a Vue VNode.
63
63
  * @param {AbstractElement | String} abstractElement The element to convert.
64
64
  * @param {Object} props The user-defined props.
65
65
  * @param {Object} attrs The user-defined native HTML attributes.
66
- * @returns {Function | String}
66
+ * @returns {VNode}
67
67
  */
68
68
  export default function convert (abstractElement, props = {}, attrs = {}) {
69
69
  // If the abstract element is a string, we'll just return a string render function
@@ -71,11 +71,9 @@ export default function convert (abstractElement, props = {}, attrs = {}) {
71
71
  return abstractElement
72
72
  }
73
73
 
74
- // Converting abstract element children into Vue render functions, then we'll execute
75
- // them to retrieve VDOM elements
74
+ // Converting abstract element children into Vue VNodes
76
75
  const children = (abstractElement.children || [])
77
76
  .map(child => convert(child))
78
- .map(renderFn => typeof renderFn === 'string' ? renderFn : renderFn())
79
77
 
80
78
  // Converting abstract element attributes into valid Vue format
81
79
  const mixins = Object.keys(abstractElement.attributes || {})
@@ -103,19 +101,18 @@ export default function convert (abstractElement, props = {}, attrs = {}) {
103
101
  }
104
102
  )
105
103
 
106
- // Now, we'll return the render function of the
104
+ // Now, we'll return the VNode
107
105
  const { class: _aClass = {}, style: aStyle = {}, ...otherAttrs } = attrs
108
106
 
109
- return () =>
110
- h(
111
- abstractElement.tag,
112
- {
113
- ...props,
114
- class: mixins.class,
115
- style: { ...mixins.style, ...aStyle },
116
- ...mixins.attrs,
117
- ...otherAttrs
118
- },
119
- children
120
- )
107
+ return h(
108
+ abstractElement.tag,
109
+ {
110
+ ...props,
111
+ class: mixins.class,
112
+ style: { ...mixins.style, ...aStyle },
113
+ ...mixins.attrs,
114
+ ...otherAttrs
115
+ },
116
+ children
117
+ )
121
118
  }