Skip to content

Commit

Permalink
Optimize the style wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Oct 8, 2020
1 parent 48ceafb commit a113ac7
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/StyleWrapper/StyleWrapperView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'react';
import cx from 'classnames';
import { settings } from '~/config';

export function getStyles(data) {
export function getInlineStyles(data) {
return {
backgroundColor: data.backgroundColor,
color: data.textColor,
textAlign: data.textAlign,
fontSize: data.fontSize,
...(data.backgroundColor ? { backgroundColor: data.backgroundColor } : {}),
...(data.textColor ? { color: data.textColor } : {}),
...(data.textAlign ? { textAlign: data.textAlign } : {}),
...(data.fontSize ? { fontSize: data.fontSize } : {}),
// fill in more
};
}
Expand All @@ -21,23 +21,35 @@ export default (props) => {
const { data = {}, children } = props;
const { style_name, align, size } = data;
const style = getStyle(style_name);
const inlineStyles = getInlineStyles(data);
const ViewComponentWrapper = style?.viewComponent;

return (
<div
className={cx('block align', style?.cssClass, align)}
style={getStyles(data)}
>
<div
className={cx({
'full-width': align === 'full',
large: size === 'l',
medium: size === 'm',
small: size === 's',
})}
>
{ViewComponentWrapper ? <ViewComponentWrapper {...props} /> : children}
</div>
return Object.keys(inlineStyles).length > 0 || style || align || size ? (
<div className={cx(style?.cssClass, { align }, align)} style={inlineStyles}>
{size ? (
<div
className={cx({
'full-width': align === 'full',
large: size === 'l',
medium: size === 'm',
small: size === 's',
})}
>
{ViewComponentWrapper ? (
<ViewComponentWrapper {...props} />
) : (
children
)}
</div>
) : ViewComponentWrapper ? (
<ViewComponentWrapper {...props} />
) : (
children
)}
</div>
) : ViewComponentWrapper ? (
<ViewComponentWrapper {...props} />
) : (
children
);
};

0 comments on commit a113ac7

Please sign in to comment.