removing inline styles and passing styles down to styled-component via props

This commit is contained in:
Alex Windett 2017-02-09 13:56:29 +00:00
parent 7b54efb036
commit f7b9ea20d0
13 changed files with 48 additions and 58 deletions

View File

@ -37,6 +37,8 @@ const Avatar = styled.div`
overflow: hidden; overflow: hidden;
position: relative; position: relative;
text-align: center; text-align: center;
${props => props.styles}
`; `;
module.exports = ({ module.exports = ({
@ -77,7 +79,7 @@ module.exports = ({
); );
return ( return (
<Avatar className={className} style={_style}> <Avatar className={className} styles={_style}>
{av} {av}
</Avatar> </Avatar>
); );

View File

@ -26,6 +26,8 @@ const StyledInput = styled.input`
&:disabled + label::after { &:disabled + label::after {
opacity: 0.3; opacity: 0.3;
} }
${props => props.styles}
`; `;
const StyledLabel = styled.label` const StyledLabel = styled.label`
@ -92,7 +94,7 @@ const Checkbox = ({
onChange={onChange} onChange={onChange}
readOnly={readOnly} readOnly={readOnly}
required={required} required={required}
style={style} styles={style}
tabIndex={tabIndex} tabIndex={tabIndex}
type='checkbox' type='checkbox'
/> />

View File

@ -18,19 +18,17 @@ const StyledButton = styled.button`
top: ${remcalc(16)}; top: ${remcalc(16)};
right: ${remcalc(16)}; right: ${remcalc(16)};
${props => props.customStyles ? props.customStyles : null} ${props => props.styles}
`; `;
const Close = ({ const Close = ({
style, style,
onClick, onClick,
customStyles = ''
}) => { }) => {
return ( return (
<StyledButton <StyledButton
customStyles={customStyles}
onClick={onClick} onClick={onClick}
style={style} styles={style}
> >
<img <img
alt="Close" alt="Close"
@ -41,7 +39,6 @@ const Close = ({
}; };
Close.propTypes = { Close.propTypes = {
customStyles: React.PropTypes.string,
onClick: React.PropTypes.func, onClick: React.PropTypes.func,
style: React.PropTypes.object style: React.PropTypes.object
}; };

View File

@ -2,12 +2,21 @@
const React = require('react'); const React = require('react');
const ReactRouter = require('react-router-dom'); const ReactRouter = require('react-router-dom');
const Styled = require('styled-components');
const {
default: styled
} = Styled;
const { const {
Link, Link,
Route Route
} = ReactRouter; } = ReactRouter;
const StyledLink = styled(Link)`
${props => props.styles}
`;
const NavLink = ({ const NavLink = ({
activeClassName, activeClassName,
activeStyle, activeStyle,
@ -39,7 +48,7 @@ const NavLink = ({
: className; : className;
return ( return (
<Link <StyledLink
className={clssnm} className={clssnm}
// eslint-disable-next-line object-curly-newline // eslint-disable-next-line object-curly-newline
style={isActive ? { ...style, ...activeStyle } : style} style={isActive ? { ...style, ...activeStyle } : style}
@ -47,7 +56,7 @@ const NavLink = ({
{...rest} {...rest}
> >
{newChildren} {newChildren}
</Link> </StyledLink>
); );
}; };

View File

@ -31,6 +31,7 @@ const StyledNotification = styled.div`
width: 100%; width: 100%;
${baseBox(0)} ${baseBox(0)}
${props => props.styles}
&::before { &::before {
background-color: ${props => colors[props.type] || colors.brandPrimary} background-color: ${props => colors[props.type] || colors.brandPrimary}
@ -60,7 +61,7 @@ const Notificaton = ({
return ( return (
<StyledNotification <StyledNotification
className={className} className={className}
style={style} styles={style}
type={type} type={type}
> >
{ renderClose } { renderClose }

View File

@ -1,19 +1,15 @@
const React = require('react'); const React = require('react');
// const composers = require('../../shared/composers');
const fns = require('../../shared/functions'); const fns = require('../../shared/functions');
const Styled = require('styled-components'); const Styled = require('styled-components');
const constants = require('../../shared/constants'); const constants = require('../../shared/constants');
// const {
// verticallyAlignCenter
// } = composers;
const { const {
remcalc remcalc
} = fns; } = fns;
const { const {
boxes boxes,
colors
} = constants; } = constants;
const { const {
@ -21,7 +17,7 @@ const {
} = Styled; } = Styled;
const RadioItem = styled.div` const RadioItem = styled.div`
background: #FFFFFF; background: ${colors.base.white};
border: ${boxes.border.unchecked}; border: ${boxes.border.unchecked};
cursor: pointer; cursor: pointer;
flaot: left; flaot: left;

View File

@ -1,33 +0,0 @@
~boxes: "../../shared/constants.js";
~colors: "../../shared/constants.js";
:root {
--border-checked: ~boxes.border.checked;
--border-unchecked: ~boxes.border.unchecked;
--border-radius: remcalc(~boxes.borderRadius);
--bottom-shaddow: ~boxes.bottomShaddow;
}
.group {
& .item {
background: #FFFFFF;
cursor: pointer;
margin-bottom: remcalc(15);
padding: remcalc(25);
@add-mixin create-base-box-properties;
&:last-child {
margin-bottom: initial;
}
&.checked {
border: var(--border-checked);
box-shadow: var(--bottom-shaddow);
}
&.disabled {
cursor: default;
}
}
}

View File

@ -32,6 +32,8 @@ const StyledInput = styled.input`
`; `;
const StyledLabel = styled.label` const StyledLabel = styled.label`
${props => props.styles}
`; `;
const StyledContent = styled.div` const StyledContent = styled.div`
@ -82,7 +84,7 @@ const Radio = ({
}) => { }) => {
return ( return (
<StyledLabel> <StyledLabel styles={style}>
<StyledInput <StyledInput
checked={checked} checked={checked}
defaultChecked={defaultChecked} defaultChecked={defaultChecked}

View File

@ -127,6 +127,8 @@ const StyledRange = styled.input`
&:focus::-ms-fill-upper { &:focus::-ms-fill-upper {
${rangeUpper} ${rangeUpper}
} }
${props => props.styles}
`; `;
const RangeSlider = ({ const RangeSlider = ({
@ -138,7 +140,7 @@ const RangeSlider = ({
<StyledRange <StyledRange
className={className} className={className}
onChange={onChange} onChange={onChange}
style={style} styles={style}
type='range' type='range'
/> />
); );

View File

@ -14,18 +14,21 @@ const StyledTitle = styled.h3`
const StyledTableWrapper = styled.section` const StyledTableWrapper = styled.section`
font-family: 'LibreFranklin', sans-serif; font-family: 'LibreFranklin', sans-serif;
font-style: normal; font-style: normal;
${props => props.styles}
`; `;
const Table = ({ const Table = ({
children, children,
columns = [], columns = [],
data = [], data = [],
style,
title, title,
}) => { }) => {
return ( return (
<StyledTableWrapper> <StyledTableWrapper styles={style}>
<StyledTitle>{title}</StyledTitle> <StyledTitle>{title}</StyledTitle>
<TableContent <TableContent
@ -40,6 +43,7 @@ Table.propTypes = {
children: React.PropTypes.node, children: React.PropTypes.node,
columns: React.PropTypes.array, columns: React.PropTypes.array,
data: React.PropTypes.array, data: React.PropTypes.array,
style: React.PropTypes.object,
title: React.PropTypes.string, title: React.PropTypes.string,
}; };

View File

@ -15,19 +15,23 @@ const StyledTableWrapper = styled.section`
border: solid 1px ${colors.base.greyDark} border: solid 1px ${colors.base.greyDark}
font-family: 'LibreFranklin', sans-serif; font-family: 'LibreFranklin', sans-serif;
font-style: normal; font-style: normal;
${props => props.styles}
`; `;
const Table = ({ const Table = ({
children, children,
style,
title, title,
}) => ( }) => (
<StyledTableWrapper> <StyledTableWrapper styles={style}>
{children} {children}
</StyledTableWrapper> </StyledTableWrapper>
); );
Table.propTypes = { Table.propTypes = {
children: React.PropTypes.node, children: React.PropTypes.node,
style: React.PropTypes.object,
title: React.PropTypes.string, title: React.PropTypes.string,
}; };

View File

@ -22,6 +22,10 @@ const {
default: styled default: styled
} = Styled; } = Styled;
const StyledDiv = styled.div`
${props => props.styles}
`;
const Label = styled.label` const Label = styled.label`
color: ${props => props.error ? colors.alert : colors.fonts.regular} color: ${props => props.error ? colors.alert : colors.fonts.regular}
`; `;
@ -81,7 +85,7 @@ const Textarea = ({
const _error = error ? (<Error>{error}</Error>) : null; const _error = error ? (<Error>{error}</Error>) : null;
return ( return (
<div> <StyledDiv styles={style}>
<Label <Label
error={error} error={error}
htmlFor={id} htmlFor={id}
@ -112,7 +116,7 @@ const Textarea = ({
value={value} value={value}
/> />
{_children} {_children}
</div> </StyledDiv>
); );
}; };

View File

@ -39,7 +39,7 @@ const StyledList = styled.ul`
padding: ${remcalc(ulPadder)}; padding: ${remcalc(ulPadder)};
min-width: ${remcalc(200)}; min-width: ${remcalc(200)};
${props => props.style} ${props => props.styles}
${baseBox()} ${baseBox()}
@ -86,7 +86,7 @@ module.exports = ({
<StyledList <StyledList
arrowPosition={arrowPosition} arrowPosition={arrowPosition}
className={className} className={className}
style={style} styles={style}
> >
{children} {children}
</StyledList> </StyledList>