Skip to content

Commit

Permalink
feat(carousel): add carousel widget (#762)
Browse files Browse the repository at this point in the history
Co-authored-by: Marc Güell Segarra <[email protected]>
  • Loading branch information
ecarreras and mguellsegarra authored Dec 13, 2024
1 parent 62e4f5d commit 14fb225
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { Alert } from "@/widgets/custom/Alert";
import { DashboardGrid } from "@/widgets/views/DashboardGrid";
import { GraphIndicator } from "@/widgets/views/Graph/GraphIndicator";
import { Spinner } from "@/widgets/custom/Spinner";
import { Carousel } from "@/widgets/custom/Carousel";

import type {
TreeView,
Expand Down Expand Up @@ -179,4 +180,5 @@ export {
Alert,
dayjs,
Spinner,
Carousel,
};
3 changes: 3 additions & 0 deletions src/widgets/WidgetFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
HTMLPreview,
Alert,
Spinner,
Carousel,
} from "@/index";
import { Image } from "./base/Image";
import { FiberGrid } from "./custom/FiberGrid";
Expand Down Expand Up @@ -133,6 +134,8 @@ const getWidgetType = (type: string) => {
return Alert;
case "spinner":
return Spinner;
case "carousel":
return Carousel;
default:
return undefined;
}
Expand Down
42 changes: 42 additions & 0 deletions src/widgets/custom/Carousel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { WidgetProps } from "@/types";
import { Carousel as CarouselOoui, Group as GroupOoui } from "@gisce/ooui";
import { Carousel as AntCarousel, theme } from "antd";
import Container from "@/widgets/containers/Container";
import styled from "styled-components";

const { defaultAlgorithm, defaultSeed } = theme;

const mapToken = defaultAlgorithm(defaultSeed);

type CarouselProps = Omit<WidgetProps, "ooui"> & {
ooui: CarouselOoui;
responsiveBehaviour?: boolean;
};

export const Carousel = (props: CarouselProps) => {
const { ooui, responsiveBehaviour = false } = props;

return (
<CustomCarousel autoplay={ooui.autoPlay} dots autoplaySpeed={5000}>
{ooui.items.map((group: GroupOoui, index: number) => (
<Container
key={index}
container={group.container}
responsiveBehaviour={responsiveBehaviour}
/>
))}
</CustomCarousel>
);
};

const CustomCarousel = styled(AntCarousel)`
.slick-dots li button {
background-color: ${mapToken.colorPrimary};
}
.slick-dots li.slick-active button {
background-color: ${mapToken.colorPrimary};
}
.slick-dots-bottom {
bottom: -15px;
}
`;

0 comments on commit 14fb225

Please sign in to comment.