36
loading...
This website collects cookies to deliver better user experience
const Button = styled.a`
/* This renders the buttons above... Edit me! */
display: inline-block;
border-radius: 3px;
padding: 0.5rem 0;
margin: 0.5rem 1rem;
width: 11rem;
background: transparent;
color: white;
border: 2px solid white;
`
// Writing this will give you a separate button component of the CSS properties
//mentioned above
<Button>Big Button</Button>
// npm
npm I styled-components
yarn add styled-components
import styled from "styled-components";
// Styled component named StyledButton
const OrangeButton = styled.button`
background-color: orange;
font-size: 1.5rem;
color: white;
border-radius: 5px;
`;
// nothing special here, works just like a normal react component.
const SomeReactComponents = () => return <OrangeButton> Login </OrangeButton>;
import styled from "styled-components";
const DynamicButton = styled.button`
font-size: 1.5rem;
color: white;
border-radius: 5px;
//props
background-color: ${props => props.bg === "red" ? "red" : "green";
`;
function SomeReactComponent() {
return (
<div>
<DynamicButton bg="Red">Red button</DynamicButton>
<DynamicButton bg="Green">Green button</DynamicButton>
</div>
)
}