Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Implement wrap around feature for `mo.carousel()` (#7709)

Andrewf948d8d142cc
diff --git a/frontend/src/components/slides/slides-component.tsx b/frontend/src/components/slides/slides-component.tsx
index 6690b58590..233e317a5a 100644
--- a/frontend/src/components/slides/slides-component.tsx
+++ b/frontend/src/components/slides/slides-component.tsx
@@ -21,6 +21,7 @@ interface SlidesComponentProps {
forceKeyboardNavigation?: boolean;
index?: string | null;
height?: string | number | null;
+ wrapAround?: boolean;
}
const SlidesComponent = ({
@@ -28,6 +29,7 @@ const SlidesComponent = ({
children,
height,
forceKeyboardNavigation = false,
+ wrapAround = false,
}: PropsWithChildren<SlidesComponentProps>): JSX.Element => {
const el = React.useRef<SwiperRef>(null);
const [isFullscreen, setIsFullscreen] = React.useState(false);
@@ -48,6 +50,10 @@ const SlidesComponent = ({
});
}, [isFullscreen]);
+ const modules = wrapAround // virtual is incompatible with loop
+ ? [Keyboard, Pagination, Zoom, Navigation]
+ : [Virtual, Keyboard, Pagination, Zoom, Navigation];
+
return (
<Swiper
ref={el}
@@ -60,7 +66,7 @@ const SlidesComponent = ({
height: isFullscreen ? "100%" : height || "550px",
}}
slidesPerView={1}
- modules={[Virtual, Keyboard, Pagination, Zoom, Navigation]}
+ modules={modules}
zoom={{
maxRatio: 5,
}}
@@ -74,10 +80,11 @@ const SlidesComponent = ({
pagination={{
clickable: true,
}}
- virtual={true}
+ virtual={!wrapAround} // virtual is incompatible with loop, turn off if loop is on
// Instant swipes, which make sequences of slides
// that overlay content more legible
speed={1}
+ loop={wrapAround}
>
{React.Children.map(children, (child, index) => {
if (child == null) {
diff --git a/frontend/src/plugins/layout/carousel/CarouselPlugin.tsx b/frontend/src/plugins/layout/carousel/CarouselPlugin.tsx
index 5a5c9690f5..e8a1edf248 100644
--- a/frontend/src/plugins/layout/carousel/CarouselPlugin.tsx
+++ b/frontend/src/plugins/layout/carousel/CarouselPlugin.tsx
@@ -36,7 +36,7 @@ export class CarouselPlugin implements IStatelessPlugin<Data> {
render(props: IStatelessPluginProps<Data>): JSX.Element {
return (
- <LazySlidesComponent {...props.data}>
+ <LazySlidesComponent {...props.data} wrapAround={true}>
{props.children}
</LazySlidesComponent>
);