import React from 'react'
import styled from 'styled-components'
import { Box } from '../../atoms/box/box'
import { Icon } from '../../atoms/icon'
import { Button } from '../../atoms/button'
const DropZoneImg = styled.div<{src: string}>`
width: 80px;
height: 80px;
margin-right: ${({ theme }): string => theme.space.lg};
background-image: url('${({ src }): string => src}');
background-size: cover;
background-repeat: no-repeat;
background-position: 50% 50%;
display: inline-block;
`
/**
* @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 '@admin-bro/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}
{onRemove && (
)}
)
}
export { DropZoneItem }
export default DropZoneItem