25 lines
804 B
TypeScript
Raw Normal View History

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