-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e052a1
commit 6ba066b
Showing
13 changed files
with
268 additions
and
157 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,66 @@ | ||
import React, { useState } from "react" | ||
import styles from "@/styles/components/image.module.css" | ||
import {ModalImage} from "@/components/modal"; | ||
import {CreditedImage} from "@/components/credits"; | ||
import {images} from "next/dist/build/webpack/config/blocks/images"; | ||
|
||
|
||
export interface ImageArrayProps { | ||
images: {url: string, name: string, credits: string, description: string}[] | ||
colour?: string | ||
enableModal?: boolean | ||
} | ||
|
||
export function ImageArray(props: ImageArrayProps) { | ||
const [currentImage, setCurrentImage] = useState(0) | ||
|
||
// Image slide show | ||
const nextImage = () => { | ||
if(currentImage === props.images.length - 1) { | ||
setCurrentImage(0) | ||
} else { | ||
setCurrentImage(currentImage + 1) | ||
} | ||
} | ||
|
||
const previousImage = () => { | ||
if(currentImage === 0) { | ||
setCurrentImage(props.images.length - 1) | ||
} else { | ||
setCurrentImage(currentImage - 1) | ||
} | ||
} | ||
|
||
return( | ||
<> | ||
<div className={styles.imageContainer}> | ||
{props.enableModal ? | ||
<ModalImage | ||
url={props.images[currentImage].url} | ||
description={props.images[currentImage].description} | ||
> | ||
<CreditedImage | ||
url={props.images[currentImage].url} | ||
alt={props.images[currentImage].name} | ||
credits={props.images[currentImage].credits} | ||
/> | ||
</ModalImage> | ||
: | ||
<CreditedImage url={props.images[currentImage].url} alt={props.images[currentImage].name} credits={props.images[currentImage].credits}/> | ||
} | ||
</div> | ||
{props.images.length > 1 && | ||
<div className={styles.imageControls}> | ||
<button onClick={previousImage}><</button> | ||
<div className={styles.dotsContainer}> | ||
{props.images.map((image, index) => { | ||
return <button key={index} onClick={() => setCurrentImage(index)} className={styles.dot + " " + (currentImage === index ? styles.active : "")}/> | ||
})} | ||
</div> | ||
<button onClick={nextImage}>></button> | ||
</div> | ||
} | ||
</> | ||
) | ||
|
||
} |
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
Oops, something went wrong.