naive-ui/packages/mixins/hollowoutable.js
songwanli2025@163.com 4f90dd3b05 merge from upstream
2019-12-17 14:36:37 +08:00

55 lines
1.7 KiB
JavaScript

// import HollowOutStyleManager from '../utils/HollowOutStyleManager'
export default {
watch: {
synthesizedTheme (value) {
if (this.avoidHollowOut) return
this.$nextTick().then(() => {
console.log('update style')
this.updateHollowOutStyle(value)
})
}
},
data () {
return {
ascendantBackgroundColor: null
}
},
methods: {
setHollowOutAffect () {
this.updateHollowOutStyle()
},
updateHollowOutStyle (theme) {
let cursor = this.$el
theme = theme || this.synthesizedTheme
while (cursor.parentElement) {
cursor = cursor.parentElement
const backgroundColorHint = cursor.getAttribute(`n-${theme}-theme-background-color-hint`)
if (backgroundColorHint === 'transparent') continue
if (backgroundColorHint) {
// console.log(cursor, backgroundColorHint, theme)
this.ascendantBackgroundColor = backgroundColorHint
break
}
const backgroundColor = getComputedStyle(cursor).backgroundColor
if (backgroundColor && backgroundColor !== 'rgba(0, 0, 0, 0)') {
// console.log(cursor, backgroundColor)
this.ascendantBackgroundColor = backgroundColor
break
}
}
// HollowOutStyleManager.registerComponent(this.hollowOutBackgroundColorId, this.ascendantBackgroundColor)
}
},
mounted () {
// this.hollowOutBackgroundColorId = 'x' + Math.random().toString(16).slice(9)
// this.$el.setAttribute('n-hollowoutable-id', this.hollowOutBackgroundColorId)
if (this.avoidHollowOut) return
this.updateHollowOutStyle()
},
beforeDestroy () {
// const id = this.hollowOutBackgroundColorId
// HollowOutStyleManager.unregisterComponent(id, 1000)
}
}