-
Notifications
You must be signed in to change notification settings - Fork 62
Add carousel component #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
887ff8d to
1fe3b66
Compare
1fe3b66 to
002845b
Compare
|
@lsouoliveira , thanks for the component. It looks nice. The Embla library is the same that shadcn uses, and it's fair to use it as a dependency. The only thing that makes me feel uncomfortable is the use of Thread to share data. I might not work with turbo frames. You might achieve a similar result using Tailwind groups. I can mark the parent as is-horizontal and apply a CSS rule based on that. Or try to use stimulus with tailwind to do the job Any inputs here? @stephannv ? |
|
@cirdes Thanks for the feedback. Your concerns about Thread.current are definitely valid. Tailwind groups should work just as well and are much simpler. |
Yeah, I prefer the tailwind (best) or stimulus solution. I faced a similar situation with combobox component that could be solved with Thread.current but I didn't like the solution at the time. |
5c6daea to
1dcd8c9
Compare
|
Hey guys, how are you doing? Do you guys plan to merge this soon? I'm really waiting for it! |
|
@jeduardo824 we are planning a 1.0 release soon, we will merge this in the next days. |
stephannv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
Thanks! Can you open a PR to https://github.com/ruby-ui/web adding the docs?
EDIT:
I removed the
CarouselContextclass. 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/uiCarousel 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--carouselcontroller. New plugins can be passed to the#initCarouselmethod.Use of
Thread.currentThe 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
orientationparameter to each child component, but this led to a lot of repetition when rendering the carousel:To address this, I created a
CarouselContextclass that wraps the root component (Carousel).CarouselContextusesThread.currentto 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