forked from iamshadmirza/react-native-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverlay.js
71 lines (64 loc) · 1.81 KB
/
Overlay.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React from 'react';
import { View, StyleSheet, Modal } from 'react-native';
import PropTypes from 'prop-types';
import { useThemeContext } from '../util/ThemeProvider';
const getContainerStyle = ({ theme, background, style }) => {
const containerStyle = [styles.container, {
backgroundColor: theme.brandColor[background],
}];
if (style) {
containerStyle.push(style);
}
return StyleSheet.flatten(containerStyle);
};
const getOverlayStyle = ({ theme, overlayBackground, overlayStyle, borderRadius, width, height }) => {
const contentStyle = [{
elevation: 1,
backgroundColor: theme.brandColor[overlayBackground],
borderRadius: borderRadius,
width: width,
height: height,
}];
if (overlayStyle) {
contentStyle.push(overlayStyle);
}
return StyleSheet.flatten(contentStyle);
};
const Overlay = (props) => {
const theme = useThemeContext();
return (
<Modal {...props}>
<View style={getContainerStyle({ ...props, theme })}>
<View style={getOverlayStyle({ ...props, theme })}>
{props.children}
</View>
</View>
</Modal>
);
};
Overlay.propTypes = {
style: PropTypes.object,
overlayStyle: PropTypes.object,
children: PropTypes.element.isRequired,
background: PropTypes.string,
overlayBackground: PropTypes.string,
borderRadius: PropTypes.number,
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
};
Overlay.defaultProps = {
background: 'semitransparent',
overlayBackground: 'clearWhite',
borderRadius: 3,
width: '80%',
height: '70%',
};
const styles = StyleSheet.create({
container: {
position: 'absolute',
top: 0, right: 0, bottom: 0, left: 0,
justifyContent: 'center',
alignItems: 'center',
},
});
export default Overlay;