ImageResizer.tsx
911 Bytes
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
import React from "react";
import "./ImageResizer.scss";
interface ImageResizerType {
size: number,
setSize: Function,
}
interface SizeInfoType {
max: number,
min: number,
gap: number,
}
const SIZE_INFO: SizeInfoType = {
max: 3,
min: 1,
gap: 1
};
function ImageResizer({ size, setSize }: ImageResizerType) {
const handleResize = (isMagnify: boolean) => {
if (isMagnify) { // 확대
if (size >= SIZE_INFO.max) return;
setSize(size += SIZE_INFO.gap);
return;
}
// 축소
if (size <= SIZE_INFO.min) {
return;
}
setSize(size -= SIZE_INFO.gap);
};
return (
<div className="image-resize-button">
<button onClick={() => handleResize(true)}><i className="fas fa-search-plus" /></button>
<button onClick={() => handleResize(false)}><i className="fas fa-search-minus" /></button>
</div>
);
}
export default ImageResizer;