Skip to content

Instantly share code, notes, and snippets.

@juunegreiros
Last active August 2, 2022 21:10
Show Gist options
  • Save juunegreiros/0ff8f3b1d2aba19062f2cfd7eda606a7 to your computer and use it in GitHub Desktop.
Save juunegreiros/0ff8f3b1d2aba19062f2cfd7eda606a7 to your computer and use it in GitHub Desktop.
Styled component example
import './Button.scss';
import { ButtonRed2 } from './Button.styles'
export type ButtonTypes = {
variant?: string;
children: React.ReactNode;
onClick: React.MouseEventHandler;
type?: 'button' | 'submit';
};
const defaultProps = {
variant: '',
type: 'button',
};
const Button: React.FC<ButtonTypes> = ({ onClick, variant, children, type }) => {
const classVariant = variant ? `button button--${variant}` : 'button';
return (
<ButtonRed2 onClick={onClick} className={classVariant} type={type} variant={variant}>
{children}
</ButtonRed2>
);
}
Button.defaultProps = defaultProps;
export default Button;
export const Title = styled.h1`
color: red;
margin: 1px;
`
const TitleVariant = styled.h1<{ banana: string }>`
color: ${({ banana }) => banana};
margin: 0;
line-height: 1.15;
font-size: 4rem;
text-align: center;
text-decoration: none;
`;
export const ButtonRed = styled.button<{variant?: string}>(({ variant }) => `
color: ${variant || 'red'};
`)
export const ButtonRed2 = styled(ButtonRed)`
background-color: purple;
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment