Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: PCardSlider 컴포넌트 구현 #99

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"react-dom": "^18.3.1",
"react-loader-spinner": "^6.1.6",
"react-router-dom": "^6.26.2",
"react-slick": "^0.30.2",
"slick-carousel": "^1.8.1",
"styled-components": "^6.1.13",
"vite-tsconfig-paths": "^5.0.1",
"xml-js": "^1.6.11",
Expand All @@ -30,6 +32,7 @@
"@eslint/js": "^9.9.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-slick": "^0.23.13",
"@types/styled-components": "^5.1.34",
"@typescript-eslint/eslint-plugin": "^8.7.0",
"@typescript-eslint/parser": "^8.7.0",
Expand Down
18 changes: 6 additions & 12 deletions src/components/PCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import * as S from './styles';
import { H16, P15 } from '@/components/Text';
import { Poster } from '@/components/Poster';
import { CommonResponseType } from '@/types/apis';
import { PItemType } from '@/types/pItem';

interface PCardProps {
pInfo: Pick<CommonResponseType, 'mt20id' | 'poster' | 'prfnm' | 'fcltynm' | 'prfpdfrom' | 'prfpdto'>;
width?: string;
rank?: number | null;
}

export const PCard = ({ pInfo, width = '225px', rank = null }: PCardProps) => {
export const PCard = ({ id, posterUrl, name, facility, period, rank, width = '225px' }: PItemType) => {
return (
<S.PCard width={width}>
<Poster src={pInfo.poster} rank={rank}></Poster>
<Poster src={posterUrl} rank={rank} />
<S.PCardText>
<H16>{pInfo.prfnm}</H16>
<P15>{pInfo.fcltynm}</P15>
<P15>{pInfo.prfpdfrom + '-' + pInfo.prfpdto}</P15>
<H16>{name}</H16>
<P15>{facility}</P15>
<P15>{period}</P15>
</S.PCardText>
</S.PCard>
);
Expand Down
17 changes: 4 additions & 13 deletions src/components/PCardGrid/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import { PCard } from '@/components/PCard';
import * as S from './styles';
import { CommonResponseType } from '@/types/apis';
import { PItemType } from '@/types/pItem';

interface PCardGridProps {
pList: Pick<CommonResponseType, 'mt20id' | 'poster' | 'prfnm' | 'fcltynm' | 'prfpdfrom' | 'prfpdto'>[];
pList: PItemType[];
width?: string;
rows?: number;
columns?: number;
gap?: number;
isRanked?: boolean;
}

export const PCardGrid = ({
pList,
width = '600px',
rows = 1,
columns = 5,
gap = 10,
isRanked = false,
}: PCardGridProps) => {
console.log(typeof pList);
export const PCardGrid = ({ pList, width = '600px', rows = 1, columns = 5, gap = 10 }: PCardGridProps) => {
return (
<S.PCardGrid width={width} rows={rows} columns={columns} gap={gap}>
{pList.map((perform, index) => (
<PCard key={index} pInfo={perform} width="100%" {...(isRanked && { rank: index + 1 })}></PCard>
<PCard key={index} {...perform} width="100%" rank={index + 1}></PCard>
))}
</S.PCardGrid>
);
Expand Down
33 changes: 33 additions & 0 deletions src/components/PCardSlider/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Slider from 'react-slick';
import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';
import * as S from './styles';
// import { CommonResponseType } from '@/types/apis';
import { PCard } from '@/components/PCard';
import { PItemType } from '@/types/pItem';

interface PCardSliderProps {
pList: PItemType[];
width?: string;
}

export const PCardSlider = ({ pList, width = '100%' }: PCardSliderProps) => {
const settings = {
infinite: true,
speed: 500,
slidesToShow: 5,
slidesToScroll: 1,
swipeToSlide: true,
};
const widthType = width.match(/[^0-9]/g)?.join('');
const PCardWidth = widthType === '%' ? '98%' : `calc(${width} / 5.2)`;
return (
<S.PCardSlider width={width}>
<Slider {...settings}>
{pList.map((perform, index) => {
return <PCard key={index} {...perform} width={PCardWidth} />;
})}
</Slider>
</S.PCardSlider>
);
};
9 changes: 9 additions & 0 deletions src/components/PCardSlider/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { styled } from 'styled-components';

export const PCardSlider = styled.div<{ width: string }>`
width: ${({ width }) => width};
.slick-prev::before,
.slick-next::before {
color: ${({ theme }) => theme.colors.gray};
}
`;
9 changes: 9 additions & 0 deletions src/types/pItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type PItemType = {
id: string;
posterUrl: string;
name: string;
facility: string;
period: string;
rank?: number;
width?: string;
};