@@ -12,6 +12,8 @@ import { ChevronNext, ChevronPrev } from "@/components/Chevron"
12
12
13
13
import { cn } from "@/lib/utils/cn"
14
14
15
+ import { Button , type ButtonProps } from "./buttons/Button"
16
+
15
17
import "swiper/css"
16
18
import "swiper/css/navigation"
17
19
import "swiper/css/pagination"
@@ -25,24 +27,100 @@ const SwiperContainer = React.forwardRef<
25
27
) )
26
28
SwiperContainer . displayName = "SwiperContainer"
27
29
30
+ const SwiperNavButton = React . forwardRef < HTMLButtonElement , ButtonProps > (
31
+ ( { children, className, ...props } , ref ) => (
32
+ < Button
33
+ ref = { ref }
34
+ variant = "ghost"
35
+ className = { cn ( "px-2" , className ) }
36
+ { ...props }
37
+ >
38
+ { children }
39
+ </ Button >
40
+ )
41
+ )
42
+ SwiperNavButton . displayName = "SwiperNavButton"
43
+
44
+ const SwiperNextButton = React . forwardRef < HTMLButtonElement , ButtonProps > (
45
+ ( { children, className, ...props } , ref ) => (
46
+ < SwiperNavButton
47
+ ref = { ref }
48
+ className = { cn ( "ui-swiper-button-next" , className ) }
49
+ { ...props }
50
+ >
51
+ { children || < ChevronNext /> }
52
+ </ SwiperNavButton >
53
+ )
54
+ )
55
+ SwiperNextButton . displayName = "SwiperNextButton"
56
+
57
+ const SwiperPrevButton = React . forwardRef < HTMLButtonElement , ButtonProps > (
58
+ ( { children, className, ...props } , ref ) => (
59
+ < SwiperNavButton
60
+ ref = { ref }
61
+ className = { cn ( "ui-swiper-button-prev" , className ) }
62
+ { ...props }
63
+ >
64
+ { children || < ChevronPrev /> }
65
+ </ SwiperNavButton >
66
+ )
67
+ )
68
+ SwiperPrevButton . displayName = "SwiperPrevButton"
69
+
70
+ const SwiperPaginationDots = React . forwardRef <
71
+ HTMLDivElement ,
72
+ React . HTMLAttributes < HTMLDivElement >
73
+ > ( ( { className, ...props } , ref ) => (
74
+ < div
75
+ ref = { ref }
76
+ className = { cn (
77
+ "ui-swiper-pagination flex w-fit flex-row" ,
78
+ "[&_.swiper-pagination-bullet]:bg-primary-high-contrast" ,
79
+ "[&_.swiper-pagination-bullet-active]:bg-primary-hover" ,
80
+ className
81
+ ) }
82
+ { ...props }
83
+ />
84
+ ) )
85
+ SwiperPaginationDots . displayName = "SwiperPaginationDots"
86
+
87
+ const SwiperNavContainer = React . forwardRef <
88
+ HTMLDivElement ,
89
+ React . HTMLAttributes < HTMLDivElement >
90
+ > ( ( { className, ...props } , ref ) => (
91
+ < div
92
+ ref = { ref }
93
+ className = { cn (
94
+ "mx-auto mt-6 flex h-6 w-fit items-center gap-4 rounded-full bg-background-highlight" ,
95
+ className
96
+ ) }
97
+ { ...props }
98
+ />
99
+ ) )
100
+ SwiperNavContainer . displayName = "SwiperNavContainer"
101
+
28
102
type SwiperProps = SwiperReactProps & {
103
+ navigation ?: React . ReactNode
29
104
children : React . ReactNode [ ]
30
105
}
31
106
const Swiper = React . forwardRef < SwiperRef , SwiperProps > (
32
- ( { children, ...props } , ref ) => {
107
+ ( { children, navigation , ...props } , ref ) => {
33
108
const { t } = useTranslation ( "common" )
34
109
return (
35
110
< SwiperReact
36
111
ref = { ref }
37
112
navigation = { {
38
- nextEl : ".swiper-button-next" ,
39
- prevEl : ".swiper-button-prev" ,
113
+ nextEl : ".ui- swiper-button-next" ,
114
+ prevEl : ".ui- swiper-button-prev" ,
40
115
} }
41
116
a11y = { {
42
117
prevSlideMessage : t ( "previous" ) ,
43
118
nextSlideMessage : t ( "next" ) ,
44
119
} }
45
- pagination = { { clickable : true , el : ".swiper-pagination" } }
120
+ pagination = { {
121
+ clickable : true ,
122
+ el : ".ui-swiper-pagination" ,
123
+ } }
46
124
keyboard
47
125
modules = { [ Navigation , Pagination , Keyboard , EffectCards ] }
48
126
slidesPerView = { 1 }
@@ -54,14 +132,25 @@ const Swiper = React.forwardRef<SwiperRef, SwiperProps>(
54
132
{ children . map ( ( child , index ) => (
55
133
< SwiperSlide key = { index } > { child } </ SwiperSlide >
56
134
) ) }
57
-
58
- < ChevronPrev className = "swiper-button-prev" />
59
- < div className = "swiper-pagination" />
60
- < ChevronNext className = "swiper-button-next" />
135
+ { navigation || (
136
+ < SwiperNavContainer >
137
+ < SwiperPrevButton />
138
+ < SwiperPaginationDots />
139
+ < SwiperNextButton />
140
+ </ SwiperNavContainer >
141
+ ) }
61
142
</ SwiperReact >
62
143
)
63
144
}
64
145
)
65
146
Swiper . displayName = "Swiper"
66
147
67
- export { Swiper , SwiperContainer }
148
+ export {
149
+ Swiper ,
150
+ SwiperContainer ,
151
+ SwiperNavButton ,
152
+ SwiperNavContainer ,
153
+ SwiperNextButton ,
154
+ SwiperPaginationDots ,
155
+ SwiperPrevButton ,
156
+ }
0 commit comments