|
1 | | -import { createElement, ReactNode, useCallback, ReactElement, useId } from "react"; |
2 | | -import { ValueStatus, GUID, ObjectItem } from "mendix"; |
3 | 1 | import { executeAction } from "@mendix/widget-plugin-platform/framework/execute-action"; |
| 2 | +import classNames from "classnames"; |
| 3 | +import { GUID, ObjectItem, ValueStatus } from "mendix"; |
| 4 | +import { createElement, ReactNode, useCallback, useId } from "react"; |
4 | 5 | import { CarouselContainerProps } from "../typings/CarouselProps"; |
5 | 6 | import { Carousel as CarouselComponent } from "./components/Carousel"; |
6 | | -import loadingCircleSvg from "./ui/loading-circle.svg"; |
7 | | -import classNames from "classnames"; |
8 | 7 | import "./ui/Carousel.scss"; |
| 8 | +import loadingCircleSvg from "./ui/loading-circle.svg"; |
9 | 9 |
|
10 | 10 | export function Carousel(props: CarouselContainerProps): ReactNode { |
11 | 11 | const { showPagination, loop, tabIndex, navigation, animation, delay, autoplay } = props; |
12 | 12 | const onClick = useCallback(() => executeAction(props.onClickAction), [props.onClickAction]); |
13 | 13 | const id = useId(); |
14 | 14 |
|
15 | | - const renderCarousel = (): ReactElement => { |
16 | | - return ( |
17 | | - <CarouselComponent |
18 | | - id={id} |
19 | | - className={props.class} |
20 | | - tabIndex={tabIndex} |
21 | | - pagination={showPagination} |
22 | | - loop={loop} |
23 | | - animation={animation} |
24 | | - autoplay={autoplay} |
25 | | - delay={delay} |
26 | | - navigation={navigation} |
27 | | - items={ |
28 | | - props.dataSource?.items?.map((item: ObjectItem) => ({ |
29 | | - id: item.id as GUID, |
30 | | - content: props.content?.get(item) |
31 | | - })) ?? [] |
32 | | - } |
33 | | - onClick={onClick} |
34 | | - /> |
35 | | - ); |
36 | | - }; |
37 | | - const renderLoading = (): ReactNode => { |
| 15 | + if (props.dataSource?.status !== ValueStatus.Available) { |
38 | 16 | return ( |
39 | 17 | <div className={classNames(props.class, "widget-carousel")} tabIndex={tabIndex}> |
40 | 18 | <img src={loadingCircleSvg} className="widget-carousel-loading-spinner" alt="" aria-hidden /> |
41 | 19 | </div> |
42 | 20 | ); |
43 | | - }; |
| 21 | + } |
44 | 22 |
|
45 | | - return props.dataSource?.status !== ValueStatus.Available ? renderLoading() : renderCarousel(); |
| 23 | + return ( |
| 24 | + <CarouselComponent |
| 25 | + id={id} |
| 26 | + className={props.class} |
| 27 | + tabIndex={tabIndex} |
| 28 | + pagination={showPagination} |
| 29 | + loop={loop} |
| 30 | + animation={animation} |
| 31 | + autoplay={autoplay} |
| 32 | + delay={delay} |
| 33 | + navigation={navigation} |
| 34 | + items={ |
| 35 | + props.dataSource?.items?.map((item: ObjectItem) => ({ |
| 36 | + id: item.id as GUID, |
| 37 | + content: props.content?.get(item) |
| 38 | + })) ?? [] |
| 39 | + } |
| 40 | + onClick={onClick} |
| 41 | + /> |
| 42 | + ); |
46 | 43 | } |
0 commit comments