11"use client" ;
22
33import { Autoplay } from "swiper/modules" ;
4- import { Swiper , SwiperSlide } from "swiper/react" ;
4+ import {
5+ Swiper ,
6+ SwiperSlide ,
7+ SwiperClass ,
8+ SwiperRef ,
9+ SwiperProps ,
10+ } from "swiper/react" ;
511import { useState , useRef } from "react" ;
612import { HiOutlineChevronLeft , HiOutlineChevronRight } from "react-icons/hi" ;
713import "swiper/css" ;
@@ -17,99 +23,95 @@ import MintAndProcessPage from "@/components/MintAndProcessPage";
1723import { useTheme } from "@/components/ThemeContext" ;
1824
1925export default function Onboard ( ) {
20- const [ isAutoplay , setIsAutoplay ] = useState ( true ) ; // Control autoplay
21- const [ showButtons , setShowButtons ] = useState ( false ) ; // Control button visibility
22- const [ isLastSlide , setIsLastSlide ] = useState ( false ) ; // Track if it's the last slide
23- const swiperRef = useRef ( null ) ; // Reference to the Swiper instance
26+ const [ isAutoplay , setIsAutoplay ] = useState ( true ) ; // Control autoplay
27+ const [ showButtons , setShowButtons ] = useState ( false ) ; // Control button visibility
28+ const [ isLastSlide , setIsLastSlide ] = useState ( false ) ; // Track if it's the last slide
29+ const swiperRef = useRef < SwiperClass > ( null ) ; // Reference to the Swiper instance
2430
25- const onBoardSlides = [
26- < OnboardScreen1 /> ,
27- < OnboardScreen2 /> ,
28- < OnboardScreen3 /> ,
29- < OnboardScreen4 /> ,
30- < OnboardScreen5 /> ,
31- < OnboardScreen6 /> ,
32- < OnboardScreen7 /> ,
33- < MintAndProcessPage /> ,
34- < RegisterUser /> ,
35- ] ;
31+ const onBoardSlides = [
32+ < OnboardScreen1 /> ,
33+ < OnboardScreen2 /> ,
34+ < OnboardScreen3 /> ,
35+ < OnboardScreen4 /> ,
36+ < OnboardScreen5 /> ,
37+ < OnboardScreen6 /> ,
38+ < OnboardScreen7 /> ,
39+ < MintAndProcessPage /> ,
40+ < RegisterUser /> ,
41+ ] ;
3642
37- const handleSlideChange = ( swiper ) => {
38- const currentIndex = swiper . activeIndex ;
39- const lastSlideIndex = onBoardSlides . length - 1 ;
43+ const handleSlideChange = ( swiper : SwiperClass ) => {
44+ const currentIndex = swiper . activeIndex ;
45+ const lastSlideIndex = onBoardSlides . length - 1 ;
4046
41- // Enable autoplay only for the first two slides
42- if ( currentIndex <= 1 ) {
43- setIsAutoplay ( true ) ;
44- setShowButtons ( false ) ; // Hide buttons for the first two slides
45- } else {
46- setIsAutoplay ( false ) ;
47- setShowButtons ( true ) ; // Show buttons for remaining slides
48- if ( swiperRef . current ) swiperRef . current . autoplay . stop ( ) ; // Stop autoplay
49- }
47+ // Enable autoplay only for the first two slides
48+ if ( currentIndex <= 1 ) {
49+ setIsAutoplay ( true ) ;
50+ setShowButtons ( false ) ; // Hide buttons for the first two slides
51+ } else {
52+ setIsAutoplay ( false ) ;
53+ setShowButtons ( true ) ; // Show buttons for remaining slides
54+ if ( swiperRef . current ) swiperRef . current ? .autoplay . stop ( ) ; // Stop autoplay
55+ }
5056
51- // Check if it's the last slide
52- setIsLastSlide ( currentIndex === lastSlideIndex ) ;
53- } ;
54- const { theme } = useTheme ( ) ;
57+ // Check if it's the last slide
58+ setIsLastSlide ( currentIndex === lastSlideIndex ) ;
59+ } ;
60+ const { theme } = useTheme ( ) ;
5561
56- return (
57- < div className = "min-h-screen flex justify-center items-center " >
58- < Swiper
59- modules = { [ Autoplay ] }
60- autoplay = {
61- isAutoplay
62- ? { delay : 3000 , disableOnInteraction : true }
63- : false
64- }
65- onSlideChange = { handleSlideChange }
66- onSwiper = { ( swiper ) => {
67- swiperRef . current = swiper ; // Save swiper instance
68- } }
69- spaceBetween = { 50 }
70- slidesPerView = { 1 }
71- loop = { false }
72- className = "h-screen w-full"
62+ return (
63+ < div className = "min-h-screen flex justify-center items-center " >
64+ < Swiper
65+ modules = { [ Autoplay ] }
66+ autoplay = {
67+ isAutoplay ? { delay : 3000 , disableOnInteraction : true } : false
68+ }
69+ onSlideChange = { handleSlideChange }
70+ onSwiper = { ( swiper : SwiperClass ) => {
71+ swiperRef . current = swiper ; // Save swiper instance
72+ } }
73+ spaceBetween = { 50 }
74+ slidesPerView = { 1 }
75+ loop = { false }
76+ className = "h-screen w-full"
77+ >
78+ { onBoardSlides . map ( ( slide , index ) => (
79+ < SwiperSlide key = { index } >
80+ < div
81+ className = { `h-screen w-full md:flex justify-center items-center ${
82+ theme === "dark" ? "bg-black text-white" : "bg-white text-black"
83+ } `}
7384 >
74- { onBoardSlides . map ( ( slide , index ) => (
75- < SwiperSlide key = { index } >
76- < div
77- className = { `h-screen w-full md:flex justify-center items-center ${
78- theme === "dark"
79- ? "bg-black text-white"
80- : "bg-white text-black"
81- } `}
82- >
83- { slide }
84- </ div >
85- </ SwiperSlide >
86- ) ) }
87- </ Swiper >
85+ { slide }
86+ </ div >
87+ </ SwiperSlide >
88+ ) ) }
89+ </ Swiper >
8890
89- { /* Conditionally render navigation buttons */ }
90- { showButtons && (
91- < >
92- { /* Left navigation button (always visible except on the first two slides) */ }
93- < button
94- onClick = { ( ) => swiperRef . current ?. slidePrev ( ) }
95- className = "absolute left-4 top-1/2 transform -translate-y-1/2 text-white bg-black bg-opacity-50 rounded-full p-3 hover:bg-opacity-75 transition z-10"
96- aria-label = "Previous slide"
97- >
98- < HiOutlineChevronLeft size = { 30 } />
99- </ button >
91+ { /* Conditionally render navigation buttons */ }
92+ { showButtons && (
93+ < >
94+ { /* Left navigation button (always visible except on the first two slides) */ }
95+ < button
96+ onClick = { ( ) => swiperRef . current ?. slidePrev ( ) }
97+ className = "absolute left-4 top-1/2 transform -translate-y-1/2 text-white bg-black bg-opacity-50 rounded-full p-3 hover:bg-opacity-75 transition z-10"
98+ aria-label = "Previous slide"
99+ >
100+ < HiOutlineChevronLeft size = { 30 } />
101+ </ button >
100102
101- { /* Right navigation button (hidden on the last slide) */ }
102- { ! isLastSlide && (
103- < button
104- onClick = { ( ) => swiperRef . current ?. slideNext ( ) }
105- className = "absolute right-4 top-1/2 transform -translate-y-1/2 text-white bg-black bg-opacity-50 rounded-full p-3 hover:bg-opacity-75 transition z-10"
106- aria-label = "Next slide"
107- >
108- < HiOutlineChevronRight size = { 30 } />
109- </ button >
110- ) }
111- </ >
112- ) }
113- </ div >
114- ) ;
103+ { /* Right navigation button (hidden on the last slide) */ }
104+ { ! isLastSlide && (
105+ < button
106+ onClick = { ( ) => swiperRef . current ?. slideNext ( ) }
107+ className = "absolute right-4 top-1/2 transform -translate-y-1/2 text-white bg-black bg-opacity-50 rounded-full p-3 hover:bg-opacity-75 transition z-10"
108+ aria-label = "Next slide"
109+ >
110+ < HiOutlineChevronRight size = { 30 } />
111+ </ button >
112+ ) }
113+ </ >
114+ ) }
115+ </ div >
116+ ) ;
115117}
0 commit comments