@times-components/ts-components 1.145.1-b32ea924749bafdf12e3e8515023538fa20e7808.3 → 1.145.1-cfea81c4084e6f91221ea00fec9fc730d5b933cb.4
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/components/carousel-component/CarouselComponent.stories.js +146 -0
- package/dist/components/carousel-component/CarouselItem.d.ts +3 -0
- package/dist/components/carousel-component/CarouselItem.js +11 -0
- package/dist/components/carousel-component/DefaultNavigationArrow.d.ts +8 -0
- package/dist/components/carousel-component/DefaultNavigationArrow.js +6 -0
- package/dist/components/carousel-component/DefaultPageDot.d.ts +8 -0
- package/dist/components/carousel-component/DefaultPageDot.js +4 -0
- package/dist/components/carousel-component/__tests__/CarouselComponent.test.d.ts +1 -0
- package/dist/components/carousel-component/__tests__/CarouselComponent.test.js +163 -0
- package/dist/components/carousel-component/__tests__/CarouselItem.test.d.ts +1 -0
- package/dist/components/carousel-component/__tests__/CarouselItem.test.js +80 -0
- package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.d.ts +1 -0
- package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.js +62 -0
- package/dist/components/carousel-component/__tests__/DefaultPageDot.test.d.ts +1 -0
- package/dist/components/carousel-component/__tests__/DefaultPageDot.test.js +68 -0
- package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.d.ts +1 -0
- package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.js +314 -0
- package/dist/components/carousel-component/hooks/useCarousel.d.ts +2 -0
- package/dist/components/carousel-component/hooks/useCarousel.js +140 -0
- package/dist/components/carousel-component/index.d.ts +4 -0
- package/dist/components/carousel-component/index.js +20 -0
- package/dist/components/carousel-component/styles.d.ts +30 -0
- package/dist/components/carousel-component/styles.js +120 -0
- package/dist/components/carousel-component/types.d.ts +46 -0
- package/dist/components/carousel-component/types.js +2 -0
- package/dist/components/opta/cricket/scorecard/OptaCricketScorecard.js +2 -10
- package/dist/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.js +17 -94
- package/dist/components/opta/football/summary/OptaFootballSummary.js +2 -10
- package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.js +18 -95
- package/dist/components/opta/rugby/summary/OptaRugbySummary.js +2 -10
- package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.js +17 -94
- package/dist/components/trip-cards/SkeletonCard.d.ts +2 -0
- package/dist/components/trip-cards/SkeletonCard.js +21 -0
- package/dist/components/trip-cards/TripCard.d.ts +3 -0
- package/dist/components/trip-cards/TripCard.js +47 -0
- package/dist/components/trip-cards/TripCards.stories.d.ts +1 -0
- package/dist/components/trip-cards/TripCards.stories.js +40 -0
- package/dist/components/trip-cards/TripCardsLayout.d.ts +3 -0
- package/dist/components/trip-cards/TripCardsLayout.js +26 -0
- package/dist/components/trip-cards/__tests__/SkeletonCard.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/SkeletonCard.test.js +139 -0
- package/dist/components/trip-cards/__tests__/TripCard.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/TripCard.test.js +95 -0
- package/dist/components/trip-cards/__tests__/TripCardsLayout.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/TripCardsLayout.test.js +277 -0
- package/dist/components/trip-cards/__tests__/assets.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/assets.test.js +165 -0
- package/dist/components/trip-cards/__tests__/helpers.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/helpers.test.js +135 -0
- package/dist/components/trip-cards/__tests__/index.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/index.test.js +437 -0
- package/dist/components/trip-cards/__tests__/mockData.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/mockData.test.js +57 -0
- package/dist/components/trip-cards/__tests__/skeletonStyles.test.d.ts +1 -0
- package/dist/components/trip-cards/__tests__/skeletonStyles.test.js +194 -0
- package/dist/components/trip-cards/assets/BoatIcon.d.ts +1 -0
- package/dist/components/trip-cards/assets/BoatIcon.js +4 -0
- package/dist/components/trip-cards/assets/CalendarIcon.d.ts +1 -0
- package/dist/components/trip-cards/assets/CalendarIcon.js +4 -0
- package/dist/components/trip-cards/assets/ChevronRightIcon.d.ts +1 -0
- package/dist/components/trip-cards/assets/ChevronRightIcon.js +4 -0
- package/dist/components/trip-cards/assets/LocationIcon.d.ts +1 -0
- package/dist/components/trip-cards/assets/LocationIcon.js +4 -0
- package/dist/components/trip-cards/assets/MoonIcon.d.ts +1 -0
- package/dist/components/trip-cards/assets/MoonIcon.js +4 -0
- package/dist/components/trip-cards/assets/index.d.ts +6 -0
- package/dist/components/trip-cards/assets/index.js +7 -0
- package/dist/components/trip-cards/helpers.d.ts +4 -0
- package/dist/components/trip-cards/helpers.js +74 -0
- package/dist/components/trip-cards/index.d.ts +4 -0
- package/dist/components/trip-cards/index.js +70 -0
- package/dist/components/trip-cards/mockData.d.ts +3 -0
- package/dist/components/trip-cards/mockData.js +323 -0
- package/dist/components/trip-cards/skeletonStyles.d.ts +9 -0
- package/dist/components/trip-cards/skeletonStyles.js +37 -0
- package/dist/components/trip-cards/styles.d.ts +39 -0
- package/dist/components/trip-cards/styles.js +387 -0
- package/dist/components/trip-cards/types.d.ts +87 -0
- package/dist/components/trip-cards/types.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/package.json +3 -3
- package/rnw.js +1 -1
- package/src/components/carousel-component/CarouselComponent.stories.tsx +220 -0
- package/src/components/carousel-component/CarouselItem.tsx +20 -0
- package/src/components/carousel-component/DefaultNavigationArrow.tsx +37 -0
- package/src/components/carousel-component/DefaultPageDot.tsx +20 -0
- package/src/components/carousel-component/__tests__/CarouselComponent.test.tsx +259 -0
- package/src/components/carousel-component/__tests__/CarouselItem.test.tsx +140 -0
- package/src/components/carousel-component/__tests__/DefaultNavigationArrow.test.tsx +153 -0
- package/src/components/carousel-component/__tests__/DefaultPageDot.test.tsx +105 -0
- package/src/components/carousel-component/hooks/__tests__/useCarousel.test.ts +438 -0
- package/src/components/carousel-component/hooks/useCarousel.ts +187 -0
- package/src/components/carousel-component/index.tsx +88 -0
- package/src/components/carousel-component/styles.ts +140 -0
- package/src/components/carousel-component/types.ts +51 -0
- package/src/components/opta/cricket/scorecard/OptaCricketScorecard.tsx +0 -13
- package/src/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.tsx +16 -126
- package/src/components/opta/cricket/scorecard/__tests__/__snapshots__/OptaCricketScorecard.test.tsx.snap +6 -5
- package/src/components/opta/football/summary/OptaFootballSummary.tsx +0 -13
- package/src/components/opta/football/summary/__tests__/OptaFootballSummary.test.tsx +18 -127
- package/src/components/opta/football/summary/__tests__/__snapshots__/OptaFootballSummary.test.tsx.snap +6 -5
- package/src/components/opta/rugby/summary/OptaRugbySummary.tsx +0 -13
- package/src/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.tsx +17 -127
- package/src/components/opta/rugby/summary/__tests__/__snapshots__/OptaRugbySummary.test.tsx.snap +6 -5
- package/src/components/trip-cards/SkeletonCard.tsx +54 -0
- package/src/components/trip-cards/TripCard.tsx +135 -0
- package/src/components/trip-cards/TripCards.stories.tsx +67 -0
- package/src/components/trip-cards/TripCardsLayout.tsx +75 -0
- package/src/components/trip-cards/__tests__/SkeletonCard.test.tsx +169 -0
- package/src/components/trip-cards/__tests__/TripCard.test.tsx +120 -0
- package/src/components/trip-cards/__tests__/TripCardsLayout.test.tsx +532 -0
- package/src/components/trip-cards/__tests__/assets.test.tsx +206 -0
- package/src/components/trip-cards/__tests__/helpers.test.ts +165 -0
- package/src/components/trip-cards/__tests__/index.test.tsx +499 -0
- package/src/components/trip-cards/__tests__/mockData.test.ts +67 -0
- package/src/components/trip-cards/__tests__/skeletonStyles.test.tsx +256 -0
- package/src/components/trip-cards/assets/BoatIcon.tsx +17 -0
- package/src/components/trip-cards/assets/CalendarIcon.tsx +17 -0
- package/src/components/trip-cards/assets/ChevronRightIcon.tsx +20 -0
- package/src/components/trip-cards/assets/LocationIcon.tsx +17 -0
- package/src/components/trip-cards/assets/MoonIcon.tsx +17 -0
- package/src/components/trip-cards/assets/index.ts +7 -0
- package/src/components/trip-cards/helpers.ts +99 -0
- package/src/components/trip-cards/index.tsx +104 -0
- package/src/components/trip-cards/mockData.ts +351 -0
- package/src/components/trip-cards/skeletonStyles.ts +46 -0
- package/src/components/trip-cards/styles.ts +426 -0
- package/src/components/trip-cards/types.ts +91 -0
- package/src/index.ts +2 -0
- package/dist/components/opta/utils/__tests__/emitEvent.test.js +0 -264
- package/dist/components/opta/utils/emitEvent.d.ts +0 -1
- package/dist/components/opta/utils/emitEvent.js +0 -9
- package/src/components/opta/utils/__tests__/emitEvent.test.tsx +0 -415
- package/src/components/opta/utils/emitEvent.ts +0 -11
- /package/dist/components/{opta/utils/__tests__/emitEvent.test.d.ts → carousel-component/CarouselComponent.stories.d.ts} +0 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { storiesOf } from '@storybook/react';
|
|
3
|
+
import { CarouselComponent, CarouselItem } from './index';
|
|
4
|
+
import styled from 'styled-components';
|
|
5
|
+
|
|
6
|
+
// Simple card component for demos
|
|
7
|
+
const SimpleCard = styled.div<{ color: string }>`
|
|
8
|
+
background: ${props => props.color};
|
|
9
|
+
height: 300px;
|
|
10
|
+
border-radius: 8px;
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
color: white;
|
|
15
|
+
font-size: 24px;
|
|
16
|
+
font-weight: 600;
|
|
17
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
const Container = styled.div`
|
|
21
|
+
max-width: 1200px;
|
|
22
|
+
margin: 40px auto;
|
|
23
|
+
padding: 0 20px;
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const Title = styled.h2`
|
|
27
|
+
margin-bottom: 24px;
|
|
28
|
+
font-size: 24px;
|
|
29
|
+
font-weight: 600;
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
storiesOf('Typescript Component/CarouselComponent', module)
|
|
33
|
+
.add('Two Cards Per Page', () => {
|
|
34
|
+
const colors = [
|
|
35
|
+
'#005C8A',
|
|
36
|
+
'#FF6B6B',
|
|
37
|
+
'#4ECDC4',
|
|
38
|
+
'#45B7D1',
|
|
39
|
+
'#96CEB4',
|
|
40
|
+
'#FFEAA7'
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const items = colors.map((color, index) => (
|
|
44
|
+
<CarouselItem
|
|
45
|
+
key={index}
|
|
46
|
+
widthConfig={{
|
|
47
|
+
mobile: '90%',
|
|
48
|
+
tablet: '70%',
|
|
49
|
+
desktop: 'calc(47% - 10px)'
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
<SimpleCard color={color}>Card {index + 1}</SimpleCard>
|
|
53
|
+
</CarouselItem>
|
|
54
|
+
));
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Container>
|
|
58
|
+
<Title>Two Cards Per Page (with peek)</Title>
|
|
59
|
+
<CarouselComponent
|
|
60
|
+
items={items}
|
|
61
|
+
options={{
|
|
62
|
+
itemsPerPage: 2
|
|
63
|
+
}}
|
|
64
|
+
showArrows={true}
|
|
65
|
+
showDots={true}
|
|
66
|
+
/>
|
|
67
|
+
</Container>
|
|
68
|
+
);
|
|
69
|
+
})
|
|
70
|
+
.add('Three Cards Per Page', () => {
|
|
71
|
+
const colors = [
|
|
72
|
+
'#005C8A',
|
|
73
|
+
'#FF6B6B',
|
|
74
|
+
'#4ECDC4',
|
|
75
|
+
'#45B7D1',
|
|
76
|
+
'#96CEB4',
|
|
77
|
+
'#FFEAA7',
|
|
78
|
+
'#DFE6E9',
|
|
79
|
+
'#74B9FF',
|
|
80
|
+
'#A29BFE'
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
const items = colors.map((color, index) => (
|
|
84
|
+
<CarouselItem
|
|
85
|
+
key={index}
|
|
86
|
+
widthConfig={{
|
|
87
|
+
mobile: '85%',
|
|
88
|
+
tablet: '40%',
|
|
89
|
+
desktop: 'calc(31% - 14px)'
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
<SimpleCard color={color}>Card {index + 1}</SimpleCard>
|
|
93
|
+
</CarouselItem>
|
|
94
|
+
));
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Container>
|
|
98
|
+
<Title>Three Cards Per Page (with peek)</Title>
|
|
99
|
+
<CarouselComponent
|
|
100
|
+
items={items}
|
|
101
|
+
options={{
|
|
102
|
+
itemsPerPage: 3
|
|
103
|
+
}}
|
|
104
|
+
showArrows={true}
|
|
105
|
+
showDots={true}
|
|
106
|
+
/>
|
|
107
|
+
</Container>
|
|
108
|
+
);
|
|
109
|
+
})
|
|
110
|
+
.add('Minimal Example', () => {
|
|
111
|
+
const items = [
|
|
112
|
+
<CarouselItem
|
|
113
|
+
key="1"
|
|
114
|
+
widthConfig={{
|
|
115
|
+
mobile: '90%',
|
|
116
|
+
tablet: '70%',
|
|
117
|
+
desktop: 'calc(47% - 10px)'
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
<SimpleCard color="#005C8A">Card 1</SimpleCard>
|
|
121
|
+
</CarouselItem>,
|
|
122
|
+
<CarouselItem
|
|
123
|
+
key="2"
|
|
124
|
+
widthConfig={{
|
|
125
|
+
mobile: '90%',
|
|
126
|
+
tablet: '70%',
|
|
127
|
+
desktop: 'calc(47% - 10px)'
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
<SimpleCard color="#FF6B6B">Card 2</SimpleCard>
|
|
131
|
+
</CarouselItem>,
|
|
132
|
+
<CarouselItem
|
|
133
|
+
key="3"
|
|
134
|
+
widthConfig={{
|
|
135
|
+
mobile: '90%',
|
|
136
|
+
tablet: '70%',
|
|
137
|
+
desktop: 'calc(47% - 10px)'
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
<SimpleCard color="#4ECDC4">Card 3</SimpleCard>
|
|
141
|
+
</CarouselItem>,
|
|
142
|
+
<CarouselItem
|
|
143
|
+
key="4"
|
|
144
|
+
widthConfig={{
|
|
145
|
+
mobile: '90%',
|
|
146
|
+
tablet: '70%',
|
|
147
|
+
desktop: 'calc(47% - 10px)'
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
<SimpleCard color="#45B7D1">Card 4</SimpleCard>
|
|
151
|
+
</CarouselItem>
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<Container>
|
|
156
|
+
<Title>Simple 4 Cards</Title>
|
|
157
|
+
<CarouselComponent items={items} />
|
|
158
|
+
</Container>
|
|
159
|
+
);
|
|
160
|
+
})
|
|
161
|
+
.add('Without Navigation', () => {
|
|
162
|
+
const colors = ['#005C8A', '#FF6B6B', '#4ECDC4', '#45B7D1'];
|
|
163
|
+
|
|
164
|
+
const items = colors.map((color, index) => (
|
|
165
|
+
<CarouselItem
|
|
166
|
+
key={index}
|
|
167
|
+
widthConfig={{
|
|
168
|
+
mobile: '90%',
|
|
169
|
+
tablet: '70%',
|
|
170
|
+
desktop: 'calc(47% - 10px)'
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
<SimpleCard color={color}>Card {index + 1}</SimpleCard>
|
|
174
|
+
</CarouselItem>
|
|
175
|
+
));
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<Container>
|
|
179
|
+
<Title>Scroll Only (No Arrows/Dots)</Title>
|
|
180
|
+
<CarouselComponent items={items} showArrows={false} showDots={false} />
|
|
181
|
+
</Container>
|
|
182
|
+
);
|
|
183
|
+
})
|
|
184
|
+
.add('Three Cards Exact Width (No Peek)', () => {
|
|
185
|
+
const colors = [
|
|
186
|
+
'#005C8A',
|
|
187
|
+
'#FF6B6B',
|
|
188
|
+
'#4ECDC4',
|
|
189
|
+
'#45B7D1',
|
|
190
|
+
'#96CEB4',
|
|
191
|
+
'#FFEAA7'
|
|
192
|
+
];
|
|
193
|
+
|
|
194
|
+
const items = colors.map((color, index) => (
|
|
195
|
+
<CarouselItem
|
|
196
|
+
key={index}
|
|
197
|
+
widthConfig={{
|
|
198
|
+
mobile: '90%',
|
|
199
|
+
tablet: '70%',
|
|
200
|
+
desktop: 'calc(33% - 10px)'
|
|
201
|
+
}}
|
|
202
|
+
>
|
|
203
|
+
<SimpleCard color={color}>Card {index + 1}</SimpleCard>
|
|
204
|
+
</CarouselItem>
|
|
205
|
+
));
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<Container>
|
|
209
|
+
<Title>Three Cards Per Page (exact width, no peek)</Title>
|
|
210
|
+
<CarouselComponent
|
|
211
|
+
items={items}
|
|
212
|
+
options={{
|
|
213
|
+
itemsPerPage: 3
|
|
214
|
+
}}
|
|
215
|
+
showArrows={true}
|
|
216
|
+
showDots={true}
|
|
217
|
+
/>
|
|
218
|
+
</Container>
|
|
219
|
+
);
|
|
220
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ItemContainer } from './styles';
|
|
3
|
+
import { CarouselItemProps } from './types';
|
|
4
|
+
|
|
5
|
+
export const CarouselItem: React.FC<CarouselItemProps> = ({
|
|
6
|
+
children,
|
|
7
|
+
widthConfig = {
|
|
8
|
+
mobile: '90%',
|
|
9
|
+
tablet: '70%',
|
|
10
|
+
desktop: 'calc(50% - 10px)',
|
|
11
|
+
xl: 'calc(50% - 10px)'
|
|
12
|
+
},
|
|
13
|
+
className
|
|
14
|
+
}) => {
|
|
15
|
+
return (
|
|
16
|
+
<ItemContainer widthConfig={widthConfig} className={className}>
|
|
17
|
+
{children}
|
|
18
|
+
</ItemContainer>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NavigationArrowButton } from './styles';
|
|
3
|
+
|
|
4
|
+
interface NavigationArrowProps {
|
|
5
|
+
direction: 'left' | 'right';
|
|
6
|
+
onClick: () => void;
|
|
7
|
+
disabled: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const DefaultNavigationArrow: React.FC<NavigationArrowProps> = ({
|
|
11
|
+
direction,
|
|
12
|
+
onClick,
|
|
13
|
+
disabled
|
|
14
|
+
}) => (
|
|
15
|
+
<NavigationArrowButton
|
|
16
|
+
direction={direction}
|
|
17
|
+
onClick={onClick}
|
|
18
|
+
disabled={disabled}
|
|
19
|
+
aria-label={`${direction === 'left' ? 'Previous' : 'Next'} items`}
|
|
20
|
+
>
|
|
21
|
+
<svg
|
|
22
|
+
width="24"
|
|
23
|
+
height="24"
|
|
24
|
+
viewBox="0 0 16 16"
|
|
25
|
+
fill="none"
|
|
26
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
27
|
+
>
|
|
28
|
+
<path
|
|
29
|
+
d={direction === 'left' ? 'M10 12L6 8L10 4' : 'M6 12L10 8L6 4'}
|
|
30
|
+
stroke="currentColor"
|
|
31
|
+
strokeWidth="1.5"
|
|
32
|
+
strokeLinecap="round"
|
|
33
|
+
strokeLinejoin="round"
|
|
34
|
+
/>
|
|
35
|
+
</svg>
|
|
36
|
+
</NavigationArrowButton>
|
|
37
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PageDotButton } from './styles';
|
|
3
|
+
|
|
4
|
+
interface PageDotProps {
|
|
5
|
+
active: boolean;
|
|
6
|
+
onClick: () => void;
|
|
7
|
+
index: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const DefaultPageDot: React.FC<PageDotProps> = ({
|
|
11
|
+
active,
|
|
12
|
+
onClick,
|
|
13
|
+
index
|
|
14
|
+
}) => (
|
|
15
|
+
<PageDotButton
|
|
16
|
+
active={active}
|
|
17
|
+
onClick={onClick}
|
|
18
|
+
aria-label={`Go to page ${index + 1}`}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { CarouselComponent } from '../index';
|
|
5
|
+
|
|
6
|
+
describe('CarouselComponent', () => {
|
|
7
|
+
const mockItems = [
|
|
8
|
+
<div key="1">Item 1</div>,
|
|
9
|
+
<div key="2">Item 2</div>,
|
|
10
|
+
<div key="3">Item 3</div>,
|
|
11
|
+
<div key="4">Item 4</div>
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
Element.prototype.scrollTo = jest.fn();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('renders all items', () => {
|
|
19
|
+
render(<CarouselComponent items={mockItems} />);
|
|
20
|
+
|
|
21
|
+
expect(screen.getByText('Item 1')).toBeInTheDocument();
|
|
22
|
+
expect(screen.getByText('Item 2')).toBeInTheDocument();
|
|
23
|
+
expect(screen.getByText('Item 3')).toBeInTheDocument();
|
|
24
|
+
expect(screen.getByText('Item 4')).toBeInTheDocument();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('renders navigation arrows by default', () => {
|
|
28
|
+
render(<CarouselComponent items={mockItems} />);
|
|
29
|
+
|
|
30
|
+
const prevButton = screen.getByLabelText('Previous items');
|
|
31
|
+
const nextButton = screen.getByLabelText('Next items');
|
|
32
|
+
|
|
33
|
+
expect(prevButton).toBeInTheDocument();
|
|
34
|
+
expect(nextButton).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('hides navigation arrows when showArrows is false', () => {
|
|
38
|
+
render(<CarouselComponent items={mockItems} showArrows={false} />);
|
|
39
|
+
|
|
40
|
+
const buttons = screen.getAllByRole('button');
|
|
41
|
+
expect(buttons.length).toBe(2);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('renders pagination dots by default', () => {
|
|
45
|
+
render(<CarouselComponent items={mockItems} />);
|
|
46
|
+
|
|
47
|
+
const dots = screen
|
|
48
|
+
.getAllByRole('button')
|
|
49
|
+
.filter(btn => !btn.querySelector('svg'));
|
|
50
|
+
|
|
51
|
+
expect(dots.length).toBeGreaterThan(0);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('hides pagination dots when showDots is false', () => {
|
|
55
|
+
render(
|
|
56
|
+
<CarouselComponent
|
|
57
|
+
items={mockItems}
|
|
58
|
+
showDots={false}
|
|
59
|
+
showArrows={false}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const buttons = screen.queryAllByRole('button');
|
|
64
|
+
|
|
65
|
+
expect(buttons.length).toBe(0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('applies custom className', () => {
|
|
69
|
+
const { container } = render(
|
|
70
|
+
<CarouselComponent items={mockItems} className="custom-carousel" />
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(container.querySelector('.custom-carousel')).toBeInTheDocument();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('handles itemsPerPage option', () => {
|
|
77
|
+
render(
|
|
78
|
+
<CarouselComponent items={mockItems} options={{ itemsPerPage: 1 }} />
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const dots = screen
|
|
82
|
+
.getAllByRole('button')
|
|
83
|
+
.filter(btn => !btn.querySelector('svg'));
|
|
84
|
+
|
|
85
|
+
expect(dots.length).toBe(4);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('handles empty items array', () => {
|
|
89
|
+
const { container } = render(<CarouselComponent items={[]} />);
|
|
90
|
+
|
|
91
|
+
expect(container.querySelector('[role="button"]')).not.toBeInTheDocument();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('handles single item', () => {
|
|
95
|
+
render(<CarouselComponent items={[<div key="1">Single Item</div>]} />);
|
|
96
|
+
|
|
97
|
+
expect(screen.getByText('Single Item')).toBeInTheDocument();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('calls onPageChange callback when provided', () => {
|
|
101
|
+
const onPageChange = jest.fn();
|
|
102
|
+
|
|
103
|
+
render(<CarouselComponent items={mockItems} options={{ onPageChange }} />);
|
|
104
|
+
|
|
105
|
+
const nextButton = screen
|
|
106
|
+
.getAllByRole('button')
|
|
107
|
+
.find(btn => btn.querySelector('svg'));
|
|
108
|
+
|
|
109
|
+
if (nextButton) {
|
|
110
|
+
fireEvent.click(nextButton);
|
|
111
|
+
expect(onPageChange).toHaveBeenCalled();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('renders with custom arrow component', () => {
|
|
116
|
+
const CustomArrow = ({ direction }: { direction: string }) => (
|
|
117
|
+
<button>Custom {direction}</button>
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
render(
|
|
121
|
+
<CarouselComponent
|
|
122
|
+
items={mockItems}
|
|
123
|
+
arrowComponent={CustomArrow as any}
|
|
124
|
+
/>
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const customArrows = screen.getAllByText(/Custom/);
|
|
128
|
+
expect(customArrows.length).toBe(2);
|
|
129
|
+
expect(customArrows[0]).toBeInTheDocument();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('renders with custom dot component', () => {
|
|
133
|
+
const CustomDot = ({ index }: { index: number }) => (
|
|
134
|
+
<button>Dot {index}</button>
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
render(
|
|
138
|
+
<CarouselComponent items={mockItems} dotComponent={CustomDot as any} />
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const customDots = screen.getAllByText(/Dot/);
|
|
142
|
+
expect(customDots.length).toBe(2);
|
|
143
|
+
expect(customDots[0]).toBeInTheDocument();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('navigates to next page when next arrow is clicked', () => {
|
|
147
|
+
render(
|
|
148
|
+
<CarouselComponent items={mockItems} options={{ itemsPerPage: 2 }} />
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const nextButton = screen.getByLabelText('Next items');
|
|
152
|
+
fireEvent.click(nextButton);
|
|
153
|
+
|
|
154
|
+
expect(Element.prototype.scrollTo).toHaveBeenCalled();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('navigates to previous page when previous arrow is clicked', () => {
|
|
158
|
+
render(
|
|
159
|
+
<CarouselComponent items={mockItems} options={{ itemsPerPage: 2 }} />
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const nextButton = screen.getByLabelText('Next items');
|
|
163
|
+
const prevButton = screen.getByLabelText('Previous items');
|
|
164
|
+
|
|
165
|
+
fireEvent.click(nextButton);
|
|
166
|
+
fireEvent.click(prevButton);
|
|
167
|
+
expect(Element.prototype.scrollTo).toHaveBeenCalled();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('handles mouse drag events', () => {
|
|
171
|
+
const { container } = render(
|
|
172
|
+
<CarouselComponent items={mockItems} options={{ itemsPerPage: 2 }} />
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const carouselRow = container.querySelector('div > div > div');
|
|
176
|
+
|
|
177
|
+
if (carouselRow) {
|
|
178
|
+
fireEvent.mouseDown(carouselRow, { pageX: 100 });
|
|
179
|
+
fireEvent.mouseMove(carouselRow, { pageX: 50 });
|
|
180
|
+
fireEvent.mouseUp(carouselRow);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
expect(carouselRow).toBeInTheDocument();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('disables previous arrow on first page', () => {
|
|
187
|
+
render(
|
|
188
|
+
<CarouselComponent items={mockItems} options={{ itemsPerPage: 2 }} />
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const prevButton = screen.getByLabelText('Previous items');
|
|
192
|
+
expect(prevButton).toBeDisabled();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('renders correct number of page dots', () => {
|
|
196
|
+
render(
|
|
197
|
+
<CarouselComponent items={mockItems} options={{ itemsPerPage: 2 }} />
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const dots = screen
|
|
201
|
+
.getAllByRole('button')
|
|
202
|
+
.filter(btn => !btn.querySelector('svg'));
|
|
203
|
+
|
|
204
|
+
expect(dots.length).toBe(2);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('handles page dot click', () => {
|
|
208
|
+
render(
|
|
209
|
+
<CarouselComponent items={mockItems} options={{ itemsPerPage: 2 }} />
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const dots = screen
|
|
213
|
+
.getAllByRole('button')
|
|
214
|
+
.filter(btn => !btn.querySelector('svg'));
|
|
215
|
+
|
|
216
|
+
if (dots[1]) {
|
|
217
|
+
fireEvent.click(dots[1]);
|
|
218
|
+
expect(Element.prototype.scrollTo).toHaveBeenCalled();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('hides dots when there is only one page', () => {
|
|
223
|
+
render(
|
|
224
|
+
<CarouselComponent
|
|
225
|
+
items={[<div key="1">Item 1</div>]}
|
|
226
|
+
options={{ itemsPerPage: 2 }}
|
|
227
|
+
/>
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
const dots = screen
|
|
231
|
+
.queryAllByRole('button')
|
|
232
|
+
.filter(btn => !btn.querySelector('svg'));
|
|
233
|
+
|
|
234
|
+
expect(dots.length).toBe(0);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('handles mouse leave event during drag', () => {
|
|
238
|
+
const { container } = render(
|
|
239
|
+
<CarouselComponent items={mockItems} options={{ itemsPerPage: 2 }} />
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const carouselRow = container.querySelector('div > div > div');
|
|
243
|
+
|
|
244
|
+
if (carouselRow) {
|
|
245
|
+
fireEvent.mouseDown(carouselRow, { pageX: 100 });
|
|
246
|
+
fireEvent.mouseMove(carouselRow, { pageX: 50 });
|
|
247
|
+
fireEvent.mouseLeave(carouselRow);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
expect(carouselRow).toBeInTheDocument();
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('applies correct styles to carousel container', () => {
|
|
254
|
+
const { container } = render(<CarouselComponent items={mockItems} />);
|
|
255
|
+
|
|
256
|
+
const carouselContainer = container.firstChild;
|
|
257
|
+
expect(carouselContainer).toBeInTheDocument();
|
|
258
|
+
});
|
|
259
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { CarouselItem } from '../CarouselItem';
|
|
5
|
+
|
|
6
|
+
describe('CarouselItem', () => {
|
|
7
|
+
it('renders children correctly', () => {
|
|
8
|
+
render(
|
|
9
|
+
<CarouselItem>
|
|
10
|
+
<div>Test Content</div>
|
|
11
|
+
</CarouselItem>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
expect(screen.getByText('Test Content')).toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('applies custom className', () => {
|
|
18
|
+
const { container } = render(
|
|
19
|
+
<CarouselItem className="custom-class">
|
|
20
|
+
<div>Test Content</div>
|
|
21
|
+
</CarouselItem>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expect(container.firstChild).toHaveClass('custom-class');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('uses default widthConfig when not provided', () => {
|
|
28
|
+
const { container } = render(
|
|
29
|
+
<CarouselItem>
|
|
30
|
+
<div>Test Content</div>
|
|
31
|
+
</CarouselItem>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('accepts custom widthConfig', () => {
|
|
38
|
+
render(
|
|
39
|
+
<CarouselItem
|
|
40
|
+
widthConfig={{
|
|
41
|
+
xs: '70%',
|
|
42
|
+
mobile: '90%',
|
|
43
|
+
tablet: '45%',
|
|
44
|
+
desktop: '30%',
|
|
45
|
+
xl: '25%'
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
<div>Test Content</div>
|
|
49
|
+
</CarouselItem>
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
expect(screen.getByText('Test Content')).toBeInTheDocument();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('accepts partial widthConfig', () => {
|
|
56
|
+
render(
|
|
57
|
+
<CarouselItem
|
|
58
|
+
widthConfig={{
|
|
59
|
+
mobile: '80%',
|
|
60
|
+
desktop: '40%'
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
<div>Test Content</div>
|
|
64
|
+
</CarouselItem>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(screen.getByText('Test Content')).toBeInTheDocument();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('renders multiple children correctly', () => {
|
|
71
|
+
render(
|
|
72
|
+
<CarouselItem>
|
|
73
|
+
<div>Child 1</div>
|
|
74
|
+
<div>Child 2</div>
|
|
75
|
+
<div>Child 3</div>
|
|
76
|
+
</CarouselItem>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(screen.getByText('Child 1')).toBeInTheDocument();
|
|
80
|
+
expect(screen.getByText('Child 2')).toBeInTheDocument();
|
|
81
|
+
expect(screen.getByText('Child 3')).toBeInTheDocument();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('handles complex child components', () => {
|
|
85
|
+
const ComplexChild = () => (
|
|
86
|
+
<div>
|
|
87
|
+
<h1>Title</h1>
|
|
88
|
+
<p>Description</p>
|
|
89
|
+
<button>Action</button>
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
render(
|
|
94
|
+
<CarouselItem>
|
|
95
|
+
<ComplexChild />
|
|
96
|
+
</CarouselItem>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
expect(screen.getByText('Title')).toBeInTheDocument();
|
|
100
|
+
expect(screen.getByText('Description')).toBeInTheDocument();
|
|
101
|
+
expect(screen.getByText('Action')).toBeInTheDocument();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('applies className along with widthConfig', () => {
|
|
105
|
+
const { container } = render(
|
|
106
|
+
<CarouselItem
|
|
107
|
+
className="custom-item"
|
|
108
|
+
widthConfig={{
|
|
109
|
+
mobile: '90%',
|
|
110
|
+
desktop: '45%'
|
|
111
|
+
}}
|
|
112
|
+
>
|
|
113
|
+
<div>Test Content</div>
|
|
114
|
+
</CarouselItem>
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(container.firstChild).toHaveClass('custom-item');
|
|
118
|
+
expect(screen.getByText('Test Content')).toBeInTheDocument();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('renders with no props except children', () => {
|
|
122
|
+
render(
|
|
123
|
+
<CarouselItem>
|
|
124
|
+
<div>Minimal Content</div>
|
|
125
|
+
</CarouselItem>
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
expect(screen.getByText('Minimal Content')).toBeInTheDocument();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('handles empty widthConfig object', () => {
|
|
132
|
+
render(
|
|
133
|
+
<CarouselItem widthConfig={{}}>
|
|
134
|
+
<div>Test Content</div>
|
|
135
|
+
</CarouselItem>
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
expect(screen.getByText('Test Content')).toBeInTheDocument();
|
|
139
|
+
});
|
|
140
|
+
});
|