diff --git a/packages/circuit-ui/components/ImageInput/ImageInput.tsx b/packages/circuit-ui/components/ImageInput/ImageInput.tsx index 34e6ec5600..bfb8080c9f 100644 --- a/packages/circuit-ui/components/ImageInput/ImageInput.tsx +++ b/packages/circuit-ui/components/ImageInput/ImageInput.tsx @@ -14,11 +14,13 @@ */ /** @jsx jsx */ -import { ChangeEvent, Fragment, InputHTMLAttributes, useState } from 'react'; +import { ChangeEvent, InputHTMLAttributes, useState } from 'react'; import { css, jsx } from '@emotion/core'; +import { Bin } from '@sumup/icons'; import Avatar from '../Avatar'; import Label from '../Label'; +import IconButton from '../IconButton'; import styled from '../../styles/styled'; import { uniqueId } from '../../util/id'; import { focusOutline, hideVisually } from '../../styles/style-mixins'; @@ -26,20 +28,24 @@ import { focusOutline, hideVisually } from '../../styles/style-mixins'; export interface ImageInputProps extends Omit, 'size'> { /** - * label + * A clear and concise description of the image input's purpose. */ label: string; /** - * alt + * A unique identifier for the input element. If not defined, a generated id is used. */ - alt: string; + id?: string; /** - * imageUrl + * An existing image URL to be displayed in the image input. */ imageUrl?: string; + /** + * An accessible label for the "remove" icon button. + */ + removeButtonLabel: string; } -const Input = styled.input( +const HiddenInput = styled.input( ({ theme }) => css` ${hideVisually()}; @@ -50,11 +56,29 @@ const Input = styled.input( `, ); -const StyledAvatar = styled(Avatar)` - :hover { - filter: brightness(90%); - cursor: pointer; - } +const StyledAvatar = styled(Avatar)( + ({ theme }) => css` + &:hover { + filter: brightness(90%); + cursor: pointer; + } + &:hover + button { + background-color: ${theme.colors.p900}; + border-color: ${theme.colors.p900}; + } + `, +); + +const ActionButton = styled(IconButton)( + ({ theme }) => css` + position: absolute; + right: -${theme.spacings.bit}; + bottom: -${theme.spacings.bit}; + `, +); + +const AddButton = styled(ActionButton)` + pointer-events: none; `; /** @@ -63,8 +87,8 @@ const StyledAvatar = styled(Avatar)` export const ImageInput = ({ label, imageUrl: initialImageUrl, - alt, id: customId, + removeButtonLabel, ...props }: ImageInputProps): JSX.Element => { const id = customId || uniqueId('imageinput_'); @@ -79,8 +103,12 @@ export const ImageInput = ({ }; return ( - - + - + {imageUrl && ( + setImageUrl(undefined)} + > + + + )} + ); };