-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: image preview enhancement (#385)
* feat: dialog content enhancement * update * feat: image carousel * update Co-authored-by: boojack <[email protected]>
- Loading branch information
Showing
4 changed files
with
122 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import * as utils from "../helpers/utils"; | ||
import Icon from "./Icon"; | ||
import { generateDialog } from "./Dialog"; | ||
import "../less/preview-image-carousel-dialog.less"; | ||
|
||
interface Props extends DialogProps { | ||
imgUrls: string[]; | ||
index: number; | ||
} | ||
|
||
const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, index }: Props) => { | ||
const handleCloseBtnClick = () => { | ||
destroy(); | ||
}; | ||
|
||
const handleDownloadBtnClick = () => { | ||
const a = document.createElement("a"); | ||
a.href = imgUrls[index]; | ||
a.download = `memos-${utils.getDateTimeString(Date.now())}.png`; | ||
a.click(); | ||
}; | ||
|
||
const handleImgContainerClick = () => { | ||
destroy(); | ||
}; | ||
|
||
const handlePrevBtnClick = () => { | ||
destroy(); | ||
if (index > 0) { | ||
showPreviewImageCarouselDialog(imgUrls, index - 1); | ||
} else { | ||
showPreviewImageCarouselDialog(imgUrls, imgUrls.length - 1); | ||
} | ||
}; | ||
|
||
const handleNextBtnClick = () => { | ||
destroy(); | ||
if (index < imgUrls.length - 1) { | ||
showPreviewImageCarouselDialog(imgUrls, index + 1); | ||
} else { | ||
showPreviewImageCarouselDialog(imgUrls, 0); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="btns-container"> | ||
<button className="btn" onClick={handleCloseBtnClick}> | ||
<Icon.X className="icon-img" /> | ||
</button> | ||
<button className="btn" onClick={handleDownloadBtnClick}> | ||
<Icon.Download className="icon-img" /> | ||
</button> | ||
<button className="btn" onClick={handlePrevBtnClick}> | ||
<Icon.ArrowLeft className="icon-img" /> | ||
</button> | ||
<button className="btn" onClick={handleNextBtnClick}> | ||
<Icon.ArrowRight className="icon-img" /> | ||
</button> | ||
</div> | ||
<div className="img-container" onClick={handleImgContainerClick}> | ||
<img onClick={(e) => e.stopPropagation()} src={imgUrls[index]} /> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default function showPreviewImageCarouselDialog(imgUrls: string[], index: number): void { | ||
generateDialog( | ||
{ | ||
className: "preview-image-carousel-dialog", | ||
}, | ||
PreviewImageDialog, | ||
{ imgUrls, index } | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@import "./mixin.less"; | ||
|
||
.preview-image-carousel-dialog { | ||
@apply p-0; | ||
z-index: 101; | ||
background-color: rgba(0, 0, 0, 0.6); | ||
|
||
> .dialog-container { | ||
@apply flex flex-col justify-center items-center relative w-full h-full p-0; | ||
background-color: unset; | ||
|
||
> .btns-container { | ||
@apply fixed top-8 right-8 flex flex-col justify-start items-center; | ||
|
||
> .btn { | ||
@apply mb-3 last:mb-0 w-8 h-8 p-1 cursor-pointer rounded opacity-90 bg-gray-300 z-10 shadow-md hover:opacity-70; | ||
|
||
> .icon-img { | ||
@apply w-6 h-auto; | ||
} | ||
} | ||
} | ||
|
||
> .img-container { | ||
@apply w-full h-full p-4 flex flex-col justify-center items-center; | ||
background-color: unset; | ||
.hide-scroll-bar(); | ||
|
||
> img { | ||
@apply h-auto w-auto max-w-full max-h-full shadow; | ||
} | ||
} | ||
} | ||
} |