Skip to content

Instantly share code, notes, and snippets.

@jasonmerino
Created October 7, 2019 15:44
Show Gist options
  • Save jasonmerino/8e92121c7867c2f926dd0d239dae6127 to your computer and use it in GitHub Desktop.
Save jasonmerino/8e92121c7867c2f926dd0d239dae6127 to your computer and use it in GitHub Desktop.
import React, { FC } from 'react';
import { ViewStyle, View } from 'react-native';
interface IProps {
top?: number;
right?: number;
bottom?: number;
left?: number;
horizontal?: number;
vertical?: number;
all?: number;
}
export const Padding: FC<IProps> = ({
children,
top,
right,
bottom,
left,
horizontal,
vertical,
all,
}) => {
const style: ViewStyle = {};
if (all !== undefined) {
style.padding = all;
}
if (vertical !== undefined) {
style.paddingVertical = vertical;
}
if (horizontal !== undefined) {
style.paddingHorizontal = horizontal;
}
if (top !== undefined) {
style.paddingTop = top;
}
if (right !== undefined) {
style.paddingRight = right;
}
if (bottom !== undefined) {
style.paddingBottom = bottom;
}
if (left !== undefined) {
style.paddingLeft = left;
}
return <View style={style}>{children}</View>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment