Skip to content

Commit 174ab31

Browse files
authored
Merge pull request #961 from Vidit-Kushwaha/chore/carousel
refactor: expose Carousel component for external usage
2 parents eb85e4c + a8deaaf commit 174ab31

File tree

6 files changed

+56
-50
lines changed

6 files changed

+56
-50
lines changed

src/custom/CatalogDetail/Carousel.tsx renamed to src/custom/Carousel/Carousel.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ChevronLeft, ChevronRight } from '@mui/icons-material';
22
import React, { ReactNode, useRef } from 'react';
3+
import { CarouselButton, CarouselContainer, CarouselWrapper } from './style';
34

45
interface CarouselProps {
56
items: ReactNode[];
@@ -9,17 +10,13 @@ interface CarouselProps {
910
itemClassName?: string;
1011
}
1112

12-
import { CarouselButton, CarouselContainer, CarouselWrapper } from './style';
13-
1413
const Carousel: React.FC<CarouselProps> = ({
1514
items,
1615
scrollAmount = 300,
1716
showNavButtons = true,
1817
itemClassName = 'carousel-item'
1918
}) => {
2019
const carouselRef = useRef<HTMLDivElement>(null);
21-
22-
// Skip rendering if no items
2320
if (!items.length) return null;
2421

2522
const scroll = (direction: 'left' | 'right') => {

src/custom/Carousel/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Carousel from './Carousel';
2+
3+
export { Carousel };

src/custom/Carousel/style.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { styled } from '../../theme';
2+
3+
export const CarouselButton = styled('button')(({ theme }) => ({
4+
position: 'absolute',
5+
top: '50%',
6+
transform: 'translateY(-50%)',
7+
zIndex: '1',
8+
background: theme.palette.background.paper,
9+
border: 'none',
10+
cursor: 'pointer',
11+
padding: '0.5rem',
12+
borderRadius: '50%',
13+
boxShadow: '0 2px 4px rgba(0, 0, 0, 0.2)',
14+
'&:hover': {
15+
background: theme.palette.primary.main,
16+
color: '#fff'
17+
},
18+
'&:first-of-type': {
19+
left: '-1.2rem'
20+
},
21+
'&:last-of-type': {
22+
right: '-1.2rem'
23+
}
24+
}));
25+
26+
export const CarouselWrapper = styled('div')({
27+
display: 'flex',
28+
alignItems: 'center',
29+
width: '100%',
30+
position: 'relative'
31+
});
32+
33+
export const CarouselContainer = styled('div')({
34+
display: 'flex',
35+
overflowX: 'auto',
36+
scrollBehavior: 'smooth',
37+
scrollSnapType: 'x mandatory',
38+
gap: '1rem',
39+
padding: '1rem 0',
40+
width: '100%',
41+
'&::-webkit-scrollbar': {
42+
display: 'none'
43+
},
44+
'.carousel-item': {
45+
flex: '0 0 auto',
46+
scrollSnapAlign: 'center',
47+
width: 'auto'
48+
}
49+
});

src/custom/CatalogDetail/RelatedDesigns.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { Carousel } from '../Carousel';
12
import { CatalogCardDesignLogo } from '../CustomCatalog';
23
import CustomCatalogCard, { Pattern } from '../CustomCatalog/CustomCard';
3-
import Carousel from './Carousel';
44
import { getHeadingText } from './helper';
55
import { AdditionalContainer, ContentHeading } from './style';
66
import { UserProfile } from './types';

src/custom/CatalogDetail/style.tsx

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -68,51 +68,6 @@ export const ContentHeading = styled('div')(() => ({
6868
width: '100%',
6969
marginBottom: '1rem'
7070
}));
71-
export const CarouselContainer = styled('div')({
72-
display: 'flex',
73-
overflowX: 'auto',
74-
scrollBehavior: 'smooth',
75-
scrollSnapType: 'x mandatory',
76-
gap: '1rem',
77-
padding: '1rem 0',
78-
width: '100%',
79-
'&::-webkit-scrollbar': {
80-
display: 'none' // Hide scrollbar for a cleaner look
81-
},
82-
'.carousel-item': {
83-
flex: '0 0 auto',
84-
scrollSnapAlign: 'center',
85-
width: 'auto' // Adjust based on your card size
86-
}
87-
});
88-
export const CarouselButton = styled('button')(({ theme }) => ({
89-
position: 'absolute',
90-
top: '50%',
91-
transform: 'translateY(-50%)',
92-
zIndex: '1',
93-
background: theme.palette.background.paper,
94-
border: 'none',
95-
cursor: 'pointer',
96-
padding: '0.5rem',
97-
borderRadius: '50%',
98-
boxShadow: '0 2px 4px rgba(0, 0, 0, 0.2)',
99-
'&:hover': {
100-
background: theme.palette.primary.main,
101-
color: '#fff'
102-
},
103-
'&:first-of-type': {
104-
left: '-1.2rem'
105-
},
106-
'&:last-of-type': {
107-
right: '-1.2rem'
108-
}
109-
}));
110-
export const CarouselWrapper = styled('div')({
111-
display: 'flex',
112-
alignItems: 'center',
113-
width: '100%',
114-
position: 'relative'
115-
});
11671

11772
export const CaveatsContainer = styled('div')(({ theme }) => ({
11873
width: '100%',

src/custom/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ActionButton } from './ActionButton';
22
import { BBChart } from './BBChart';
33
import { BookmarkNotification } from './BookmarkNotification';
4+
import { Carousel } from './Carousel';
45
import CatalogFilter, { CatalogFilterProps } from './CatalogFilter/CatalogFilter';
56
import { ChapterCard } from './ChapterCard';
67
import { CollaboratorAvatarGroup } from './CollaboratorAvatarGroup';
@@ -72,6 +73,7 @@ export {
7273
ActionButton,
7374
BBChart,
7475
BookmarkNotification,
76+
Carousel,
7577
CatalogCardDesignLogo,
7678
CatalogFilter,
7779
ChapterCard,

0 commit comments

Comments
 (0)