vue3-yuanma/packages/runtime-dom/src/modules/class.ts

22 lines
625 B
TypeScript
Raw Normal View History

import { ElementWithTransition } from '../components/CSSTransition'
2019-10-05 14:35:19 +00:00
// compiler should normalize class + :class bindings on the same element
2018-09-19 15:35:38 +00:00
// into a single binding ['staticClass', dynamic]
export function patchClass(
el: ElementWithTransition,
value: string,
isSVG: boolean
) {
// if this is an element during a transition, take the temporary transition
// classes into account.
if (el._vtc) {
value = [value, ...el._vtc].join(' ')
}
2018-09-19 15:35:38 +00:00
// directly setting className should be faster than setAttribute in theory
if (isSVG) {
2018-09-24 23:11:14 +00:00
el.setAttribute('class', value)
2018-09-19 15:35:38 +00:00
} else {
2018-09-24 23:11:14 +00:00
el.className = value
2018-09-19 15:35:38 +00:00
}
}