-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-67: Add image preview and lightbox
- Loading branch information
Showing
12 changed files
with
207 additions
and
189 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
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,41 @@ | ||
import { Backdrop, Box, Container, Link, Popover, } from "@mui/material"; | ||
import { UsersState } from "../store/features/users/userSlice"; | ||
import "./styles/UserInfo.css"; | ||
import "./styles/common.css" | ||
import UserInfo from "./UserInfo"; | ||
import { useState } from "react"; | ||
import { openInBrowser } from "../helper/BrowserUtils"; | ||
|
||
interface LightBoxImageProps { | ||
src: string; | ||
} | ||
|
||
function LightBoxImage(props: LightBoxImageProps) { | ||
const [open, setOpen]: any = useState(false); | ||
|
||
const handleClose = () => { | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<Box> | ||
<img src={props.src} onClick={() => setOpen(true)} style={{ maxWidth: '100%', maxHeight: '100%', cursor: 'pointer' }} /> | ||
<Backdrop | ||
sx={{ color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1, backdropFilter: 'blur(5px)', padding: '50px 10px 10px 10px' }} | ||
open={open} | ||
onClick={handleClose} | ||
> | ||
<Box sx={{ display: 'flex', flexDirection: 'column', height: '100%', width: '100%' }}> | ||
<Box sx={{ flexShrink: 0, display: 'contents' }}> | ||
<img src={props.src} style={{ height: 'auto', width: 'auto', maxWidth: '100%', maxHeight: 'calc(100% - 2em)', objectFit: 'contain' }} /> | ||
</Box> | ||
<Box sx={{ flexShrink: 1, textAlign: 'center'}}> | ||
<Link href="#" color="inherit" underline="hover" onClick={() => openInBrowser(props.src)}>Open In Browser</Link> | ||
</Box> | ||
</Box> | ||
</Backdrop> | ||
</Box> | ||
); | ||
} | ||
|
||
export default LightBoxImage; |
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,5 @@ | ||
import { invoke } from "@tauri-apps/api"; | ||
|
||
export function openInBrowser(url: string) { | ||
invoke('open_browser', { url: url }); | ||
} |
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,26 @@ | ||
import { Container } from '@mui/material'; | ||
import parse, { DOMNode, HTMLReactParserOptions, domToReact } from 'html-react-parser'; | ||
import LightBoxImage from '../components/LightBoxImage'; | ||
|
||
export default class MessageUIHelper { | ||
private input: string; | ||
|
||
constructor(input: string) { | ||
this.input = input; | ||
} | ||
|
||
build() { | ||
const options: HTMLReactParserOptions = { | ||
replace: ({ name, attribs, children }: any) => { | ||
switch (name) { | ||
case 'img': | ||
return (<Container > | ||
<LightBoxImage src={attribs.src} /> | ||
</Container>); | ||
} | ||
}, | ||
}; | ||
|
||
return parse(this.input, options); | ||
} | ||
} |
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
Oops, something went wrong.