forked from codesquad-members-2023/second-hand
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
200 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useState } from 'react'; | ||
import * as S from './CarouselStyle'; | ||
import { SLIDER_HEIGHT } from '@constants/style'; | ||
import { getFileNameFromUrl } from '@services/slide/slide'; | ||
import { Icon } from '@commons/index'; | ||
import { CarouselPageIndicator } from './CarouselPageIndicator/CarouselPageIndicator'; | ||
|
||
interface CarouselProps { | ||
urls: string[]; | ||
height?: number; | ||
width?: number; | ||
} | ||
|
||
export const Carousel = ({ | ||
urls, | ||
height = SLIDER_HEIGHT, | ||
width = 393, | ||
}: CarouselProps) => { | ||
const [currentCarousel, setCurrentCarousel] = useState(0); | ||
|
||
const moveCarousel = (direction: 'next' | 'previous') => { | ||
console.log(1); | ||
const totalCarousel = urls.length; | ||
setCurrentCarousel((prevSlide) => { | ||
if (direction === 'previous') { | ||
return prevSlide === 0 ? totalCarousel - 1 : prevSlide - 1; | ||
} | ||
return prevSlide === totalCarousel - 1 ? 0 : prevSlide + 1; | ||
}); | ||
}; | ||
|
||
return ( | ||
<S.Carousel height={height} width={width}> | ||
<S.CarouselContainer | ||
height={height} | ||
width={width} | ||
currentCarousel={currentCarousel} | ||
imagesCounts={urls.length} | ||
> | ||
{urls.map((url) => { | ||
const fileName = getFileNameFromUrl(url); | ||
return ( | ||
<S.CarouselImage | ||
src={url} | ||
key={fileName} | ||
alt={fileName} | ||
height={height} | ||
width={width} | ||
/> | ||
); | ||
})} | ||
</S.CarouselContainer> | ||
<CarouselPageIndicator | ||
imageCounts={urls.length} | ||
currentIndex={currentCarousel} | ||
/> | ||
{urls.length >= 2 && ( | ||
<S.CarouselButton | ||
direction="previous" | ||
onClick={() => moveCarousel('previous')} | ||
> | ||
<Icon size={48} name="chevronLeft" color="systemBackgroundWeak" /> | ||
</S.CarouselButton> | ||
)} | ||
{urls.length >= 2 && ( | ||
<S.CarouselButton direction="next" onClick={() => moveCarousel('next')}> | ||
<Icon size={48} name="chevronRight" color="systemBackgroundWeak" /> | ||
</S.CarouselButton> | ||
)} | ||
</S.Carousel> | ||
); | ||
}; |
26 changes: 26 additions & 0 deletions
26
fe/src/components/commons/Carousel/CarouselPageIndicator/CarouselPageIndicator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as S from './CarouselPageIndicatorStyle'; | ||
|
||
interface CarouselPageIndicatorProps { | ||
imageCounts: number; | ||
currentIndex: number; | ||
} | ||
|
||
export const CarouselPageIndicator = ({ | ||
imageCounts, | ||
currentIndex, | ||
}: CarouselPageIndicatorProps) => { | ||
const elements = Array.from({ length: imageCounts }).map((_, i) => { | ||
return { id: i }; | ||
}); | ||
|
||
return ( | ||
<S.CarouselPageIndicator> | ||
{elements.map((element) => ( | ||
<S.Element | ||
key={element.id} | ||
className={currentIndex === element.id ? 'active' : ''} | ||
/> | ||
))} | ||
</S.CarouselPageIndicator> | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
fe/src/components/commons/Carousel/CarouselPageIndicator/CarouselPageIndicatorStyle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const CarouselPageIndicator = styled.div` | ||
display: flex; | ||
z-index: 1; | ||
position: absolute; | ||
bottom: 0; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
background: linear-gradient( | ||
rgba(60, 60, 67, 0) 0%, | ||
rgba(60, 60, 67, 0.3) 100% | ||
); | ||
-webkit-box-align: center; | ||
align-items: center; | ||
-webkit-box-pack: center; | ||
justify-content: center; | ||
width: 100%; | ||
height: 44px; | ||
`; | ||
|
||
export const Element = styled.div` | ||
width: 8px; | ||
height: 8px; | ||
border-radius: 100%; | ||
margin-right: 10px; | ||
background-color: rgba(255, 255, 255, 0.3); | ||
&:last-child { | ||
margin: 0; | ||
} | ||
&.active { | ||
background-color: ${({ theme }) => theme.palette.white}; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import styled from 'styled-components'; | ||
|
||
export interface CarouselStyleProps { | ||
width?: number; | ||
height?: number; | ||
} | ||
|
||
export interface CarouselContainerStyleProps { | ||
imagesCounts: number; | ||
currentCarousel: number; | ||
width: number; | ||
height: number; | ||
} | ||
|
||
export interface CarouselButtonStyleProps { | ||
direction: 'previous' | 'next'; | ||
} | ||
|
||
export const Carousel = styled.div<CarouselStyleProps>` | ||
width: ${({ width }) => width}px; | ||
height: ${({ height }) => height}px; | ||
overflow-x: hidden; | ||
position: relative; | ||
`; | ||
|
||
export const CarouselContainer = styled.div<CarouselContainerStyleProps>` | ||
display: flex; | ||
width: ${({ width, imagesCounts }) => imagesCounts * width}px; | ||
transform: translateX( | ||
${({ currentCarousel, width }) => currentCarousel * width * -1}px | ||
); | ||
height: ${({ height }) => height}px; | ||
`; | ||
|
||
export const CarouselImage = styled.img` | ||
object-fit: cover; | ||
`; | ||
|
||
export const CarouselButton = styled.div<CarouselButtonStyleProps>` | ||
position: absolute; | ||
top: 40%; | ||
${({ direction }) => (direction === 'previous' ? 'left: 0;' : 'right: 0;')} | ||
cursor: pointer; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters