@@ -17,6 +17,8 @@ defmodule PetalComponents.Carousel do
17
17
use Phoenix.Component
18
18
import PetalComponents.Icon , only: [ icon: 1 ]
19
19
import Phoenix.LiveView.Utils , only: [ random_id: 0 ]
20
+ alias Phoenix.HTML.Link
21
+ import PetalComponents.Link
20
22
21
23
@ doc """
22
24
The `carousel` component is used to create interactive carousels with customizable attributes
@@ -56,6 +58,9 @@ defmodule PetalComponents.Carousel do
56
58
attr :title , :string , doc: "Title of the slide"
57
59
attr :description , :string , doc: "Description of the slide"
58
60
attr :class , :string , doc: "Custom CSS class for additional styling"
61
+ attr :image , :string , doc: "URL of the image to display in the slide"
62
+ attr :navigate , :string , doc: "Internal route to navigate to when the slide is clicked"
63
+ attr :href , :string , doc: "External URL to navigate to when the slide is clicked"
59
64
end
60
65
61
66
def carousel ( assigns ) do
@@ -125,18 +130,15 @@ defmodule PetalComponents.Carousel do
125
130
end
126
131
}
127
132
>
128
- < div class = "pc-carousel__slide-content " >
129
- < div class = "pc-carousel__content " >
130
- < div class = "pc-carousel__content-wrapper " >
131
- < div class = "pc-carousel__title " >
132
- { slide [ :title ] || "Slide #{ index + 1 } " }
133
- </ div >
134
- < p :if = { ! is_nil ( slide [ :description ] ) } class = "pc-carousel__description " >
135
- { slide [ :description ] }
136
- </ p >
137
- </ div >
138
- </ div >
139
- </ div >
133
+ < . slide_content
134
+ slide = { slide }
135
+ index = { index }
136
+ navigate = { slide [ :navigate ] }
137
+ href = { slide [ :href ] }
138
+ image = { slide [ :image ] }
139
+ title = { slide [ :title ] || "Slide #{ index + 1 } " }
140
+ description = { slide [ :description ] }
141
+ />
140
142
</ div >
141
143
</ div >
142
144
@@ -183,4 +185,31 @@ defmodule PetalComponents.Carousel do
183
185
defp text_position_class ( "center" ) , do: "[&_.description-wrapper]:text-center"
184
186
defp text_position_class ( "end" ) , do: "[&_.description-wrapper]:text-end"
185
187
defp text_position_class ( _ ) , do: ""
188
+
189
+ defp slide_content ( assigns ) do
190
+ ~H"""
191
+ < div class = "pc-carousel__slide-content " >
192
+ < div :if = { ! is_nil ( @ image ) } class = "pc-carousel__image-wrapper " >
193
+ < img src = { @ image } class = "pc-carousel__image " />
194
+ </ div >
195
+ < div class = "pc-carousel__content " >
196
+ < div class = "pc-carousel__content-wrapper " >
197
+ < div class = "pc-carousel__title " >
198
+ { @ title }
199
+ </ div >
200
+ < p :if = { ! is_nil ( @ description ) } class = "pc-carousel__description " >
201
+ { @ description }
202
+ </ p >
203
+ </ div >
204
+ </ div >
205
+ </ div >
206
+
207
+ < . link :if = { @ navigate } to = { @ navigate } class = "pc-carousel__link absolute inset-0 z-20 " >
208
+ < span class = "sr-only " > View slide details</ span >
209
+ </ . link >
210
+ < a :if = { @ href } href = { @ href } class = "pc-carousel__link absolute inset-0 z-20 " >
211
+ < span class = "sr-only " > View external link</ span >
212
+ </ a >
213
+ """
214
+ end
186
215
end
0 commit comments