Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
EDIT:
I removed the
CarouselContext
class. Now, the orientation-based styling of each component is set using thegroup-[.is-horizontal]:
andgroup-[.is-vertical]:
Tailwind selectors.I also added keyboard events to mimic the shadcn component. When the right arrow key is pressed, the carousel moves to the next slide, and when the left arrow key is pressed, it moves to the previous slide.
ORIGINAL:
This PR adds a Carousel component based on the shadcn/ui
New JavaScript Dependency
The
shadcn/ui
Carousel component uses the Embla library to build the carousel, so I had to add it to the project. The Embla library allows users to add plugins during API initialization. Ruby ui users can add plugins by modifying theruby-ui--carousel
controller. New plugins can be passed to the#initCarousel
method.Use of
Thread.current
The carousel supports two orientations: horizontal and vertical. Each orientation affects the classes of all Carousel child components (
CarouselContent
,CarouselItem
,CarouselPrevious
, andCarouselNext
).Initially, I added an
orientation
parameter to each child component, but this led to a lot of repetition when rendering the carousel:To address this, I created a
CarouselContext
class that wraps the root component (Carousel
).CarouselContext
usesThread.current
to set a local variable that all components inside the Carousel block can access. This new approach allowed me to eliminate parameter repetition:Demonstration
showcase.mp4