Repository navigation
Add typed React components and automatic carousel setup - #9
Conversation
🦋 Changeset detectedLatest commit: 3a6c5fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
marlonmarcello
left a comment
There was a problem hiding this comment.
@copilot the should make sure that we support React 19+ and we should tag the component with use client.
We should also support the beforeChange event, not just the afterChange.
Lets also add a few methods to the context so that we can pragmatically call both setPosition and swipe.
Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Added React 19 validation and the |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved issues leave React slide structure and state out of sync, mishandle nested carousel events, break React behavior in cloned slides, and impose React on vanilla consumers.
5 open issues
What changed in this PR
Adds a typed React entry point around the existing carousel core, reducing manual DOM setup, lifecycle management, and stylesheet handling.
Changes:
- Introduces structural components, controls, and a context hook for carousel state.
- Automatically initializes and destroys the core and imports animation-suppression styles.
- Adds package exports, TypeScript support, and React usage documentation.
| File | Description |
|---|---|
tsconfig.json |
Enables React JSX and includes TSX sources. |
src/react/style.css |
Imports core styles and suppresses transitions during dragging and instant moves. |
src/react/index.tsx |
Adds typed components, lifecycle handling, and the context hook. |
src/react/css.d.ts |
Declares CSS imports for TypeScript. |
scripts/copy-css.js |
Copies React styles into the distribution. |
README.md |
Documents React components and usage. |
package.json |
Exports the React entry point and adds React dependency metadata. |
package-lock.json |
Records updated package and dependency metadata. |
Review effort: Balanced
|
@copilot let's make sure we add a |
Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
|
@marlonmarcello I've opened a new pull request, #10, to work on those changes. Once the pull request is ready, I'll request review from you. |
Add the React items API and a core render-plan commit handshake while preserving vanilla DOM cloning. Preserve keyed copies across item and selector updates, enforce valid list markup, and protect React-owned DOM and styles during lifecycle changes. Guard interactions until render plans commit and add regression coverage.
NicholasLancey
left a comment
There was a problem hiding this comment.
I've tested this locally using the existing demos, and created a few of my own, and everything is working as expected.
I've also reviewed both react/index.tsx and src/index.ts as that's where the majority of the work is, and everything seems OK to me.
Would be great to get some more eyes on this one as it's a big'un!
Updated the version of '@wethegit/gordito-carousel' from minor to major

React support
What this PR adds
This PR adds a React entry point to Gordito. Consumers can compose a carousel with typed components instead of wiring the DOM contract and core lifecycle themselves.
Infinite navigation is still a core feature. The React adapter renders its own slide copies so their handlers and content work correctly. Vanilla consumers keep the existing DOM-cloning path and do not need to install React.
The scope includes:
Carousel, structural helpers, previous/next buttons, and pagination components. TheitemsAPI generates the list and track, with semantic list-item roots by default.useCarousel()exposes the core instance, current slide,setPosition(), and directionalswipe(). The root accepts before/after change callbacks.@wethegit/gordito-carousel/reactexport, a'use client'entry point, an optional React peer dependency, and structural CSS.Suggested review order
itemsmode and manually authored structure.buildOut(),commitRenderPlan(), anddestroy(). Then check the pending-plan interaction guards and restrictions on imperative DOM mutation.How the rendering integration works
Core owns navigation, measurements, and runtime state. React owns the slide nodes and component lifetimes. Navigation and drag initiation are ignored while a plan is pending, rather than running against incomplete DOM.
Originals are keyed by source item identity. Copies also include their rendered position in the key. Matching occurrences can retain their component state when the list changes. Removed occurrences unmount normally. The rendered copy set stays bounded during navigation.
Behavior and trade-offs to review
initialSlide, which defaults to zero. Selector changes must rediscover excluded originals without unnecessarily remounting surviving copies.addSlide(),removeSlide(),filterSlides(), andunfilterSlides()throw before mutation. Teardown removes core-owned state without restoring stale styles over current React props.items, infinite copies use DOM cloning and do not acquire React handlers. Review the distinction so consumers are not led toward the wrong mode for interactive slides.Automated coverage
The tests use JSDOM. They do not establish that real layout, transitions, or pointer gestures work correctly in a browser.
How to test this PR
Run the checks
Use the Node version in
.nvmrc. From the repository root:npm i npm run test npm run check npm run build npm run site:buildTry the live examples
Run
npm run dev, open the URL printed by Vite, and follow React. Each demo has its source and suggested interactions./react/#featured— viewport-wide photo fan. Loop in both directions, rapidly change targets, drag freely, select neighboring photos, and resize across the desktop/mobile breakpoint. Watch both viewport edges for gaps or visible corrections. This is a visual stress case, not a timed performance benchmark./react/#interactive— handlers and shared state. Save a card, loop through its copies, then edit its caption and save again. Counts should stay synchronized and the saved message should use the latest text. Check the hook button and before/after event readout too./react/#editable— source updates. Rename and reorder cards. Remove the selected last card, clear everything, then add items again. Look for lost state, invalid selection, or DOM errors./react/#selectors— filtering and style updates. Turn off “Featured only” and confirm A returns. Toggle “Infinite + blue accent” to change an option and inline styles together. Originals and copies should keep the new appearance. Inspect the ordered track for directlichildren.Validation recorded so far
Important
These were exploratory browser checks, not a committed end-to-end suite. A narrow desktop viewport is not a real touch-device test.