Skip to content

Commit 8b9af68

Browse files
committed
feat: add title prop, change default title text generation
1 parent bdf703e commit 8b9af68

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/CIcon.vue

+21-2
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,24 @@ export default {
2626
].includes(size)
2727
},
2828
customClasses: [String, Array, Object],
29-
src: String
29+
src: String,
30+
title: String
3031
},
3132
computed: {
3233
iconName () {
3334
const iconNameIsKebabCase = this.name && this.name.includes('-')
3435
return iconNameIsKebabCase ? this.toCamelCase(this.name) : this.name
3536
},
37+
titleString () {
38+
if (this.title) {
39+
return this.title
40+
} else if (this.iconName) {
41+
return this.generateTitle(this.iconName)
42+
}
43+
return 'icon'
44+
},
3645
titleCode () {
37-
return this.iconName ? `<title>${this.iconName}</title>` : ''
46+
return `<title>${this.titleString}</title>`
3847
},
3948
code () {
4049
if (this.content) {
@@ -65,6 +74,16 @@ export default {
6574
return str.replace(/([-_][a-z0-9])/ig, ($1) => {
6675
return $1.toUpperCase().replace('-', '')
6776
})
77+
},
78+
generateTitle (title) {
79+
return this.getValidTitle(title).replace(/([a-z0-9])([A-Z])/g, '$1 $2')
80+
},
81+
getValidTitle (title) {
82+
if (['cil', 'cib', 'cif', 'cis'].includes(title.substring(0,3))) {
83+
return title.slice(3)
84+
} else {
85+
return title.charAt(0).toUpperCase() + title.slice(1)
86+
}
6887
}
6988
}
7089
}

src/CIconRaw.vue

+21-2
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,24 @@ export default {
2626
].includes(size)
2727
},
2828
customClasses: [String, Array, Object],
29-
src: String
29+
src: String,
30+
title: String
3031
},
3132
computed: {
3233
iconName () {
3334
const iconNameIsKebabCase = this.name && this.name.includes('-')
3435
return iconNameIsKebabCase ? this.toCamelCase(this.name) : this.name
3536
},
37+
titleString () {
38+
if (this.title) {
39+
return this.title
40+
} else if (this.iconName) {
41+
return this.generateTitle(this.iconName)
42+
}
43+
return 'icon'
44+
},
3645
titleCode () {
37-
return this.iconName ? `<title>${this.iconName}</title>` : ''
46+
return `<title>${this.titleString}</title>`
3847
},
3948
code () {
4049
if (this.content) {
@@ -65,6 +74,16 @@ export default {
6574
return str.replace(/([-_][a-z0-9])/ig, ($1) => {
6675
return $1.toUpperCase().replace('-', '')
6776
})
77+
},
78+
generateTitle (title) {
79+
return this.getValidTitle(title).replace(/([a-z0-9])([A-Z])/g, '$1 $2')
80+
},
81+
getValidTitle (title) {
82+
if (['cil', 'cib', 'cif', 'cis'].includes(title.substring(0,3))) {
83+
return title.slice(3)
84+
} else {
85+
return title.charAt(0).toUpperCase() + title.slice(1)
86+
}
6887
}
6988
}
7089
}

src/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export declare class CIcon extends Vue {
66
size: string
77
customClasses: [string, Array<any>, object]
88
src: string
9+
title: string
910
}
1011

1112
export declare class CIconRaw extends CIcon {}

0 commit comments

Comments
 (0)