feat: wip import resource UI

This commit is contained in:
Ahmed Bouhuolia
2024-03-20 04:55:35 +02:00
parent aba06991d4
commit 1d8cec5069
21 changed files with 291 additions and 118 deletions

View File

@@ -1,5 +1,6 @@
// @ts-nocheck
import React from 'react';
import { Ref, useCallback } from 'react';
import clsx from 'classnames';
import {
Accept,
@@ -226,6 +227,7 @@ export const Dropzone = (_props: DropzoneProps) => {
});
const isIdle = !isDragAccept && !isDragReject;
assignRef(openRef, open);
return (
<DropzoneProvider
@@ -264,3 +266,26 @@ Dropzone.displayName = '@mantine/dropzone/Dropzone';
Dropzone.Accept = DropzoneAccept;
Dropzone.Idle = DropzoneIdle;
Dropzone.Reject = DropzoneReject;
type PossibleRef<T> = Ref<T> | undefined;
export function assignRef<T>(ref: PossibleRef<T>, value: T) {
if (typeof ref === 'function') {
ref(value);
} else if (typeof ref === 'object' && ref !== null && 'current' in ref) {
(ref as React.MutableRefObject<T>).current = value;
}
}
export function mergeRefs<T>(...refs: PossibleRef<T>[]) {
return (node: T | null) => {
refs.forEach((ref) => assignRef(ref, node));
};
}
export function useMergedRef<T>(...refs: PossibleRef<T>[]) {
return useCallback(mergeRefs(...refs), refs);
}