coles-solid-library 0.3.9 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +19 -19
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -599,8 +599,15 @@ const Carousel = ({
|
|
|
599
599
|
const [internalIndex, setInternalIndex] = createSignal(startingIndex);
|
|
600
600
|
const [propIndex, other] = splitProps(props, ["currentIndex"]);
|
|
601
601
|
const [, setCarouselBodyRef] = createSignal(null);
|
|
602
|
+
// Unified read/write for controlled vs uncontrolled usage
|
|
602
603
|
const getPropIndex = () => propIndex.currentIndex ? propIndex.currentIndex[0]() : internalIndex();
|
|
603
|
-
const setPropIndex = index =>
|
|
604
|
+
const setPropIndex = index => {
|
|
605
|
+
if (propIndex.currentIndex) {
|
|
606
|
+
propIndex.currentIndex[1](index);
|
|
607
|
+
} else {
|
|
608
|
+
setInternalIndex(index);
|
|
609
|
+
}
|
|
610
|
+
};
|
|
604
611
|
const [currSlideName] = useContext(carouselTitleContext);
|
|
605
612
|
// ----- Memoized Values -----
|
|
606
613
|
const getElementsLength = createMemo(() => {
|
|
@@ -625,12 +632,8 @@ const Carousel = ({
|
|
|
625
632
|
return [theProps.children];
|
|
626
633
|
}
|
|
627
634
|
});
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
return getPropIndex();
|
|
631
|
-
}
|
|
632
|
-
return internalIndex();
|
|
633
|
-
});
|
|
635
|
+
// The active index should always come from external control if provided
|
|
636
|
+
const currentIndex = createMemo(() => getPropIndex());
|
|
634
637
|
const slideName = createMemo(() => {
|
|
635
638
|
if (Object.keys(props).includes('elements') && getElementsLength() > 0) {
|
|
636
639
|
return getElementsArray()[currentIndex()]?.name;
|
|
@@ -659,23 +662,20 @@ const Carousel = ({
|
|
|
659
662
|
});
|
|
660
663
|
// ----- Functions -----
|
|
661
664
|
const nextSlide = () => {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
} else {
|
|
665
|
-
setInternalIndex(0);
|
|
666
|
-
}
|
|
665
|
+
const next = currentIndex() !== getElementsLength() - 1 ? currentIndex() + 1 : 0;
|
|
666
|
+
setPropIndex(next);
|
|
667
667
|
};
|
|
668
668
|
const prevSlide = () => {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
} else {
|
|
672
|
-
setInternalIndex(getElementsLength() - 1);
|
|
673
|
-
}
|
|
669
|
+
const prev = currentIndex() !== 0 ? currentIndex() - 1 : getElementsLength() - 1;
|
|
670
|
+
setPropIndex(prev);
|
|
674
671
|
};
|
|
675
672
|
// ----- Effects -----
|
|
673
|
+
// Keep internal signal in sync when switching from uncontrolled to controlled or external changes
|
|
676
674
|
createRenderEffect(() => {
|
|
677
|
-
if (
|
|
678
|
-
|
|
675
|
+
if (!propIndex.currentIndex) return; // controlled only
|
|
676
|
+
// Mirror external index into internal for consistency (e.g., if component logic elsewhere reads internalIndex)
|
|
677
|
+
if (internalIndex() !== propIndex.currentIndex[0]()) {
|
|
678
|
+
setInternalIndex(propIndex.currentIndex[0]());
|
|
679
679
|
}
|
|
680
680
|
});
|
|
681
681
|
// ----- TSX -----
|