Skip to content

Instantly share code, notes, and snippets.

@rich-97
Last active October 28, 2020 19:12
Show Gist options
  • Save rich-97/cbf5e9551640fbce0d5f1d8d886152e5 to your computer and use it in GitHub Desktop.
Save rich-97/cbf5e9551640fbce0d5f1d8d886152e5 to your computer and use it in GitHub Desktop.
React - Margin Component
import PropTypes from 'prop-types';
import styled from "styled-components";
const Margin = styled.div`
${props => {
const { top, right, left, bottom } = props;
return `
margin: ${top} ${right} ${left} ${bottom};
`;
}}
`;
Margin.propTypes = {
top: PropTypes.string,
right: PropTypes.string,
left: PropTypes.string,
bottom: PropTypes.string,
}
Margin.defaultProps = {
top: '0px',
right: '0px',
left: '0px',
bottom: '0px',
};
export default Margin;
import styled from "styled-components";
interface Props {
top?: string;
right?: string;
left?: string;
bottom?: string;
}
const Margin = styled.div<Props>`
${props => {
const { top, right, left, bottom } = props;
return `
margin-left: ${left};
margin-top: ${top};
margin-right: ${right};
margin-bottom: ${bottom};
`;
}}
`;
export default Margin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment