@times-components/ts-components 1.146.2-0831d531868ee6854720b5b42c0a1ccdbe6a4a70.45 → 1.146.2-784617dc4a33959b8795da1d7f425c9929322fae.24

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.
Files changed (138) hide show
  1. package/dist/components/travel-mini-cta/__tests__/index.test.js +262 -0
  2. package/dist/components/travel-mini-cta/index.d.ts +10 -0
  3. package/dist/components/travel-mini-cta/index.js +93 -0
  4. package/dist/components/travel-mini-cta/styles.d.ts +42 -0
  5. package/dist/components/travel-mini-cta/styles.js +268 -0
  6. package/dist/components/travel-mini-cta/travel-mini-cta.stories.js +8 -0
  7. package/dist/components/travel-mini-cta/types.d.ts +10 -0
  8. package/dist/components/{trip-cards → travel-mini-cta}/types.js +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +2 -2
  11. package/dist/utils/applyDarkMode.d.ts +1 -0
  12. package/dist/utils/applyDarkMode.js +12 -0
  13. package/dist/utils/getMediaQuery.d.ts +11 -0
  14. package/dist/utils/getMediaQuery.js +19 -0
  15. package/dist/utils/index.d.ts +2 -0
  16. package/dist/utils/index.js +3 -0
  17. package/package.json +3 -3
  18. package/rnw.js +1 -1
  19. package/src/components/travel-mini-cta/__tests__/__snapshots__/index.test.tsx.snap +211 -0
  20. package/src/components/travel-mini-cta/__tests__/index.test.tsx +330 -0
  21. package/src/components/travel-mini-cta/index.tsx +190 -0
  22. package/src/components/travel-mini-cta/styles.ts +331 -0
  23. package/src/components/travel-mini-cta/travel-mini-cta.stories.tsx +23 -0
  24. package/src/components/travel-mini-cta/types.ts +10 -0
  25. package/src/index.ts +1 -2
  26. package/src/utils/applyDarkMode.ts +12 -0
  27. package/src/utils/getMediaQuery.ts +25 -0
  28. package/src/utils/index.ts +2 -0
  29. package/dist/components/carousel-component/CarouselComponent.stories.js +0 -146
  30. package/dist/components/carousel-component/CarouselItem.d.ts +0 -3
  31. package/dist/components/carousel-component/CarouselItem.js +0 -12
  32. package/dist/components/carousel-component/DefaultNavigationArrow.d.ts +0 -8
  33. package/dist/components/carousel-component/DefaultNavigationArrow.js +0 -6
  34. package/dist/components/carousel-component/DefaultPageDot.d.ts +0 -8
  35. package/dist/components/carousel-component/DefaultPageDot.js +0 -4
  36. package/dist/components/carousel-component/__tests__/CarouselComponent.test.d.ts +0 -1
  37. package/dist/components/carousel-component/__tests__/CarouselComponent.test.js +0 -163
  38. package/dist/components/carousel-component/__tests__/CarouselItem.test.d.ts +0 -1
  39. package/dist/components/carousel-component/__tests__/CarouselItem.test.js +0 -80
  40. package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.d.ts +0 -1
  41. package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.js +0 -62
  42. package/dist/components/carousel-component/__tests__/DefaultPageDot.test.d.ts +0 -1
  43. package/dist/components/carousel-component/__tests__/DefaultPageDot.test.js +0 -68
  44. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.d.ts +0 -1
  45. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.js +0 -459
  46. package/dist/components/carousel-component/hooks/useCarousel.d.ts +0 -2
  47. package/dist/components/carousel-component/hooks/useCarousel.js +0 -167
  48. package/dist/components/carousel-component/index.d.ts +0 -4
  49. package/dist/components/carousel-component/index.js +0 -20
  50. package/dist/components/carousel-component/styles.d.ts +0 -28
  51. package/dist/components/carousel-component/styles.js +0 -172
  52. package/dist/components/carousel-component/types.d.ts +0 -53
  53. package/dist/components/carousel-component/types.js +0 -2
  54. package/dist/components/trip-cards/SkeletonCard.d.ts +0 -7
  55. package/dist/components/trip-cards/SkeletonCard.js +0 -22
  56. package/dist/components/trip-cards/TripCard.d.ts +0 -3
  57. package/dist/components/trip-cards/TripCard.js +0 -62
  58. package/dist/components/trip-cards/TripCards.stories.d.ts +0 -1
  59. package/dist/components/trip-cards/TripCards.stories.js +0 -159
  60. package/dist/components/trip-cards/TripCardsLayout.d.ts +0 -3
  61. package/dist/components/trip-cards/TripCardsLayout.js +0 -63
  62. package/dist/components/trip-cards/__tests__/SkeletonCard.test.d.ts +0 -1
  63. package/dist/components/trip-cards/__tests__/SkeletonCard.test.js +0 -139
  64. package/dist/components/trip-cards/__tests__/TripCard.test.d.ts +0 -1
  65. package/dist/components/trip-cards/__tests__/TripCard.test.js +0 -95
  66. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.d.ts +0 -1
  67. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.js +0 -351
  68. package/dist/components/trip-cards/__tests__/assets.test.d.ts +0 -1
  69. package/dist/components/trip-cards/__tests__/assets.test.js +0 -165
  70. package/dist/components/trip-cards/__tests__/helpers.test.d.ts +0 -1
  71. package/dist/components/trip-cards/__tests__/helpers.test.js +0 -220
  72. package/dist/components/trip-cards/__tests__/index.test.js +0 -478
  73. package/dist/components/trip-cards/__tests__/mockData.test.d.ts +0 -1
  74. package/dist/components/trip-cards/__tests__/mockData.test.js +0 -57
  75. package/dist/components/trip-cards/__tests__/skeletonStyles.test.d.ts +0 -1
  76. package/dist/components/trip-cards/__tests__/skeletonStyles.test.js +0 -194
  77. package/dist/components/trip-cards/assets/BoatIcon.d.ts +0 -1
  78. package/dist/components/trip-cards/assets/BoatIcon.js +0 -4
  79. package/dist/components/trip-cards/assets/CalendarIcon.d.ts +0 -1
  80. package/dist/components/trip-cards/assets/CalendarIcon.js +0 -4
  81. package/dist/components/trip-cards/assets/ChevronRightIcon.d.ts +0 -1
  82. package/dist/components/trip-cards/assets/ChevronRightIcon.js +0 -4
  83. package/dist/components/trip-cards/assets/LocationIcon.d.ts +0 -1
  84. package/dist/components/trip-cards/assets/LocationIcon.js +0 -4
  85. package/dist/components/trip-cards/assets/MoonIcon.d.ts +0 -1
  86. package/dist/components/trip-cards/assets/MoonIcon.js +0 -4
  87. package/dist/components/trip-cards/assets/index.d.ts +0 -6
  88. package/dist/components/trip-cards/assets/index.js +0 -7
  89. package/dist/components/trip-cards/helpers.d.ts +0 -12
  90. package/dist/components/trip-cards/helpers.js +0 -158
  91. package/dist/components/trip-cards/index.d.ts +0 -4
  92. package/dist/components/trip-cards/index.js +0 -68
  93. package/dist/components/trip-cards/mockData.d.ts +0 -3
  94. package/dist/components/trip-cards/mockData.js +0 -317
  95. package/dist/components/trip-cards/skeletonStyles.d.ts +0 -9
  96. package/dist/components/trip-cards/skeletonStyles.js +0 -37
  97. package/dist/components/trip-cards/styles.d.ts +0 -43
  98. package/dist/components/trip-cards/styles.js +0 -404
  99. package/dist/components/trip-cards/types.d.ts +0 -122
  100. package/src/components/carousel-component/CarouselComponent.stories.tsx +0 -220
  101. package/src/components/carousel-component/CarouselItem.tsx +0 -26
  102. package/src/components/carousel-component/DefaultNavigationArrow.tsx +0 -37
  103. package/src/components/carousel-component/DefaultPageDot.tsx +0 -20
  104. package/src/components/carousel-component/__tests__/CarouselComponent.test.tsx +0 -259
  105. package/src/components/carousel-component/__tests__/CarouselItem.test.tsx +0 -140
  106. package/src/components/carousel-component/__tests__/DefaultNavigationArrow.test.tsx +0 -153
  107. package/src/components/carousel-component/__tests__/DefaultPageDot.test.tsx +0 -105
  108. package/src/components/carousel-component/hooks/__tests__/useCarousel.test.ts +0 -625
  109. package/src/components/carousel-component/hooks/useCarousel.ts +0 -229
  110. package/src/components/carousel-component/index.tsx +0 -92
  111. package/src/components/carousel-component/styles.ts +0 -188
  112. package/src/components/carousel-component/types.ts +0 -62
  113. package/src/components/trip-cards/SkeletonCard.tsx +0 -64
  114. package/src/components/trip-cards/TripCard.tsx +0 -187
  115. package/src/components/trip-cards/TripCards.stories.tsx +0 -224
  116. package/src/components/trip-cards/TripCardsLayout.tsx +0 -169
  117. package/src/components/trip-cards/__tests__/SkeletonCard.test.tsx +0 -169
  118. package/src/components/trip-cards/__tests__/TripCard.test.tsx +0 -120
  119. package/src/components/trip-cards/__tests__/TripCardsLayout.test.tsx +0 -669
  120. package/src/components/trip-cards/__tests__/assets.test.tsx +0 -206
  121. package/src/components/trip-cards/__tests__/helpers.test.ts +0 -272
  122. package/src/components/trip-cards/__tests__/index.test.tsx +0 -550
  123. package/src/components/trip-cards/__tests__/mockData.test.ts +0 -67
  124. package/src/components/trip-cards/__tests__/skeletonStyles.test.tsx +0 -256
  125. package/src/components/trip-cards/assets/BoatIcon.tsx +0 -17
  126. package/src/components/trip-cards/assets/CalendarIcon.tsx +0 -17
  127. package/src/components/trip-cards/assets/ChevronRightIcon.tsx +0 -20
  128. package/src/components/trip-cards/assets/LocationIcon.tsx +0 -17
  129. package/src/components/trip-cards/assets/MoonIcon.tsx +0 -17
  130. package/src/components/trip-cards/assets/index.ts +0 -7
  131. package/src/components/trip-cards/helpers.ts +0 -207
  132. package/src/components/trip-cards/index.tsx +0 -122
  133. package/src/components/trip-cards/mockData.ts +0 -345
  134. package/src/components/trip-cards/skeletonStyles.ts +0 -46
  135. package/src/components/trip-cards/styles.ts +0 -450
  136. package/src/components/trip-cards/types.ts +0 -131
  137. /package/dist/components/{trip-cards → travel-mini-cta}/__tests__/index.test.d.ts +0 -0
  138. /package/dist/components/{carousel-component/CarouselComponent.stories.d.ts → travel-mini-cta/travel-mini-cta.stories.d.ts} +0 -0
@@ -1,187 +0,0 @@
1
- import React, { FC, useState } from 'react';
2
- import { Placeholder } from '@times-components/image';
3
- import { TripCardProps } from './types';
4
- import {
5
- CardContainer,
6
- ImageContainer,
7
- CardImage,
8
- OfferLabel,
9
- GiftBanner,
10
- CardContent,
11
- TopContainer,
12
- BottomContainer,
13
- Headline,
14
- DataPointsList,
15
- DataPoint,
16
- DataIcon,
17
- PriceSection,
18
- PriceContainer,
19
- OfferContainer,
20
- PriceLabel,
21
- OriginalPrice,
22
- CurrentPrice,
23
- LogoContainer,
24
- CTAButton,
25
- PriceSuffix,
26
- StyledLink
27
- } from './styles';
28
- import { MoonIcon, LocationIcon, BoatIcon, CalendarIcon } from './assets';
29
- import { tealiumTrackingHandler } from '../../helpers/tracking/TrackingHandler';
30
- import { getDeviceType } from './helpers';
31
-
32
- export const TripCard: FC<TripCardProps> = ({
33
- card,
34
- isStaticGrid,
35
- imgHeight = {},
36
- source
37
- }) => {
38
- const [imageLoaded, setImageLoaded] = useState(false);
39
- const deviceType = getDeviceType();
40
- console.log('source in TripCard:', source);
41
- const trackEvent = (
42
- eventName: string,
43
- parentName: string,
44
- sectionDetails: string
45
- ) => {
46
- tealiumTrackingHandler(
47
- eventName,
48
- 'navigation',
49
- 'click',
50
- parentName,
51
- sectionDetails,
52
- {
53
- device_type: deviceType,
54
- source_page: source || 'unknown'
55
- }
56
- );
57
- };
58
-
59
- const handleCardClick = () =>
60
- trackEvent('travel card selected', card.headline, 'trip cards');
61
-
62
- const handleCTAClick = () =>
63
- trackEvent(
64
- 'trip card cta clicked',
65
- card.headline,
66
- card.cta_text || 'View Itinerary'
67
- );
68
-
69
- const handleLogoClick = () =>
70
- trackEvent(
71
- 'trip provider logo clicked',
72
- card.headline,
73
- `trip provider - ${card.logo_url}`
74
- );
75
-
76
- return (
77
- <CardContainer>
78
- <StyledLink
79
- href={card.cta_url}
80
- target="_blank"
81
- rel="noopener noreferrer"
82
- onClick={handleCardClick}
83
- >
84
- <ImageContainer isStaticGrid={isStaticGrid} {...imgHeight}>
85
- {!imageLoaded && <Placeholder />}
86
- <CardImage
87
- src={card.image}
88
- alt={card.headline}
89
- onLoad={() => setImageLoaded(true)}
90
- isLoaded={imageLoaded}
91
- />
92
- {card.offer_label && <OfferLabel>{card.offer_label}</OfferLabel>}
93
- {card.gift_banner && <GiftBanner>{card.gift_banner}</GiftBanner>}
94
- </ImageContainer>
95
- </StyledLink>
96
-
97
- <CardContent>
98
- <TopContainer>
99
- <StyledLink
100
- href={card.cta_url}
101
- target="_blank"
102
- rel="noopener noreferrer"
103
- onClick={handleCardClick}
104
- >
105
- <Headline>{card.headline}</Headline>
106
- </StyledLink>
107
-
108
- <DataPointsList>
109
- {card.date && (
110
- <DataPoint>
111
- <DataIcon>
112
- <CalendarIcon />
113
- </DataIcon>
114
- <span>{card.date}</span>
115
- </DataPoint>
116
- )}
117
- {card.duration && (
118
- <DataPoint>
119
- <DataIcon>
120
- <MoonIcon />
121
- </DataIcon>
122
- <span>{card.duration}</span>
123
- </DataPoint>
124
- )}
125
- {card.route && (
126
- <DataPoint>
127
- <DataIcon>
128
- <LocationIcon />
129
- </DataIcon>
130
- <span>{card.route}</span>
131
- </DataPoint>
132
- )}
133
- {card.ship && (
134
- <DataPoint>
135
- <DataIcon>
136
- <BoatIcon />
137
- </DataIcon>
138
- <span>{card.ship}</span>
139
- </DataPoint>
140
- )}
141
- </DataPointsList>
142
- </TopContainer>
143
-
144
- <BottomContainer>
145
- <PriceSection>
146
- <PriceContainer>
147
- {card.price !== 'Enquire now' && (
148
- <OfferContainer>
149
- {<PriceLabel>From</PriceLabel>}
150
- {card.original_price && (
151
- <OriginalPrice>{card.original_price}</OriginalPrice>
152
- )}
153
- </OfferContainer>
154
- )}
155
- <CurrentPrice $isEnquire={card.price === 'Enquire now'}>
156
- {card.price}
157
- {card.price !== 'Enquire now' && <PriceSuffix>pp</PriceSuffix>}
158
- </CurrentPrice>
159
- </PriceContainer>
160
-
161
- {card.logo && (
162
- <LogoContainer>
163
- <a
164
- href={card.logo_url}
165
- target="_blank"
166
- rel="noopener noreferrer"
167
- onClick={handleLogoClick}
168
- >
169
- <img src={card.logo} alt="Partner logo" />
170
- </a>
171
- </LogoContainer>
172
- )}
173
- </PriceSection>
174
-
175
- <CTAButton
176
- href={card.cta_url}
177
- target="_blank"
178
- rel="noopener noreferrer"
179
- onClick={handleCTAClick}
180
- >
181
- {card.cta_text || 'View Itinerary'}
182
- </CTAButton>
183
- </BottomContainer>
184
- </CardContent>
185
- </CardContainer>
186
- );
187
- };
@@ -1,224 +0,0 @@
1
- import React from 'react';
2
- import { storiesOf } from '@storybook/react';
3
- import { TripCards } from './index';
4
- import styled from 'styled-components';
5
- import { defaultTripCardImgHeight } from './helpers';
6
-
7
- const spacing = (multiplier: number) => `${multiplier * 8}px`;
8
-
9
- const breakpoints = {
10
- medium: 768,
11
- wide: 1024
12
- };
13
-
14
- const InteractiveContainer = styled.div`
15
- position: relative;
16
- margin-bottom: ${spacing(4)};
17
- padding: 0 ${spacing(2)};
18
-
19
- @media (min-width: ${breakpoints.medium}px) {
20
- width: 80.8%;
21
- margin-left: auto;
22
- margin-right: auto;
23
- padding: 0;
24
- }
25
-
26
- @media (min-width: ${breakpoints.wide}px) {
27
- width: 56.2%;
28
- }
29
- `;
30
-
31
- storiesOf('Typescript Component/TripCards', module)
32
- .add('Channel View Two Cards', () => (
33
- <TripCards
34
- element={{
35
- class: 'trip-cards',
36
- tripcards: btoa(JSON.stringify([2074350, 2140335])),
37
- title: 'Similar cruises',
38
- titleurl: 'https://www.thetimes.com/travel/holidays',
39
- description: 'Brought to you by Times Holidays'
40
- }}
41
- useMockData={true}
42
- maxWidthItemConfig={{
43
- xs: '85%',
44
- mobile: '87%',
45
- tablet: '44%',
46
- desktop: '314px',
47
- xl: '368px'
48
- }}
49
- widthContainerConfig={{
50
- tablet: '728px',
51
- desktop: '984px',
52
- xl: '1144px'
53
- }}
54
- />
55
- ))
56
- .add('Channel View Three Cards', () => (
57
- <TripCards
58
- element={{
59
- class: 'trip-cards',
60
- tripcards: btoa(JSON.stringify([2074350, 2140335, 2177685])),
61
- title: 'Featured Voyages',
62
- titleurl: 'https://www.thetimes.com/travel/holidays',
63
- description: 'Handpicked by our travel experts'
64
- }}
65
- forceStaticGrid={true}
66
- maxWidthItemConfig={{
67
- xs: '85%',
68
- mobile: '87%',
69
- tablet: '44%',
70
- desktop: '314px',
71
- xl: '368px'
72
- }}
73
- widthContainerConfig={{
74
- tablet: '728px',
75
- desktop: '984px',
76
- xl: '1144px'
77
- }}
78
- useMockData={true}
79
- />
80
- ))
81
- .add('Article View Two Trip Cards', () => (
82
- <InteractiveContainer>
83
- <TripCards
84
- element={{
85
- class: 'trip-cards',
86
- tripcards: btoa(JSON.stringify([2074350, 2140335])),
87
- title: 'Similar cruises',
88
- titleurl: 'https://www.thetimes.com/travel/holidays',
89
- description: 'Brought to you by Times Holidays'
90
- }}
91
- useMockData={true}
92
- maxWidthItemConfig={{
93
- mobile: '320px',
94
- tablet: '260px',
95
- desktop: '260px',
96
- xl: '300px'
97
- }}
98
- widthContainerConfig={{
99
- mobile: '390px',
100
- tablet: '620px',
101
- desktop: '574px',
102
- xl: '663px'
103
- }}
104
- imgHeight={defaultTripCardImgHeight}
105
- />
106
- </InteractiveContainer>
107
- ))
108
- .add('Article View Three Cards', () => (
109
- <InteractiveContainer>
110
- <TripCards
111
- element={{
112
- class: 'trip-cards',
113
- tripcards: btoa(JSON.stringify([2074350, 2140335, 2177685])),
114
- title: 'Similar cruises',
115
- titleurl: 'https://www.thetimes.com/travel/holidays',
116
- description: 'Brought to you by Times Holidays'
117
- }}
118
- useMockData={true}
119
- maxWidthItemConfig={{
120
- mobile: '320px',
121
- tablet: '260px',
122
- desktop: '260px',
123
- xl: '300px'
124
- }}
125
- widthContainerConfig={{
126
- mobile: '390px',
127
- tablet: '620px',
128
- desktop: '574px',
129
- xl: '663px'
130
- }}
131
- imgHeight={{ ...defaultTripCardImgHeight, $heightXs: '100%' }}
132
- />
133
- </InteractiveContainer>
134
- ))
135
- .add('Article View Two Trip Cards', () => (
136
- <InteractiveContainer>
137
- <TripCards
138
- element={{
139
- class: 'trip-cards',
140
- tripcards: btoa(JSON.stringify([2074350, 2140335])),
141
- title: 'Similar cruises',
142
- titleurl: 'https://www.thetimes.com/travel/holidays',
143
- description: 'Brought to you by Times Holidays'
144
- }}
145
- useMockData={true}
146
- maxWidthItemConfig={{
147
- mobile: '320px',
148
- tablet: '260px',
149
- desktop: '260px',
150
- xl: '300px'
151
- }}
152
- widthContainerConfig={{
153
- mobile: '390px',
154
- tablet: '620px',
155
- desktop: '574px',
156
- xl: '663px'
157
- }}
158
- imgHeight={defaultTripCardImgHeight}
159
- />
160
- </InteractiveContainer>
161
- ))
162
- .add('Article View Trip Cards', () => (
163
- <InteractiveContainer>
164
- <TripCards
165
- element={{
166
- class: 'trip-cards',
167
- tripcards: btoa(JSON.stringify([2074350, 2140335, 2177685])),
168
- title: 'Similar cruises',
169
- titleurl: 'https://www.thetimes.com/travel/holidays',
170
- description: 'Brought to you by Times Holidays'
171
- }}
172
- useMockData={true}
173
- maxWidthItemConfig={{
174
- mobile: '320px',
175
- tablet: '260px',
176
- desktop: '260px',
177
- xl: '300px'
178
- }}
179
- widthContainerConfig={{
180
- mobile: '390px',
181
- tablet: '620px',
182
- desktop: '574px',
183
- xl: '663px'
184
- }}
185
- imgHeight={defaultTripCardImgHeight}
186
- />
187
- </InteractiveContainer>
188
- ))
189
- .add('Article View Six Cards', () => (
190
- <InteractiveContainer>
191
- <TripCards
192
- element={{
193
- class: 'trip-cards',
194
- tripcards: btoa(
195
- JSON.stringify([
196
- 2074350,
197
- 2140335,
198
- 2177685,
199
- 2074351,
200
- 2140336,
201
- 2177686
202
- ])
203
- ),
204
- title: 'Similar cruises',
205
- titleurl: 'https://www.thetimes.com/travel/holidays',
206
- description: 'Brought to you by Times Holidays'
207
- }}
208
- useMockData={true}
209
- maxWidthItemConfig={{
210
- mobile: '320px',
211
- tablet: '260px',
212
- desktop: '260px',
213
- xl: '300px'
214
- }}
215
- widthContainerConfig={{
216
- mobile: '390px',
217
- tablet: '620px',
218
- desktop: '574px',
219
- xl: '663px'
220
- }}
221
- imgHeight={defaultTripCardImgHeight}
222
- />
223
- </InteractiveContainer>
224
- ));
@@ -1,169 +0,0 @@
1
- import React, { FC, useRef, useState, useEffect } from 'react';
2
- import { CarouselComponent, CarouselItem } from '../carousel-component';
3
- import { TripCardsLayoutProps } from './types';
4
- import {
5
- Container,
6
- TitleSection,
7
- TitleBar,
8
- TitleContent,
9
- Title,
10
- Subtitle,
11
- TitleLink,
12
- StaticCardsGrid
13
- } from './styles';
14
- import { ChevronRightIcon } from './assets';
15
- import { tealiumTrackingHandler } from '../../helpers/tracking/TrackingHandler';
16
-
17
- export const TripCardsLayout: FC<TripCardsLayoutProps> = ({
18
- element,
19
- items,
20
- CardComponent,
21
- itemsPerPage,
22
- widthContainerConfig = {},
23
- widthItemConfig,
24
- maxWidthItemConfig,
25
- imgHeight,
26
- forceStaticGrid,
27
- source
28
- }) => {
29
- const { titleurl, title, description } = element;
30
- const gridRef = useRef<HTMLDivElement>(null);
31
- const [hasOverflow, setHasOverflow] = useState(false);
32
- const [isTabletMobile, setIsTabletMobile] = useState(false);
33
-
34
- const isStaticGrid = items.length === 2 || forceStaticGrid;
35
-
36
- // Handle responsive breakpoint detection
37
- useEffect(() => {
38
- const mediaQuery = window.matchMedia('(max-width: 1024px)');
39
- const handleMediaChange = (e: MediaQueryListEvent | MediaQueryList) => {
40
- setIsTabletMobile(e.matches);
41
- };
42
- handleMediaChange(mediaQuery);
43
- mediaQuery.addEventListener('change', handleMediaChange);
44
-
45
- return () => {
46
- mediaQuery.removeEventListener('change', handleMediaChange);
47
- };
48
- }, []);
49
-
50
- useEffect(
51
- () => {
52
- if (!isStaticGrid || !gridRef.current) {
53
- setHasOverflow(false);
54
- return;
55
- }
56
-
57
- const checkOverflow = () => {
58
- if (gridRef.current) {
59
- const isOverflowing =
60
- gridRef.current.scrollWidth > gridRef.current.clientWidth;
61
- setHasOverflow(isOverflowing);
62
- }
63
- };
64
-
65
- checkOverflow();
66
- const resizeObserver = new ResizeObserver(checkOverflow);
67
- resizeObserver.observe(gridRef.current);
68
-
69
- return () => {
70
- resizeObserver.disconnect();
71
- };
72
- },
73
- [isStaticGrid, items.length]
74
- );
75
-
76
- const shouldUseCarousel =
77
- (isTabletMobile && items.length >= 3) || !isStaticGrid || hasOverflow;
78
-
79
- const onTitleClick = () => {
80
- tealiumTrackingHandler(
81
- 'trip cards section title',
82
- 'navigation',
83
- 'click',
84
- 'Trip Cards',
85
- title || 'trip cards section',
86
- {
87
- source_page: source || 'unknown'
88
- }
89
- );
90
- };
91
-
92
- console.log('source in TripCard:', source);
93
-
94
- return (
95
- <Container data-testid="trip-cards-container" {...widthContainerConfig}>
96
- <TitleSection data-testid="title-section">
97
- <TitleBar
98
- data-testid="title-bar"
99
- applyRightPadding={!!widthContainerConfig.mobile}
100
- >
101
- <TitleContent data-testid="title-content">
102
- {titleurl ? (
103
- <TitleLink
104
- href={titleurl}
105
- target="_blank"
106
- rel="noopener noreferrer"
107
- onClick={onTitleClick}
108
- data-testid="trip-cards-title-link"
109
- style={{ textDecoration: 'none', color: 'inherit' }}
110
- >
111
- <Title data-testid="trip-cards-title">{title}</Title>
112
- </TitleLink>
113
- ) : (
114
- <Title data-testid="trip-cards-title">{title}</Title>
115
- )}
116
- <Subtitle data-testid="trip-cards-subtitle">{description}</Subtitle>
117
- </TitleContent>
118
- {titleurl && (
119
- <TitleLink
120
- href={titleurl}
121
- target="_blank"
122
- rel="noopener noreferrer"
123
- data-testid="title-link"
124
- onClick={onTitleClick}
125
- >
126
- <ChevronRightIcon />
127
- </TitleLink>
128
- )}
129
- </TitleBar>
130
- </TitleSection>
131
-
132
- {!shouldUseCarousel ? (
133
- <StaticCardsGrid data-testid="static-cards-grid" ref={gridRef}>
134
- {items.map(item => (
135
- <CardComponent
136
- imgHeight={imgHeight}
137
- key={item.id}
138
- card={item.data}
139
- isStaticGrid={true}
140
- forceStaticGrid={forceStaticGrid}
141
- source={source}
142
- />
143
- ))}
144
- </StaticCardsGrid>
145
- ) : (
146
- <CarouselComponent
147
- items={items.map(item => (
148
- <CarouselItem
149
- key={item.id}
150
- widthItemConfig={widthItemConfig}
151
- maxWidthItemConfig={maxWidthItemConfig}
152
- >
153
- <CardComponent
154
- card={item.data}
155
- imgHeight={imgHeight}
156
- source={source}
157
- />
158
- </CarouselItem>
159
- ))}
160
- options={{
161
- itemsPerPage
162
- }}
163
- showArrows={!isStaticGrid}
164
- showDots={true}
165
- />
166
- )}
167
- </Container>
168
- );
169
- };