cutelee

feat: 파일 로드 기능 구현

1 .my-editor.tui-image-editor-container { 1 .my-editor.tui-image-editor-container {
2 .tui-image-editor-header { 2 .tui-image-editor-header {
3 - min-width: initial !important; 3 + display: none;
4 } 4 }
5 5
6 .tui-image-editor-submenu .tui-image-editor-submenu-item .tui-image-editor-button { 6 .tui-image-editor-submenu .tui-image-editor-submenu-item .tui-image-editor-button {
......
1 +.my-header {
2 + position: fixed;
3 + width: 100%;
4 + height: 50px;
5 + //background: white;
6 + z-index: 10;
7 +
8 + button {
9 + float: right;
10 + height: 35px;
11 + margin-top: 20px;
12 + font-size: 14px;
13 + border: none;
14 + border-radius: 5px;
15 + margin-right: 10px;
16 + cursor: pointer;
17 + }
18 +
19 + .file-box {
20 + .file-box-button {
21 + //background: white;
22 + }
23 +
24 + #input-image-file {
25 + display: none;
26 + }
27 + }
28 +}
...\ No newline at end of file ...\ No newline at end of file
1 +import React, { ChangeEvent } from "react";
2 +import ToastEditor from "tui-image-editor";
3 +
4 +import "./EditorHeader.scss";
5 +
6 +// TODO: 버튼 노출 규칙 정리하기
7 +// TODO: 다크모드/라이트모드에 따른 버튼 스타일 수정하기
8 +// TODO: 다크모드 토글 버튼을 input 타입 checked로 변경하기
9 +
10 +interface EditorHeaderProps {
11 + editor: ToastEditor;
12 + imageLoad: boolean
13 +}
14 +
15 +function EditorHeader({ editor, imageLoad }: EditorHeaderProps) {
16 + function onLoadImage(e: ChangeEvent<HTMLInputElement>): void {
17 + const { files } = e.target;
18 + if (files) {
19 + editor.loadImageFromFile(files[0])
20 + .then((result: any) => console.log(result));
21 + }
22 + }
23 +
24 + return (
25 + <div className="my-header">
26 + <button>다크모드</button>
27 + {imageLoad ? (
28 + <>
29 + <button>다운로드</button>
30 + <button>저장하기</button>
31 + <button>새 작업</button>
32 + </>
33 + ) : (
34 + <>
35 + <span className="file-box">
36 + <button><label htmlFor="input-image-file" className="file-box-button">파일 로드</label></button>
37 + <input type="file" accept="image/*" id="input-image-file" onChange={(e: ChangeEvent<HTMLInputElement>) => onLoadImage(e)}/>
38 + </span>
39 +
40 + <button>URL 불러오기</button>
41 + </>
42 + )}
43 +
44 + </div>
45 + );
46 +}
47 +
48 +export default EditorHeader;
...\ No newline at end of file ...\ No newline at end of file
1 +export { default } from "./EditorHeader";
...\ No newline at end of file ...\ No newline at end of file
1 import React, { useRef, useEffect, useState } from "react"; 1 import React, { useRef, useEffect, useState } from "react";
2 import ToastEditor from "tui-image-editor"; 2 import ToastEditor from "tui-image-editor";
3 3
4 +import EditorHeader from "./EditorHeader";
5 +
4 import { editorOptions } from "utils/editorOptions"; 6 import { editorOptions } from "utils/editorOptions";
5 7
6 import "tui-image-editor/dist/tui-image-editor.css"; 8 import "tui-image-editor/dist/tui-image-editor.css";
...@@ -24,7 +26,10 @@ function EditorPage() { ...@@ -24,7 +26,10 @@ function EditorPage() {
24 }, []); 26 }, []);
25 27
26 return ( 28 return (
29 + <>
30 + <EditorHeader editor={editor} imageLoad={false} />
27 <div className="my-editor" ref={imageEditorRef} /> 31 <div className="my-editor" ref={imageEditorRef} />
32 + </>
28 ); 33 );
29 } 34 }
30 35
......
1 +import React from "react";
2 +
3 +function ImageResizer() {
4 + return (
5 + <div>이미지 크기 변경</div>
6 + );
7 +}
8 +
9 +export default ImageResizer;
...\ No newline at end of file ...\ No newline at end of file
1 +export { default } from "./ImageResizer";
...\ No newline at end of file ...\ No newline at end of file