Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(components): WIP prototype LightBox changes #2310

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions packages/components/src/LightBox/LightBox.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@
}

.toolbar {
display: flex;
position: absolute;
top: 0;
right: 0;
z-index: var(--elevation-base);
padding: var(--space-small) var(--space-base);
color: var(--color-text--secondary);
font-size: var(--typography--fontSize-large);
background-color: var(--color-surface--background);
justify-content: space-between;
}

Expand All @@ -67,19 +68,59 @@
min-height: 0;
}

.overlay {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: var(--color-overlay);
}

.image {
position: absolute;
top: 50%;
max-width: 100%;
max-height: 100%;
max-width: 700px;
max-height: 700px;
margin: auto;
}

.backgroundBlur {
display: flex;
width: 100%;
height: 100%;
backdrop-filter: blur(10px);
background-color: var(--color-overlay);
}

.backgroundImage {
width: 100%;
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
}

.thumbnailList {
display: flex;
position: absolute;
bottom: 0;
width: 100%;
list-style: none;
gap: var(--space-base);
justify-content: center;

li {
display: block;
width: 70px;
height: 70px;
padding: var(--space-small);
border: 1px solid var(--color-white);
border-radius: var(--radius-base);

&[data-no-item] {
border-color: transparent;
}
}

.thumbnail {
display: block;
width: 100%;
height: 100%;
border-radius: var(--radius-base);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
background-origin: content-box;
}
}
5 changes: 4 additions & 1 deletion packages/components/src/LightBox/LightBox.module.css.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ declare const styles: {
readonly "toolbar": string;
readonly "title": string;
readonly "imagesWrapper": string;
readonly "overlay": string;
readonly "image": string;
readonly "backgroundBlur": string;
readonly "backgroundImage": string;
readonly "thumbnailList": string;
readonly "thumbnail": string;
};
export = styles;

116 changes: 73 additions & 43 deletions packages/components/src/LightBox/LightBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useIsMounted } from "@jobber/hooks/useIsMounted";
import styles from "./LightBox.module.css";
import { ButtonDismiss } from "../ButtonDismiss";
import { Button } from "../Button";
import { AtlantisThemeContextProvider } from "../AtlantisThemeContext";

interface PresentedImage {
title?: string;
Expand Down Expand Up @@ -126,52 +127,66 @@ export function LightBox({
const template = (
<>
{open && (
<div
className={styles.lightboxWrapper}
tabIndex={0}
aria-label="Lightbox"
key="Lightbox"
ref={lightboxRef}
>
<div className={styles.toolbar}>
<span className={styles.title}>
{images[currentImageIndex].title}
</span>
<ButtonDismiss ariaLabel="Close" onClick={handleRequestClose} />
</div>
<div className={styles.imagesWrapper}>
<AnimatePresence initial={false}>
<motion.img
key={currentImageIndex}
variants={variants}
src={images[currentImageIndex].url}
custom={direction}
className={styles.image}
style={{ y: "-50%" }}
initial="enter"
animate="center"
exit="exit"
transition={imageTransition}
drag="x"
dragConstraints={{ left: 0, right: 0 }}
dragElastic={1}
onDragEnd={handleOnDragEnd}
/>
</AnimatePresence>
</div>
<AtlantisThemeContextProvider dangerouslyOverrideTheme="dark">
<div
className={styles.lightboxWrapper}
tabIndex={0}
aria-label="Lightbox"
key="Lightbox"
ref={lightboxRef}
>
<div className={styles.toolbar}>
{/* {images[currentImageIndex].title} */}
<ButtonDismiss ariaLabel="Close" onClick={handleRequestClose} />
</div>
<div className={styles.imagesWrapper}>
<div
className={styles.backgroundImage}
onClick={handleRequestClose}
style={{
backgroundImage: `url("${images[currentImageIndex].url}")`,
}}
>
<div className={styles.backgroundBlur} />
</div>
<AnimatePresence initial={false}>
<motion.img
key={currentImageIndex}
variants={variants}
src={images[currentImageIndex].url}
custom={direction}
className={styles.image}
style={{ y: "-50%" }}
initial="enter"
animate="center"
exit="exit"
transition={imageTransition}
drag="x"
dragConstraints={{ left: 0, right: 0 }}
dragElastic={1}
onDragEnd={handleOnDragEnd}
/>
</AnimatePresence>
</div>

{images.length > 1 && (
<>
<PreviousButton onClick={debouncedHandlePrevious} />
<NextButton onClick={debouncedHandleNext} />
</>
)}
{images.length > 1 && (
<>
<PreviousButton onClick={debouncedHandlePrevious} />
<NextButton onClick={debouncedHandleNext} />
</>
)}

<div className={styles.toolbar}>
{images[currentImageIndex].caption}
<ul className={styles.thumbnailList}>
<ThumbnailListItem
imageUrl={images[currentImageIndex - 1]?.url}
/>
<ThumbnailListItem imageUrl={images[currentImageIndex]?.url} />
<ThumbnailListItem
imageUrl={images[currentImageIndex + 1]?.url}
/>
</ul>
</div>
<div className={styles.overlay} onClick={handleRequestClose} />
</div>
</AtlantisThemeContextProvider>
)}
</>
);
Expand Down Expand Up @@ -255,3 +270,18 @@ function togglePrintStyles(open: boolean) {
console.error(error);
}
}

function ThumbnailListItem({ imageUrl }: { readonly imageUrl?: string }) {
if (imageUrl) {
return (
<li>
<div
className={styles.thumbnail}
style={{ backgroundImage: `url("${imageUrl}")` }}
/>
</li>
);
}

return <li data-no-item />;
}
Loading