Skip to content

docs(attachments): add high-quality preview example for image file #960

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

Merged
Merged
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
29 changes: 28 additions & 1 deletion components/attachments/demo/with-sender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ const Demo = () => {

const senderRef = React.useRef<GetRef<typeof Sender>>(null);

React.useEffect(() => {
// Clear all created object URLs when the component is unmounted
return () => {
items.forEach((item) => {
if (item.url?.startsWith('blob:')) {
URL.revokeObjectURL(item.url);
}
});
};
}, []);

const senderHeader = (
<Sender.Header
title="Attachments"
Expand All @@ -27,7 +38,23 @@ const Demo = () => {
// Mock not real upload file
beforeUpload={() => false}
items={items}
onChange={({ fileList }) => setItems(fileList)}
onChange={({ file, fileList }) => {
const updatedFileList = fileList.map((item) => {
if (item.uid === file.uid && file.status !== 'removed' && item.originFileObj) {
// clear URL
if (item.url?.startsWith('blob:')) {
URL.revokeObjectURL(item.url);
}
// create new preview URL
return {
...item,
url: URL.createObjectURL(item.originFileObj),
};
}
return item;
});
setItems(updatedFileList);
}}
placeholder={(type) =>
type === 'drop'
? {
Expand Down