-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d82aff
commit 8680e79
Showing
3 changed files
with
63 additions
and
33 deletions.
There are no files selected for viewing
41 changes: 27 additions & 14 deletions
41
packages/react/src/components/file-upload/file-upload-dropzone.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
packages/solid/src/components/file-upload/file-upload-dropzone.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
packages/vue/src/components/file-upload/file-upload-dropzone.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |