-
Notifications
You must be signed in to change notification settings - Fork 2
/
Spacer.tsx
57 lines (50 loc) · 1.21 KB
/
Spacer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React from "react";
import { View } from "react-native";
import { hexToRgba, IOColors, IOSpacer } from "../../core";
type BaseSpacerProps = {
orientation: "vertical" | "horizontal";
size: IOSpacer;
};
type SpacerProps = {
size?: IOSpacer;
};
const DEFAULT_SIZE: IOSpacer = 16;
/* Debug Mode */
const debugMode = false;
const debugBg = hexToRgba(IOColors.red, 0.2);
/**
Native `Spacer` component
@param {string} orientation
@param {IOSpacer} size
*/
const Spacer = ({ orientation, size }: BaseSpacerProps) => {
const style = React.useMemo(
() => ({
...(orientation === "vertical" && {
height: size
}),
...(orientation === "horizontal" && {
width: size
}),
...((debugMode as boolean) && {
backgroundColor: debugBg
})
}),
[orientation, size]
);
return <View style={style} />;
};
/**
Horizontal spacer component
@param {IOSpacer} size
*/
export const HSpacer = ({ size = DEFAULT_SIZE }: SpacerProps) => (
<Spacer orientation={"horizontal"} size={size} />
);
/**
Vertical spacer component
@param {IOSpacer} size
*/
export const VSpacer = ({ size = DEFAULT_SIZE }: SpacerProps) => (
<Spacer orientation={"vertical"} size={size} />
);