in packages/synchro-charts-react/src/react-component-lib/utils/attachEventProps.ts [24:44]
export function getClassName(classList: DOMTokenList, newProps: any, oldProps: any) {
// map the classes to Maps for performance
const currentClasses = arrayToMap(classList);
const incomingPropClasses = arrayToMap(newProps.className ? newProps.className.split(' ') : []);
const oldPropClasses = arrayToMap(oldProps.className ? oldProps.className.split(' ') : []);
const finalClassNames: string[] = [];
// loop through each of the current classes on the component
// to see if it should be a part of the classNames added
currentClasses.forEach(currentClass => {
if (incomingPropClasses.has(currentClass)) {
// add it as its already included in classnames coming in from newProps
finalClassNames.push(currentClass);
incomingPropClasses.delete(currentClass);
} else if (!oldPropClasses.has(currentClass)) {
// add it as it has NOT been removed by user
finalClassNames.push(currentClass);
}
});
incomingPropClasses.forEach(s => finalClassNames.push(s));
return finalClassNames.join(' ');
}