-
Notifications
You must be signed in to change notification settings - Fork 5
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: 모두의 정원 게시글 아이템 구현 #340
The head ref may contain hidden characters: "feature/337-\uBAA8\uB450\uC758_\uC815\uC6D0_\uAC8C\uC2DC\uAE00"
Changes from 12 commits
442c1ef
1c7565e
ab9c71d
ec3d7fe
4b75101
74ea124
0d3dcf8
be96a7d
7389b07
74d93e9
c650f52
019ec68
b158ffe
7fb2a53
6557da4
c428062
a900a88
14106a7
66a2b5c
5185e86
7ea5eef
3013330
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import SeeMoreContentBox from '.'; | ||
|
||
const meta: Meta<typeof SeeMoreContentBox> = { | ||
component: SeeMoreContentBox, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof SeeMoreContentBox>; | ||
|
||
export const ShortContent: Story = { | ||
args: { | ||
maxHeight: '32px', | ||
children: '안녕하세요', | ||
}, | ||
}; | ||
|
||
export const LongContent: Story = { | ||
args: { | ||
maxHeight: '32px', | ||
children: ` | ||
제가 LA에 있을때는 말이죠 정말 제가 꿈에 무대인 메이저리그로 진출해서 가는 식당마다 싸인해달라 기자들은 항상 붙어다니며 취재하고 제가 그 머~ 어~ 대통령이 된 기분이였어요 | ||
그런데 17일만에 17일만에 마이너리그로 떨어졌어요 못던져서 그만두고 그냥 확 한국으로 가버리고 싶었어요 | ||
그래서 집에 가는길에 그 맥주6개 달린거 있잖아요 맥주6개 그걸 사가지고 집으로 갔어요 | ||
그전에는 술먹으면 야구 못하는줄 알았어요 그냥 한국으로 | ||
`, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { styled } from 'styled-components'; | ||
|
||
export const Wrapper = styled.div<{ hiddenOver: boolean; maxHeight: string }>` | ||
position: relative; | ||
width: 100%; | ||
height: ${({ hiddenOver, maxHeight }) => (hiddenOver ? maxHeight : 'max-content')}; | ||
`; | ||
|
||
export const ContentBox = styled.div<{ hiddenOver: boolean; maxHeight: string }>` | ||
overflow: hidden; | ||
max-height: ${({ hiddenOver, maxHeight }) => (hiddenOver ? `calc(${maxHeight} - 1.4rem)` : '')}; | ||
`; | ||
|
||
export const SeeMoreButtonArea = styled.div` | ||
position: absolute; | ||
z-index: ${(props) => props.theme.zIndex.fixed}; | ||
bottom: 0; | ||
|
||
display: flex; | ||
justify-content: start; | ||
|
||
width: 100%; | ||
`; | ||
|
||
export const SeeMoreButton = styled.button` | ||
width: max-content; | ||
height: 1.2rem; | ||
font-size: 1.2rem; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useState } from 'react'; | ||
|
||
type ShowState = 'NOT_OVER' | 'HIDDEN_OVER' | 'SHOW_OVER'; | ||
|
||
const useShowState = (maxHeight: `${number}px`) => { | ||
const [showState, setShowState] = useState<ShowState>('NOT_OVER'); | ||
|
||
const wrapperRef = (instance: HTMLDivElement | null) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C해당 함수의 역할이 제가 이해하기로는 show의 상태를 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ref로 instance를 받아야만 해서 이렇게 작성하긴 했습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instance로 받는 것이라면, 그 파라마터의 이름이 instanceRef와 같은 식으로 가고, 변수 명은 행동 위주로 가면 더 좋을것 같긴 하네요! |
||
if (!instance) return; | ||
|
||
const maxHeightNumber = Number(maxHeight.slice(0, -2)); | ||
|
||
if (showState === 'NOT_OVER' && instance.offsetHeight > maxHeightNumber) { | ||
setShowState('HIDDEN_OVER'); | ||
} | ||
}; | ||
|
||
const showOver = () => { | ||
setShowState('SHOW_OVER'); | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 실제로 사용할 때 리뷰를 다시 닫을 것 같지는 않아서 |
||
return { showState, wrapperRef, showOver }; | ||
}; | ||
|
||
export default useShowState; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ContentBox, SeeMoreButton, SeeMoreButtonArea, Wrapper } from './SeeMoreContentBox.styles'; | ||
import useShowState from './hooks/useShowState'; | ||
|
||
interface SeeMoreContentBoxProps { | ||
children: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 이걸 PropsWithChildren을 안써도 children을 제대로 받아오네요 😲 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 맞아요! children 이라는 네이밍의 필드면 가져옵니다~ |
||
maxHeight?: `${number}px`; | ||
} | ||
|
||
const SeeMoreContentBox = ({ children: content, maxHeight = '64px' }: SeeMoreContentBoxProps) => { | ||
const { showState, wrapperRef, showOver } = useShowState(maxHeight); | ||
const paragraphList = content.trim().split(/(?:\r?\n)+/); | ||
|
||
return ( | ||
<Wrapper ref={wrapperRef} maxHeight={maxHeight} hiddenOver={showState === 'HIDDEN_OVER'}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ref에 메서드를 할당 할수도 있었군요...! |
||
<ContentBox maxHeight={maxHeight} hiddenOver={showState === 'HIDDEN_OVER'}> | ||
{paragraphList.shift()} | ||
{paragraphList.map((paragraph) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C여기에서 key가 없다고 스토리북이 울부짖는데 어떻게 생각하시나요?? |
||
<> | ||
<br /> | ||
<br /> | ||
{paragraph} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rparagraph에 시맨틱 태그 추가 부탁드려요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p 태그 말씀하는 것 맞나요? 추가하겠습니다! |
||
</> | ||
))} | ||
</ContentBox> | ||
{showState === 'HIDDEN_OVER' && ( | ||
<SeeMoreButtonArea> | ||
<SeeMoreButton onClick={showOver}>더보기</SeeMoreButton> | ||
</SeeMoreButtonArea> | ||
)} | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default SeeMoreContentBox; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ import Flowerpot from 'components/@common/Icons/Flowerpot'; | |
import House from 'components/@common/Icons/House'; | ||
import Sun from 'components/@common/Icons/Sun'; | ||
import Wind from 'components/@common/Icons/Wind'; | ||
import SeeMoreContentBox from 'components/@common/SeeMoreContentBox'; | ||
import { convertDateKorYear } from 'utils/date'; | ||
import theme from 'style/theme.style'; | ||
import { | ||
Content, | ||
ContentArea, | ||
DaySince, | ||
Environment, | ||
EnvironmentItem, | ||
|
@@ -25,12 +26,12 @@ import { | |
type GardenPostItemProps = Omit<GardenPostItemType, 'id' | 'updatedAt'>; | ||
WaiNaat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const GardenPostItem = ({ content, createdAt, manageLevel, petPlant }: GardenPostItemProps) => { | ||
const postingDate = convertDateKorYear(createdAt).slice(5); | ||
const postingDate = convertDateKorYear(createdAt); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저의 스토리북에서는 괜찮은데 혹시 폰트 적용 후에도 짤리시나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
return ( | ||
<Wrapper> | ||
<Header> | ||
<PetPlantImage src={petPlant.imageUrl} /> | ||
<PetPlantImage src={petPlant.imageUrl} alt="반려식물" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C갑자기 생각난건데 이 사진을 크게 보여줄 필요는 없겠죠?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아마 나중에 포스팅 용 사진이 따로 추가될 것 같습니다~ |
||
<HeaderContent> | ||
<PetPlantNickname>{petPlant.nickname}</PetPlantNickname> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<DaySince> | ||
|
@@ -93,22 +94,9 @@ const GardenPostItem = ({ content, createdAt, manageLevel, petPlant }: GardenPos | |
<WaterCycleTag>물 주기: {petPlant.waterCycle}일</WaterCycleTag> | ||
<ManageLevelTag>{manageLevel}에게 추천해요</ManageLevelTag> | ||
</TagArea> | ||
<Content> | ||
{content | ||
.trim() | ||
.split(/(?:\r?\n)+/) | ||
.map((paragraph, index) => | ||
index ? ( | ||
<> | ||
<br /> | ||
<br /> | ||
{paragraph} | ||
</> | ||
) : ( | ||
paragraph | ||
) | ||
)} | ||
</Content> | ||
<ContentArea> | ||
<SeeMoreContentBox>{content}</SeeMoreContentBox> | ||
</ContentArea> | ||
</Wrapper> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import type { DateFormat } from './date'; | ||
import type { ManageLevel } from './dictionaryPlant'; | ||
import type { PetPlantDetails } from './petPlant'; | ||
|
||
export interface GardenPostItem { | ||
id: number; | ||
content: string; | ||
createdAt: string; | ||
updatedAt: string; | ||
createdAt: DateFormat; | ||
updatedAt: DateFormat; | ||
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
manageLevel: Exclude<ManageLevel, '정보없음'>; | ||
petPlant: Pick< | ||
PetPlantDetails, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R
camelCase로 된 props에 transient props 부탁드려요 🙏🙏🙏