This repository has been archived by the owner on Feb 19, 2022. It is now read-only.
/
app.jsx
69 lines (65 loc) · 1.68 KB
/
app.jsx
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
/* eslint-env browser */
/* eslint-disable new-cap,no-magic-numbers */
import React, { Component, PropTypes } from "react";
import ReactDOM from "react-dom";
import AutoLayout, { View, Subview, AutoDOM, constrain } from "../src/index.js";
class Rectangle extends Component {
static propTypes = {
layout: PropTypes.shape({
top: PropTypes.number,
right: PropTypes.number,
bottom: PropTypes.number,
left: PropTypes.number
})
};
render() {
return (
<div style={{
position: "absolute",
top: this.props.layout.top || 0,
right: this.props.layout.right || 0,
bottom: this.props.layout.bottom || 0,
left: this.props.layout.left || 0
}}
>
<p>What time is it?</p>
</div>
);
}
}
const SubRectangle = Subview(Rectangle);
class App extends Component {
render() {
return (
<AutoLayout>
<View
name="main"
container="div"
width={400}
height={250}
>
<AutoDOM.div
name="autobot"
intrinsicWidth={100}
intrinsicHeight={100}
constraints = {[
constrain().subview("autobot").centerX.to.equal.superview.centerX
]}
>
<p>demo</p>
<p>time!</p>
</AutoDOM.div>
<SubRectangle
name="rectangle"
intrinsicWidth={20}
intrinsicHeight={20}
constraints={[
constrain().subview("rectangle").centerX.to.equal.superview.centerX
]}
/>
</View>
</AutoLayout>
);
}
}
ReactDOM.render(<App />, document.getElementById("content"));