You need to provide className for the wrapper/container as styled-component injecting the styles through it:
const SignupForm = ({ className }) => (
<form className={className}>
<input className="input" />
<button className="button">Button</button>
</form>
);
const Form = styled(SignupForm)`
.input {
background-color: palegreen;
}
.button {
background-color: palevioletred;
}
`;
You need to provide className for the wrapper/container as styled-component injecting the styles through it:
const SignupForm = ({ className }) => (
<form className={className}>
<input className="input" />
<button className="button">Button</button>
</form>
);
const Form = styled(SignupForm)`
.input {
background-color: palegreen;
}
.button {
background-color: palevioletred;
}
`;
Just add extra atrribute className by using attrs to existing styled component.
const FormWrapper = styled.div.attrs({
className: 'SignupForm',
})`
.input {
/* Custom Styles */
}
.button {
/* Custom Styles */
}
`
styled-components vs className for css styling ?
There isn't a standard at this point from what I can tell.
I personally use styled-components and find it much easier. Big benefit being styles related to component are within the same file, so the modularity is good.
Tailwind has been picking up steam, especially good for rapid development.
More on reddit.comCan we use styled components export className ?
Append custom class names to styled component
reactjs - How to define className in styled components - Stack Overflow
I'm getting started with learning react. I was wondering if styled-components is the standard, or people use className for styling in Prod apps ?
There isn't a standard at this point from what I can tell.
I personally use styled-components and find it much easier. Big benefit being styles related to component are within the same file, so the modularity is good.
Tailwind has been picking up steam, especially good for rapid development.
classNames prop: built-in; harder to use with CSS modules and annoying to conditionally concatenate classes, requires naming classes (naming is hard).
style prop: built-in; cannot use media queries, annoying to use (inlined) inside some components, harder to use style that are derived from props.
styled-components/emotion: 3rd party; extra bundle size, CSS-in-JS add runtime processing time. However, more productive. fixes previous issues and some CSS annoyances (eg. specifity).
You can remove the className prop and add a prop isIndented={props.linkIndentHome} props.linkIndentHome is a bool that holds true or false, to represent if its indented or not.
Pass the prop to the Li component and use it there to take the decision. Something like as follow:
const Li = styled.li`
border-bottom: 1px dotted #D3D3D3;
text-indent: 3rem;
...other styles
${props => props.isIndented && `
border-bottom: 1px dotted
...whatever other styles for indentation
`}
`
if you want default className use this , in my case my project was typescript too so i had too specify types too
let Container = styled.div.attrs<LayoutProps|
SpaceProps|HTMLAttributes<any>>(props=>{
return {className: `${props.className} container`}
})`
${layout}
${flex}
${space}