Skip to content

Commit

Permalink
SOEOPSFY24-206 | add slider component
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahongsf committed Nov 6, 2024
1 parent ca1b925 commit bbbb296
Show file tree
Hide file tree
Showing 18 changed files with 269 additions and 17 deletions.
52 changes: 52 additions & 0 deletions app/components/Slideshow/Carousel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { HTMLAttributes } from "react";
import { Slideshow } from "@/components/Slideshow/Slideshow";

type Props = HTMLAttributes<HTMLElement> & {
children: React.ReactNode;
};

export const Carousel = ({ children, ...props }: Props) => {
const slides = React.Children.toArray(children);

return (
<article {...props} aria-labelledby="carousel-label">
<div className="relative left-1/2 mb-32 mt-0 w-screen -translate-x-1/2">
<Slideshow className="mx-auto w-[calc(100%-50px)] xl:w-[calc(100%-150px)]">
{slides.map((slide, slideIndex) => {
return (
<CarouselSlide
key={slideIndex} // You can use slideIndex or slide.id if available
slide={slide}
slideNumber={slideIndex + 1}
totalSlides={slides.length}
/>
);
})}
</Slideshow>
</div>
</article>
);
};

const CarouselSlide = ({
slide,
slideNumber,
totalSlides,
}: {
slide: React.ReactNode;
slideNumber: number;
totalSlides: number;
}) => {
const labelId = `slide-${slideNumber}`;

return (
<div
role="group"
aria-roledescription="slide"
aria-labelledby={labelId}
aria-label={`${slideNumber} of ${totalSlides}`}
>
{slide}
</div>
);
};
127 changes: 127 additions & 0 deletions app/components/Slideshow/Slideshow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"use client";

import { HTMLAttributes, JSX, useEffect, useRef } from "react";
import Slider, { CustomArrowProps, Settings } from "react-slick";
import {
ArrowLongRightIcon,
ArrowLongLeftIcon,
} from "@heroicons/react/16/solid";
import { cnb } from "cnbuilder";

const NextArrow = ({ className, onClick }: CustomArrowProps) => {
const slickDisabled = className?.includes("slick-disabled");
return (
<button
className={cnb(
"hocus:outline-3 absolute right-5 top-1/2 z-50 flex h-20 w-20 items-center justify-center rounded-full border-2 border-white bg-digital-red hocus:bg-digital-red hocus:outline hocus:outline-digital-red",
{
"bg-black-40 hocus:bg-black-40 hocus:outline-0": slickDisabled,
},
)}
onClick={onClick}
aria-label="Next"
disabled={slickDisabled}
>
<ArrowLongRightIcon width={40} className="text-white" />
</button>
);
};

const PrevArrow = ({ className, onClick }: CustomArrowProps) => {
const slickDisabled = className?.includes("slick-disabled");
return (
<button
className={cnb(
"hocus:outline-3 absolute left-5 top-1/2 z-50 flex h-20 w-20 items-center justify-center rounded-full border-2 border-white bg-digital-red hocus:bg-digital-red hocus:outline hocus:outline-digital-red",
{
"bg-black-40 hocus:bg-black-40 hocus:outline-0": slickDisabled,
},
)}
onClick={onClick}
aria-label="Previous"
disabled={slickDisabled}
>
<ArrowLongLeftIcon width={40} className="text-white" />
</button>
);
};

type SlideshowProps = HTMLAttributes<HTMLDivElement> & {
children: JSX.Element | JSX.Element[];
slideshowProps?: Omit<Settings, "children">;
};

// Slide padding styles are added in the tailwind index.css file.
export const Slideshow = ({
children,
slideshowProps,
...props
}: SlideshowProps) => {
const slideShowRef = useRef<HTMLDivElement>(null);

const adjustSlideLinks = () => {
// Set tabindex attributes based on if the slides are visible or not.
const hiddenLinks = slideShowRef.current?.querySelectorAll(
".slick-slide:not(.slick-active) a",
);
if (hiddenLinks) {
[...hiddenLinks].map((link) => link.setAttribute("tabindex", "-1"));
}

const visibleLinks = slideShowRef.current?.querySelectorAll(
".slick-slide.slick-active a",
);
if (visibleLinks) {
[...visibleLinks].map((link) => link.removeAttribute("tabindex"));
}
};

useEffect(() => {
adjustSlideLinks();
}, []);

const settings: Settings = {
afterChange: () => adjustSlideLinks(),
autoplay: false,
centerMode: false,
className:
"[&_.slick-track]:flex [&_.slick-track] [&_.slick-slider]:relative [&_.slick-slide>div]:h-full [&_.slick-slide>div>div]:h-full",
dots: false,
infinite: false,
initialSlide: 0,
nextArrow: <NextArrow />,
prevArrow: <PrevArrow />,
slidesToScroll: 1,
slidesToShow: 3,
speed: 500,
responsive: [
{
breakpoint: 1200,
settings: {
slidesToShow: 2,
slidesToScroll: 1,
centerMode: false,
},
},
{
breakpoint: 768,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
centerMode: false,
},
},
],
...slideshowProps,
};
return (
<section
ref={slideShowRef}
{...props}
aria-roledescription="carousel"
className={cnb("relative", props.className)}
>
<Slider {...settings}>{children}</Slider>
</section>
);
};
2 changes: 1 addition & 1 deletion out/404.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/example.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions out/example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ f:I[3120,[],"MetadataBoundary"]
5:HL["/soe-centennial-nextjs/_next/static/media/b27868729ad8c262-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}]
6:HL["/soe-centennial-nextjs/_next/static/media/d90e10e85a15eaad-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}]
7:HL["/soe-centennial-nextjs/_next/static/media/db3cc5ff6037fbad-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}]
8:HL["/soe-centennial-nextjs/_next/static/css/8ffb7d69ec5bfd11.css","style"]
0:{"P":null,"b":"bvTuTpkh0u1y18TL7vMF9","p":"/soe-centennial-nextjs","c":["","example"],"i":false,"f":[[["",{"children":["example",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",["$","$9","c",{"children":[[["$","link","0",{"rel":"stylesheet","href":"/soe-centennial-nextjs/_next/static/css/8ffb7d69ec5bfd11.css","precedence":"next","crossOrigin":"$undefined","nonce":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__variable_6f86a8 __variable_cf1540 __variable_2df5e6 __variable_0f68e0","children":["$","$La",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$Lb",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]]}],{"children":["example",["$","$9","c",{"children":[null,["$","$La",null,{"parallelRouterKey":"children","segmentPath":["children","example","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$Lb",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]]}],{"children":["__PAGE__",["$","$9","c",{"children":["$Lc",null,["$","$Ld",null,{"children":"$Le"}]]}],{},null]},null]},null],["$","$9","h",{"children":[null,["$","$9","18KMif99nL_HGuaiPtR6X",{"children":[["$","$Lf",null,{"children":"$L10"}],["$","$L11",null,{"children":"$L12"}],["$","meta",null,{"name":"next-size-adjust"}]]}]]}]]],"m":"$undefined","G":["$13","$undefined"],"s":false,"S":true}
8:HL["/soe-centennial-nextjs/_next/static/css/6e166f209665cd3e.css","style"]
0:{"P":null,"b":"JlPzRU5Vr_WXUv9ctJK1X","p":"/soe-centennial-nextjs","c":["","example"],"i":false,"f":[[["",{"children":["example",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",["$","$9","c",{"children":[[["$","link","0",{"rel":"stylesheet","href":"/soe-centennial-nextjs/_next/static/css/6e166f209665cd3e.css","precedence":"next","crossOrigin":"$undefined","nonce":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__variable_6f86a8 __variable_cf1540 __variable_2df5e6 __variable_0f68e0","children":["$","$La",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$Lb",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]]}],{"children":["example",["$","$9","c",{"children":[null,["$","$La",null,{"parallelRouterKey":"children","segmentPath":["children","example","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$Lb",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]]}],{"children":["__PAGE__",["$","$9","c",{"children":["$Lc",null,["$","$Ld",null,{"children":"$Le"}]]}],{},null]},null]},null],["$","$9","h",{"children":[null,["$","$9","LYRPRloNIIqvXJ2WIrB32",{"children":[["$","$Lf",null,{"children":"$L10"}],["$","$L11",null,{"children":"$L12"}],["$","meta",null,{"name":"next-size-adjust"}]]}]]}]]],"m":"$undefined","G":["$13","$undefined"],"s":false,"S":true}
14:I[9811,["143","static/chunks/143-d5e7c922eea4f50f.js","932","static/chunks/932-fb842629337a0d1a.js","648","static/chunks/648-c2fc404aadb72cc6.js","691","static/chunks/691-cb9ee8f48ae8671c.js","265","static/chunks/265-99e99a0904e152b6.js","915","static/chunks/app/example/page-87f781fe0821337f.js"],"Skiplink"]
21:I[9298,["143","static/chunks/143-d5e7c922eea4f50f.js","932","static/chunks/932-fb842629337a0d1a.js","648","static/chunks/648-c2fc404aadb72cc6.js","691","static/chunks/691-cb9ee8f48ae8671c.js","265","static/chunks/265-99e99a0904e152b6.js","915","static/chunks/app/example/page-87f781fe0821337f.js"],"FeatureHero"]
22:I[843,["143","static/chunks/143-d5e7c922eea4f50f.js","932","static/chunks/932-fb842629337a0d1a.js","648","static/chunks/648-c2fc404aadb72cc6.js","691","static/chunks/691-cb9ee8f48ae8671c.js","265","static/chunks/265-99e99a0904e152b6.js","915","static/chunks/app/example/page-87f781fe0821337f.js"],"ShapeAnimation"]
Expand Down
2 changes: 1 addition & 1 deletion out/example/story.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions out/example/story.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ f:I[3120,[],"MetadataBoundary"]
5:HL["/soe-centennial-nextjs/_next/static/media/b27868729ad8c262-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}]
6:HL["/soe-centennial-nextjs/_next/static/media/d90e10e85a15eaad-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}]
7:HL["/soe-centennial-nextjs/_next/static/media/db3cc5ff6037fbad-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}]
8:HL["/soe-centennial-nextjs/_next/static/css/8ffb7d69ec5bfd11.css","style"]
0:{"P":null,"b":"bvTuTpkh0u1y18TL7vMF9","p":"/soe-centennial-nextjs","c":["","example","story"],"i":false,"f":[[["",{"children":["example",{"children":["story",{"children":["__PAGE__",{}]}]}]},"$undefined","$undefined",true],["",["$","$9","c",{"children":[[["$","link","0",{"rel":"stylesheet","href":"/soe-centennial-nextjs/_next/static/css/8ffb7d69ec5bfd11.css","precedence":"next","crossOrigin":"$undefined","nonce":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__variable_6f86a8 __variable_cf1540 __variable_2df5e6 __variable_0f68e0","children":["$","$La",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$Lb",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]]}],{"children":["example",["$","$9","c",{"children":[null,["$","$La",null,{"parallelRouterKey":"children","segmentPath":["children","example","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$Lb",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]]}],{"children":["story",["$","$9","c",{"children":[null,["$","$La",null,{"parallelRouterKey":"children","segmentPath":["children","example","children","story","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$Lb",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]]}],{"children":["__PAGE__",["$","$9","c",{"children":["$Lc",null,["$","$Ld",null,{"children":"$Le"}]]}],{},null]},null]},null]},null],["$","$9","h",{"children":[null,["$","$9","ZWy6VXXroacbG0zRBjQ1d",{"children":[["$","$Lf",null,{"children":"$L10"}],["$","$L11",null,{"children":"$L12"}],["$","meta",null,{"name":"next-size-adjust"}]]}]]}]]],"m":"$undefined","G":["$13","$undefined"],"s":false,"S":true}
8:HL["/soe-centennial-nextjs/_next/static/css/6e166f209665cd3e.css","style"]
0:{"P":null,"b":"JlPzRU5Vr_WXUv9ctJK1X","p":"/soe-centennial-nextjs","c":["","example","story"],"i":false,"f":[[["",{"children":["example",{"children":["story",{"children":["__PAGE__",{}]}]}]},"$undefined","$undefined",true],["",["$","$9","c",{"children":[[["$","link","0",{"rel":"stylesheet","href":"/soe-centennial-nextjs/_next/static/css/6e166f209665cd3e.css","precedence":"next","crossOrigin":"$undefined","nonce":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__variable_6f86a8 __variable_cf1540 __variable_2df5e6 __variable_0f68e0","children":["$","$La",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$Lb",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]]}],{"children":["example",["$","$9","c",{"children":[null,["$","$La",null,{"parallelRouterKey":"children","segmentPath":["children","example","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$Lb",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]]}],{"children":["story",["$","$9","c",{"children":[null,["$","$La",null,{"parallelRouterKey":"children","segmentPath":["children","example","children","story","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$Lb",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]]}],{"children":["__PAGE__",["$","$9","c",{"children":["$Lc",null,["$","$Ld",null,{"children":"$Le"}]]}],{},null]},null]},null]},null],["$","$9","h",{"children":[null,["$","$9","TRm_S0KRq7shzqypxSCQO",{"children":[["$","$Lf",null,{"children":"$L10"}],["$","$L11",null,{"children":"$L12"}],["$","meta",null,{"name":"next-size-adjust"}]]}]]}]]],"m":"$undefined","G":["$13","$undefined"],"s":false,"S":true}
14:I[9811,["143","static/chunks/143-d5e7c922eea4f50f.js","932","static/chunks/932-fb842629337a0d1a.js","648","static/chunks/648-c2fc404aadb72cc6.js","265","static/chunks/265-99e99a0904e152b6.js","352","static/chunks/app/example/story/page-f45fd0aef4b8bbbf.js"],"Skiplink"]
21:I[9298,["143","static/chunks/143-d5e7c922eea4f50f.js","932","static/chunks/932-fb842629337a0d1a.js","648","static/chunks/648-c2fc404aadb72cc6.js","265","static/chunks/265-99e99a0904e152b6.js","352","static/chunks/app/example/story/page-f45fd0aef4b8bbbf.js"],"FeatureHero"]
22:I[7825,["143","static/chunks/143-d5e7c922eea4f50f.js","932","static/chunks/932-fb842629337a0d1a.js","648","static/chunks/648-c2fc404aadb72cc6.js","265","static/chunks/265-99e99a0904e152b6.js","352","static/chunks/app/example/story/page-f45fd0aef4b8bbbf.js"],"TimelineSidebar"]
Expand Down
2 changes: 1 addition & 1 deletion out/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions out/index.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/timeline.html

Large diffs are not rendered by default.

Loading

0 comments on commit bbbb296

Please sign in to comment.