"use client"; import { attachmentInputItem, type AttachmentInputItemVariantProps, } from "@seed-design/css/recipes/attachment-input-item"; import { composeRefs } from "@radix-ui/react-compose-refs"; import { dataAttr } from "@seed-design/dom-utils"; import { AttachmentDisplay as AttachmentDisplayPrimitive, AttachmentDisplayItemProvider, useAttachmentDisplayContext, useAttachmentDisplayItem, type DisplayItemEntry, } from "@seed-design/react-attachment-display"; import { Primitive, type PrimitiveProps } from "@seed-design/react-primitive"; import clsx from "clsx"; import * as React from "react"; import { createRenderTrackingContext } from "../../utils/createRenderTrackingContext"; import { createSlotRecipeContext } from "../../utils/createSlotRecipeContext"; const { useClassNames, ClassNamesProvider, withContext } = createSlotRecipeContext(attachmentInputItem); // Tracks whether a Backdrop (overlay) is rendered so the Thumbnail/Metadata can emit // `data-has-overlay` for the css recipe. Styling-only signal owned by the styled layer. const overlayTracker = createRenderTrackingContext("AttachmentDisplayItemOverlay"); export interface AttachmentDisplayItemProps extends Omit, PrimitiveProps, React.LiHTMLAttributes { entry: DisplayItemEntry; } export const AttachmentDisplayItem = React.forwardRef( ({ className, entry, ...props }, ref) => { const { stateProps } = useAttachmentDisplayContext(); const api = useAttachmentDisplayItem(entry); const [variantProps, otherProps] = attachmentInputItem.splitVariantProps({ type: "image", ...props, }); const classNames = attachmentInputItem(variantProps); return ( ); }, ); AttachmentDisplayItem.displayName = "AttachmentDisplayItem"; //////////////////////////////////////////////////////////////////////////////////// export interface AttachmentDisplayItemImageProps extends AttachmentDisplayPrimitive.ItemImageProps {} export const AttachmentDisplayItemImage = withContext< HTMLImageElement, AttachmentDisplayItemImageProps >(AttachmentDisplayPrimitive.ItemImage, "image"); //////////////////////////////////////////////////////////////////////////////////// export interface AttachmentDisplayItemThumbnailProps extends PrimitiveProps, React.HTMLAttributes {} export const AttachmentDisplayItemThumbnail = React.forwardRef< HTMLDivElement, AttachmentDisplayItemThumbnailProps >(({ className, ...props }, ref) => { const classNames = useClassNames(); const { stateProps } = useAttachmentDisplayContext(); const { isRendered } = overlayTracker.useRenderTracking(); return ( ); }); AttachmentDisplayItemThumbnail.displayName = "AttachmentDisplayItemThumbnail"; //////////////////////////////////////////////////////////////////////////////////// export interface AttachmentDisplayItemMetadataProps extends PrimitiveProps, React.HTMLAttributes {} export const AttachmentDisplayItemMetadata = React.forwardRef< HTMLDivElement, AttachmentDisplayItemMetadataProps >(({ className, ...props }, ref) => { const classNames = useClassNames(); const { stateProps } = useAttachmentDisplayContext(); const { isRendered } = overlayTracker.useRenderTracking(); return ( ); }); AttachmentDisplayItemMetadata.displayName = "AttachmentDisplayItemMetadata"; //////////////////////////////////////////////////////////////////////////////////// export interface AttachmentDisplayItemBackdropProps extends AttachmentDisplayPrimitive.ItemBackdropProps {} export const AttachmentDisplayItemBackdrop = React.forwardRef< HTMLDivElement, AttachmentDisplayItemBackdropProps >(({ className, ...props }, ref) => { const classNames = useClassNames(); const { trackRef } = overlayTracker.useRenderTracking(); return ( ); }); AttachmentDisplayItemBackdrop.displayName = "AttachmentDisplayItemBackdrop"; //////////////////////////////////////////////////////////////////////////////////// export interface AttachmentDisplayItemBadgeProps extends PrimitiveProps, React.HTMLAttributes {} export const AttachmentDisplayItemBadge = React.forwardRef< HTMLDivElement, AttachmentDisplayItemBadgeProps >(({ className, children, ...props }, ref) => { const classNames = useClassNames(); return ( {children} ); }); AttachmentDisplayItemBadge.displayName = "AttachmentDisplayItemBadge"; //////////////////////////////////////////////////////////////////////////////////// export interface AttachmentDisplayItemActionButtonProps extends PrimitiveProps, React.ButtonHTMLAttributes {} export const AttachmentDisplayItemActionButton = React.forwardRef< HTMLButtonElement, AttachmentDisplayItemActionButtonProps >(({ className, ...props }, ref) => { const classNames = useClassNames(); return ( ); }); AttachmentDisplayItemActionButton.displayName = "AttachmentDisplayItemActionButton"; //////////////////////////////////////////////////////////////////////////////////// export interface AttachmentDisplayItemRemoveButtonProps extends AttachmentDisplayPrimitive.ItemRemoveButtonProps {} export const AttachmentDisplayItemRemoveButton = withContext< HTMLButtonElement, AttachmentDisplayItemRemoveButtonProps >(AttachmentDisplayPrimitive.ItemRemoveButton, "removeButton");