mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-15 04:42:23 +08:00
refactor(holloutable): use inline css
This commit is contained in:
parent
d1d05b7c84
commit
3ef604a31a
@ -9,7 +9,8 @@
|
|||||||
>
|
>
|
||||||
<circle
|
<circle
|
||||||
:style="{
|
:style="{
|
||||||
strokeWidth
|
strokeWidth,
|
||||||
|
stroke
|
||||||
}"
|
}"
|
||||||
class="n-base-loading-circular-path"
|
class="n-base-loading-circular-path"
|
||||||
cx="50"
|
cx="50"
|
||||||
@ -32,6 +33,10 @@ export default {
|
|||||||
strokeWidth: {
|
strokeWidth: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: null
|
default: null
|
||||||
|
},
|
||||||
|
stroke: {
|
||||||
|
type: String,
|
||||||
|
default: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
|
@ -31,16 +31,14 @@
|
|||||||
>
|
>
|
||||||
<n-spin
|
<n-spin
|
||||||
v-if="loading"
|
v-if="loading"
|
||||||
:class="{
|
:stroke="simulateHollowOut ? ascendantBackgroundColor : null"
|
||||||
'simulate-hollow-out-stroke': simulateHollowOut
|
|
||||||
}"
|
|
||||||
:size="null"
|
:size="null"
|
||||||
:stroke-width="4"
|
:stroke-width="4"
|
||||||
/>
|
/>
|
||||||
<n-icon
|
<n-icon
|
||||||
v-else
|
v-else
|
||||||
:class="{
|
:style="{
|
||||||
'simulate-hollow-out-fill': simulateHollowOut
|
fill: simulateHollowOut ? ascendantBackgroundColor : null
|
||||||
}"
|
}"
|
||||||
class="n-icon-slot"
|
class="n-icon-slot"
|
||||||
>
|
>
|
||||||
@ -53,10 +51,9 @@
|
|||||||
<div
|
<div
|
||||||
v-if="!circle && $slots.default"
|
v-if="!circle && $slots.default"
|
||||||
class="n-button__content"
|
class="n-button__content"
|
||||||
:class="{
|
:style="{
|
||||||
'simulate-hollow-out-text': simulateHollowOut
|
color: simulateHollowOut ? ascendantBackgroundColor : null
|
||||||
}"
|
}"
|
||||||
:style="style"
|
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
@ -77,16 +74,14 @@
|
|||||||
>
|
>
|
||||||
<n-spin
|
<n-spin
|
||||||
v-if="loading"
|
v-if="loading"
|
||||||
:class="{
|
:stroke="simulateHollowOut ? ascendantBackgroundColor : null"
|
||||||
'simulate-hollow-out-stroke': simulateHollowOut
|
|
||||||
}"
|
|
||||||
:stroke-width="4"
|
:stroke-width="4"
|
||||||
/>
|
/>
|
||||||
<n-icon
|
<n-icon
|
||||||
v-else
|
v-else
|
||||||
class="n-icon-slot"
|
class="n-icon-slot"
|
||||||
:class="{
|
:style="{
|
||||||
'simulate-hollow-out-fill': simulateHollowOut
|
fill: simulateHollowOut ? ascendantBackgroundColor : null
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<slot
|
<slot
|
||||||
@ -172,7 +167,6 @@ export default {
|
|||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
style: {},
|
|
||||||
enterPressed: false,
|
enterPressed: false,
|
||||||
rippling: false,
|
rippling: false,
|
||||||
rippleTimer: null
|
rippleTimer: null
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
class="n-radio-button"
|
class="n-radio-button"
|
||||||
:class="{
|
:class="{
|
||||||
'n-radio-button--disabled': disabled,
|
'n-radio-button--disabled': disabled,
|
||||||
'n-radio-button--checked': checked,
|
'n-radio-button--checked': checked
|
||||||
'simulate-hollow-out-text': shouldSimulateHollowOutText
|
|
||||||
}"
|
}"
|
||||||
:tabindex="disabled ? -1 : 0"
|
:tabindex="disabled ? -1 : 0"
|
||||||
@keyup.enter="handleKeyUpEnter"
|
@keyup.enter="handleKeyUpEnter"
|
||||||
@ -42,9 +41,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
shouldSimulateHollowOutText () {
|
// shouldSimulateHollowOutText () {
|
||||||
return this.checked && (this.NRadioGroup.synthesizedTheme === 'dark')
|
// return this.checked && (this.NRadioGroup.synthesizedTheme === 'dark')
|
||||||
},
|
// },
|
||||||
checked () {
|
checked () {
|
||||||
if (this.NRadioGroup) {
|
if (this.NRadioGroup) {
|
||||||
return this.NRadioGroup.value === this.value
|
return this.NRadioGroup.value === this.value
|
||||||
|
@ -23,14 +23,17 @@
|
|||||||
<div
|
<div
|
||||||
v-for="mark in computedMarks"
|
v-for="mark in computedMarks"
|
||||||
:key="mark.label"
|
:key="mark.label"
|
||||||
class="n-slider-dot simulate-hollow-out-background"
|
class="n-slider-dot"
|
||||||
:style="mark.style"
|
:style="{
|
||||||
|
backgroundColor: ascendantBackgroundColor,
|
||||||
|
...mark.style
|
||||||
|
}"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
ref="firstHandle"
|
ref="firstHandle"
|
||||||
class="n-slider-handle simulate-hollow-out-background"
|
class="n-slider-handle"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
:style="firstHandleStyle"
|
:style="firstHandleStyle"
|
||||||
@mousedown="handleFirstHandleMouseDown"
|
@mousedown="handleFirstHandleMouseDown"
|
||||||
@ -40,7 +43,7 @@
|
|||||||
<div
|
<div
|
||||||
v-if="range"
|
v-if="range"
|
||||||
ref="secondHandle"
|
ref="secondHandle"
|
||||||
class="n-slider-handle simulate-hollow-out-background"
|
class="n-slider-handle"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
:style="secondHandleStyle"
|
:style="secondHandleStyle"
|
||||||
@mousedown="handleSecondHandleMouseDown"
|
@mousedown="handleSecondHandleMouseDown"
|
||||||
@ -221,12 +224,14 @@ export default {
|
|||||||
},
|
},
|
||||||
firstHandleStyle () {
|
firstHandleStyle () {
|
||||||
return {
|
return {
|
||||||
|
backgroundColor: this.ascendantBackgroundColor,
|
||||||
left: ((this.firstHandleValue - this.min) / (this.max - this.min) * 100) + '%',
|
left: ((this.firstHandleValue - this.min) / (this.max - this.min) * 100) + '%',
|
||||||
zIndex: this.firstHandleActive ? 1 : 0
|
zIndex: this.firstHandleActive ? 1 : 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
secondHandleStyle () {
|
secondHandleStyle () {
|
||||||
return {
|
return {
|
||||||
|
backgroundColor: this.ascendantBackgroundColor,
|
||||||
left: ((this.secondHandleValue - this.min) / (this.max - this.min) * 100) + '%',
|
left: ((this.secondHandleValue - this.min) / (this.max - this.min) * 100) + '%',
|
||||||
zIndex: this.secondHandleActive ? 1 : 0
|
zIndex: this.secondHandleActive ? 1 : 0
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,13 @@
|
|||||||
>
|
>
|
||||||
<transition name="n-spin--transition">
|
<transition name="n-spin--transition">
|
||||||
<n-base-loading
|
<n-base-loading
|
||||||
|
v-if="spinning"
|
||||||
:class="{
|
:class="{
|
||||||
[`n-spin--${size}-size`]: true
|
[`n-spin--${size}-size`]: true
|
||||||
}"
|
}"
|
||||||
|
:stroke="stroke"
|
||||||
:stroke-width="strokeWidth"
|
:stroke-width="strokeWidth"
|
||||||
:theme="synthesizedTheme"
|
:theme="synthesizedTheme"
|
||||||
v-if="spinning"
|
|
||||||
class="n-spin"
|
class="n-spin"
|
||||||
/>
|
/>
|
||||||
</transition>
|
</transition>
|
||||||
@ -24,12 +25,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<n-base-loading
|
<n-base-loading
|
||||||
|
v-else
|
||||||
:class="{
|
:class="{
|
||||||
[`n-spin--${size}-size`]: size
|
[`n-spin--${size}-size`]: size
|
||||||
}"
|
}"
|
||||||
|
:stroke="stroke"
|
||||||
:stroke-width="strokeWidth"
|
:stroke-width="strokeWidth"
|
||||||
:theme="synthesizedTheme"
|
:theme="synthesizedTheme"
|
||||||
v-else
|
|
||||||
class="n-spin"
|
class="n-spin"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
@ -46,6 +48,10 @@ export default {
|
|||||||
},
|
},
|
||||||
mixins: [withapp, themeable],
|
mixins: [withapp, themeable],
|
||||||
props: {
|
props: {
|
||||||
|
stroke: {
|
||||||
|
type: String,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
size: {
|
size: {
|
||||||
type: [String, Number],
|
type: [String, Number],
|
||||||
default: 'medium'
|
default: 'medium'
|
||||||
|
@ -13,20 +13,22 @@
|
|||||||
>
|
>
|
||||||
<n-icon
|
<n-icon
|
||||||
v-if="synthesizedStatus === 'finish'"
|
v-if="synthesizedStatus === 'finish'"
|
||||||
type="md-checkmark"
|
>
|
||||||
/>
|
<md-checkmark />
|
||||||
|
</n-icon>
|
||||||
<n-icon
|
<n-icon
|
||||||
v-else-if="synthesizedStatus === 'error'"
|
v-else-if="synthesizedStatus === 'error'"
|
||||||
type="md-close"
|
>
|
||||||
/>
|
<md-close />
|
||||||
|
</n-icon>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
<transition name="n-step-indicator--transition">
|
<transition name="n-step-indicator--transition">
|
||||||
<div
|
<div
|
||||||
v-if="!(synthesizedStatus === 'finish' || synthesizedStatus === 'error')"
|
v-if="!(synthesizedStatus === 'finish' || synthesizedStatus === 'error')"
|
||||||
class="n-step-indicator__index"
|
class="n-step-indicator__index"
|
||||||
:class="{
|
:style="{
|
||||||
'simulate-hollow-out-text': synthesizedStatus === 'process'
|
color: synthesizedStatus === 'process' ? ascendantBackgroundColor : null
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
{{ index }}
|
{{ index }}
|
||||||
@ -53,6 +55,8 @@
|
|||||||
<script>
|
<script>
|
||||||
import NIcon from '../../Icon'
|
import NIcon from '../../Icon'
|
||||||
import hollowoutable from '../../../mixins/hollowoutable'
|
import hollowoutable from '../../../mixins/hollowoutable'
|
||||||
|
import mdClose from '../../../icons/md-close'
|
||||||
|
import mdCheckmark from '../../../icons/md-checkmark'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'NStep',
|
name: 'NStep',
|
||||||
@ -62,7 +66,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
NIcon
|
NIcon,
|
||||||
|
mdCheckmark,
|
||||||
|
mdClose
|
||||||
},
|
},
|
||||||
mixins: [hollowoutable],
|
mixins: [hollowoutable],
|
||||||
props: {
|
props: {
|
||||||
|
@ -7,7 +7,12 @@
|
|||||||
>
|
>
|
||||||
<div class="n-timeline-item-timeline">
|
<div class="n-timeline-item-timeline">
|
||||||
<div class="n-timeline-item-timeline__line" />
|
<div class="n-timeline-item-timeline__line" />
|
||||||
<div class="n-timeline-item-timeline__circle simulate-hollow-out-background" />
|
<div
|
||||||
|
class="n-timeline-item-timeline__circle"
|
||||||
|
:style="{
|
||||||
|
backgroundColor: ascendantBackgroundColor
|
||||||
|
}"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="n-timeline-item-content">
|
<div class="n-timeline-item-content">
|
||||||
<div
|
<div
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import HollowOutStyleManager from '../utils/HollowOutStyleManager'
|
// import HollowOutStyleManager from '../utils/HollowOutStyleManager'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
watch: {
|
watch: {
|
||||||
@ -11,8 +11,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
ascendantBackgroundColor: null,
|
ascendantBackgroundColor: null
|
||||||
CSSNode: null
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -38,17 +37,17 @@ export default {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HollowOutStyleManager.registerComponent(this.hollowOutBackgroundColorId, this.ascendantBackgroundColor)
|
// HollowOutStyleManager.registerComponent(this.hollowOutBackgroundColorId, this.ascendantBackgroundColor)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
this.hollowOutBackgroundColorId = 'x' + Math.random().toString(16).slice(9)
|
// this.hollowOutBackgroundColorId = 'x' + Math.random().toString(16).slice(9)
|
||||||
this.$el.setAttribute('n-hollowoutable-id', this.hollowOutBackgroundColorId)
|
// this.$el.setAttribute('n-hollowoutable-id', this.hollowOutBackgroundColorId)
|
||||||
if (this.avoidHollowOut) return
|
if (this.avoidHollowOut) return
|
||||||
this.updateHollowOutStyle()
|
this.updateHollowOutStyle()
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
const id = this.hollowOutBackgroundColorId
|
// const id = this.hollowOutBackgroundColorId
|
||||||
HollowOutStyleManager.unregisterComponent(id, 1000)
|
// HollowOutStyleManager.unregisterComponent(id, 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
class HollowOutStyleManager {
|
|
||||||
constructor () {
|
|
||||||
this.idStyleMap = new Map()
|
|
||||||
this.CSSNode = document.createElement('style')
|
|
||||||
this.CSSNode.type = 'text/css'
|
|
||||||
}
|
|
||||||
styleForComponent (id, backgroundColor) {
|
|
||||||
if (!backgroundColor) return ''
|
|
||||||
return `[n-hollowoutable-id=${id}] .simulate-hollow-out-text {
|
|
||||||
color: ${backgroundColor}!important;
|
|
||||||
}
|
|
||||||
[n-hollowoutable-id=${id}] .simulate-hollow-out-background {
|
|
||||||
background-color: ${backgroundColor}!important;
|
|
||||||
}
|
|
||||||
[n-hollowoutable-id=${id}] .simulate-hollow-out-stroke circle {
|
|
||||||
stroke: ${backgroundColor}!important;
|
|
||||||
}
|
|
||||||
[n-hollowoutable-id=${id}] .simulate-hollow-out-fill path {
|
|
||||||
fill: ${backgroundColor}!important;
|
|
||||||
}
|
|
||||||
`
|
|
||||||
}
|
|
||||||
get styleLiteral () {
|
|
||||||
let style = ''
|
|
||||||
this.idStyleMap.forEach((value) => {
|
|
||||||
style += value
|
|
||||||
})
|
|
||||||
// console.log('styleLiteral', style)
|
|
||||||
return style
|
|
||||||
}
|
|
||||||
updateCSSNode () {
|
|
||||||
this.CSSNode.innerHTML = this.styleLiteral
|
|
||||||
const headEl = document.querySelector('head')
|
|
||||||
if (!headEl.contains(this.CSSNode)) {
|
|
||||||
headEl.appendChild(this.CSSNode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
registerComponent (id, backgroundColor) {
|
|
||||||
// console.log('registerComponent', id, backgroundColor)
|
|
||||||
this.idStyleMap.set(id, this.styleForComponent(id, backgroundColor))
|
|
||||||
this.updateCSSNode()
|
|
||||||
}
|
|
||||||
unregisterComponent (id, delay) {
|
|
||||||
this.idStyleMap.delete(id)
|
|
||||||
window.setTimeout(() => {
|
|
||||||
this.updateCSSNode()
|
|
||||||
}, delay)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default new HollowOutStyleManager()
|
|
@ -141,7 +141,7 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
&:hover {
|
&:hover {
|
||||||
@include e(border-mask) {
|
@include e(border-mask) {
|
||||||
box-shadow: inset 0 0 0 $--radio-border-mask-width map-get($--radio-button-border-color, 'hover');
|
box-shadow: map-get($--radio-button-box-shadow, 'hover');
|
||||||
transition: box-shadow .3s $default-cubic-bezier;
|
transition: box-shadow .3s $default-cubic-bezier;
|
||||||
}
|
}
|
||||||
@include not-m(checked) {
|
@include not-m(checked) {
|
||||||
@ -150,7 +150,7 @@
|
|||||||
}
|
}
|
||||||
&:focus:not(:active) {
|
&:focus:not(:active) {
|
||||||
@include e(border-mask) {
|
@include e(border-mask) {
|
||||||
box-shadow: inset 0 0 0 1px map-get($--radio-button-label-color, 'active'), 0 0 0 2px change-color(map-get($--radio-button-label-color, 'active'), $alpha: .3);
|
box-shadow: map-get($--radio-button-box-shadow, 'focus')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@
|
|||||||
top: 50%;
|
top: 50%;
|
||||||
right: 0;
|
right: 0;
|
||||||
@include b(slider-dot) {
|
@include b(slider-dot) {
|
||||||
transition: box-shadow .3s $default-cubic-bezier;
|
transition: box-shadow .3s $default-cubic-bezier, background-color .3s $default-cubic-bezier;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
transform: translateX(-50%) translateY(-50%);
|
transform: translateX(-50%) translateY(-50%);
|
||||||
height: $--slider-dot-size;
|
height: $--slider-dot-size;
|
||||||
|
@ -17,9 +17,12 @@
|
|||||||
@include b(step-indicator) {
|
@include b(step-indicator) {
|
||||||
background-color: map-get($--steps-step-background-color, $status);
|
background-color: map-get($--steps-step-background-color, $status);
|
||||||
box-shadow: 0 0 0 1px map-get($--steps-step-border-color, $status);
|
box-shadow: 0 0 0 1px map-get($--steps-step-border-color, $status);
|
||||||
@include e(icon, index) {
|
@include e(index) {
|
||||||
color: map-get($--steps-step-indicator-color, $status);
|
color: map-get($--steps-step-indicator-color, $status);
|
||||||
}
|
}
|
||||||
|
@include e(icon) {
|
||||||
|
fill: map-get($--steps-step-indicator-color, $status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +98,7 @@
|
|||||||
@include e(icon) {
|
@include e(icon) {
|
||||||
@include fade-in-transition-ease-in-out(step-indicator, .3s);
|
@include fade-in-transition-ease-in-out(step-indicator, .3s);
|
||||||
transition: color .3s $default-cubic-bezier;
|
transition: color .3s $default-cubic-bezier;
|
||||||
color: rgba(255,255,255,0.3);
|
fill: rgba(255,255,255,0.3);
|
||||||
width: 16px;
|
width: 16px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
@ -22,9 +22,13 @@
|
|||||||
) !global;
|
) !global;
|
||||||
$--radio-button-label-color: (
|
$--radio-button-label-color: (
|
||||||
'default': $--n-secondary-text-color,
|
'default': $--n-secondary-text-color,
|
||||||
'active': $--n-primary-color,
|
'active': black,
|
||||||
'hover': $--n-primary-color
|
'hover': $--n-primary-color
|
||||||
) !global;
|
) !global;
|
||||||
$--radio-disabled-opacity: .4 !global;
|
$--radio-disabled-opacity: .4 !global;
|
||||||
$--radio-border-mask-width: 1px !global;
|
$--radio-border-mask-width: 1px !global;
|
||||||
|
$--radio-button-box-shadow: (
|
||||||
|
'focus': (inset 0 0 0 1px $--n-primary-color, 0 0 0 2px change-color($--n-primary-color, $alpha: .3)),
|
||||||
|
'hover': inset 0 0 0 $--radio-border-mask-width $--n-primary-color
|
||||||
|
) !global;
|
||||||
}
|
}
|
@ -27,4 +27,8 @@
|
|||||||
) !global;
|
) !global;
|
||||||
$--radio-disabled-opacity: .4 !global;
|
$--radio-disabled-opacity: .4 !global;
|
||||||
$--radio-border-mask-width: 0px !global;
|
$--radio-border-mask-width: 0px !global;
|
||||||
|
$--radio-button-box-shadow: (
|
||||||
|
'focus': (inset 0 0 0 1px $--n-primary-color, 0 0 0 2px change-color($--n-primary-color, $alpha: .3)),
|
||||||
|
'hover': inset 0 0 0 $--radio-border-mask-width $--n-primary-color
|
||||||
|
) !global;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user