|
59 | 59 | <script src="//unpkg.com/react-dom@15/dist/react-dom.min.js"></script> |
60 | 60 | <script src="//cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.29/browser.min.js"></script> |
61 | 61 | <script src="../dist/react-draggable.js"></script> |
62 | | -<script type="text/babel"> |
63 | | - var Draggable = ReactDraggable; |
64 | | - var App = React.createClass({ |
65 | | - getInitialState: function () { |
66 | | - return { |
67 | | - activeDrags: 0, |
68 | | - deltaPosition: { |
69 | | - x: 0, y: 0 |
70 | | - }, |
71 | | - controlledPosition: { |
72 | | - x: -400, y: 200 |
73 | | - } |
74 | | - }; |
75 | | - }, |
76 | | - |
77 | | - handleDrag: function (e, ui) { |
78 | | - const {x, y} = this.state.deltaPosition; |
79 | | - this.setState({ |
80 | | - deltaPosition: { |
81 | | - x: x + ui.deltaX, |
82 | | - y: y + ui.deltaY, |
83 | | - } |
84 | | - }); |
85 | | - }, |
86 | | - |
87 | | - onStart: function() { |
88 | | - this.setState({activeDrags: ++this.state.activeDrags}); |
89 | | - }, |
90 | | - |
91 | | - onStop: function() { |
92 | | - this.setState({activeDrags: --this.state.activeDrags}); |
93 | | - }, |
94 | | - |
95 | | - // For controlled component |
96 | | - adjustXPos: function(e) { |
97 | | - e.preventDefault(); |
98 | | - e.stopPropagation(); |
99 | | - const {x, y} = this.state.controlledPosition; |
100 | | - this.setState({controlledPosition: {x: x - 10, y}}); |
101 | | - }, |
102 | | - |
103 | | - adjustYPos: function(e) { |
104 | | - e.preventDefault(); |
105 | | - e.stopPropagation(); |
106 | | - const {controlledPosition} = this.state; |
107 | | - const {x, y} = this.state.controlledPosition; |
108 | | - this.setState({controlledPosition: {x, y: y - 10}}); |
109 | | - }, |
110 | | - |
111 | | - onControlledDrag: function(e, position) { |
112 | | - const {x, y} = position; |
113 | | - this.setState({controlledPosition: {x, y}}); |
114 | | - }, |
115 | | - |
116 | | - onControlledDragStop: function(e, position) { |
117 | | - const {x, y} = position; |
118 | | - this.setState({controlledPosition: {x, y}}); |
119 | | - }, |
120 | | - |
121 | | - render: function () { |
122 | | - const dragHandlers = {onStart: this.onStart, onStop: this.onStop}; |
123 | | - const {deltaPosition, controlledPosition} = this.state; |
124 | | - return ( |
125 | | - <div> |
126 | | - <h1>React Draggable</h1> |
127 | | - <p>Active DragHandlers: {this.state.activeDrags}</p> |
128 | | - <p> |
129 | | - <a href="https://github.com/mzabriskie/react-draggable/blob/master/example/index.html">Demo Source</a> |
130 | | - </p> |
131 | | - <Draggable zIndex={100} {...dragHandlers}> |
132 | | - <div className="box">I can be dragged anywhere</div> |
133 | | - </Draggable> |
134 | | - <Draggable axis="x" {...dragHandlers}> |
135 | | - <div className="box cursor-x">I can only be dragged horizonally</div> |
136 | | - </Draggable> |
137 | | - <Draggable axis="y" {...dragHandlers}> |
138 | | - <div className="box cursor-y">I can only be dragged vertically</div> |
139 | | - </Draggable> |
140 | | - <Draggable onStart={() => false}> |
141 | | - <div className="box">I don't want to be dragged</div> |
142 | | - </Draggable> |
143 | | - <Draggable onDrag={this.handleDrag} {...dragHandlers}> |
144 | | - <div className="box"> |
145 | | - <div>I track my deltas</div> |
146 | | - <div>x: {deltaPosition.x.toFixed(0)}, y: {deltaPosition.y.toFixed(0)}</div> |
147 | | - </div> |
148 | | - </Draggable> |
149 | | - <Draggable handle="strong" {...dragHandlers}> |
150 | | - <div className="box no-cursor"> |
151 | | - <strong className="cursor"><div>Drag here</div></strong> |
152 | | - <div>You must click my handle to drag me</div> |
153 | | - </div> |
154 | | - </Draggable> |
155 | | - <Draggable cancel="strong" {...dragHandlers}> |
156 | | - <div className="box"> |
157 | | - <strong className="no-cursor">Can't drag here</strong> |
158 | | - <div>Dragging here works</div> |
159 | | - </div> |
160 | | - </Draggable> |
161 | | - <Draggable grid={[25, 25]} {...dragHandlers}> |
162 | | - <div className="box">I snap to a 25 x 25 grid</div> |
163 | | - </Draggable> |
164 | | - <Draggable grid={[50, 50]} {...dragHandlers}> |
165 | | - <div className="box">I snap to a 50 x 50 grid</div> |
166 | | - </Draggable> |
167 | | - <Draggable bounds={{top: -100, left: -100, right: 100, bottom: 100}} zIndex={5} {...dragHandlers}> |
168 | | - <div className="box">I can only be moved 100px in any direction.</div> |
169 | | - </Draggable> |
170 | | - <div className="box" style={{height: '500px', width: '500px', position: 'relative', overflow: 'auto', padding: '0'}}> |
171 | | - <div style={{height: '1000px', width: '1000px', padding: '10px'}}> |
172 | | - <Draggable bounds="parent" {...dragHandlers}> |
173 | | - <div className="box"> |
174 | | - I can only be moved within my offsetParent.<br /><br /> |
175 | | - Both parent padding and child margin work properly. |
176 | | - </div> |
177 | | - </Draggable> |
178 | | - <Draggable bounds="parent" {...dragHandlers}> |
179 | | - <div className="box"> |
180 | | - I also can only be moved within my offsetParent.<br /><br /> |
181 | | - Both parent padding and child margin work properly. |
182 | | - </div> |
183 | | - </Draggable> |
184 | | - </div> |
185 | | - </div> |
186 | | - <Draggable bounds="body" {...dragHandlers}> |
187 | | - <div className="box"> |
188 | | - I can only be moved within the confines of the body element. |
189 | | - </div> |
190 | | - </Draggable> |
191 | | - <Draggable> |
192 | | - <div className="box" style={{position: 'absolute', bottom: '100px', right: '100px'}} {...dragHandlers}> |
193 | | - I already have an absolute position. |
194 | | - </div> |
195 | | - </Draggable> |
196 | | - <Draggable defaultPosition={{x: 25, y: 25}} {...dragHandlers}> |
197 | | - <div className="box"> |
198 | | - {"I have a default position of {x: 25, y: 25}, so I'm slightly offset."} |
199 | | - </div> |
200 | | - </Draggable> |
201 | | - <Draggable zIndex={100} position={controlledPosition} {...dragHandlers} onDrag={this.onControlledDrag}> |
202 | | - <div className="box"> |
203 | | - My position can be changed programmatically. <br /> |
204 | | - I have a drag handler to sync state. |
205 | | - <p> |
206 | | - <a href="#" onClick={this.adjustXPos}>Adjust x ({controlledPosition.x})</a> |
207 | | - </p> |
208 | | - <p> |
209 | | - <a href="#" onClick={this.adjustYPos}>Adjust y ({controlledPosition.y})</a> |
210 | | - </p> |
211 | | - </div> |
212 | | - </Draggable> |
213 | | - <Draggable zIndex={100} position={controlledPosition} {...dragHandlers} onStop={this.onControlledDragStop}> |
214 | | - <div className="box"> |
215 | | - My position can be changed programmatically. <br /> |
216 | | - I have a dragStop handler to sync state. |
217 | | - <p> |
218 | | - <a href="#" onClick={this.adjustXPos}>Adjust x ({controlledPosition.x})</a> |
219 | | - </p> |
220 | | - <p> |
221 | | - <a href="#" onClick={this.adjustYPos}>Adjust y ({controlledPosition.y})</a> |
222 | | - </p> |
223 | | - </div> |
224 | | - </Draggable> |
225 | | - |
226 | | - </div> |
227 | | - ); |
228 | | - } |
229 | | - }); |
230 | | - |
231 | | - ReactDOM.render(<App/>, document.getElementById('container')); |
232 | | -</script> |
| 62 | +<script type="text/babel" src="../example/example.js"></script> |
233 | 63 | </body> |
234 | 64 | </html> |
0 commit comments