botframework-webchat-component
Version:
React component of botframework-webchat
25 lines (20 loc) • 732 B
JavaScript
export default function mirrorStyle(mirrorSelector, styles) {
const mirrored = {};
for (const [key, value] of Object.entries(styles)) {
if (typeof value === 'number' || typeof value === 'string') {
const patchedKey = key.replace(/(^left|^right|Left|Right)/u, match =>
match === 'Left' ? 'Right' : match === 'left' ? 'right' : match === 'Right' ? 'Left' : 'left'
);
mirrored[patchedKey] = value;
} else {
mirrored[key] = mirrorStyle('', value);
}
}
const relative = /^&\s*/gu.exec(mirrorSelector) || '';
return mirrorSelector
? {
[`${relative}:not(${mirrorSelector.substr(relative.length)})`]: styles,
[mirrorSelector]: mirrored
}
: mirrored;
}