@team-monolith/cds 1.80.0 → 1.80.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,11 @@
1
1
  import React from "react";
2
- export declare function FileTypeAlertDialog(props: {
2
+ interface FileTypeAlertDialogProps {
3
3
  open: boolean;
4
4
  onClose: () => void;
5
+ /** 다이얼로그에 표시될 콘텐츠 */
5
6
  content: React.ReactNode;
7
+ /** 다시 업로드 버튼 클릭 시 파일 선택 브라우저를 띄우기 위한 callback */
6
8
  openFileBrowser: () => void;
7
- }): import("@emotion/react/jsx-runtime").JSX.Element;
9
+ }
10
+ export declare function FileTypeAlertDialog(props: FileTypeAlertDialogProps): import("@emotion/react/jsx-runtime").JSX.Element;
11
+ export {};
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from "./components/Banner";
5
5
  export * from "./components/Book";
6
6
  export * from "./components/Button";
7
7
  export * from "./components/CheckboxInput";
8
+ export * from "./components/FileTypeAlertDialog";
8
9
  export * from "./components/Input";
9
10
  export * from "./components/Modal";
10
11
  export * from "./components/Pagination";
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export * from "./components/Banner";
5
5
  export * from "./components/Book";
6
6
  export * from "./components/Button";
7
7
  export * from "./components/CheckboxInput";
8
+ export * from "./components/FileTypeAlertDialog";
8
9
  export * from "./components/Input";
9
10
  export * from "./components/Modal";
10
11
  export * from "./components/Pagination";
@@ -1,5 +1,7 @@
1
+ type FileType = "image" | "pdf" | "file";
1
2
  interface FileSelectInputProps {
2
- accept?: string;
3
+ /** accept 타입 얼럿 다이얼로그에 표시될 typeStr을 지정하는 fileType */
4
+ fileType: FileType;
3
5
  onChange: (value: string) => void;
4
6
  }
5
7
  /**
@@ -13,34 +13,47 @@ import { Button, CdsContext } from "../../..";
13
13
  import { UploadLineIcon } from "../../../icons";
14
14
  import styled from "@emotion/styled";
15
15
  import { FileTypeAlertDialog } from "../../../components/FileTypeAlertDialog";
16
+ const fileTypeMap = {
17
+ image: { accept: "image/*", typeStr: "이미지 파일" },
18
+ pdf: { accept: ".pdf", typeStr: "pdf 파일" },
19
+ file: {},
20
+ };
16
21
  /**
17
22
  * 파일 탐색기를 열어 특정 파일을 업로드 한 후, 그 경로를 onChange로 전달합니다.
18
23
  * @param props
19
24
  * @returns
20
25
  */
21
26
  export function FileSelectInput(props) {
22
- const { onChange, accept } = props;
27
+ const { onChange, fileType } = props;
23
28
  const [alertOpen, setAlertOpen] = useState(false);
24
29
  const inputRef = useRef(null);
25
30
  const cdsContext = useContext(CdsContext);
31
+ const { accept, typeStr } = fileTypeMap[fileType];
26
32
  return (_jsxs(_Fragment, { children: [_jsx(Button, { fullWidth: true, color: "grey", size: "medium", label: "\uD30C\uC77C \uC120\uD0DD\uD558\uAE30", onClick: () => {
27
33
  var _a;
28
34
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.click();
29
35
  }, startIcon: _jsx(UploadLineIcon, {}) }), _jsx(HiddenInput, { ref: inputRef, type: "file", accept: accept, onChange: (event) => __awaiter(this, void 0, void 0, function* () {
30
- var _a, _b;
36
+ var _a, _b, _c;
31
37
  const file = (_a = event.target.files) === null || _a === void 0 ? void 0 : _a[0];
32
38
  if (!file)
33
39
  return;
34
- if (accept && !file.type.match(accept)) {
35
- event.target.value = "";
36
- setAlertOpen(true);
37
- return;
40
+ if (accept) {
41
+ // 특정 파일 타입에 대해서 검사하므로 복수개의 accept는 고려하지 않음
42
+ const isTypeValid = accept.startsWith('.')
43
+ ? accept.slice(1) === ((_b = file.name.split('.').pop()) === null || _b === void 0 ? void 0 : _b.toLowerCase())
44
+ : file.type.match(accept);
45
+ if (!isTypeValid) {
46
+ event.target.value = "";
47
+ setAlertOpen(true);
48
+ return;
49
+ }
38
50
  }
39
- const uploadByFile = (_b = cdsContext.lexical) === null || _b === void 0 ? void 0 : _b.uploadByFile;
51
+ const uploadByFile = (_c = cdsContext.lexical) === null || _c === void 0 ? void 0 : _c.uploadByFile;
40
52
  if (uploadByFile) {
41
53
  onChange(yield uploadByFile(file));
42
54
  }
43
- }) }), _jsx(FileTypeAlertDialog, { open: alertOpen, onClose: () => setAlertOpen(false), openFileBrowser: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, content: _jsxs(_Fragment, { children: ["\uC5C5\uB85C\uB4DC\uD560 \uC218 \uC5C6\uB294 \uD30C\uC77C\uC785\uB2C8\uB2E4.", _jsx("br", {}), "\uC774\uBBF8\uC9C0 \uD30C\uC77C\uC744 \uC5C5\uB85C\uB4DC\uD574\uC8FC\uC138\uC694."] }) })] }));
55
+ }) }), fileType !== "file" && ( // file 타입의 경우 얼럿 다이얼로그를 띄우지 않음
56
+ _jsx(FileTypeAlertDialog, { open: alertOpen, onClose: () => setAlertOpen(false), openFileBrowser: () => { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, content: _jsxs(_Fragment, { children: ["\uC5C5\uB85C\uB4DC\uD560 \uC218 \uC5C6\uB294 \uD30C\uC77C\uC785\uB2C8\uB2E4.", _jsx("br", {}), `${typeStr}을 업로드해주세요.`] }) }))] }));
44
57
  }
45
58
  const HiddenInput = styled.input `
46
59
  display: none;
@@ -36,7 +36,7 @@ export function InsertImageDialog(props) {
36
36
  }, disableIconPadding: true }, { children: [_jsx(StyledAlertDialogTitle, Object.assign({ onClose: handleOnClose }, { children: title })), _jsx(AlertDialogContent, { children: _jsxs(Inputs, { children: [_jsx(FileSelectInput, { onChange: (value) => {
37
37
  setValue("src", value);
38
38
  setPreviewSrc(value);
39
- }, accept: "image/*" }), _jsx(FormInput, { name: "src", control: control, placeholder: "https://www.pexels.com/photo/n-2848492", size: "medium", label: "URL", fullWidth: true, startIcon: _jsx(LinkIcon, {}), inputProps: {
39
+ }, fileType: "image" }), _jsx(FormInput, { name: "src", control: control, placeholder: "https://www.pexels.com/photo/n-2848492", size: "medium", label: "URL", fullWidth: true, startIcon: _jsx(LinkIcon, {}), inputProps: {
40
40
  onBlur: () => {
41
41
  setPreviewSrc(watch("src"));
42
42
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-monolith/cds",
3
- "version": "1.80.0",
3
+ "version": "1.80.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,