codogo-react-widgets
Version:
Provides a unified way to access the styling of commonly used widgets across different apps
51 lines (43 loc) • 1.6 kB
JavaScript
import _extends from "babel-runtime/helpers/extends";
import _taggedTemplateLiteral from "babel-runtime/helpers/taggedTemplateLiteral";
var _templateObject = _taggedTemplateLiteral(["\n\theight: ", ";\n\twidth: ", ";\n"], ["\n\theight: ", ";\n\twidth: ", ";\n"]),
_templateObject2 = _taggedTemplateLiteral(["\n\twidth: 100%;\n\theight: 100%;\n\tbackground-color: ", ";\n"], ["\n\twidth: 100%;\n\theight: 100%;\n\tbackground-color: ", ";\n"]);
import styled, { withTheme } from "styled-components";
import * as R from "ramda";
import feather from "feather-icons";
var IconWrapper = styled.div(_templateObject, R.propOr("1em", "size"), R.propOr("1em", "size"));
var NoIcon = styled.div(_templateObject2, R.prop("stroke"));
var Icon = function Icon(props) {
var stroke = R.path(["theme", "colors", props.stroke], props) || props.stroke || "currentColor";
if (props.iconKey) {
var dsih = {
__html: feather.icons[props.iconKey].toSvg(Object.assign({
width: "100%",
height: "100%",
stroke: stroke
}, props.strokeWidth ? {
strokeWidth: props.strokeWidth
} : {}))
};
return React.createElement(IconWrapper, _extends({}, props, { dangerouslySetInnerHTML: dsih }));
}
if (props.icon) {
return React.createElement(
IconWrapper,
props,
React.createElement(props.icon, _extends({
width: "100%",
height: "100%",
stroke: stroke,
color: stroke
}, R.pick(["strokeWidth"])(props)))
);
} else {
return React.createElement(
IconWrapper,
props,
React.createElement(NoIcon, { stroke: stroke })
);
}
};
export default withTheme(Icon);