Skip to content

Commit 49faf6f

Browse files
committed
docs(attachments): add high-quality preview example for image attachments
1 parent c175f7d commit 49faf6f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

components/attachments/demo/with-sender.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { CloudUploadOutlined, LinkOutlined } from '@ant-design/icons';
22
import { Attachments, AttachmentsProps, Sender } from '@ant-design/x';
3-
import { App, Badge, Button, Flex, type GetProp, type GetRef, Typography } from 'antd';
3+
import { App, Badge, Button, Flex, type GetProp, type GetRef, Typography, UploadProps } from 'antd';
44
import React from 'react';
55

6+
type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0];
7+
68
const Demo = () => {
79
const [open, setOpen] = React.useState(true);
810
const [items, setItems] = React.useState<GetProp<AttachmentsProps, 'items'>>([]);
@@ -27,7 +29,20 @@ const Demo = () => {
2729
// Mock not real upload file
2830
beforeUpload={() => false}
2931
items={items}
30-
onChange={({ fileList }) => setItems(fileList)}
32+
onChange={({ file, fileList }) => {
33+
if (file.status === 'removed') {
34+
setItems(fileList);
35+
return;
36+
}
37+
file.url = window.URL.createObjectURL(file as FileType);
38+
const newFileList = fileList.slice();
39+
newFileList.splice(
40+
fileList.findIndex((item) => item.uid === file.uid),
41+
1,
42+
file,
43+
);
44+
setItems(newFileList);
45+
}}
3146
placeholder={(type) =>
3247
type === 'drop'
3348
? {

0 commit comments

Comments
 (0)