index.stories.js
2.41 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React from 'react';
import {storiesOf} from '@storybook/react';
import 'tui-image-editor/dist/tui-image-editor.css';
import 'tui-color-picker/dist/tui-color-picker.css';
import ImageEditor from '../src/index';
const stories = storiesOf('Toast UI ImageEditor', module);
const props = {
includeUI: {
loadImage: {
path: 'img/sampleImage2.png',
name: 'sampleImage2'
},
initMenu: 'shape',
uiSize: {
height: '700px',
width: '1000px'
}
},
cssMaxWidth: 700,
cssMaxHeight: 500
};
stories.add('Include default UI', () => <ImageEditor {...props} />);
stories.add('Using Method', () => {
class Story extends React.Component {
ref = React.createRef();
imageEditor = null;
componentDidMount() {
this.imageEditor = this.ref.current.getInstance();
}
flipImageByAxis(isXAxis) {
this.imageEditor[isXAxis ? 'flipX' : 'flipY']()
.then((status) => {
console.log('flipX: ', status.flipX);
console.log('flipY: ', status.flipY);
console.log('angle: ', status.angle);
})
['catch']((message) => {
console.log('error: ', message);
});
}
render() {
return (
<>
<ImageEditor ref={this.ref} {...props} />
<button
onClick={() => {
this.flipImageByAxis(true);
}}
>
Flip-X!
</button>
<button
onClick={() => {
this.flipImageByAxis(false);
}}
>
Flip-Y!
</button>
</>
);
}
}
return <Story />;
});
stories.add('Events', () => {
class Story2 extends React.Component {
ref = React.createRef();
imageEditor = null;
componentDidMount() {
this.imageEditor = this.ref.current.getInstance();
}
render() {
return (
<ImageEditor
ref={this.ref}
{...props}
onMousedown={(event, originPointer) => {
console.log(event);
console.log(originPointer);
}}
onAddText={(pos) => {
const {x: ox, y: oy} = pos.originPosition;
const {x: cx, y: cy} = pos.clientPosition;
console.log(`text position on canvas(x, y): ${ox}px, ${oy}px`);
console.log(`text position on brwoser(x, y): ${cx}px, ${cy}px`);
}}
/>
);
}
}
return <Story2 />;
});