mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-18 12:34:25 +08:00
refactor(mixins/textransparentable): support theme change
This commit is contained in:
parent
f23aae715d
commit
fb89fb42bf
@ -1,10 +1,46 @@
|
||||
export default {
|
||||
watch: {
|
||||
synthesizedTheme () {
|
||||
this.$nextTick().then(() => {
|
||||
document.querySelector('head').removeChild(this.cssNode)
|
||||
this.setCSSNode()
|
||||
document.querySelector('head').appendChild(this.cssNode)
|
||||
})
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
ascendantBackgroundColor: null,
|
||||
cssNode: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
setCSSNode () {
|
||||
let cursor = this.$el
|
||||
while (cursor.parentElement) {
|
||||
cursor = cursor.parentElement
|
||||
const backgroundColor = getComputedStyle(cursor).backgroundColor
|
||||
if (backgroundColor && backgroundColor !== 'rgba(0, 0, 0, 0)') {
|
||||
this.ascendantBackgroundColor = backgroundColor
|
||||
break
|
||||
}
|
||||
}
|
||||
const id = 'x' + Math.random().toString(16).slice(9)
|
||||
this.$el.setAttribute('n-background-id', id)
|
||||
this.cssNode = document.createElement('style')
|
||||
this.cssNode.innerHTML = `[n-background-id=${id}] .simulate-transparent-text {
|
||||
color: ${this.ascendantBackgroundColor}!important;
|
||||
}
|
||||
[n-background-id=${id}] .simulate-transparent-background {
|
||||
background-color: ${this.ascendantBackgroundColor}!important;
|
||||
}
|
||||
[n-background-id=${id}] .simulate-transparent-stroke circle {
|
||||
stroke: ${this.ascendantBackgroundColor}!important;
|
||||
}
|
||||
`
|
||||
this.cssNode.type = 'text/css'
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
let cursor = this.$el
|
||||
while (cursor.parentElement) {
|
||||
|
Loading…
Reference in New Issue
Block a user