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 5 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
108 changes: 108 additions & 0 deletions src/components/RealTimeKeyword/RealTimeKeyword.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { ListItem, Typo } from '@yourssu/design-system-react';
import styled from 'styled-components';

interface StyledContainerProps {
containerPadding: string;
containerWidth: string;
containerHeight: string;
Hanna922 marked this conversation as resolved.
Show resolved Hide resolved
}
export const StyledContainer = styled.div<StyledContainerProps>`
Hanna922 marked this conversation as resolved.
Show resolved Hide resolved
position: relative;
padding: ${(prop: StyledContainerProps) => prop.containerPadding};
width: ${(prop: StyledContainerProps) => prop.containerWidth};
height: ${(prop: StyledContainerProps) => prop.containerHeight};
Hanna922 marked this conversation as resolved.
Show resolved Hide resolved
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: ${(prop: StyledTitleContainerProps) => prop.titleContainerPadding};
margin-bottom: ${(prop: StyledTitleContainerProps) => prop.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: ${(props) => `repeat(${10 / props.columnCount}, 1fr)`};
grid-template-columns: ${(props) => `repeat(${props.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: ${(prop) => (prop.$rank < 4 ? '#8a2ac5' : '#8E9398')};
font-family: 'Spoqa Han Sans Neo';
font-size: 1.125rem;
font-style: normal;
font-weight: 500;
line-height: 130%;
Hanna922 marked this conversation as resolved.
Show resolved Hide resolved
`;

interface StyledListItemKeywordProps {
keywordWidth: string;
}

export const StyledListItemKeyword = styled.p<StyledListItemKeywordProps>`
width: ${(prop: StyledListItemKeywordProps) => prop.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: ${(prop: StyledImageProps) => prop.imageWidth};
height: ${(prop: StyledImageProps) => prop.imageHeight};

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

export type RealTimeKeywordStyleProps = StyledContainerProps &
StyledTitleContainerProps &
StyledUpdateDateProps &
StyledListProps &
StyledListItemKeywordProps &
StyledImageProps;
136 changes: 136 additions & 0 deletions src/components/RealTimeKeyword/RealTimeKeyword.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
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 {
StyledContainer,
StyledTitleContainer,
StyledImage,
StyledTitle,
StyledUpdateDate,
StyledList,
StyledListItemRanking,
StyledListItemKeyword,
StyledListItem,
RealTimeKeywordStyleProps,
} from '@/components/RealTimeKeyword/RealTimeKeyword.style.ts';
import { useGetRealTimeKeyword } from '@/search/hooks/useGetRealTimeKeyword.ts';
import { formatDateTime } from '@/utils/formatDateTime.ts';

type VariantType = 'home' | 'search';

const variantStyles: { [key in VariantType]: RealTimeKeywordStyleProps } = {
Hanna922 marked this conversation as resolved.
Show resolved Hide resolved
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',
},
};

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