Fix/SW-1563 accessibility

* fix(SW-1563): Added new IconButton component to the design system and removed Icon variant inside the Button component
* fix(SW-1563): Added buttons around clickable images and changed to design system components
* fix(SW-1563): Renamed variants to match Figma
* fix(SW-1563): Renamed AriaButton to ButtonRAC

Approved-by: Michael Zetterberg
Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-05-02 06:27:30 +00:00
parent efcbde1647
commit 8b32abbefc
32 changed files with 909 additions and 547 deletions

View File

@@ -0,0 +1,160 @@
.galleryContainer {
display: grid;
gap: var(--Space-x2);
padding: var(--Space-x2);
height: 100%;
overflow-y: auto;
background-color: var(--Base-Background-Primary-Normal);
}
.mobileGallery {
display: grid;
grid-template-columns: 1fr 1fr;
gap: var(--Space-x1);
padding-bottom: var(--Space-x3);
}
.thumbnailContainer {
position: relative;
height: 242px;
}
.fullWidthImage {
grid-column: 1 / -1;
height: 240px;
}
.imageButton {
position: relative;
height: 100%;
width: 100%;
padding: 0;
border-width: 0;
background-color: transparent;
cursor: pointer;
border-radius: var(--Corner-radius-Medium);
overflow: hidden;
z-index: 0;
&:focus-visible {
outline-offset: -2px; /* Adjust the outline offset as wrappers uses overflow-hidden */
}
}
.image {
transition: opacity 0.3s ease-in-out;
object-fit: cover;
z-index: -1;
}
@media screen and (max-width: 767px) {
.desktopCloseIcon,
.desktopGallery {
display: none;
}
.closeButton {
justify-self: start;
}
}
@media screen and (min-width: 768px) {
.mobileGallery,
.mobileCloseIcon {
display: none;
}
.galleryContainer {
padding: var(--Spacing-x5) var(--Spacing-x6);
}
.closeButton {
position: absolute;
top: var(--Space-x2);
right: var(--Space-x2);
z-index: 1;
}
.desktopGallery {
display: grid;
grid-template-rows: 28px 1fr 7.8125rem;
row-gap: var(--Spacing-x-one-and-half);
background-color: var(--Base-Background-Primary-Normal);
height: 100%;
position: relative;
overflow: hidden;
}
.galleryHeader {
display: flex;
align-items: center;
}
.imageCaption {
background-color: var(--Base-Surface-Subtle-Normal);
padding: var(--Spacing-x-half) var(--Spacing-x1);
border-radius: var(--Corner-radius-Small);
color: var(--Text-Secondary);
}
.mainImageWrapper {
position: relative;
width: 100%;
}
.mainImageContainer {
width: 100%;
height: 100%;
will-change: transform;
position: absolute;
}
.desktopThumbnailGrid {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: var(--Spacing-x1);
max-height: 7.8125rem;
overflow: hidden;
}
.thumbnailContainer {
height: 125px;
}
.fullWidthImage {
grid-column: auto;
height: auto;
}
.thumbnailContainer img {
border-radius: var(--Corner-radius-Small);
}
.navigationButton {
position: absolute;
top: 50%;
transform: translateY(-50%);
background-color: var(--Component-Button-Inverted-Fill-Default);
color: var(--Component-Button-Inverted-On-fill-Default);
border-radius: var(--Corner-radius-rounded);
padding: 10px;
cursor: pointer;
border-width: 0;
display: flex;
z-index: 1;
box-shadow: 0px 0px 8px 1px #0000001a;
&:hover {
background-color: var(--Component-Button-Inverted-Fill-Hover);
color: var(--Component-Button-Inverted-On-fill-Hover);
}
}
.galleryPrevButton {
left: var(--Spacing-x2);
}
.galleryNextButton {
right: var(--Spacing-x2);
}
}

View File

@@ -0,0 +1,202 @@
"use client"
import { AnimatePresence, motion } from "framer-motion"
import { useState } from "react"
import { Button as ButtonRAC } from "react-aria-components"
import { useIntl } from "react-intl"
import { IconButton } from "@scandic-hotels/design-system/IconButton"
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
import { Typography } from "@scandic-hotels/design-system/Typography"
import Image from "@/components/Image"
import styles from "./gallery.module.css"
import type { GalleryProps } from "@/types/components/lightbox/lightbox"
export default function Gallery({
images,
onClose,
onSelectImage,
onImageClick,
selectedImage,
hideLabel,
}: GalleryProps) {
const intl = useIntl()
const [animateLeft, setAnimateLeft] = useState(true)
const mainImage = selectedImage || images[0]
const mainImageIndex = images.findIndex((img) => img === mainImage)
function getThumbImages() {
const thumbs = []
for (let i = 1; i <= Math.min(5, images.length); i++) {
const index = (mainImageIndex + i) % images.length
thumbs.push(images[index])
}
return thumbs
}
function handleNext() {
setAnimateLeft(true)
const nextIndex = (mainImageIndex + 1) % images.length
onSelectImage(images[nextIndex])
}
function handlePrev() {
setAnimateLeft(false)
const prevIndex = (mainImageIndex - 1 + images.length) % images.length
onSelectImage(images[prevIndex])
}
const variants = {
initial: (animateLeft: boolean) => ({
opacity: 0,
x: animateLeft ? 300 : -300,
}),
animate: { opacity: 1, x: 0 },
exit: (animateLeft: boolean) => ({
opacity: 0,
x: animateLeft ? -300 : 300,
}),
}
return (
<div className={styles.galleryContainer}>
<IconButton
theme="Black"
style="Muted"
className={styles.closeButton}
onPress={onClose}
aria-label={intl.formatMessage({
defaultMessage: "Close",
})}
>
<MaterialIcon
icon="chevron_left"
color="CurrentColor"
size={24}
className={styles.mobileCloseIcon}
/>
<MaterialIcon
icon="close"
color="CurrentColor"
size={24}
className={styles.desktopCloseIcon}
/>
</IconButton>
{/* Desktop Gallery */}
<div className={styles.desktopGallery}>
<Typography variant="Body/Supporting text (caption)/smRegular">
<p className={styles.galleryHeader}>
{mainImage.caption && !hideLabel && (
<span className={styles.imageCaption}>{mainImage.caption}</span>
)}
</p>
</Typography>
<div className={styles.mainImageWrapper}>
<AnimatePresence initial={false} custom={animateLeft}>
<motion.div
key={mainImage.src}
className={styles.mainImageContainer}
custom={animateLeft}
variants={variants}
initial="initial"
animate="animate"
exit="exit"
transition={{ duration: 0.3 }}
>
<ButtonRAC
onPress={onImageClick}
className={styles.imageButton}
aria-label={intl.formatMessage({
defaultMessage: "Open image",
})}
>
<Image
src={mainImage.src}
alt={mainImage.alt}
fill
sizes="(min-width: 1000px) 1000px, 100vw"
className={styles.image}
/>
</ButtonRAC>
</motion.div>
</AnimatePresence>
<motion.button
className={`${styles.navigationButton} ${styles.galleryPrevButton}`}
onClick={handlePrev}
>
<MaterialIcon icon="arrow_back" color="CurrentColor" />
</motion.button>
<motion.button
className={`${styles.navigationButton} ${styles.galleryNextButton}`}
onClick={handleNext}
>
<MaterialIcon icon="arrow_forward" color="CurrentColor" />
</motion.button>
</div>
<div className={styles.desktopThumbnailGrid}>
<AnimatePresence initial={false}>
{getThumbImages().map((image, index) => (
<motion.div
key={image.smallSrc || image.src}
className={styles.thumbnailContainer}
initial={{ opacity: 0, x: 50 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -50 }}
transition={{ duration: 0.2, delay: index * 0.05 }}
>
<ButtonRAC
className={styles.imageButton}
onPress={() => onSelectImage(image)}
aria-label={intl.formatMessage({
defaultMessage: "Open image",
})}
>
<Image
src={image.smallSrc || image.src}
alt={image.alt}
fill
sizes="200px"
className={styles.image}
/>
</ButtonRAC>
</motion.div>
))}
</AnimatePresence>
</div>
</div>
{/* Mobile Gallery */}
<div className={styles.mobileGallery}>
{images.map((image, index) => (
<motion.div
key={image.smallSrc || image.src}
className={`${styles.thumbnailContainer} ${index % 3 === 0 ? styles.fullWidthImage : ""}`}
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3, delay: index * 0.05 }}
>
<ButtonRAC
className={styles.imageButton}
aria-label={intl.formatMessage({ defaultMessage: "Open image" })}
onPress={() => {
onSelectImage(image)
onImageClick()
}}
>
<Image
src={image.smallSrc || image.src}
alt={image.alt}
fill
sizes="100vw"
className={styles.image}
/>
</ButtonRAC>
</motion.div>
))}
</div>
</div>
)
}