Advertisement
Guest User

Tester component

a guest
Dec 13th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react'
  2. import ImageEditor from './ImageEditor'
  3. import SliderControl from './SliderControl'
  4. import Sidekick from './Sidekick'
  5.  
  6. export default class Test extends Component {
  7.     constructor(props) {
  8.         super(props);
  9.         this.state = {}
  10.         this.imageEditor = React.createRef();
  11.     }
  12.  
  13.     handleSubmit(e) {
  14.         this.setState({
  15.             crop: this.imageEditor.current.getCroppedCanvas()
  16.         });
  17.     }
  18.  
  19.     handleRotation(value){
  20.         this.imageEditor.current.rotateTo(value);
  21.     }
  22.  
  23.     handleScaling(value){
  24.         this.imageEditor.current.scale(value);
  25.     }
  26.  
  27.     handleHorizontalMoving(xPos){
  28.         const canvasData = this.imageEditor.current.getCanvasData();
  29.         console.log(canvasData);
  30.         this.imageEditor.current.moveTo(xPos * canvasData.width, canvasData.top);
  31.     }
  32.  
  33.     handleVerticalMoving(yPos){
  34.         const canvasData = this.imageEditor.current.getCanvasData();
  35.         this.imageEditor.current.moveTo(canvasData.left, yPos * canvasData.height);
  36.     }
  37.  
  38.     handleInput(e) {
  39.         this.setState({
  40.             image: URL.createObjectURL(e.target.files[0])
  41.         })
  42.     }
  43.  
  44.     render() {
  45.         return (
  46.             <div style={{
  47.                 position: "absolute",
  48.                 top: 0,
  49.                 left: 0,
  50.                 display: "flex",
  51.                 background: "#f6f6f6",
  52.                 padding: "2rem 1rem",
  53.                 width: "100%",
  54.                 height: "100%",
  55.                 margin: "0 auto",
  56.             }}>
  57.                 <div style={{
  58.                     width: '100%',
  59.                     maxWidth: 1024,
  60.                     margin: '0 auto',
  61.                     display: "flex"
  62.                 }} >
  63.  
  64.                     <div style={{
  65.                         flexGrow: 2,
  66.                         padding: "1rem",
  67.                         display: "flex"
  68.                     }}>
  69.                         <div style={{
  70.                             position: "relative",
  71.                             flexGrow: 1
  72.                         }}>
  73.                             {this.state.image &&
  74.                                 <ImageEditor
  75.                                     ref={this.imageEditor}
  76.                                     imageURI={this.state.image}
  77.  
  78.                                 />}
  79.                         </div>
  80.                     </div>
  81.                     <div style={{
  82.                         flexGrow: 1,
  83.                         padding: "1rem"
  84.                     }}>
  85.                         <Sidekick title="Title">
  86.                             <SliderControl
  87.                                 label="Rotation"
  88.                                 iconName="sync-alt"
  89.                                 minValue={-90}
  90.                                 maxValue={90}
  91.                                 defaultValue={0}
  92.                                 step={0.01}
  93.                                 onChange={this.handleRotation.bind(this)}
  94.                             />
  95.                             <SliderControl
  96.                                 label="X-pos"
  97.                                 iconName="arrows-alt-h"
  98.                                 minValue={-1}
  99.                                 maxValue={1}
  100.                                 defaultValue={0}
  101.                                 step={0.01}
  102.                                 onChange={this.handleHorizontalMoving.bind(this)}
  103.                             />
  104.                             <SliderControl
  105.                                 label="Y-pos"
  106.                                 iconName="arrows-alt-v"
  107.                                 minValue={-1}
  108.                                 maxValue={1}
  109.                                 defaultValue={0}
  110.                                 step={0.01}
  111.                                 onChange={this.handleVerticalMoving.bind(this)}
  112.                             />
  113.                             <SliderControl
  114.                                 label="Scaling"
  115.                                 iconName="expand"
  116.                                 minValue={.5}
  117.                                 maxValue={1.5}
  118.                                 defaultValue={1}
  119.                                 step={0.01}
  120.                                 onChange={this.handleScaling.bind(this)}
  121.                             />
  122.                             <input type="submit" onClick={this.handleSubmit.bind(this)}/>
  123.                         </Sidekick>
  124.                         <input type="file" onChange={this.handleInput.bind(this)} />
  125.                         {
  126.                             this.state.crop &&
  127.                             <img src={this.state.crop} alt=""/>
  128.                         }
  129.                     </div>
  130.                 </div>
  131.             </div>
  132.         )
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement