Skip to content
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

Add carousel widget #762

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ecarreras et va molar el truco de l'styled components eh? :P

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sí si! Gràcies això he pogut tunejar els colors pq no estava pensant per fons clars

.slick-dots li button {
background-color: ${mapToken.colorPrimary};
}
.slick-dots li.slick-active button {
background-color: ${mapToken.colorPrimary};
}
.slick-dots-bottom {
bottom: -15px;
}
`;
Loading