Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIx File Upload #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions examples/email/src/modules/emailPage/components/NewEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,23 @@ const NewEmail: React.FC<NewEmailProps> = ({ replyTo }) => {
))}
</Box>
<FileUpload id="file-upload" onChange={handleFileUpload}>
<Button
disabled={fileAttachment.length === 1}
variant="outline"
size="extraSmall"
>
<PaperclipIcon width={16} height={16} />
<Text>Choose File</Text>
</Button>
<label htmlFor="file-upload">
<Button
disabled={fileAttachment.length === 1}
variant="outline"
size="extraSmall"
onClick={(e) => {
e.preventDefault();
const label = document.querySelector(
`label[for="file-upload"]`
) as HTMLLabelElement | null;
label?.click();
}}
>
<PaperclipIcon width={16} height={16} />
<Text>Choose File</Text>
</Button>
</label>
</FileUpload>
<Button
onClick={sendHandler}
Expand Down
4 changes: 2 additions & 2 deletions examples/email/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6802,7 +6802,7 @@ __metadata:

"shared-components@file:../../packages/shared-components::locator=email-app%40workspace%3A.":
version: 0.1.0
resolution: "shared-components@file:../../packages/shared-components#../../packages/shared-components::hash=2a0c9e&locator=email-app%40workspace%3A."
resolution: "shared-components@file:../../packages/shared-components#../../packages/shared-components::hash=7c4fa1&locator=email-app%40workspace%3A."
dependencies:
"@emotion/react": "npm:^11.13.0"
"@radix-ui/react-dialog": "npm:^1.1.1"
Expand All @@ -6823,7 +6823,7 @@ __metadata:
peerDependencies:
react: ^18.3.1
react-dom: ^18.3.1
checksum: 10/087e67f0222975179d77acfb8fcf5e03e41606321966c384a224c327deca3e0543f1a1d611ebdb5e78ab93bbd209784753c406e8aeae0eaec1cb4d95dedd81b4
checksum: 10/119704823277de12a38993c983d9c60c77ce862fbb966d0e7a793928688d76cbc461b0914143d7619ffd6eed3dd7406c53477a6a5e9181937c81eb03b89f8578
languageName: node
linkType: hard

Expand Down
18 changes: 2 additions & 16 deletions packages/shared-components/src/blocks/fileUpload/FileUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DragEventHandler, forwardRef, ReactNode, useRef } from 'react';
import { DragEventHandler, forwardRef, ReactNode } from 'react';
import styled, { FlattenSimpleInterpolation } from 'styled-components';

export type FileUploadProps = {
Expand All @@ -23,29 +23,15 @@ const Container = styled.div<{ css?: FlattenSimpleInterpolation }>`

export const FileUpload = forwardRef<HTMLInputElement, FileUploadProps>(
({ disabled, children, onChange, onDrop, id }, ref) => {
const inputRef = useRef<HTMLInputElement | null>(null);

const handleDragOver: DragEventHandler<HTMLDivElement> = (e) => {
e.preventDefault();
};

const handleClick = () => {
if (inputRef.current && !disabled) {
inputRef.current.click();
}
};

return (
<Container
ref={ref}
onDrop={onDrop}
onDragOver={handleDragOver}
onClick={handleClick}
>
<Container ref={ref} onDrop={onDrop} onDragOver={handleDragOver}>
{children}
<input
id={id}
ref={inputRef}
type="file"
accept="image/*"
hidden={true}
Expand Down