I'd like to make reusable styled components where each component has its default attributes but for specific things, like size, I'd like to specify with each use of the component.
For example, I have this InputField Component:
import React from "react";
import styled from "styled-components";
const InputFieldContainer = styled.input`
background: #252c37;
border-radius: 15px;
border: 0px;
width: 80%; /// THESE TWO I HAVE
height: 75px; // HARDCODED THE SIZE
font-size: 30px;
color: white;
padding-left: 15px;
margin-bottom: 30px;
&::placeholder {
color: white;
}
`;
function InputField(props) {
return (
<div>
<InputFieldContainer
type={props.type}
value={props.value}
name={props.name}
placeholder={props.placeholder}
onChange={props.onChange}
/>
</div>
);
}
export default InputField;
However, every time I use this component, I want to be able to change some values (like width and height) with each use. In other words, I do not want to hard code some CSS values, just gain the ability to be able to specify them once they are used.
For example:
<InputField
type="password"
value={null}
placeholder="password"
label="password"
name="password"
onChange={null}
width = "100px". // I know this isn't possible, but used as example
></InputField>
I know there may be ways around this using CSS by using it's priority list (inline CSS etc.) but surely there's a more robust/cleaner way?