2015-06-03 19:53:08 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-06-03 19:53:08 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2015-06-03 19:53:08 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2015-06-03 19:53:08 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-10 22:44:52 +00:00
|
|
|
const React = require('React');
|
|
|
|
const View = require('View');
|
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
const BorderBox = require('BorderBox');
|
|
|
|
const resolveBoxStyle = require('resolveBoxStyle');
|
2015-06-03 19:53:08 +00:00
|
|
|
|
2018-05-10 22:44:52 +00:00
|
|
|
const flattenStyle = require('flattenStyle');
|
2015-06-03 19:53:08 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ElementBox extends React.Component<$FlowFixMeProps> {
|
2015-06-03 19:53:08 +00:00
|
|
|
render() {
|
2018-05-10 22:44:52 +00:00
|
|
|
const style = flattenStyle(this.props.style) || {};
|
|
|
|
const margin = resolveBoxStyle('margin', style);
|
|
|
|
const padding = resolveBoxStyle('padding', style);
|
|
|
|
let frameStyle = this.props.frame;
|
2015-06-03 19:53:08 +00:00
|
|
|
if (margin) {
|
|
|
|
frameStyle = {
|
|
|
|
top: frameStyle.top - margin.top,
|
|
|
|
left: frameStyle.left - margin.left,
|
|
|
|
height: frameStyle.height + margin.top + margin.bottom,
|
|
|
|
width: frameStyle.width + margin.left + margin.right,
|
|
|
|
};
|
|
|
|
}
|
2018-05-10 22:44:52 +00:00
|
|
|
let contentStyle = {
|
2015-06-03 19:53:08 +00:00
|
|
|
width: this.props.frame.width,
|
|
|
|
height: this.props.frame.height,
|
|
|
|
};
|
|
|
|
if (padding) {
|
|
|
|
contentStyle = {
|
|
|
|
width: contentStyle.width - padding.left - padding.right,
|
|
|
|
height: contentStyle.height - padding.top - padding.bottom,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<View style={[styles.frame, frameStyle]} pointerEvents="none">
|
|
|
|
<BorderBox box={margin} style={styles.margin}>
|
|
|
|
<BorderBox box={padding} style={styles.padding}>
|
|
|
|
<View style={[styles.content, contentStyle]} />
|
|
|
|
</BorderBox>
|
|
|
|
</BorderBox>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-10 22:44:52 +00:00
|
|
|
const styles = StyleSheet.create({
|
2015-06-03 19:53:08 +00:00
|
|
|
frame: {
|
|
|
|
position: 'absolute',
|
|
|
|
},
|
|
|
|
content: {
|
2015-06-03 20:55:52 +00:00
|
|
|
backgroundColor: 'rgba(200, 230, 255, 0.8)',
|
2015-06-03 19:53:08 +00:00
|
|
|
},
|
|
|
|
padding: {
|
2015-06-03 20:55:52 +00:00
|
|
|
borderColor: 'rgba(77, 255, 0, 0.3)',
|
2015-06-03 19:53:08 +00:00
|
|
|
},
|
|
|
|
margin: {
|
2015-06-03 20:55:52 +00:00
|
|
|
borderColor: 'rgba(255, 132, 0, 0.3)',
|
2015-06-03 19:53:08 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = ElementBox;
|