import React from 'react'
import { styled } from '@styled-components'
import { Box } from '../../atoms/box/index.js'
import { Icon } from '../../atoms/icon/index.js'
import { Button } from '../../atoms/button/index.js'
import { Text } from '../../atoms/text/index.js'
import { humanFileSize } from '../../utils/index.js'
const DropZoneImg = styled.div<{ src: string }>`
width: 100%;
height: 100%;
background-image: url('${({ src }) => src}');
background-size: cover;
background-repeat: no-repeat;
background-position: 50% 50%;
border-radius: ${({ theme }) => theme.space.sm};
`
const Wrapper = styled.div`
padding: ${({ theme }) => theme.space.md};
display: flex;
align-items: center;
margin-top: ${({ theme }) => theme.space.lg};
gap: ${({ theme }) => theme.space.lg};
border: ${({ theme }) => theme.borders.default};
border-color: ${({ theme }) => theme.colors.grey40};
border-radius: ${({ theme }) => theme.space.sm};
`
/**
* @memberof DropZoneItem
* @alias DropZoneItemProps
*/
export type DropZoneItemProps = {
/**
* Actual file buffer
*/
file?: File
/**
* Handler function triggered after clicking remove
*/
onRemove?: () => void
/**
* Preview image. If `file` is given and it is a image then `src` will be
* overridden by this image.
*/
src?: string
/**
* filename. If 'file' is given it overrides what was given as a `filename`
*/
filename?: string
}
/**
* @classdesc
*
*
*
* Single uploaded file. Usually it is used within {@link DropZone}, but it can also be
* reused anywhere
*
* ### Usage
*
* ```javascript
* import { DropZoneItem, DropZoneItemProps } from '@adminjs/design-system'
* ```
*
* @see DropZoneItem
* @hideconstructor
* @see DropZoneItemProps
* @example
* return (
*
* )
* @component
* @subcategory Molecules
* @section design-system
*/
const DropZoneItem: React.FC = (props) => {
const { file, onRemove, filename } = props
let { src } = props
if (file && ['image/png', 'image/jpeg', 'image/gif'].includes(file.type)) {
src = URL.createObjectURL(file)
}
return (
{src ? : }
{file?.name || filename}
{file && (
{new Date(file.lastModified).toLocaleString()} {humanFileSize(file.size, 'MB')}
)}
{onRemove && (
)}
)
}
DropZoneItem.displayName = 'DropZoneItem'
export { DropZoneItem }
export default DropZoneItem