Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: changes the way of passing color to colorable mixin #2953

Merged
merged 1 commit into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/VAlert/VAlert.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export default {

computed: {
classes () {
const colorProp = (this.type && !this.color) ? 'type' : 'computedColor'
const color = (this.type && !this.color) ? this.type : this.computedColor
const classes = {
'alert--dismissible': this.dismissible,
'alert--outline': this.outline
}

return this.outline ? this.addTextColorClassChecks(classes, colorProp)
: this.addBackgroundColorClassChecks(classes, colorProp)
return this.outline ? this.addTextColorClassChecks(classes, color)
: this.addBackgroundColorClassChecks(classes, color)
},
computedIcon () {
if (this.icon || !this.type) return this.icon
Expand Down
2 changes: 1 addition & 1 deletion src/components/VAvatar/VAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default {
const size = `${parseInt(props.size)}px`
data.style.height = size
data.style.width = size
data.class = Colorable.methods.addBackgroundColorClassChecks.call(props, {}, 'color')
data.class = Colorable.methods.addBackgroundColorClassChecks.call(props, {}, props.color)

return h('div', data, children)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/VChip/VChip.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
})

return (this.textColor || this.outline)
? this.addTextColorClassChecks(classes, this.textColor ? 'textColor' : 'color')
? this.addTextColorClassChecks(classes, this.textColor || this.color)
: classes
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/VIcon/VIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default {
'icon--right': props.right,
'theme--dark': props.dark,
'theme--light': props.light
}, props.color ? Colorable.methods.addTextColorClassChecks.call(props, {}, 'color') : {})
}, props.color ? Colorable.methods.addTextColorClassChecks.call(props, {}, props.color) : {})

// Order classes
// * Component class
Expand Down
2 changes: 1 addition & 1 deletion src/components/VPicker/VPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default {
staticClass: 'picker__title',
'class': this.addBackgroundColorClassChecks({
'picker__title--landscape': this.landscape
}, 'computedTitleColor')
}, this.computedTitleColor)
}, this.$slots.title)
},
genBodyTransition () {
Expand Down
6 changes: 3 additions & 3 deletions src/components/VSlider/VSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default {
}, [
h('div', {
staticClass: 'slider__thumb--label',
'class': this.addBackgroundColorClassChecks({}, 'computedThumbColor')
'class': this.addBackgroundColorClassChecks({}, this.computedThumbColor)
}, [
h('span', {}, this.inputValue)
])
Expand All @@ -263,7 +263,7 @@ export default {
const children = []
children.push(h('div', {
staticClass: 'slider__thumb',
'class': this.addBackgroundColorClassChecks({}, 'computedThumbColor')
'class': this.addBackgroundColorClassChecks({}, this.computedThumbColor)
}))

this.thumbLabel && children.push(this.genThumbLabel(h))
Expand Down Expand Up @@ -303,7 +303,7 @@ export default {
const children = [
h('div', {
staticClass: 'slider__track',
'class': this.addBackgroundColorClassChecks({}, 'computedTrackColor'),
'class': this.addBackgroundColorClassChecks({}, this.computedTrackColor),
style: this.trackStyles
}),
h('div', {
Expand Down
2 changes: 1 addition & 1 deletion src/components/VTimePicker/VTimePickerClock.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default {
}

children.push(this.$createElement('span', {
'class': this.addBackgroundColorClassChecks(classes, value === this.value ? 'computedColor' : null),
'class': this.addBackgroundColorClassChecks(classes, value === this.value ? this.computedColor : null),
style: this.getTransform(value),
domProps: { innerHTML: `<span>${pad(value, this.pad)}</span>` }
}))
Expand Down
20 changes: 8 additions & 12 deletions src/mixins/colorable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,22 @@ export default {
},

methods: {
addBackgroundColorClassChecks (obj = {}, prop = 'computedColor') {
addBackgroundColorClassChecks (obj = {}, color = this.computedColor) {
const classes = Object.assign({}, obj)

if (prop && this[prop]) {
classes[this[prop]] = true
if (color) {
classes[color] = true
}

return classes
},
addTextColorClassChecks (obj = {}, prop = 'computedColor') {
addTextColorClassChecks (obj = {}, color = this.computedColor) {
const classes = Object.assign({}, obj)

if (prop && this[prop]) {
const parts = this[prop].trim().split(' ')

let color = parts[0] + '--text'

if (parts.length > 1) color += ' text--' + parts[1]

classes[color] = !!this[prop]
if (color) {
const [colorName, colorModifier] = color.trim().split(' ')
classes[colorName + '--text'] = true
colorModifier && (classes['text--' + colorModifier] = true)
}

return classes
Expand Down