Last active
May 6, 2024 12:31
-
-
Save yoavniran/f3b6e3f14a67d7a0ddcae3df82fc60b9 to your computer and use it in GitHub Desktop.
React-Uploady preview with progress demo - CustomImagePreview.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import styled from "styled-components" | |
import { useItemProgressListener } from "@rpldy/uploady"; | |
const PreviewImage = styled.img` | |
margin: 5px; | |
max-width: 200px; | |
height: auto; | |
transition: opacity 0.4s; | |
${({ completed }) => `opacity: ${completed / 100};`} | |
`; | |
const CustomImagePreview = ({ id, url }) => { | |
const [completed, setCompleted] = useState(0); | |
useItemProgressListener(item => { | |
if (item.id === id) { | |
setCompleted(item.completed); | |
} | |
}); | |
return <PreviewImage src={url} completed={completed} />; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment