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

refactor: 검색 키워드 컴포넌트 통합 #189

Merged
merged 16 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
34 changes: 34 additions & 0 deletions src/components/RealTimeKeyword/RealTimeKeyword.constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { RealTimeKeywordStyleProps } from '@/components/RealTimeKeyword/RealTimeKeyword.style.ts';

export type VariantType = 'home' | 'search';

export const variantStyles: { [key in VariantType]: RealTimeKeywordStyleProps } = {
home: {
$containerPadding: '1rem',
$containerWidth: '32.5rem',
$containerHeight: 'auto',
$titleContainerPadding: '0.3125rem 0.5rem',
$titleContainerMarginBottom: '0.5rem',
$updateDateTypo: 'caption2',
$columnCount: 2,
$keywordWidth: '7.375rem',
$imageWidth: '10.3125rem',
$imageHeight: '6.875rem',
$imageTop: '-1.125rem',
$imageRight: '0.9375rem',
},
search: {
$containerPadding: '1.25rem',
$containerWidth: '25rem',
$containerHeight: '38.7rem',
$titleContainerPadding: '0.5rem',
$titleContainerMarginBottom: '0.75rem',
$updateDateTypo: 'body3',
$columnCount: 1,
$keywordWidth: 'auto',
$imageWidth: '12.6875rem',
$imageHeight: '8.5rem',
$imageTop: '-3.125rem',
$imageRight: '0',
},
};
105 changes: 105 additions & 0 deletions src/components/RealTimeKeyword/RealTimeKeyword.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { ListItem, Typo } from '@yourssu/design-system-react';
import styled from 'styled-components';

interface StyledContainerProps {
$containerPadding: string;
$containerWidth: string;
$containerHeight: string;
}

export const StyledContainer = styled.div<StyledContainerProps>`
position: relative;
padding: ${({ $containerPadding }) => $containerPadding};
width: ${({ $containerWidth }) => $containerWidth};
height: ${({ $containerHeight }) => $containerHeight};
border-radius: 0.75rem;
border: 1px solid ${({ theme }) => theme.color.borderNormal};
background: ${({ theme }) => theme.color.bgNormal};
`;

interface StyledTitleContainerProps {
$titleContainerPadding: string;
$titleContainerMarginBottom: string;
}

export const StyledTitleContainer = styled.div<StyledTitleContainerProps>`
padding: ${({ $titleContainerPadding }) => $titleContainerPadding};
margin-bottom: ${({ $titleContainerMarginBottom }) => $titleContainerMarginBottom};
`;

export const StyledTitle = styled.div`
margin-bottom: 0.5rem;
color: ${({ theme }) => theme.color.textPrimary};
${({ theme }) => theme.typo.subtitle3};
`;

interface StyledUpdateDateProps {
$updateDateTypo: Typo;
}

export const StyledUpdateDate = styled.div<StyledUpdateDateProps>`
color: ${({ theme }) => theme.color.textTertiary};
${({ theme, $updateDateTypo }) => theme.typo[$updateDateTypo]};
`;

interface StyledListProps {
$columnCount: number;
}

export const StyledList = styled.div<StyledListProps>`
display: grid;
grid-template-rows: ${({ $columnCount }) => `repeat(${10 / $columnCount}, 1fr)`};
grid-template-columns: ${({ $columnCount }) => `repeat(${$columnCount}, 1fr)`};
grid-auto-flow: column;
grid-column-gap: 0.5rem;
`;

export const StyledListItem = styled(ListItem)`
padding: 0.625rem 0.75rem;
`;

interface StyledRankProps {
$rank: number;
}

export const StyledListItemRanking = styled.span<StyledRankProps>`
color: ${({ $rank }) => ($rank < 4 ? '#8a2ac5' : '#8E9398')};
${({ theme }) => theme.typo.subtitle4};
`;

interface StyledListItemKeywordProps {
$keywordWidth: string;
}

export const StyledListItemKeyword = styled.p<StyledListItemKeywordProps>`
width: ${({ $keywordWidth }) => $keywordWidth};
color: ${({ theme }) => theme.color.textPrimary};
${({ theme }) => theme.typo.body1};

white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
`;

interface StyledImageProps {
$imageWidth: string;
$imageHeight: string;
$imageTop: string;
$imageRight: string;
}

export const StyledImage = styled.img<StyledImageProps>`
width: ${({ $imageWidth }) => $imageWidth};
height: ${({ $imageHeight }) => $imageHeight};

position: absolute;
right: ${({ $imageRight }) => $imageRight};
top: ${({ $imageTop }) => $imageTop};
`;

export type RealTimeKeywordStyleProps = StyledContainerProps &
StyledTitleContainerProps &
StyledUpdateDateProps &
StyledListProps &
StyledListItemKeywordProps &
StyledImageProps;
106 changes: 106 additions & 0 deletions src/components/RealTimeKeyword/RealTimeKeyword.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { Suspense } from 'react';

import { IcSearchLine, IconContext } from '@yourssu/design-system-react';
import { Link } from 'react-router-dom';

import RealTimeKeywordImage from '@/assets/realTimeKeyword.webp';
import {
variantStyles,
VariantType,
} from '@/components/RealTimeKeyword/RealTimeKeyword.constant.ts';
import {
StyledContainer,
StyledTitleContainer,
StyledImage,
StyledTitle,
StyledUpdateDate,
StyledList,
StyledListItemRanking,
StyledListItemKeyword,
StyledListItem,
} from '@/components/RealTimeKeyword/RealTimeKeyword.style.ts';
import { useGetRealTimeKeyword } from '@/search/hooks/useGetRealTimeKeyword.ts';
import { formatDateTime } from '@/utils/formatDateTime.ts';

interface RealTimeKeywordProps {
variant: VariantType;
}

export const RealTimeKeyword = ({ variant }: RealTimeKeywordProps) => {
const { data } = useGetRealTimeKeyword();
const {
$containerPadding,
$containerWidth,
$containerHeight,
$titleContainerPadding,
$titleContainerMarginBottom,
$updateDateTypo,
$columnCount,
$keywordWidth,
$imageWidth,
$imageHeight,
$imageTop,
$imageRight,
} = variantStyles[variant];

return (
<StyledContainer
$containerPadding={$containerPadding}
$containerWidth={$containerWidth}
$containerHeight={$containerHeight}
>
<Suspense
fallback={
<StyledUpdateDate $updateDateTypo={$updateDateTypo}>연결 중입니다.</StyledUpdateDate>
}
>
<StyledTitleContainer
$titleContainerPadding={$titleContainerPadding}
$titleContainerMarginBottom={$titleContainerMarginBottom}
>
<StyledTitle>
숨쉬듯이
<br />
검색한 키워드
Hanna922 marked this conversation as resolved.
Show resolved Hide resolved
</StyledTitle>
<StyledUpdateDate
$updateDateTypo={$updateDateTypo}
>{`${formatDateTime(data.basedTime)} 기준`}</StyledUpdateDate>
</StyledTitleContainer>
<StyledImage
$imageHeight={$imageHeight}
$imageWidth={$imageWidth}
$imageRight={$imageRight}
$imageTop={$imageTop}
src={RealTimeKeywordImage}
alt="뿌슝이"
/>
<StyledList $columnCount={$columnCount}>
{data.queries.map((value, index) => (
<Link key={value.query} to={`/search?query=${value.query}`}>
<StyledListItem
key={value.query}
leftIcon={
<StyledListItemRanking $rank={index + 1}>{index + 1}</StyledListItemRanking>
}
rightIcon={
<IconContext.Provider
value={{
color: '#8A2AC5',
}}
>
<IcSearchLine />
</IconContext.Provider>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IconContext는 여러 개의 아이콘에 동일한 스타일을 적용하기 위한 목적이라서 저도 얼마 전에 앎
아이콘 1개에 스타일을 입히는 상황에서는 Icon Component에 바로 넣어서 쓰는 방법도 쓸 수 있습니다~!

Copy link
Collaborator Author

@owl1753 owl1753 May 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인해보니 icon 크기가 figma 디자인과 다른 점이 있어서 같이 수정했습니다 design: figma icon 관련 변경 사항 적용
근데 yds props만으로 해결할 수 없는 부분이 있어서 css를 좀 건드렸는데... 괜찮을까요?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



음...........

이거 디자인 팀에서 ListItem을 변형해서 쓴 게 아니라 그냥 ListItem이 아니네요
보통 YDS 컴포넌트면 컴포넌트명 옆에 바로가기가 뜨는데

image

image

검색어 옆에는 안 뜸 (피그마 Search 페이지 가도 동일하게 안 뜸)
제롬이 채널에 한나 태그해서 올린 메시지 에린도 확인했던데 회의하고 있으면 아마 답장이 오지 않을지 ^^~!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

에엥 이거 잘못 확인 하셨다고 스레드에 말씀하시는 게 좋을 것 같아요 ㅜ.ㅜ

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 수정 사항 남은 거 맞나요? 수정 완료 되시면 코멘트나 request review 한 번 더 요청 주세용

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹 남은 거 마자요 회의때 ListItem 말고 li 태그로 바꾸기로 했음 !!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hanna922 리뷰 요청이 다시 안돼서... 태그로도 알람이 가나 모르겠네요

}
>
<StyledListItemKeyword $keywordWidth={$keywordWidth}>
{value.query}
</StyledListItemKeyword>
</StyledListItem>
</Link>
))}
</StyledList>
</Suspense>
</StyledContainer>
);
};
81 changes: 0 additions & 81 deletions src/home/components/SearchKeyword/SearchKeyword.style.ts

This file was deleted.

61 changes: 0 additions & 61 deletions src/home/components/SearchKeyword/SearchKeyword.tsx

This file was deleted.

Loading