Skip to content

Commit

Permalink
refactor: implement dropzone props
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Jan 13, 2025
1 parent 0d82aff commit 8680e79
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 33 deletions.
41 changes: 27 additions & 14 deletions packages/react/src/components/file-upload/file-upload-dropzone.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import { mergeProps } from '@zag-js/react'
import { forwardRef } from 'react'
import { type HTMLProps, type PolymorphicProps, ark } from '../factory'
import { useFileUploadContext } from './use-file-upload-context'
import type { DropzoneProps } from "@zag-js/file-upload";
import { mergeProps } from "@zag-js/react";
import { forwardRef } from "react";
import { createSplitProps } from "../../utils/create-split-props";
import { type HTMLProps, type PolymorphicProps, ark } from "../factory";
import { useFileUploadContext } from "./use-file-upload-context";

export interface FileUploadDropzoneBaseProps extends PolymorphicProps {}
export interface FileUploadDropzoneProps extends HTMLProps<'div'>, FileUploadDropzoneBaseProps {}
export interface FileUploadDropzoneBaseProps
extends PolymorphicProps,
DropzoneProps {}
export interface FileUploadDropzoneProps
extends HTMLProps<"div">,
FileUploadDropzoneBaseProps {}

export const FileUploadDropzone = forwardRef<HTMLDivElement, FileUploadDropzoneProps>(
(props, ref) => {
const fileUpload = useFileUploadContext()
const mergedProps = mergeProps(fileUpload.getDropzoneProps(), props)
export const FileUploadDropzone = forwardRef<
HTMLDivElement,
FileUploadDropzoneProps
>((props, ref) => {
const [dropzoneProps, localProps] = createSplitProps<DropzoneProps>()(props, [
"disableClick",
]);
const fileUpload = useFileUploadContext();
const mergedProps = mergeProps(
fileUpload.getDropzoneProps(dropzoneProps),
localProps,
);

return <ark.div {...mergedProps} ref={ref} />
},
)
return <ark.div {...mergedProps} ref={ref} />;
});

FileUploadDropzone.displayName = 'FileUploadDropzone'
FileUploadDropzone.displayName = "FileUploadDropzone";
30 changes: 21 additions & 9 deletions packages/solid/src/components/file-upload/file-upload-dropzone.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import { mergeProps } from '@zag-js/solid'
import { type HTMLProps, type PolymorphicProps, ark } from '../factory'
import { useFileUploadContext } from './use-file-upload-context'
import type { DropzoneProps } from "@zag-js/file-upload";
import { mergeProps } from "@zag-js/solid";
import { createSplitProps } from "../../utils/create-split-props";
import { type HTMLProps, type PolymorphicProps, ark } from "../factory";
import { useFileUploadContext } from "./use-file-upload-context";

export interface FileUploadDropzoneBaseProps extends PolymorphicProps<'div'> {}
export interface FileUploadDropzoneProps extends HTMLProps<'div'>, FileUploadDropzoneBaseProps {}
export interface FileUploadDropzoneBaseProps
extends PolymorphicProps<"div">,
DropzoneProps {}
export interface FileUploadDropzoneProps
extends HTMLProps<"div">,
FileUploadDropzoneBaseProps {}

export const FileUploadDropzone = (props: FileUploadDropzoneProps) => {
const fileUpload = useFileUploadContext()
const mergedProps = mergeProps(() => fileUpload().getDropzoneProps(), props)
const [dropzoneProps, localProps] = createSplitProps<DropzoneProps>()(props, [
"disableClick",
]);
const fileUpload = useFileUploadContext();
const mergedProps = mergeProps(
() => fileUpload().getDropzoneProps(dropzoneProps),
localProps,
);

return <ark.div {...mergedProps} />
}
return <ark.div {...mergedProps} />;
};
25 changes: 15 additions & 10 deletions packages/vue/src/components/file-upload/file-upload-dropzone.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
<script lang="ts">
import type { HTMLAttributes } from 'vue'
import type { PolymorphicProps } from '../factory'
import type { DropzoneProps } from "@zag-js/file-upload";
import type { HTMLAttributes } from "vue";
import type { PolymorphicProps } from "../factory";
export interface FileUploadDropzoneBaseProps extends PolymorphicProps {}
export interface FileUploadDropzoneBaseProps
extends PolymorphicProps,
DropzoneProps {}
export interface FileUploadDropzoneProps
extends FileUploadDropzoneBaseProps,
/**
* @vue-ignore
*/
HTMLAttributes {}
extends FileUploadDropzoneBaseProps,
/**
* @vue-ignore
*/
HTMLAttributes {}
</script>

<script setup lang="ts">
import { ark } from '../factory'
import { useFileUploadContext } from './use-file-upload-context'
import { useForwardExpose } from '../../utils'
defineProps<FileUploadDropzoneProps>()
const props = withDefaults(defineProps<FileUploadDropzoneProps>(), {
disableClick: undefined,
} satisfies BooleanDefaults<DropzoneProps>)
const fileUpload = useFileUploadContext()
useForwardExpose()
</script>

<template>
<ark.div v-bind="fileUpload.getDropzoneProps()" :as-child="asChild">
<ark.div v-bind="fileUpload.getDropzoneProps(props)" :as-child="asChild">
<slot />
</ark.div>
</template>

0 comments on commit 8680e79

Please sign in to comment.