-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathFontAwesomeIcon.js
163 lines (150 loc) · 3.64 KB
/
FontAwesomeIcon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { parse as faParse, icon as faIcon } from '@fortawesome/fontawesome-svg-core'
import convert from '../converter'
import log from '../logger'
import { objectWithKey, classList } from '../utils'
function normalizeIconArgs (icon) {
// this has everything that it needs to be rendered which means it was probably imported
// directly from an icon svg package
if (icon && typeof icon === 'object' && icon.prefix && icon.iconName && icon.icon) {
return icon
}
if (faParse.icon) {
return faParse.icon(icon)
}
if (icon === null) {
return null
}
if (typeof icon === 'object' && icon.prefix && icon.iconName) {
return icon
}
if (Array.isArray(icon) && icon.length === 2) {
return { prefix: icon[0], iconName: icon[1] }
}
if (typeof icon === 'string') {
return { prefix: 'fas', iconName: icon }
}
}
export default {
name: 'FontAwesomeIcon',
functional: true,
props: {
beat: {
type: Boolean,
default: false
},
border: {
type: Boolean,
default: false
},
fade: {
type: Boolean,
default: false
},
fixedWidth: {
type: Boolean,
default: false
},
flash: {
type: Boolean,
default: false
},
flip: {
type: [Boolean, String],
default: false,
validator: (value) => [true, false, 'horizontal', 'vertical', 'both'].indexOf(value) > -1
},
icon: {
type: [Object, Array, String],
required: true
},
mask: {
type: [Object, Array, String],
default: null
},
listItem: {
type: Boolean,
default: false
},
pull: {
type: String,
default: null,
validator: (value) => ['right', 'left'].indexOf(value) > -1
},
pulse: {
type: Boolean,
default: false
},
rotation: {
type: [String, Number],
default: null,
validator: (value) => [90, 180, 270].indexOf(parseInt(value, 10)) > -1
},
swapOpacity: {
type: Boolean,
default: false
},
size: {
type: String,
default: null,
validator: (value) => ['2xs', 'xs', 'sm', 'lg', 'xl', '2xl', '1x', '2x', '3x', '4x', '5x', '6x', '7x', '8x', '9x', '10x'].indexOf(value) > -1
},
spin: {
type: Boolean,
default: false
},
spinPulse: {
type: Boolean,
default: false
},
spinReverse: {
type: Boolean,
default: false
},
transform: {
type: [String, Object],
default: null
},
symbol: {
type: [Boolean, String],
default: false
},
title: {
type: String,
default: null
},
inverse: {
type: Boolean,
default: false
},
bounce: {
type: Boolean,
default: false
},
shake: {
type: Boolean,
default: false
},
beatFade: {
type: Boolean,
default: false
}
},
render (createElement, context) {
const { props } = context
const { icon: iconArgs, mask: maskArgs, symbol, title } = props
const icon = normalizeIconArgs(iconArgs)
const classes = objectWithKey('classes', classList(props))
const transform = objectWithKey('transform', (typeof props.transform === 'string') ? faParse.transform(props.transform) : props.transform)
const mask = objectWithKey('mask', normalizeIconArgs(maskArgs))
const renderedIcon = faIcon(
icon,
{ ...classes, ...transform, ...mask, symbol, title }
)
if (!renderedIcon) {
return log('Could not find one or more icon(s)', icon, mask)
}
const { abstract } = renderedIcon
const convertCurry = convert.bind(null, createElement)
return convertCurry(abstract[0], {}, context.data)
}
}