Skip to content

Commit

Permalink
Grab previous className from the node.sel if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Klingler committed Jun 11, 2018
1 parent f83f3d9 commit 7b06852
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ import { style } from 'typestyle';

import { StyledVNodeData } from './types';

export const makeClassName = (oldClassName: string, newClassName: string): string => {
const makeClassName = (oldClassName: string, newClassName: string): string => {
return `${oldClassName} ${newClassName}`.trim();
};

export const updateVNode = (node: VNode, attributeAccessor: (attribute: string, className: string) => void): void => {
const data: StyledVNodeData = node.data as StyledVNodeData;

if (data.css) {
data.props = data.props || {};
attributeAccessor('class', makeClassName(data.props.className || '', style(data.css)));
let previousClassName;

if (data.props && data.props.className) {
previousClassName = data.props.className;
} else if (node.sel) {
const dotIdx = node.sel.indexOf('.');
if (dotIdx >= 0) {
previousClassName = node.sel.slice(dotIdx + 1);
}
}

attributeAccessor('class', makeClassName(previousClassName || '', style(data.css)));
}
};

Expand Down

0 comments on commit 7b06852

Please sign in to comment.