Skip to content

Commit

Permalink
feat: add title prop, change default title text generation
Browse files Browse the repository at this point in the history
  • Loading branch information
woothu committed Jan 7, 2020
1 parent bdf703e commit 8b9af68
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/CIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ export default {
].includes(size)
},
customClasses: [String, Array, Object],
src: String
src: String,
title: String
},
computed: {
iconName () {
const iconNameIsKebabCase = this.name && this.name.includes('-')
return iconNameIsKebabCase ? this.toCamelCase(this.name) : this.name
},
titleString () {
if (this.title) {
return this.title
} else if (this.iconName) {
return this.generateTitle(this.iconName)
}
return 'icon'
},
titleCode () {
return this.iconName ? `<title>${this.iconName}</title>` : ''
return `<title>${this.titleString}</title>`
},
code () {
if (this.content) {
Expand Down Expand Up @@ -65,6 +74,16 @@ export default {
return str.replace(/([-_][a-z0-9])/ig, ($1) => {
return $1.toUpperCase().replace('-', '')
})
},
generateTitle (title) {
return this.getValidTitle(title).replace(/([a-z0-9])([A-Z])/g, '$1 $2')
},
getValidTitle (title) {
if (['cil', 'cib', 'cif', 'cis'].includes(title.substring(0,3))) {
return title.slice(3)
} else {
return title.charAt(0).toUpperCase() + title.slice(1)
}
}
}
}
Expand Down
23 changes: 21 additions & 2 deletions src/CIconRaw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ export default {
].includes(size)
},
customClasses: [String, Array, Object],
src: String
src: String,
title: String
},
computed: {
iconName () {
const iconNameIsKebabCase = this.name && this.name.includes('-')
return iconNameIsKebabCase ? this.toCamelCase(this.name) : this.name
},
titleString () {
if (this.title) {
return this.title
} else if (this.iconName) {
return this.generateTitle(this.iconName)
}
return 'icon'
},
titleCode () {
return this.iconName ? `<title>${this.iconName}</title>` : ''
return `<title>${this.titleString}</title>`
},
code () {
if (this.content) {
Expand Down Expand Up @@ -65,6 +74,16 @@ export default {
return str.replace(/([-_][a-z0-9])/ig, ($1) => {
return $1.toUpperCase().replace('-', '')
})
},
generateTitle (title) {
return this.getValidTitle(title).replace(/([a-z0-9])([A-Z])/g, '$1 $2')
},
getValidTitle (title) {
if (['cil', 'cib', 'cif', 'cis'].includes(title.substring(0,3))) {
return title.slice(3)
} else {
return title.charAt(0).toUpperCase() + title.slice(1)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export declare class CIcon extends Vue {
size: string
customClasses: [string, Array<any>, object]
src: string
title: string
}

export declare class CIconRaw extends CIcon {}

0 comments on commit 8b9af68

Please sign in to comment.