Skip to content

Commit

Permalink
fix(form-builder): allow for upload of items when dropping over text (s…
Browse files Browse the repository at this point in the history
…anity-io#3234)

* fix(form-builder): allow for upload of items when dropping over text

* refactor(form-builder): fix pointer events to match all message and add useMemo
  • Loading branch information
RitaDias authored Apr 7, 2022
1 parent d42ef78 commit b5f4b49
Showing 1 changed file with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import React, {useMemo} from 'react'
import {BinaryDocumentIcon, AccessDeniedIcon, ImageIcon, ReadOnlyIcon} from '@sanity/icons'
import {Flex, Text} from '@sanity/ui'
import styled from 'styled-components'
import {FileLike} from '../../../sanity/uploads/types'

interface Props {
Expand All @@ -13,11 +13,15 @@ interface Props {
directUploads: boolean
}

const RootFlex = styled(Flex)`
pointer-events: none;
`

export function PlaceholderText(props: Props) {
const {hoveringFiles, type, readOnly, acceptedFiles, rejectedFilesCount, directUploads} = props
const isFileType = type === 'file'

function MessageIcon() {
const messageIcon = useMemo(() => {
if (readOnly) {
return <ReadOnlyIcon />
}
Expand All @@ -27,13 +31,13 @@ export function PlaceholderText(props: Props) {
}

return isFileType ? <BinaryDocumentIcon /> : <ImageIcon />
}
}, [directUploads, hoveringFiles, isFileType, readOnly, rejectedFilesCount])

function MessageText() {
const messageText = useMemo(() => {
let message = `Drag or paste ${type} here`

if (!directUploads) {
message = `Can't upload files here`
return `Can't upload files here`
}

if (readOnly) {
Expand All @@ -49,23 +53,16 @@ export function PlaceholderText(props: Props) {
}
}

return (
<Text size={1} muted>
{message}
</Text>
)
}
return message
}, [acceptedFiles.length, directUploads, hoveringFiles, readOnly, rejectedFilesCount, type])

return (
<>
<Flex justify="center">
<Text muted>
<MessageIcon />
</Text>
</Flex>
<Flex justify="center">
<MessageText />
</Flex>
</>
<RootFlex align="center" gap={2} justify="center">
<Text muted>{messageIcon}</Text>

<Text size={1} muted>
{messageText}
</Text>
</RootFlex>
)
}

0 comments on commit b5f4b49

Please sign in to comment.