/
index.js
56 lines (45 loc) · 1.38 KB
/
index.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
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { space, justifyContent, alignItems } from 'styled-system';
import { pick, omit } from 'underscore';
import compactObject from 'react/util/compactObject';
import Box from 'react/components/UI/Box';
const Inner = styled(Box)`
display: flex;
flex-direction: column;
flex-grow: 1;
background-color: white;
border: 1px solid ${x => x.theme.colors.gray.regular};
overflow-y: auto;
-webkit-overflow-scrolling: touch;
height: 100%;
`;
const INNER_PROPS_KEYS = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'justifyContent', 'alignItems'];
const BorderedBox = ({
children, ...rest
}) => {
// Allow the innerbox to have configurable padding
const innerProps = compactObject(pick(rest, ...INNER_PROPS_KEYS));
// While the input can still have configurable margins
const outerProps = omit(rest, ...INNER_PROPS_KEYS);
return (
<Box bg="gray.semiLight" p="5px" borderRadius="0.25em" {...outerProps}>
<Inner {...innerProps}>
{children}
</Inner>
</Box>
);
};
BorderedBox.propTypes = {
children: PropTypes.node.isRequired,
...space.propTypes,
...alignItems.propTypes,
...justifyContent.propTypes,
};
BorderedBox.defaultProps = {
...INNER_PROPS_KEYS.reduce((memo, key) => (
{ ...memo, [key]: null }
), {}),
};
export default BorderedBox;