@mbao01/common 0.0.34 → 0.0.35

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,10 +1,13 @@
1
1
  /// <reference types="react" />
2
- import type { FileUploaderProps } from "./types";
2
+ import type { FileUploaderInputProps, FileUploaderProps } from "./types";
3
3
  export declare const FileUploader: {
4
4
  ({ className, dropzoneOptions, value, onValueChange, reSelect, orientation, children, dir, ...props }: FileUploaderProps): import("react/jsx-runtime").JSX.Element;
5
5
  displayName: string;
6
6
  Content: import("react").ForwardRefExoticComponent<import("react").HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
7
- Input: import("react").ForwardRefExoticComponent<import("react").HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
7
+ Input: {
8
+ ({ className, children, ...props }: FileUploaderInputProps): import("react/jsx-runtime").JSX.Element;
9
+ displayName: string;
10
+ };
8
11
  Item: import("react").ForwardRefExoticComponent<{
9
12
  index: number;
10
13
  } & import("react").HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
@@ -7,12 +7,14 @@ export type FileUploaderProps = {
7
7
  dropzoneOptions: DropzoneOptions;
8
8
  orientation?: "horizontal" | "vertical";
9
9
  } & React.HTMLAttributes<HTMLDivElement>;
10
+ export type FileUploaderInputProps = React.InputHTMLAttributes<HTMLInputElement>;
10
11
  export type DirectionOptions = "rtl" | "ltr" | undefined;
11
12
  export type FileUploaderContextType = {
12
13
  dropzoneState: DropzoneState;
13
14
  isLOF: boolean;
14
15
  isFileTooBig: boolean;
15
16
  removeFileFromSet: (index: number) => void;
17
+ removeAll: () => void;
16
18
  activeIndex: number;
17
19
  setActiveIndex: Dispatch<SetStateAction<number>>;
18
20
  orientation: "horizontal" | "vertical";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mbao01/common",
3
3
  "private": false,
4
- "version": "0.0.34",
4
+ "version": "0.0.35",
5
5
  "type": "module",
6
6
  "author": "Ayomide Bakare",
7
7
  "license": "MIT",
@@ -145,5 +145,5 @@
145
145
  "react-dom": "^18.2.0",
146
146
  "typescript": "^5.2.2"
147
147
  },
148
- "gitHead": "cc3e285416d8c9184e0bf597400550d08847001e"
148
+ "gitHead": "4e024b19d151c05b6c1580f461e348f5376c33b9"
149
149
  }
@@ -4,7 +4,11 @@ import { forwardRef, useCallback, useEffect, useRef, useState } from "react";
4
4
  import { useDropzone, FileRejection } from "react-dropzone";
5
5
  import { toast } from "sonner";
6
6
  import { TrashIcon } from "@radix-ui/react-icons";
7
- import type { DirectionOptions, FileUploaderProps } from "./types";
7
+ import type {
8
+ DirectionOptions,
9
+ FileUploaderInputProps,
10
+ FileUploaderProps,
11
+ } from "./types";
8
12
  import { cn } from "../../utilities";
9
13
  import { FileUploaderContext } from "./FileUploaderContext";
10
14
  import { useFileUpload } from "./useFileUpload";
@@ -44,6 +48,10 @@ export const FileUploader = ({
44
48
  [value, onValueChange]
45
49
  );
46
50
 
51
+ const removeAll = useCallback(() => {
52
+ onValueChange(null);
53
+ }, [onValueChange]);
54
+
47
55
  const handleKeyDown = useCallback(
48
56
  (e: React.KeyboardEvent<HTMLDivElement>) => {
49
57
  e.preventDefault();
@@ -169,6 +177,7 @@ export const FileUploader = ({
169
177
  isLOF,
170
178
  isFileTooBig,
171
179
  removeFileFromSet,
180
+ removeAll,
172
181
  activeIndex,
173
182
  setActiveIndex,
174
183
  orientation,
@@ -262,15 +271,15 @@ const FileUploaderItem = forwardRef<
262
271
 
263
272
  FileUploaderItem.displayName = "FileUploaderItem";
264
273
 
265
- const FileUploaderInput = forwardRef<
266
- HTMLDivElement,
267
- React.HTMLAttributes<HTMLDivElement>
268
- >(({ className, children, ...props }, ref) => {
274
+ const FileUploaderInput = ({
275
+ className,
276
+ children,
277
+ ...props
278
+ }: FileUploaderInputProps) => {
269
279
  const { dropzoneState, isFileTooBig, isLOF } = useFileUpload();
270
280
  const rootProps = isLOF ? {} : dropzoneState.getRootProps();
271
281
  return (
272
282
  <div
273
- ref={ref}
274
283
  {...props}
275
284
  className={`relative w-full ${
276
285
  isLOF ? "opacity-50 cursor-not-allowed " : "cursor-pointer "
@@ -293,14 +302,15 @@ const FileUploaderInput = forwardRef<
293
302
  {children}
294
303
  </div>
295
304
  <input
296
- ref={dropzoneState.inputRef}
305
+ {...props}
297
306
  disabled={isLOF}
307
+ ref={dropzoneState.inputRef}
298
308
  {...dropzoneState.getInputProps()}
299
309
  className={`${isLOF ? "cursor-not-allowed" : ""}`}
300
310
  />
301
311
  </div>
302
312
  );
303
- });
313
+ };
304
314
 
305
315
  FileUploaderInput.displayName = "FileInput";
306
316
 
@@ -9,6 +9,9 @@ export type FileUploaderProps = {
9
9
  orientation?: "horizontal" | "vertical";
10
10
  } & React.HTMLAttributes<HTMLDivElement>;
11
11
 
12
+ export type FileUploaderInputProps =
13
+ React.InputHTMLAttributes<HTMLInputElement>;
14
+
12
15
  export type DirectionOptions = "rtl" | "ltr" | undefined;
13
16
 
14
17
  export type FileUploaderContextType = {
@@ -16,6 +19,7 @@ export type FileUploaderContextType = {
16
19
  isLOF: boolean;
17
20
  isFileTooBig: boolean;
18
21
  removeFileFromSet: (index: number) => void;
22
+ removeAll: () => void;
19
23
  activeIndex: number;
20
24
  setActiveIndex: Dispatch<SetStateAction<number>>;
21
25
  orientation: "horizontal" | "vertical";