-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Misc. changes related to media grid, figcaption handling, demo login …
…layout (#249)
- Loading branch information
Showing
16 changed files
with
234 additions
and
176 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 was deleted.
Oops, something went wrong.
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,8 @@ | ||
import dynamic from "next/dynamic"; | ||
import React from "react"; | ||
|
||
const NoSsr = (props) => <React.Fragment>{props.children}</React.Fragment>; | ||
|
||
export default dynamic(() => Promise.resolve(NoSsr), { | ||
ssr: false, | ||
}); |
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,79 @@ | ||
import Image from "next/image"; | ||
import { useEffect, useRef, useState } from "react"; | ||
|
||
export const Grid = ({ images, actions, onClick }) => { | ||
const ref = useRef<HTMLDivElement>(null); | ||
const [width, setWidth] = useState(200); | ||
|
||
useEffect(() => { | ||
handleResize(); | ||
}, [ref.current]); | ||
|
||
useEffect(() => { | ||
window.addEventListener("resize", handleResize); | ||
|
||
return () => { | ||
window.removeEventListener("resize", handleResize); | ||
}; | ||
}, []); | ||
|
||
const handleResize = () => { | ||
if (ref.current) { | ||
const node = ref.current.firstChild; | ||
if (node) { | ||
//@ts-ignore | ||
setWidth(node.clientWidth); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="grid" ref={ref}> | ||
{images.map((image, index) => { | ||
image = getDimensions({ ...image }, width - 20); | ||
return ( | ||
<div className="image-item"> | ||
<Image | ||
{...image} | ||
src={image.url} | ||
loading="lazy" | ||
alt="kkkk" | ||
onClick={() => onClick && onClick(index)} | ||
/> | ||
{actions && actions(index)} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
<style jsx>{` | ||
.grid { | ||
display: grid; | ||
grid-gap: 10px; | ||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); | ||
grid-auto-rows: minmax(50px, auto); | ||
} | ||
.image-item { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-evenly; | ||
background: rgb(var(--content-bg)); | ||
flex-direction: column; | ||
} | ||
`}</style> | ||
</> | ||
); | ||
}; | ||
|
||
function getDimensions(image, availableWidth: number) { | ||
const aspectRatio = image.width / image.height; | ||
image.width = availableWidth; | ||
image.height = availableWidth / aspectRatio; | ||
|
||
while (image.height > availableWidth) { | ||
image.width -= 1; | ||
image.height -= 1; | ||
} | ||
|
||
return image; | ||
} |
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
Oops, something went wrong.