mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 10:31:50 +08:00
feat: file upload components
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
import Button from '@/ui/button/button';
|
||||||
|
import { FC, useRef, ChangeEvent, ReactElement } from 'react';
|
||||||
|
import { styled } from '@/styles';
|
||||||
|
interface Props {
|
||||||
|
uploadType?: string;
|
||||||
|
view?: ReactElement;
|
||||||
|
accept?: string;
|
||||||
|
fileChange: (file: File) => void;
|
||||||
|
}
|
||||||
|
export const Upload: FC<Props> = props => {
|
||||||
|
const { fileChange, accept } = props;
|
||||||
|
const input_ref = useRef<HTMLInputElement>(null);
|
||||||
|
const _chooseFile = () => {
|
||||||
|
if (input_ref.current) {
|
||||||
|
input_ref.current.click();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const _handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const files = e.target.files;
|
||||||
|
if (!files) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const file = files[0];
|
||||||
|
fileChange(file);
|
||||||
|
if (input_ref.current) {
|
||||||
|
input_ref.current.value = '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<UploadStyle onClick={_chooseFile}>
|
||||||
|
{props.view ?? <Button>Upload</Button>}
|
||||||
|
<input
|
||||||
|
ref={input_ref}
|
||||||
|
type="file"
|
||||||
|
style={{ display: 'none' }}
|
||||||
|
onChange={_handleInputChange}
|
||||||
|
accept={accept}
|
||||||
|
/>
|
||||||
|
</UploadStyle>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const UploadStyle = styled('div')(() => {
|
||||||
|
return {
|
||||||
|
display: 'inline-block',
|
||||||
|
};
|
||||||
|
});
|
||||||
@@ -16,6 +16,7 @@ import { WorkspaceDelete } from './delete';
|
|||||||
import { Workspace as StoreWorkspace } from '@blocksuite/store';
|
import { Workspace as StoreWorkspace } from '@blocksuite/store';
|
||||||
import { debounce } from '@/utils';
|
import { debounce } from '@/utils';
|
||||||
import { WorkspaceLeave } from './leave';
|
import { WorkspaceLeave } from './leave';
|
||||||
|
import { Upload } from '@/components/file-upload';
|
||||||
|
|
||||||
export const GeneralPage = ({
|
export const GeneralPage = ({
|
||||||
workspace,
|
workspace,
|
||||||
@@ -71,7 +72,14 @@ export const GeneralPage = ({
|
|||||||
|
|
||||||
return workspace ? (
|
return workspace ? (
|
||||||
<div>
|
<div>
|
||||||
<StyledSettingH2 marginTop={56}>Workspace Avatar</StyledSettingH2>
|
<StyledSettingH2 marginTop={56}>
|
||||||
|
Workspace Avatar
|
||||||
|
<Upload
|
||||||
|
fileChange={file => {
|
||||||
|
console.log(file);
|
||||||
|
}}
|
||||||
|
></Upload>
|
||||||
|
</StyledSettingH2>
|
||||||
<StyledSettingAvatarContent>
|
<StyledSettingAvatarContent>
|
||||||
<StyledSettingAvatar
|
<StyledSettingAvatar
|
||||||
alt="workspace avatar"
|
alt="workspace avatar"
|
||||||
|
|||||||
Reference in New Issue
Block a user