parent
28dbc5714c
commit
683f306193
6 changed files with 183 additions and 58 deletions
@ -0,0 +1,3 @@ |
||||
import { createContext } from 'react'; |
||||
|
||||
export const g_modal_gallery_context = createContext([{}, () => { }]); |
@ -0,0 +1,82 @@ |
||||
import React, { useState, useEffect } from 'react'; |
||||
import Box from '@material-ui/core/Box'; |
||||
|
||||
import { makeStyles } from '@material-ui/core/styles'; |
||||
|
||||
const useStyles = makeStyles(theme => ({ |
||||
background: { |
||||
width: "100%", |
||||
height: "100%", |
||||
overflow: "auto", |
||||
position: "absolute", |
||||
"background-color": "rgba(0,0,0,1)", |
||||
'overflow': 'hidden', |
||||
}, |
||||
image_container: { |
||||
'width': '100%', |
||||
'height': '100%', |
||||
'overflow': 'hidden', |
||||
}, |
||||
image: { |
||||
'object-fit': 'contain', |
||||
'width': '100%', |
||||
'height': '100%', |
||||
'overflow': 'hidden', |
||||
}, |
||||
})); |
||||
|
||||
export function GalleryImageRender(props) { |
||||
const { src } = props; |
||||
const classes = useStyles(); |
||||
|
||||
return ( |
||||
<img src={src} |
||||
className={classes.image} /> |
||||
); |
||||
} |
||||
|
||||
export function GalleryImage(props) { |
||||
const { photo } = props; |
||||
|
||||
// First show the fast (thumbnail) image.
|
||||
const [src, setSrc] = useState(photo.state.thumbnailpath); |
||||
|
||||
// Start a fetch of the full image, then show that.
|
||||
useEffect(() => { |
||||
console.log("Fetching..."); |
||||
fetch(photo.state.path) |
||||
.then(() => { |
||||
console.log("Fetch done. setting image."); |
||||
setSrc(photo.state.path); |
||||
}) |
||||
}, []); |
||||
|
||||
return ( |
||||
<GalleryImageRender src={src}/> |
||||
); |
||||
} |
||||
|
||||
export function Gallery(props) { |
||||
const { onClose, items, current_item } = props; |
||||
const classes = useStyles(); |
||||
|
||||
var maybe_photo = false; |
||||
if (items && items.length > 0 && current_item < items.length) { |
||||
maybe_photo = items[current_item]; |
||||
} |
||||
|
||||
return ( |
||||
<> |
||||
<Box |
||||
className={classes.background} |
||||
onClick={onClose}> |
||||
<Box className={classes.image_container}> |
||||
{ |
||||
maybe_photo && |
||||
<GalleryImage photo={maybe_photo} /> |
||||
} |
||||
</Box> |
||||
</Box> |
||||
</> |
||||
); |
||||
} |
@ -0,0 +1,37 @@ |
||||
import React, { useState, useEffect } from 'react' |
||||
import ReactDOM from 'react-dom' |
||||
|
||||
import { makeStyles } from '@material-ui/core/styles' |
||||
|
||||
const useStyles = makeStyles(theme => ({ |
||||
modal: { |
||||
position: "fixed", |
||||
top: '0px', |
||||
left: '0px', |
||||
width: '100%', |
||||
height: '100vh', |
||||
'z-index': '1300', //Material UI "modal" value
|
||||
}, |
||||
})); |
||||
|
||||
export function Modal(props) { |
||||
const { children, active } = props; |
||||
const [el, setEl] = useState(null); |
||||
const classes = useStyles(); |
||||
|
||||
useEffect(() => { |
||||
const new_el = document.createElement('div'); |
||||
new_el.className = classes.modal; |
||||
setEl(new_el); |
||||
document.getElementById('root').appendChild(new_el); |
||||
}, []); |
||||
|
||||
if(!el) { |
||||
return <></>; |
||||
} |
||||
if(el) { |
||||
el.style.visibility = active ? 'visible' : 'hidden'; |
||||
} |
||||
return ReactDOM.createPortal(children, el); |
||||
} |
||||
|
Loading…
Reference in new issue