|
1 | | -<template> |
2 | | - <svg |
3 | | - v-if="!src" |
4 | | - xmlns="http://www.w3.org/2000/svg" |
5 | | - :viewBox="viewBox" |
6 | | - :class="computedClasses" |
7 | | - v-html="titleCode + iconCode" |
8 | | - role="img" |
9 | | - ></svg> |
10 | | - <img |
11 | | - v-else |
12 | | - :src="src" |
13 | | - role="img" |
14 | | - /> |
15 | | -</template> |
16 | | - |
17 | 1 | <script> |
| 2 | +import CIconRaw from './CIconRaw' |
18 | 3 | export default { |
19 | 4 | name: 'CIcon', |
20 | | - props: { |
21 | | - name: String, |
22 | | - content: [String, Array], |
23 | | - size: { |
24 | | - type: String, |
25 | | - validator: size => [ |
26 | | - 'custom-size', 'sm', 'lg', 'xl', |
27 | | - '2xl', '3xl', '4xl', '5xl', '6xl', '7xl', '8xl', '9xl' |
28 | | - ].includes(size) |
29 | | - }, |
30 | | - customClasses: [String, Array, Object], |
31 | | - src: String, |
32 | | - title: String |
33 | | - }, |
34 | | - computed: { |
35 | | - iconName () { |
36 | | - const iconNameIsKebabCase = this.name && this.name.includes('-') |
37 | | - return iconNameIsKebabCase ? this.toCamelCase(this.name) : this.name |
38 | | - }, |
39 | | - titleCode () { |
40 | | - return this.title ? `<title>${this.title}</title>` : '' |
41 | | - }, |
42 | | - code () { |
43 | | - if (this.content) { |
44 | | - return this.content |
45 | | - } else if (this.$root.$options.icons) { |
46 | | - return this.$root.$options.icons[this.iconName] |
47 | | - } |
48 | | - }, |
49 | | - iconCode () { |
50 | | - return Array.isArray(this.code) ? this.code[1] || this.code[0] : this.code |
51 | | - }, |
52 | | - scale () { |
53 | | - return Array.isArray(this.code) && this.code.length > 1 ? this.code[0] : '64 64' |
54 | | - }, |
55 | | - viewBox () { |
56 | | - return this.$attrs.viewBox || `0 0 ${this.scale}` |
57 | | - }, |
58 | | - computedSize () { |
59 | | - return this.$attrs.width || this.$attrs.height ? 'custom-size' : this.size |
60 | | - }, |
61 | | - computedClasses () { |
62 | | - return this.customClasses || |
63 | | - ['c-icon', { [`c-icon-${this.computedSize}`]: this.computedSize }] |
64 | | - } |
65 | | - }, |
66 | | - methods: { |
67 | | - toCamelCase (str) { |
68 | | - return str.replace(/([-_][a-z0-9])/ig, ($1) => { |
69 | | - return $1.toUpperCase().replace('-', '') |
70 | | - }) |
71 | | - } |
72 | | - } |
| 5 | + extends: CIconRaw |
73 | 6 | } |
74 | 7 | </script> |
75 | 8 |
|
|
0 commit comments