-
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
82e8852
commit 20ef906
Showing
11 changed files
with
751 additions
and
721 deletions.
There are no files selected for viewing
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
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
43 changes: 24 additions & 19 deletions
43
packages/react/src/components/file-upload/file-upload-item-preview-image.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,28 +1,33 @@ | ||
import { mergeProps } from '@zag-js/react' | ||
import { forwardRef, useEffect, useState } from 'react' | ||
import { type HTMLProps, type PolymorphicProps, ark } from '../factory' | ||
import { useFileUploadContext } from './use-file-upload-context' | ||
import { useFileUploadItemPropsContext } from './use-file-upload-item-props-context' | ||
import { mergeProps } from "@zag-js/react"; | ||
import { forwardRef, useEffect, useState } from "react"; | ||
import { type HTMLProps, type PolymorphicProps, ark } from "../factory"; | ||
import { useFileUploadContext } from "./use-file-upload-context"; | ||
import { useFileUploadItemPropsContext } from "./use-file-upload-item-props-context"; | ||
|
||
export interface FileUploadItemPreviewImageBaseProps extends PolymorphicProps {} | ||
export interface FileUploadItemPreviewImageProps | ||
extends HTMLProps<'img'>, | ||
FileUploadItemPreviewImageBaseProps {} | ||
extends HTMLProps<"img">, | ||
FileUploadItemPreviewImageBaseProps {} | ||
|
||
export const FileUploadItemPreviewImage = forwardRef< | ||
HTMLImageElement, | ||
FileUploadItemPreviewImageProps | ||
HTMLImageElement, | ||
FileUploadItemPreviewImageProps | ||
>((props, ref) => { | ||
const [url, setUrl] = useState<string>('') | ||
const fileUpload = useFileUploadContext() | ||
const itemProps = useFileUploadItemPropsContext() | ||
const mergedProps = mergeProps(fileUpload.getItemPreviewImageProps({ ...itemProps, url }), props) | ||
const [url, setUrl] = useState<string>(""); | ||
const fileUpload = useFileUploadContext(); | ||
const itemProps = useFileUploadItemPropsContext(); | ||
const mergedProps = mergeProps( | ||
fileUpload.getItemPreviewImageProps({ ...itemProps, url }), | ||
props, | ||
); | ||
|
||
useEffect(() => { | ||
return fileUpload.createFileUrl(itemProps.file, (url) => setUrl(url)) | ||
}, [itemProps, fileUpload]) | ||
useEffect(() => { | ||
return fileUpload.createFileUrl(itemProps.file, (url) => setUrl(url)); | ||
}, [itemProps, fileUpload]); | ||
|
||
return <ark.img {...mergedProps} ref={ref} /> | ||
}) | ||
if (!url) return null; | ||
|
||
FileUploadItemPreviewImage.displayName = 'FileUploadItemPreviewImage' | ||
return <ark.img {...mergedProps} ref={ref} />; | ||
}); | ||
|
||
FileUploadItemPreviewImage.displayName = "FileUploadItemPreviewImage"; |
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
Oops, something went wrong.