ar-design 0.2.89 → 0.2.91

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,5 +1,5 @@
1
1
  .ar-typography-title {
2
2
  color: var(--gray-700);
3
3
  font-family: var(--system);
4
- /* -webkit-text-stroke: 0.5px var(--gray-700); */
4
+ font-weight: 400;
5
5
  }
@@ -1,19 +1,18 @@
1
- .ar-upload-button > .button.multiple > .preview {
1
+ .ar-upload-button > .button.dropzone > .preview {
2
2
  position: relative;
3
3
  display: flex;
4
4
  flex-direction: row;
5
5
  flex-wrap: nowrap;
6
6
  width: 100%;
7
7
  height: 100%;
8
- border-right: solid 1px rgba(var(--black-rgb), 0.75);
9
8
  }
10
- .ar-upload-button > .button.multiple > .preview > .selected-image {
9
+ .ar-upload-button > .button.dropzone > .preview > .selected-image {
11
10
  height: 100%;
12
11
  object-fit: fill;
13
12
  object-position: top;
14
13
  }
15
14
 
16
- .ar-upload-button > .button.multiple > .items {
15
+ .ar-upload-button > .button.dropzone > .items {
17
16
  display: flex;
18
17
  flex-direction: column;
19
18
  flex-wrap: nowrap;
@@ -21,10 +20,11 @@
21
20
  backdrop-filter: blur(5px);
22
21
  width: 10rem;
23
22
  height: 12.5rem;
23
+ border-left: solid 1px rgba(var(--black-rgb), 0.75);
24
24
  overflow-x: hidden;
25
25
  overflow-y: auto;
26
26
  }
27
- .ar-upload-button > .button.multiple > .items > .item {
27
+ .ar-upload-button > .button.dropzone > .items > .item {
28
28
  --size: 5rem;
29
29
 
30
30
  display: flex;
@@ -37,14 +37,14 @@
37
37
  border-bottom: solid 1px rgba(var(--black-rgb), 0.75);
38
38
  overflow: hidden;
39
39
  }
40
- .ar-upload-button > .button.multiple > .items > .item > .buttons {
40
+ .ar-upload-button > .button.dropzone > .items > .item > .buttons {
41
41
  position: absolute;
42
42
  inset: 0;
43
43
  display: flex;
44
44
  justify-content: center;
45
45
  align-items: center;
46
46
  }
47
- .ar-upload-button > .button.multiple > .items > .item > .buttons::before {
47
+ .ar-upload-button > .button.dropzone > .items > .item > .buttons::before {
48
48
  position: absolute;
49
49
  inset: 0;
50
50
  content: "";
@@ -52,10 +52,10 @@
52
52
  z-index: 1;
53
53
  transition: background-color 250ms ease-in-out;
54
54
  }
55
- .ar-upload-button > .button.multiple > .items > .item > .buttons:hover::before {
55
+ .ar-upload-button > .button.dropzone > .items > .item > .buttons:hover::before {
56
56
  background-color: rgba(var(--black-rgb), 0.75);
57
57
  }
58
- .ar-upload-button > .button.multiple > .items > .item > .buttons > div {
58
+ .ar-upload-button > .button.dropzone > .items > .item > .buttons > div {
59
59
  display: flex;
60
60
  flex-direction: row;
61
61
  visibility: hidden;
@@ -63,17 +63,17 @@
63
63
  z-index: 2;
64
64
  transition: visibility 250ms, opacity 250ms ease-in-out;
65
65
  }
66
- .ar-upload-button > .button.multiple > .items > .item > .buttons:hover div {
66
+ .ar-upload-button > .button.dropzone > .items > .item > .buttons:hover div {
67
67
  visibility: visible;
68
68
  opacity: 1;
69
69
  }
70
- .ar-upload-button > .button.multiple > .items > .item > img {
70
+ .ar-upload-button > .button.dropzone > .items > .item > img {
71
71
  width: 100%;
72
72
  height: 100%;
73
73
  object-fit: cover;
74
74
  object-position: top;
75
75
  }
76
- .ar-upload-button > .button.multiple > .items > .item .error {
76
+ .ar-upload-button > .button.dropzone > .items > .item .error {
77
77
  position: absolute;
78
78
  inset: 0;
79
79
  display: flex;
@@ -81,7 +81,7 @@
81
81
  justify-content: center;
82
82
  align-items: center;
83
83
  gap: 0.5rem;
84
- background-color: rgba(var(--danger-rgb), 0.5);
84
+ background-color: rgba(var(--danger-rgb), 0.75);
85
85
  color: var(--white);
86
86
  font-size: 0.75rem;
87
87
  font-weight: 700;
@@ -89,7 +89,7 @@
89
89
  z-index: 5;
90
90
  }
91
91
 
92
- .ar-upload-button > .button.multiple > .preview > .informations {
92
+ .ar-upload-button > .button.dropzone > .preview > .informations {
93
93
  visibility: visible;
94
94
  opacity: 1;
95
95
  display: flex;
@@ -104,16 +104,16 @@
104
104
  padding: 0.5rem;
105
105
  transition: visibility 250ms, opacity 250ms ease-in-out;
106
106
  }
107
- .ar-upload-button > .button.multiple > .preview > .informations > .file-name {
107
+ .ar-upload-button > .button.dropzone > .preview > .informations > .file-name {
108
108
  color: var(--white);
109
109
  font-size: 0.75rem;
110
110
  font-weight: 700;
111
111
  }
112
- .ar-upload-button > .button.multiple > .preview > .informations > div {
112
+ .ar-upload-button > .button.dropzone > .preview > .informations > div {
113
113
  display: flex;
114
114
  gap: 0.25rem;
115
115
  }
116
- .ar-upload-button > .button.multiple > .preview > .informations > div > .file-size {
116
+ .ar-upload-button > .button.dropzone > .preview > .informations > div > .file-size {
117
117
  background-color: var(--primary);
118
118
  padding: 0.25rem 0 0.25rem 0.25rem;
119
119
  border-radius: var(--border-radius-sm);
@@ -121,7 +121,7 @@
121
121
  font-size: 0.75rem;
122
122
  font-weight: 700;
123
123
  }
124
- .ar-upload-button > .button.multiple > .preview > .informations > div > .file-size > .size-type {
124
+ .ar-upload-button > .button.dropzone > .preview > .informations > div > .file-size > .size-type {
125
125
  background-color: rgba(var(--black-rgb), 0.5);
126
126
  margin-left: 0.25rem;
127
127
  border-top-right-radius: var(--border-radius-sm);
@@ -130,7 +130,7 @@
130
130
  color: var(--primary);
131
131
  font-weight: 700;
132
132
  }
133
- .ar-upload-button > .button.multiple > .preview > .informations > div > .file-type {
133
+ .ar-upload-button > .button.dropzone > .preview > .informations > div > .file-type {
134
134
  background-color: var(--warning);
135
135
  padding: 0.25rem;
136
136
  border-radius: var(--border-radius-sm);
@@ -0,0 +1,143 @@
1
+ .ar-upload {
2
+ position: relative;
3
+ display: flex;
4
+ flex-direction: column;
5
+ flex-wrap: nowrap;
6
+ gap: 1rem;
7
+ width: 100%;
8
+ height: 100%;
9
+
10
+ > button {
11
+ width: max-content !important;
12
+ }
13
+
14
+ > ul {
15
+ display: flex;
16
+ flex-direction: column;
17
+ gap: 0.75rem;
18
+
19
+ > li {
20
+ position: relative;
21
+ display: flex;
22
+ flex-direction: column;
23
+ gap: 0.5rem;
24
+ padding: 0.5rem;
25
+ border: solid 1px var(--gray-300);
26
+ border-radius: var(--border-radius-sm);
27
+ overflow: hidden;
28
+
29
+ &::before {
30
+ position: absolute;
31
+ inset: 0;
32
+ content: "";
33
+ background-color: transparent;
34
+ z-index: 1;
35
+ transition: background-color 250ms ease-in-out;
36
+ }
37
+
38
+ &:hover {
39
+ border: solid 1px transparent;
40
+ }
41
+ &:hover::before {
42
+ background-color: rgba(var(--black-rgb), 0.75);
43
+ }
44
+
45
+ &:has(> .error) {
46
+ border: solid 1px var(--danger);
47
+ }
48
+
49
+ .error {
50
+ position: absolute;
51
+ inset: 0;
52
+ display: flex;
53
+ flex-direction: column;
54
+ justify-content: center;
55
+ align-items: center;
56
+ gap: 0.5rem;
57
+ background-color: rgba(var(--danger-rgb), 0.75);
58
+ color: var(--white);
59
+ font-size: 0.75rem;
60
+ font-weight: 700;
61
+ text-align: center;
62
+ z-index: 5;
63
+ }
64
+
65
+ .buttons {
66
+ position: absolute;
67
+ inset: 0;
68
+ display: flex;
69
+ justify-content: center;
70
+ align-items: center;
71
+
72
+ &:hover {
73
+ div {
74
+ visibility: visible;
75
+ opacity: 1;
76
+ }
77
+ }
78
+
79
+ &::before {
80
+ position: absolute;
81
+ inset: 0;
82
+ content: "";
83
+ background-color: transparent;
84
+ z-index: 1;
85
+ transition: background-color 250ms ease-in-out;
86
+ }
87
+
88
+ &:hover::before {
89
+ background-color: rgba(var(--black-rgb), 0.75);
90
+ }
91
+
92
+ > div {
93
+ display: flex;
94
+ flex-direction: row;
95
+ visibility: hidden;
96
+ opacity: 0;
97
+ z-index: 2;
98
+ transition: visibility 250ms, opacity 250ms ease-in-out;
99
+ }
100
+ }
101
+
102
+ > .file-name {
103
+ color: var(--gray-700);
104
+ font-size: 0.75rem;
105
+ font-weight: 700;
106
+ }
107
+
108
+ > div {
109
+ display: flex;
110
+ gap: 0.25rem;
111
+
112
+ > .file-size {
113
+ background-color: var(--primary);
114
+ padding: 0.25rem 0 0.25rem 0.25rem;
115
+ border-radius: var(--border-radius-sm);
116
+ color: var(--white);
117
+ font-size: 0.65rem;
118
+ font-weight: 700;
119
+
120
+ > .size-type {
121
+ background-color: rgba(var(--black-rgb), 0.5);
122
+ margin-left: 0.25rem;
123
+ border-top-right-radius: var(--border-radius-sm);
124
+ border-bottom-right-radius: var(--border-radius-sm);
125
+ padding: 0.25rem;
126
+ color: var(--primary);
127
+ font-size: 0.65rem;
128
+ font-weight: 700;
129
+ }
130
+ }
131
+
132
+ > .file-type {
133
+ background-color: var(--warning);
134
+ padding: 0.25rem;
135
+ border-radius: var(--border-radius-sm);
136
+ color: var(--black);
137
+ font-size: 0.65rem;
138
+ font-weight: 700;
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
@@ -31,7 +31,7 @@
31
31
  user-select: none;
32
32
  transition: border 250ms, box-shadow 250ms ease-in-out;
33
33
  }
34
- .ar-upload-button > .button.multiple {
34
+ .ar-upload-button > .button.dropzone {
35
35
  height: 12.5rem !important;
36
36
  }
37
37
  .ar-upload-button > .button.has-file {
@@ -40,11 +40,11 @@
40
40
  gap: 0 !important;
41
41
  align-items: flex-start !important;
42
42
  }
43
- .ar-upload-button > .button:not(.multiple):hover .preview > .informations {
43
+ .ar-upload-button > .button:not(.dropzone):hover .preview > .informations {
44
44
  visibility: hidden;
45
45
  opacity: 0;
46
46
  }
47
- .ar-upload-button > .button:not(.multiple):has(.preview > img):hover {
47
+ .ar-upload-button > .button:not(.dropzone):has(.preview > img):hover {
48
48
  border: solid 1px transparent !important;
49
49
  }
50
50
  .ar-upload-button > .button:has(.preview > img) {
@@ -163,5 +163,5 @@
163
163
  color: var(--gray-500);
164
164
  }
165
165
 
166
- @import url("./preview-selected-files.css");
167
- @import url("./animations.css");
166
+ @import url("./list.css");
167
+ @import url("./dropzone.css");
@@ -29,8 +29,7 @@ button.filled:not(.disabled) {
29
29
  &.blue {
30
30
  background-color: var(--blue-500);
31
31
 
32
- &:hover,
33
- &:focus {
32
+ &:hover {
34
33
  background-color: var(--blue-300);
35
34
  }
36
35
  }
@@ -69,8 +68,7 @@ button.filled:not(.disabled) {
69
68
  &.purple {
70
69
  background-color: var(--purple-500);
71
70
 
72
- &:hover,
73
- &:focus {
71
+ &:hover {
74
72
  background-color: var(--purple-300);
75
73
  }
76
74
  }
@@ -109,8 +107,7 @@ button.filled:not(.disabled) {
109
107
  &.pink {
110
108
  background-color: var(--pink-500);
111
109
 
112
- &:hover,
113
- &:focus {
110
+ &:hover {
114
111
  background-color: var(--pink-300);
115
112
  }
116
113
  }
@@ -149,8 +146,7 @@ button.filled:not(.disabled) {
149
146
  &.red {
150
147
  background-color: var(--red-500);
151
148
 
152
- &:hover,
153
- &:focus {
149
+ &:hover {
154
150
  background-color: var(--red-300);
155
151
  }
156
152
  }
@@ -189,8 +185,7 @@ button.filled:not(.disabled) {
189
185
  &.orange {
190
186
  background-color: var(--orange-500);
191
187
 
192
- &:hover,
193
- &:focus {
188
+ &:hover {
194
189
  background-color: var(--orange-300);
195
190
  }
196
191
  }
@@ -229,8 +224,7 @@ button.filled:not(.disabled) {
229
224
  &.yellow {
230
225
  background-color: var(--yellow-500);
231
226
 
232
- &:hover,
233
- &:focus {
227
+ &:hover {
234
228
  background-color: var(--yellow-300);
235
229
  }
236
230
  }
@@ -269,8 +263,7 @@ button.filled:not(.disabled) {
269
263
  &.green {
270
264
  background-color: var(--green-500);
271
265
 
272
- &:hover,
273
- &:focus {
266
+ &:hover {
274
267
  background-color: var(--green-300);
275
268
  }
276
269
  }
@@ -309,8 +302,7 @@ button.filled:not(.disabled) {
309
302
  &.teal {
310
303
  background-color: var(--teal-500);
311
304
 
312
- &:hover,
313
- &:focus {
305
+ &:hover {
314
306
  background-color: var(--teal-300);
315
307
  }
316
308
  }
@@ -349,8 +341,7 @@ button.filled:not(.disabled) {
349
341
  &.cyan {
350
342
  background-color: var(--cyan-500);
351
343
 
352
- &:hover,
353
- &:focus {
344
+ &:hover {
354
345
  background-color: var(--cyan-300);
355
346
  }
356
347
  }
@@ -389,8 +380,7 @@ button.filled:not(.disabled) {
389
380
  &.gray {
390
381
  background-color: var(--gray-500);
391
382
 
392
- &:hover,
393
- &:focus {
383
+ &:hover {
394
384
  background-color: var(--gray-300);
395
385
  }
396
386
  }
@@ -429,8 +419,7 @@ button.filled:not(.disabled) {
429
419
  &.light {
430
420
  background-color: var(--light-500);
431
421
 
432
- &:hover,
433
- &:focus {
422
+ &:hover {
434
423
  background-color: var(--light-300);
435
424
  }
436
425
  }
@@ -1,8 +1,8 @@
1
1
  import React from "react";
2
2
  interface IProps {
3
- selectedFile: File | undefined;
3
+ selectedFile: File;
4
4
  handleFileToBase64: (file: File) => Promise<string>;
5
5
  handleFileRemove: (fileToRemove: File) => void;
6
6
  }
7
- declare const _default: React.MemoExoticComponent<({ selectedFile, handleFileToBase64, handleFileRemove }: IProps) => React.JSX.Element | undefined>;
7
+ declare const _default: React.MemoExoticComponent<({ selectedFile, handleFileToBase64, handleFileRemove }: IProps) => React.JSX.Element>;
8
8
  export default _default;
@@ -0,0 +1,27 @@
1
+ import React, { memo } from "react";
2
+ import { ARIcon } from "../../icons";
3
+ import Button from "../button";
4
+ const Buttons = ({ selectedFile, handleFileToBase64, handleFileRemove }) => {
5
+ return (React.createElement("div", { className: "buttons" },
6
+ React.createElement("div", null,
7
+ React.createElement(Button, { variant: "borderless", color: "purple", type: "button", icon: { element: React.createElement(ARIcon, { icon: "Download", fill: "currentColor" }) }, onClick: (e) => {
8
+ e.stopPropagation();
9
+ const url = window.URL.createObjectURL(selectedFile);
10
+ const a = document.createElement("a");
11
+ a.href = url;
12
+ a.download = selectedFile.name;
13
+ a.click();
14
+ window.URL.revokeObjectURL(url);
15
+ } }),
16
+ selectedFile.type.includes("image") && (React.createElement(Button, { variant: "borderless", color: "blue", type: "button", icon: { element: React.createElement(ARIcon, { variant: "fill", icon: "Eye", fill: "currentColor" }) }, onClick: async (e) => {
17
+ e.stopPropagation();
18
+ const base64 = await handleFileToBase64(selectedFile);
19
+ const newTab = window.open();
20
+ newTab?.document.write(`<img src="${base64}" title="${selectedFile.name}" alt="${selectedFile.name}" />`);
21
+ } })),
22
+ React.createElement(Button, { variant: "borderless", color: "red", type: "button", icon: { element: React.createElement(ARIcon, { variant: "fill", icon: "Trash", fill: "currentColor" }) }, onClick: (e) => {
23
+ e.stopPropagation();
24
+ handleFileRemove(selectedFile);
25
+ } }))));
26
+ };
27
+ export default memo(Buttons);
@@ -2,9 +2,9 @@ import React from "react";
2
2
  import { ValidationError } from ".";
3
3
  interface IProps {
4
4
  selectedFiles: File[];
5
- validationErrors: ValidationError[];
5
+ validationErrors?: ValidationError[];
6
6
  handleFileToBase64: (file: File) => Promise<string>;
7
7
  handleFileRemove: (fileToRemove: File) => void;
8
8
  }
9
- declare const _default: React.MemoExoticComponent<({ selectedFiles, validationErrors, handleFileToBase64, handleFileRemove }: IProps) => false | React.JSX.Element>;
9
+ declare const _default: React.MemoExoticComponent<({ selectedFiles, validationErrors, handleFileToBase64, handleFileRemove }: IProps) => React.JSX.Element | null>;
10
10
  export default _default;
@@ -0,0 +1,55 @@
1
+ import React, { memo, useEffect, useState } from "react";
2
+ import { ARIcon } from "../../icons";
3
+ import Utils from "../../../libs/infrastructure/shared/Utils";
4
+ import Buttons from "./Buttons";
5
+ const Dropzone = ({ selectedFiles, validationErrors = [], handleFileToBase64, handleFileRemove }) => {
6
+ const [selectedFile, setSelectedFile] = useState(undefined);
7
+ const [selectedFileBase64, setSelectedFileBase64] = useState(undefined);
8
+ const [fileBase64Map, setFileBase64Map] = useState({});
9
+ // methods
10
+ const handleSelectFile = async (file) => {
11
+ setSelectedFile(file);
12
+ setSelectedFileBase64(fileBase64Map[file.name]);
13
+ };
14
+ const renderFileCard = (file) => {
15
+ const fileInfo = Utils.GetFileTypeInformation(file.type);
16
+ const message = validationErrors.find((v) => v.fileName === file.name)?.message;
17
+ const base64 = fileBase64Map[file.name];
18
+ return (React.createElement("div", { key: file.name, className: "item", style: { backgroundColor: fileInfo.color }, onMouseEnter: (e) => {
19
+ e.stopPropagation();
20
+ handleSelectFile(file);
21
+ } },
22
+ message && (React.createElement("div", { className: "error" },
23
+ React.createElement(ARIcon, { variant: "fill", icon: "ExclamationDiamond", fill: "var(--white)" }),
24
+ React.createElement("span", null, message))),
25
+ React.createElement(Buttons, { selectedFile: file, handleFileToBase64: handleFileToBase64, handleFileRemove: handleFileRemove }),
26
+ file.type.includes("image") ? (React.createElement("img", { src: base64 })) : (React.createElement(ARIcon, { icon: fileInfo.icon ?? "Document", fill: "var(--white)", size: 32 }))));
27
+ };
28
+ // useEffects
29
+ useEffect(() => {
30
+ if (selectedFiles.length === 0)
31
+ return;
32
+ (async () => {
33
+ const newMap = {};
34
+ for (const file of selectedFiles) {
35
+ const base64 = await handleFileToBase64(file);
36
+ newMap[file.name] = base64;
37
+ }
38
+ setFileBase64Map(newMap);
39
+ setSelectedFile(selectedFiles[0]);
40
+ setSelectedFileBase64(newMap[selectedFiles[0].name]);
41
+ })();
42
+ }, [selectedFiles]);
43
+ return selectedFile ? (React.createElement(React.Fragment, null,
44
+ React.createElement("div", { className: "preview" },
45
+ selectedFile.type.includes("image") ? (React.createElement("img", { src: selectedFileBase64, className: "selected-image" })) : ("Önizleme Yok."),
46
+ React.createElement("div", { className: "informations" },
47
+ React.createElement("span", { className: "file-name" }, selectedFile.name),
48
+ React.createElement("div", null,
49
+ React.createElement("span", { className: "file-size" },
50
+ (selectedFile.size / 1024).toFixed(3),
51
+ React.createElement("span", { className: "size-type" }, "KB")),
52
+ React.createElement("span", { className: "file-type" }, Utils.GetFileTypeInformation(selectedFile.type).readableType)))),
53
+ selectedFiles.length > 1 && React.createElement("div", { className: "items" }, selectedFiles.map((file) => renderFileCard(file))))) : null;
54
+ };
55
+ export default memo(Dropzone);
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import { ValidationError } from ".";
3
+ interface IProps {
4
+ selectedFiles: File[];
5
+ validationErrors?: ValidationError[];
6
+ handleFileToBase64: (file: File) => Promise<string>;
7
+ handleFileRemove: (fileToRemove: File) => void;
8
+ }
9
+ declare const _default: React.MemoExoticComponent<({ selectedFiles, validationErrors, handleFileToBase64, handleFileRemove }: IProps) => React.JSX.Element>;
10
+ export default _default;
@@ -0,0 +1,22 @@
1
+ import React, { memo } from "react";
2
+ import { ARIcon } from "../../icons";
3
+ import Utils from "../../../libs/infrastructure/shared/Utils";
4
+ import Buttons from "./Buttons";
5
+ const List = ({ selectedFiles, validationErrors = [], handleFileToBase64, handleFileRemove }) => {
6
+ return (React.createElement(React.Fragment, null,
7
+ React.createElement("ul", null, selectedFiles.map((selectedFile) => {
8
+ const message = validationErrors.find((v) => v.fileName === selectedFile.name)?.message;
9
+ return (React.createElement("li", null,
10
+ message && (React.createElement("div", { className: "error" },
11
+ React.createElement(ARIcon, { variant: "fill", icon: "ExclamationDiamond", fill: "var(--white)" }),
12
+ React.createElement("span", null, message))),
13
+ React.createElement(Buttons, { selectedFile: selectedFile, handleFileToBase64: handleFileToBase64, handleFileRemove: handleFileRemove }),
14
+ React.createElement("span", { className: "file-name" }, selectedFile.name),
15
+ React.createElement("div", null,
16
+ React.createElement("span", { className: "file-size" },
17
+ (selectedFile.size / 1024).toFixed(3),
18
+ React.createElement("span", { className: "size-type" }, "KB")),
19
+ React.createElement("span", { className: "file-type" }, Utils.GetFileTypeInformation(selectedFile.type).readableType))));
20
+ }))));
21
+ };
22
+ export default memo(List);
@@ -108,5 +108,6 @@ type Props = {
108
108
  * ```
109
109
  */
110
110
  maxSize?: number;
111
+ type?: "list" | "dropzone";
111
112
  } & (IMultiple | ISingle) & IValidation & IDisabled;
112
113
  export default Props;
@@ -1,9 +1,10 @@
1
1
  import React, { useCallback, useEffect, useRef, useState } from "react";
2
2
  import "../../../assets/css/components/form/upload/styles.css";
3
3
  import { ARIcon } from "../../icons";
4
- import PreviewSelectedFile from "./PreviewSelectedFile";
5
- import PreviewSelectedFiles from "./PreviewSelectedFiles";
6
- const Upload = ({ text, file, onChange, allowedTypes, maxSize, multiple }) => {
4
+ import Dropzone from "./Dropzone";
5
+ import Button from "../button";
6
+ import List from "./List";
7
+ const Upload = ({ text, file, onChange, allowedTypes, maxSize, type = "list", multiple }) => {
7
8
  // refs
8
9
  const _firstLoad = useRef(false);
9
10
  const _input = useRef(null);
@@ -115,6 +116,11 @@ const Upload = ({ text, file, onChange, allowedTypes, maxSize, multiple }) => {
115
116
  }
116
117
  setClassName((prev) => prev.filter((c) => c !== "dragging"));
117
118
  }, []);
119
+ const renderUploadFile = (params) => {
120
+ return (React.createElement("div", { ref: _arUplaod, className: "ar-upload" },
121
+ React.createElement("input", { ref: _input, type: "file", onChange: (event) => handleFileChange(event.target.files), multiple: multiple }),
122
+ params.children));
123
+ };
118
124
  // useEffects
119
125
  useEffect(() => {
120
126
  (async () => {
@@ -176,26 +182,38 @@ const Upload = ({ text, file, onChange, allowedTypes, maxSize, multiple }) => {
176
182
  }
177
183
  }, [file]);
178
184
  useEffect(() => {
179
- if (multiple)
180
- setClassName((prev) => [...prev, "multiple"]);
185
+ if (type === "dropzone")
186
+ setClassName((prev) => [...prev, "dropzone"]);
181
187
  }, []);
182
- return (React.createElement("div", { ref: _arUplaod, className: "ar-upload" },
183
- React.createElement("input", { ref: _input, type: "file", onChange: (event) => handleFileChange(event.target.files), multiple: multiple }),
184
- React.createElement("div", { className: "ar-upload-button" },
185
- React.createElement("div", { className: className.map((c) => c).join(" "), onDragEnter: handleDrag, onDragLeave: handleDrag, onDragOver: handleDrag, onDrop: handleDrop, onClick: () => {
186
- if (_input.current)
187
- _input.current.click();
188
- } },
189
- multiple ? (React.createElement(PreviewSelectedFiles, { selectedFiles: selectedFiles, validationErrors: validationErrors, handleFileToBase64: handleFileToBase64, handleFileRemove: handleFileRemove })) : (React.createElement(PreviewSelectedFile, { selectedFile: selectedFile, handleFileToBase64: handleFileToBase64, handleFileRemove: handleFileRemove })),
190
- !selectedFile && selectedFiles.length === 0 && (React.createElement(React.Fragment, null,
191
- React.createElement("div", { className: "upload" },
192
- React.createElement(ARIcon, { variant: "fill", icon: "CloudUpload", size: 32 }),
193
- React.createElement("div", { className: "properies" },
194
- allowedTypes && (React.createElement("div", { className: "allow-types" }, allowedTypes?.map((allowedType) => allowedType.split("/")[1].toLocaleUpperCase()).join(", "))),
195
- maxSize && React.createElement("div", { className: "max-size" },
196
- "up to ",
197
- maxSize,
198
- "MB"))),
199
- text && React.createElement("span", null, text)))))));
188
+ switch (type) {
189
+ case "list":
190
+ return renderUploadFile({
191
+ children: (React.createElement(React.Fragment, null,
192
+ React.createElement(Button, { variant: "outlined", color: "gray", icon: { element: React.createElement(ARIcon, { variant: "fill", icon: "CloudUpload" }) }, onClick: () => {
193
+ if (_input.current)
194
+ _input.current.click();
195
+ } }, text && React.createElement("span", null, text)),
196
+ React.createElement(List, { selectedFiles: selectedFiles.length === 0 && selectedFile ? [selectedFile] : selectedFiles, validationErrors: validationErrors, handleFileToBase64: handleFileToBase64, handleFileRemove: handleFileRemove }))),
197
+ });
198
+ case "dropzone":
199
+ return renderUploadFile({
200
+ children: (React.createElement("div", { className: "ar-upload-button" },
201
+ React.createElement("div", { className: className.map((c) => c).join(" "), onDragEnter: handleDrag, onDragLeave: handleDrag, onDragOver: handleDrag, onDrop: handleDrop, onClick: () => {
202
+ if (_input.current)
203
+ _input.current.click();
204
+ } },
205
+ React.createElement(Dropzone, { selectedFiles: selectedFiles.length === 0 && selectedFile ? [selectedFile] : selectedFiles, validationErrors: validationErrors, handleFileToBase64: handleFileToBase64, handleFileRemove: handleFileRemove }),
206
+ !selectedFile && selectedFiles.length === 0 && (React.createElement(React.Fragment, null,
207
+ React.createElement("div", { className: "upload" },
208
+ React.createElement(ARIcon, { variant: "fill", icon: "CloudUpload", size: 32 }),
209
+ React.createElement("div", { className: "properies" },
210
+ allowedTypes && (React.createElement("div", { className: "allow-types" }, allowedTypes?.map((allowedType) => allowedType.split("/")[1].toLocaleUpperCase()).join(", "))),
211
+ maxSize && React.createElement("div", { className: "max-size" },
212
+ "up to ",
213
+ maxSize,
214
+ "MB"))),
215
+ text && React.createElement("span", null, text)))))),
216
+ });
217
+ }
200
218
  };
201
219
  export default Upload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.2.89",
3
+ "version": "0.2.91",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -1,14 +0,0 @@
1
- @keyframes count {
2
- 0% {
3
- transform: scale(1);
4
- }
5
- 50% {
6
- box-shadow: 0 0 0 2.5px rgba(var(--warning-rgb), 0.25);
7
- color: var(--warning);
8
- /* -webkit-text-stroke: 1px var(--warning); */
9
- transform: scale(1.25);
10
- }
11
- 100% {
12
- transform: scale(1);
13
- }
14
- }
@@ -1,46 +0,0 @@
1
- import React, { memo, useEffect, useState } from "react";
2
- import Button from "../button";
3
- import { ARIcon } from "../../icons";
4
- const PreviewSelectedFile = ({ selectedFile, handleFileToBase64, handleFileRemove }) => {
5
- // states
6
- const [selectedFileBase64, setSelectedFileBase64] = useState(undefined);
7
- // useEffects
8
- useEffect(() => {
9
- (async () => {
10
- if (!selectedFile)
11
- return;
12
- setSelectedFileBase64(await handleFileToBase64(selectedFile));
13
- })();
14
- }, [selectedFile]);
15
- return (selectedFile && (React.createElement("div", { className: "preview" },
16
- React.createElement("div", { className: "buttons" },
17
- React.createElement("div", null,
18
- React.createElement(Button, { variant: "borderless", type: "button", icon: { element: React.createElement(ARIcon, { icon: "Download", fill: "currentColor" }) }, onClick: (event) => {
19
- event.stopPropagation();
20
- const url = window.URL.createObjectURL(selectedFile);
21
- const a = document.createElement("a");
22
- a.href = url;
23
- a.download = selectedFile.name;
24
- a.click();
25
- // Belleği temizle
26
- window.URL.revokeObjectURL(url);
27
- } }),
28
- React.createElement(Button, { variant: "borderless", type: "button", icon: { element: React.createElement(ARIcon, { variant: "fill", icon: "Eye", fill: "currentColor" }) }, onClick: (event) => {
29
- event.stopPropagation();
30
- const newTab = window.open();
31
- newTab?.document.write(`<img src="${selectedFileBase64}" title="${selectedFile.name}" alt="${selectedFile.name}" />`);
32
- } }),
33
- React.createElement(Button, { variant: "borderless", color: "red", type: "button", icon: { element: React.createElement(ARIcon, { variant: "fill", icon: "Trash", fill: "currentColor" }) }, onClick: (event) => {
34
- event.stopPropagation();
35
- handleFileRemove(selectedFile);
36
- } }))),
37
- React.createElement("img", { src: selectedFileBase64 }),
38
- React.createElement("div", { className: "informations" },
39
- React.createElement("span", { className: "file-name" }, selectedFile.name),
40
- React.createElement("div", null,
41
- React.createElement("span", { className: "file-size" },
42
- (selectedFile.size / 1024).toFixed(3),
43
- React.createElement("span", { className: "size-type" }, "KB")),
44
- React.createElement("span", { className: "file-type" }, selectedFile.type.split("/")[1].toLocaleUpperCase()))))));
45
- };
46
- export default memo(PreviewSelectedFile);
@@ -1,65 +0,0 @@
1
- import React, { memo, useEffect, useState } from "react";
2
- import Button from "../button";
3
- import { ARIcon } from "../../icons";
4
- import Utils from "../../../libs/infrastructure/shared/Utils";
5
- const PreviewSelectedFiles = ({ selectedFiles, validationErrors, handleFileToBase64, handleFileRemove }) => {
6
- // states
7
- const [items, setItems] = useState([]);
8
- const [selectedFile, setSelectedFile] = useState(undefined);
9
- const [selectedFileBase64, setSelectedFileBase64] = useState(undefined);
10
- // useEffects
11
- useEffect(() => {
12
- (async () => {
13
- const items = await Promise.all(selectedFiles.map(async (selectedFile) => {
14
- const fileInformation = Utils.GetFileTypeInformation(selectedFile.type);
15
- const _selectedFileBase64 = await handleFileToBase64(selectedFile);
16
- const message = validationErrors.find((validationError) => validationError.fileName === selectedFile.name)?.message;
17
- return (React.createElement("div", { className: "item", style: { backgroundColor: fileInformation.color }, onClick: (event) => event.stopPropagation(), onMouseOver: async (event) => {
18
- event.stopPropagation();
19
- setSelectedFileBase64(await handleFileToBase64(selectedFile));
20
- setSelectedFile(selectedFile);
21
- } },
22
- message && (React.createElement("div", { className: "error" },
23
- React.createElement(ARIcon, { variant: "fill", icon: "ExclamationDiamond", fill: "var(--white)" }),
24
- React.createElement("span", null, message))),
25
- React.createElement("div", { className: "buttons" },
26
- React.createElement("div", null,
27
- React.createElement(Button, { variant: "borderless", type: "button", icon: { element: React.createElement(ARIcon, { icon: "Download", fill: "currentColor" }) }, onClick: (event) => {
28
- event.stopPropagation();
29
- const url = window.URL.createObjectURL(selectedFile);
30
- const a = document.createElement("a");
31
- a.href = url;
32
- a.download = selectedFile.name;
33
- a.click();
34
- // Belleği temizle
35
- window.URL.revokeObjectURL(url);
36
- } }),
37
- selectedFile.type.includes("image") && (React.createElement(Button, { variant: "borderless", type: "button", icon: { element: React.createElement(ARIcon, { variant: "fill", icon: "Eye", fill: "currentColor" }) }, onClick: (event) => {
38
- event.stopPropagation();
39
- const newTab = window.open();
40
- newTab?.document.write(`<img src="${_selectedFileBase64}" title="${selectedFile.name}" alt="${selectedFile.name}" />`);
41
- } })),
42
- React.createElement(Button, { variant: "borderless", color: "red", type: "button", icon: { element: React.createElement(ARIcon, { variant: "fill", icon: "Trash", fill: "currentColor" }) }, onClick: (event) => {
43
- event.stopPropagation();
44
- handleFileRemove(selectedFile);
45
- } }))),
46
- selectedFile.type.includes("image") ? (React.createElement("img", { src: _selectedFileBase64 })) : (React.createElement(ARIcon, { icon: fileInformation.icon ?? "Document", fill: "var(--white)", size: 32 }))));
47
- }));
48
- setItems(items);
49
- setSelectedFileBase64(await handleFileToBase64(selectedFiles[0]));
50
- setSelectedFile(selectedFiles[0]);
51
- })();
52
- }, [selectedFiles, validationErrors]);
53
- return (selectedFiles.length > 0 && (React.createElement(React.Fragment, null,
54
- React.createElement("div", { className: "preview" },
55
- selectedFile?.type.includes("image") ? (React.createElement("img", { src: selectedFileBase64, className: "selected-image" })) : ("Önizleme Yok."),
56
- selectedFile && (React.createElement("div", { className: "informations" },
57
- React.createElement("span", { className: "file-name" }, selectedFile.name),
58
- React.createElement("div", null,
59
- React.createElement("span", { className: "file-size" },
60
- (selectedFile.size / 1024).toFixed(3),
61
- React.createElement("span", { className: "size-type" }, "KB")),
62
- React.createElement("span", { className: "file-type" }, Utils.GetFileTypeInformation(selectedFile.type).readableType))))),
63
- React.createElement("div", { className: "items" }, items))));
64
- };
65
- export default memo(PreviewSelectedFiles);