@wavv/ui 2.3.7-alpha.1 → 2.3.7-alpha.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.
@@ -9,6 +9,7 @@ import { marginProps, paddingProps, widthHeightProps } from "./helpers/styledPro
9
9
  const DropZone_DropZone = ({ label = 'Drop here', showFileList = true, disabled, invalid, errorMessage, supportedFormats, maxFileSize, acceptedFileTypes, allowsMultiple, defaultCamera, acceptDirectory, onDrop, onFilesAdded, onFilesRemoved, width, margin, marginTop, marginRight, marginBottom, marginLeft, ...rest })=>{
10
10
  const [files, setFiles] = useState([]);
11
11
  const [sizeValidationError, setSizeValidationError] = useState(null);
12
+ const [typeValidationError, setTypeValidationError] = useState(null);
12
13
  const instanceId = useId();
13
14
  const hasFileCallbacks = !!onFilesAdded || !!onFilesRemoved;
14
15
  const shouldManageFiles = showFileList || hasFileCallbacks;
@@ -51,7 +52,7 @@ const DropZone_DropZone = ({ label = 'Drop here', showFileList = true, disabled,
51
52
  const { valid, oversized } = validateFileSizes(newFileList);
52
53
  if (oversized.length > 0) {
53
54
  const oversizedNames = oversized.map((file)=>file.name).join(', ');
54
- setSizeValidationError(`Error: ${oversizedNames} ${1 === oversized.length ? 'exceeds' : 'exceed'} maximum file size of ${maxFileSize}`);
55
+ setSizeValidationError(`${oversizedNames} ${1 === oversized.length ? 'exceeds' : 'exceed'} maximum file size of ${maxFileSize}`);
55
56
  } else setSizeValidationError(null);
56
57
  if (0 === valid.length) return;
57
58
  const newEntries = valid.map((file, index)=>({
@@ -68,7 +69,17 @@ const DropZone_DropZone = ({ label = 'Drop here', showFileList = true, disabled,
68
69
  };
69
70
  const handleFileDrop = async (event)=>{
70
71
  let fileItems = event.items.filter((file)=>'file' === file.kind);
71
- if (acceptedFileTypes && acceptedFileTypes.length > 0) fileItems = fileItems.filter((file)=>matchesFileTypes(file, acceptedFileTypes));
72
+ if (acceptedFileTypes && acceptedFileTypes.length > 0) {
73
+ const allFileItems = [
74
+ ...fileItems
75
+ ];
76
+ fileItems = fileItems.filter((file)=>matchesFileTypes(file, acceptedFileTypes));
77
+ const unsupportedItems = allFileItems.filter((file)=>!matchesFileTypes(file, acceptedFileTypes));
78
+ if (unsupportedItems.length > 0 && shouldManageFiles) {
79
+ const unsupportedNames = unsupportedItems.map((item)=>item.name || 'Unknown file').join(', ');
80
+ setTypeValidationError(`${unsupportedNames} ${1 === unsupportedItems.length ? 'is not a supported file type' : 'are not supported file types'}`);
81
+ } else setTypeValidationError(null);
82
+ } else setTypeValidationError(null);
72
83
  if (!allowsMultiple && fileItems.length > 1) fileItems = fileItems.slice(0, 1);
73
84
  if (shouldManageFiles) {
74
85
  const filePromises = fileItems.map((item)=>{
@@ -103,6 +114,14 @@ const DropZone_DropZone = ({ label = 'Drop here', showFileList = true, disabled,
103
114
  };
104
115
  const showManagedFileList = showFileList && files.length > 0;
105
116
  const showFileInfo = !!supportedFormats || !!maxFileSize;
117
+ const getErrorMessage = ()=>{
118
+ if (errorMessage) return errorMessage;
119
+ const errors = [];
120
+ if (typeValidationError) errors.push(typeValidationError);
121
+ if (sizeValidationError) errors.push(sizeValidationError);
122
+ return errors.length > 0 ? errors.join('. ') : null;
123
+ };
124
+ const displayError = getErrorMessage();
106
125
  return /*#__PURE__*/ jsxs(Container, {
107
126
  ...containerProps,
108
127
  children: [
@@ -131,8 +150,8 @@ const DropZone_DropZone = ({ label = 'Drop here', showFileList = true, disabled,
131
150
  })
132
151
  ]
133
152
  }),
134
- (errorMessage || sizeValidationError) && /*#__PURE__*/ jsx(ErrorMessageText, {
135
- children: errorMessage || sizeValidationError
153
+ displayError && /*#__PURE__*/ jsx(ErrorMessageText, {
154
+ children: displayError
136
155
  })
137
156
  ]
138
157
  }),
@@ -164,10 +183,10 @@ const DropZone_DropZone = ({ label = 'Drop here', showFileList = true, disabled,
164
183
  children: file.name
165
184
  }),
166
185
  !disabled && /*#__PURE__*/ jsx(Button, {
167
- icon: "close",
168
- size: "small",
186
+ tiny: true,
169
187
  subtle: true,
170
188
  secondary: true,
189
+ icon: "close",
171
190
  onClick: ()=>handleRemoveFile(file.id)
172
191
  })
173
192
  ]
@@ -230,7 +249,8 @@ const ErrorMessageText = styled(StyledText)(({ theme })=>({
230
249
  }));
231
250
  const FileList = styled.div(({ theme })=>({
232
251
  display: 'flex',
233
- flexDirection: 'column',
252
+ flexDirection: 'row',
253
+ flexWrap: 'wrap',
234
254
  gap: theme.size.xs
235
255
  }));
236
256
  const FileItem = styled.div(({ theme })=>({
@@ -245,7 +265,7 @@ const FileItem = styled.div(({ theme })=>({
245
265
  }));
246
266
  const FileName = styled.div(({ theme })=>({
247
267
  fontSize: theme.font.size.sm,
248
- lineHeight: '14px',
268
+ lineHeight: '12px',
249
269
  flex: 1,
250
270
  overflow: 'hidden',
251
271
  textOverflow: 'ellipsis',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavv/ui",
3
- "version": "2.3.7-alpha.1",
3
+ "version": "2.3.7-alpha.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {