@zayne-labs/ui-react 0.6.2 → 0.7.0
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.
- package/dist/esm/{chunk-ENDWJXPF.js → chunk-L2SROZYQ.js} +2 -2
- package/dist/esm/{chunk-ENDWJXPF.js.map → chunk-L2SROZYQ.js.map} +1 -1
- package/dist/esm/common/await/index.d.ts +7 -5
- package/dist/esm/common/await/index.js +37 -2
- package/dist/esm/common/await/index.js.map +1 -1
- package/dist/esm/common/focus-scope/index.d.ts +32 -0
- package/dist/esm/common/focus-scope/index.js +232 -0
- package/dist/esm/common/focus-scope/index.js.map +1 -0
- package/dist/esm/common/show/index.js +48 -2
- package/dist/esm/common/show/index.js.map +1 -1
- package/dist/esm/common/slot/index.js +1 -1
- package/dist/esm/common/suspense-with-boundary/index.js +11 -2
- package/dist/esm/common/suspense-with-boundary/index.js.map +1 -1
- package/dist/esm/common/switch/index.js +38 -2
- package/dist/esm/common/switch/index.js.map +1 -1
- package/dist/esm/common/teleport/index.js +28 -1
- package/dist/esm/common/teleport/index.js.map +1 -1
- package/dist/esm/ui/card/index.js +43 -4
- package/dist/esm/ui/card/index.js.map +1 -1
- package/dist/esm/ui/carousel/index.js +272 -4
- package/dist/esm/ui/carousel/index.js.map +1 -1
- package/dist/esm/ui/drag-scroll/index.js +117 -2
- package/dist/esm/ui/drag-scroll/index.js.map +1 -1
- package/dist/esm/ui/drop-zone/index.js +137 -2
- package/dist/esm/ui/drop-zone/index.js.map +1 -1
- package/dist/esm/ui/form/index.js +508 -12
- package/dist/esm/ui/form/index.js.map +1 -1
- package/package.json +8 -11
- package/dist/esm/chunk-CB2EZJYW.js +0 -31
- package/dist/esm/chunk-CB2EZJYW.js.map +0 -1
- package/dist/esm/chunk-CWUEUCR5.js +0 -3
- package/dist/esm/chunk-CWUEUCR5.js.map +0 -1
- package/dist/esm/chunk-DJIVSXN7.js +0 -24
- package/dist/esm/chunk-DJIVSXN7.js.map +0 -1
- package/dist/esm/chunk-E42DOTGX.js +0 -119
- package/dist/esm/chunk-E42DOTGX.js.map +0 -1
- package/dist/esm/chunk-FPCKBOJN.js +0 -50
- package/dist/esm/chunk-FPCKBOJN.js.map +0 -1
- package/dist/esm/chunk-GVL6BLX5.js +0 -274
- package/dist/esm/chunk-GVL6BLX5.js.map +0 -1
- package/dist/esm/chunk-LIUXM66P.js +0 -509
- package/dist/esm/chunk-LIUXM66P.js.map +0 -1
- package/dist/esm/chunk-NPIJ4XZP.js +0 -13
- package/dist/esm/chunk-NPIJ4XZP.js.map +0 -1
- package/dist/esm/chunk-PNYEIX7F.js +0 -3
- package/dist/esm/chunk-PNYEIX7F.js.map +0 -1
- package/dist/esm/chunk-PXYYL2LL.js +0 -45
- package/dist/esm/chunk-PXYYL2LL.js.map +0 -1
- package/dist/esm/chunk-RQZL6ZG6.js +0 -139
- package/dist/esm/chunk-RQZL6ZG6.js.map +0 -1
- package/dist/esm/chunk-SVQ4WBSO.js +0 -40
- package/dist/esm/chunk-SVQ4WBSO.js.map +0 -1
- package/dist/esm/common/index.d.ts +0 -12
- package/dist/esm/common/index.js +0 -12
- package/dist/esm/common/index.js.map +0 -1
- package/dist/esm/index.d.ts +0 -20
- package/dist/esm/index.js +0 -19
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/ui/index.d.ts +0 -11
- package/dist/esm/ui/index.js +0 -19
- package/dist/esm/ui/index.js.map +0 -1
|
@@ -1,5 +1,140 @@
|
|
|
1
|
-
|
|
2
|
-
import '../../chunk-OHG7GB7O.js';
|
|
1
|
+
import { cnMerge } from '../../chunk-OHG7GB7O.js';
|
|
3
2
|
import '../../chunk-PZ5AY32C.js';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { useRef, useState } from 'react';
|
|
5
|
+
import { handleFileValidation } from '@zayne-labs/toolkit-core';
|
|
6
|
+
import { useToggle, useCallbackRef } from '@zayne-labs/toolkit-react';
|
|
7
|
+
import { mergeTwoProps, composeRefs } from '@zayne-labs/toolkit-react/utils';
|
|
8
|
+
import { isFunction } from '@zayne-labs/toolkit-type-helpers';
|
|
9
|
+
|
|
10
|
+
var useDropZone = (props) => {
|
|
11
|
+
const inputRef = useRef(null);
|
|
12
|
+
const {
|
|
13
|
+
allowedFileTypes,
|
|
14
|
+
children,
|
|
15
|
+
classNames,
|
|
16
|
+
disallowDuplicates = true,
|
|
17
|
+
existingFiles,
|
|
18
|
+
extraInputProps,
|
|
19
|
+
extraRootProps,
|
|
20
|
+
fileLimit,
|
|
21
|
+
maxFileSize,
|
|
22
|
+
onUpload,
|
|
23
|
+
onUploadError,
|
|
24
|
+
onUploadSuccess,
|
|
25
|
+
render,
|
|
26
|
+
validator
|
|
27
|
+
// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- Can be undefined
|
|
28
|
+
} = props ?? {};
|
|
29
|
+
const [isDragging, toggleIsDragging] = useToggle(false);
|
|
30
|
+
const [acceptedFiles, setAcceptedFiles] = useState([]);
|
|
31
|
+
const handleFileUpload = useCallbackRef(
|
|
32
|
+
(event) => {
|
|
33
|
+
if (event.defaultPrevented) return;
|
|
34
|
+
if (event.type === "drop") {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
toggleIsDragging(false);
|
|
37
|
+
}
|
|
38
|
+
const fileList = event.type === "drop" ? event.dataTransfer.files : event.target.files;
|
|
39
|
+
if (fileList === null) {
|
|
40
|
+
console.warn("No file selected");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const validFilesArray = handleFileValidation({
|
|
44
|
+
existingFileArray: existingFiles,
|
|
45
|
+
newFileList: fileList,
|
|
46
|
+
onError: onUploadError,
|
|
47
|
+
onSuccess: onUploadSuccess,
|
|
48
|
+
validationSettings: {
|
|
49
|
+
allowedFileTypes,
|
|
50
|
+
disallowDuplicates,
|
|
51
|
+
fileLimit,
|
|
52
|
+
maxFileSize
|
|
53
|
+
},
|
|
54
|
+
validator
|
|
55
|
+
});
|
|
56
|
+
if (validFilesArray.length === 0) return;
|
|
57
|
+
setAcceptedFiles(validFilesArray);
|
|
58
|
+
onUpload?.({ acceptedFiles: validFilesArray, event });
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
const handleDragOver = (event) => {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
toggleIsDragging(true);
|
|
64
|
+
};
|
|
65
|
+
const handleDragLeave = (event) => {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
toggleIsDragging(false);
|
|
68
|
+
};
|
|
69
|
+
const getRenderProps = () => ({
|
|
70
|
+
acceptedFiles,
|
|
71
|
+
inputRef,
|
|
72
|
+
isDragging,
|
|
73
|
+
openFilePicker: () => inputRef.current?.click()
|
|
74
|
+
});
|
|
75
|
+
const computedChildren = children ?? render;
|
|
76
|
+
const getChildren = () => isFunction(computedChildren) ? computedChildren(getRenderProps()) : computedChildren;
|
|
77
|
+
const getRootProps = (rootProps) => {
|
|
78
|
+
const mergedRootProps = mergeTwoProps(extraRootProps, rootProps);
|
|
79
|
+
return {
|
|
80
|
+
...mergedRootProps,
|
|
81
|
+
className: cnMerge(
|
|
82
|
+
"relative isolate flex flex-col",
|
|
83
|
+
mergedRootProps.className,
|
|
84
|
+
classNames?.base,
|
|
85
|
+
isDragging && ["opacity-60", classNames?.activeDrag, rootProps?.classNames?.activeDrag]
|
|
86
|
+
),
|
|
87
|
+
"data-active-drag": isDragging,
|
|
88
|
+
"data-part": "root",
|
|
89
|
+
"data-scope": "dropzone",
|
|
90
|
+
onDragEnter: handleDragOver,
|
|
91
|
+
onDragLeave: handleDragLeave,
|
|
92
|
+
onDragOver: handleDragOver,
|
|
93
|
+
onDrop: handleFileUpload
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
const getInputProps = (inputProps) => {
|
|
97
|
+
const mergedInputProps = mergeTwoProps(extraInputProps, inputProps);
|
|
98
|
+
return {
|
|
99
|
+
...mergedInputProps,
|
|
100
|
+
accept: allowedFileTypes ? allowedFileTypes.join(", ") : mergedInputProps.accept,
|
|
101
|
+
className: cnMerge(
|
|
102
|
+
"absolute inset-0 z-[100] cursor-pointer opacity-0",
|
|
103
|
+
classNames?.input,
|
|
104
|
+
mergedInputProps.className
|
|
105
|
+
),
|
|
106
|
+
"data-active-drag": isDragging,
|
|
107
|
+
"data-part": "input",
|
|
108
|
+
"data-scope": "dropzone",
|
|
109
|
+
onChange: (event) => {
|
|
110
|
+
mergedInputProps.onChange?.(event);
|
|
111
|
+
handleFileUpload(event);
|
|
112
|
+
},
|
|
113
|
+
ref: composeRefs([inputRef, mergedInputProps.ref]),
|
|
114
|
+
type: "file"
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
acceptedFiles,
|
|
119
|
+
computedChildren,
|
|
120
|
+
getChildren,
|
|
121
|
+
getInputProps,
|
|
122
|
+
getRenderProps,
|
|
123
|
+
getRootProps,
|
|
124
|
+
handleDragLeave,
|
|
125
|
+
handleDragOver,
|
|
126
|
+
handleFileUpload,
|
|
127
|
+
inputRef,
|
|
128
|
+
isDragging
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/components/ui/drop-zone/drop-zone.tsx
|
|
133
|
+
function DropZone(props) {
|
|
134
|
+
const api = useDropZone(props);
|
|
135
|
+
return /* @__PURE__ */ React.createElement("div", { ...api.getRootProps() }, /* @__PURE__ */ React.createElement("input", { ...api.getInputProps() }), api.getChildren());
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { DropZone, useDropZone };
|
|
4
139
|
//# sourceMappingURL=index.js.map
|
|
5
140
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/ui/drop-zone/use-drop-zone.ts","../../../../src/components/ui/drop-zone/drop-zone.tsx"],"names":[],"mappings":";;;;;;;;;AAgGa,IAAA,WAAA,GAAc,CAAC,KAA4B,KAAA;AACvD,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A,CAAI,cACZ,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,OAAO,EAAA,EAAA,GAAG,IAAI,aAAc,EAAA,EAAG,CAE/B,EAAA,GAAA,CAAI,aACN,CAAA;AAEF","file":"index.js","sourcesContent":["\"use client\";\n\nimport { cnMerge } from \"@/lib/utils/cn\";\nimport { type FileValidationOptions, handleFileValidation } from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef, useToggle } from \"@zayne-labs/toolkit-react\";\nimport {\n\ttype DiscriminatedRenderProps,\n\ttype InferProps,\n\tcomposeRefs,\n\tmergeTwoProps,\n} from \"@zayne-labs/toolkit-react/utils\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useRef, useState } from \"react\";\n\ntype RenderProps = {\n\tacceptedFiles: File[];\n\tinputRef: React.RefObject<HTMLInputElement | null>;\n\tisDragging: boolean;\n\topenFilePicker: () => void;\n};\n\nexport type RootProps = InferProps<\"div\"> & {\n\tclassNames?: {\n\t\tactiveDrag?: string;\n\t\tbase?: string;\n\t};\n};\n\nexport type InputProps = InferProps<\"input\">;\n\ntype DropZoneRenderProps = DiscriminatedRenderProps<\n\tReact.ReactNode | ((props: RenderProps) => React.ReactNode)\n>;\n\nexport type UseDropZoneProps = DropZoneRenderProps & {\n\t/**\n\t * Allowed file types to be uploaded.\n\t */\n\tallowedFileTypes?: string[];\n\n\tclassNames?: { activeDrag?: string; base?: string; input?: string };\n\t/**\n\t * Whether to disallow duplicate files\n\t * @default true\n\t */\n\tdisallowDuplicates?: boolean;\n\n\t/**\n\t * Existing files to be uploaded\n\t */\n\texistingFiles?: File[];\n\n\t/**\n\t * Extra props to pass to the input element\n\t */\n\textraInputProps?: InputProps;\n\n\t/**\n\t * Extra props to pass to the root element\n\t */\n\textraRootProps?: RootProps;\n\n\t/**\n\t * Maximum number of files that can be uploaded.\n\t */\n\tfileLimit?: number;\n\n\t/**\n\t * Maximum file size in MB\n\t */\n\tmaxFileSize?: number;\n\n\t/**\n\t * Callback function to handle file upload\n\t */\n\tonUpload?: (details: {\n\t\tacceptedFiles: File[];\n\t\tevent: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLDivElement>;\n\t}) => void;\n\n\t/**\n\t * Callback function to handle file upload errors\n\t */\n\tonUploadError?: FileValidationOptions[\"onError\"];\n\n\t/**\n\t * Callback function to handle file upload success\n\t */\n\tonUploadSuccess?: FileValidationOptions[\"onSuccess\"];\n\n\t/**\n\t * Custom validator function to handle file validation\n\t */\n\tvalidator?: (context: { existingFileArray: File[] | undefined; newFileList: FileList }) => File[];\n};\n\nexport const useDropZone = (props: UseDropZoneProps) => {\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\n\tconst {\n\t\tallowedFileTypes,\n\t\tchildren,\n\t\tclassNames,\n\t\tdisallowDuplicates = true,\n\t\texistingFiles,\n\t\textraInputProps,\n\t\textraRootProps,\n\t\tfileLimit,\n\t\tmaxFileSize,\n\t\tonUpload,\n\t\tonUploadError,\n\t\tonUploadSuccess,\n\t\trender,\n\t\tvalidator,\n\t\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- Can be undefined\n\t} = props ?? {};\n\n\tconst [isDragging, toggleIsDragging] = useToggle(false);\n\n\tconst [acceptedFiles, setAcceptedFiles] = useState<File[]>([]);\n\n\tconst handleFileUpload = useCallbackRef(\n\t\t(event: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLDivElement>) => {\n\t\t\tif (event.defaultPrevented) return;\n\n\t\t\tif (event.type === \"drop\") {\n\t\t\t\tevent.preventDefault();\n\t\t\t\ttoggleIsDragging(false);\n\t\t\t}\n\n\t\t\tconst fileList =\n\t\t\t\tevent.type === \"drop\"\n\t\t\t\t\t? (event as React.DragEvent).dataTransfer.files\n\t\t\t\t\t: (event as React.ChangeEvent<HTMLInputElement>).target.files;\n\n\t\t\tif (fileList === null) {\n\t\t\t\tconsole.warn(\"No file selected\");\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst validFilesArray = handleFileValidation({\n\t\t\t\texistingFileArray: existingFiles,\n\t\t\t\tnewFileList: fileList,\n\t\t\t\tonError: onUploadError,\n\t\t\t\tonSuccess: onUploadSuccess,\n\t\t\t\tvalidationSettings: {\n\t\t\t\t\tallowedFileTypes,\n\t\t\t\t\tdisallowDuplicates,\n\t\t\t\t\tfileLimit,\n\t\t\t\t\tmaxFileSize,\n\t\t\t\t},\n\t\t\t\tvalidator,\n\t\t\t});\n\n\t\t\tif (validFilesArray.length === 0) return;\n\n\t\t\tsetAcceptedFiles(validFilesArray);\n\n\t\t\tonUpload?.({ acceptedFiles: validFilesArray, event });\n\t\t}\n\t);\n\n\tconst handleDragOver = (event: React.DragEvent<HTMLDivElement>) => {\n\t\tevent.preventDefault();\n\t\ttoggleIsDragging(true);\n\t};\n\n\tconst handleDragLeave = (event: React.DragEvent<HTMLDivElement>) => {\n\t\tevent.preventDefault();\n\t\ttoggleIsDragging(false);\n\t};\n\n\tconst getRenderProps = () =>\n\t\t({\n\t\t\tacceptedFiles,\n\t\t\tinputRef,\n\t\t\tisDragging,\n\t\t\topenFilePicker: () => inputRef.current?.click(),\n\t\t}) satisfies RenderProps;\n\n\tconst computedChildren = children ?? render;\n\n\tconst getChildren = () =>\n\t\tisFunction(computedChildren) ? computedChildren(getRenderProps()) : computedChildren;\n\n\tconst getRootProps = (rootProps?: RootProps) => {\n\t\tconst mergedRootProps = mergeTwoProps(extraRootProps, rootProps);\n\n\t\treturn {\n\t\t\t...mergedRootProps,\n\t\t\tclassName: cnMerge(\n\t\t\t\t\"relative isolate flex flex-col\",\n\t\t\t\tmergedRootProps.className,\n\t\t\t\tclassNames?.base,\n\t\t\t\tisDragging && [\"opacity-60\", classNames?.activeDrag, rootProps?.classNames?.activeDrag]\n\t\t\t),\n\t\t\t\"data-active-drag\": isDragging,\n\t\t\t\"data-part\": \"root\",\n\t\t\t\"data-scope\": \"dropzone\",\n\t\t\tonDragEnter: handleDragOver,\n\t\t\tonDragLeave: handleDragLeave,\n\t\t\tonDragOver: handleDragOver,\n\t\t\tonDrop: handleFileUpload,\n\t\t};\n\t};\n\n\tconst getInputProps = (inputProps?: InputProps) => {\n\t\tconst mergedInputProps = mergeTwoProps(extraInputProps, inputProps);\n\n\t\treturn {\n\t\t\t...mergedInputProps,\n\t\t\taccept: allowedFileTypes ? allowedFileTypes.join(\", \") : mergedInputProps.accept,\n\t\t\tclassName: cnMerge(\n\t\t\t\t\"absolute inset-0 z-[100] cursor-pointer opacity-0\",\n\t\t\t\tclassNames?.input,\n\t\t\t\tmergedInputProps.className\n\t\t\t),\n\t\t\t\"data-active-drag\": isDragging,\n\t\t\t\"data-part\": \"input\",\n\t\t\t\"data-scope\": \"dropzone\",\n\t\t\tonChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\t\tmergedInputProps.onChange?.(event);\n\t\t\t\thandleFileUpload(event);\n\t\t\t},\n\t\t\tref: composeRefs([inputRef, mergedInputProps.ref]),\n\t\t\ttype: \"file\",\n\t\t};\n\t};\n\n\treturn {\n\t\tacceptedFiles,\n\t\tcomputedChildren,\n\t\tgetChildren,\n\t\tgetInputProps,\n\t\tgetRenderProps,\n\t\tgetRootProps,\n\t\thandleDragLeave,\n\t\thandleDragOver,\n\t\thandleFileUpload,\n\t\tinputRef,\n\t\tisDragging,\n\t};\n};\n","import * as React from \"react\";\n\nimport { type UseDropZoneProps, useDropZone } from \"./use-drop-zone\";\n\nfunction DropZone(props: UseDropZoneProps) {\n\tconst api = useDropZone(props);\n\n\treturn (\n\t\t<div {...api.getRootProps()}>\n\t\t\t<input {...api.getInputProps()} />\n\n\t\t\t{api.getChildren()}\n\t\t</div>\n\t);\n}\n\nexport { DropZone };\n"]}
|