-
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 all 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,30 @@ | ||
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.6rem)` : ''}; | ||
`; | ||
|
||
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) => { | ||
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,33 @@ | ||
import { Fragment } from 'react'; | ||
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'}> | ||
<ContentBox $maxHeight={maxHeight} $hiddenOver={showState === 'HIDDEN_OVER'}> | ||
{paragraphList.map((paragraph, index) => ( | ||
<Fragment key={paragraph}> | ||
{index !== 0 && <br />} | ||
<p>{paragraph}</p> | ||
</Fragment> | ||
))} | ||
</ContentBox> | ||
{showState === 'HIDDEN_OVER' && ( | ||
<SeeMoreButtonArea> | ||
<SeeMoreButton onClick={showOver}>더보기</SeeMoreButton> | ||
</SeeMoreButtonArea> | ||
)} | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default SeeMoreContentBox; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { ComponentProps } from 'react'; | ||
import GardenPostItem from '.'; | ||
|
||
const meta: Meta<typeof GardenPostItem> = { | ||
component: GardenPostItem, | ||
argTypes: { | ||
createdAt: { | ||
table: { | ||
type: { | ||
summary: 'DateFormat', | ||
detail: 'YYYY-MM-DD 형식의 문자열', | ||
}, | ||
}, | ||
control: 'text', | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof GardenPostItem>; | ||
|
||
const defaultArgs: ComponentProps<typeof GardenPostItem> = { | ||
createdAt: '1999-12-16', | ||
dictionaryPlantName: '연봉', | ||
content: '한달차인데 저는 이거 이렇게 키우고있어요', | ||
manageLevel: '초보자', | ||
petPlant: { | ||
imageUrl: 'https://images.unsplash.com/photo-1667342608690-828e1a839ead', | ||
nickname: '초퍼', | ||
location: '거실', | ||
flowerpot: '플라스틱/유리/캔', | ||
light: '창문 밖에서 해를 받아요', | ||
wind: '창문이 없지만 바람이 통해요', | ||
daySince: 32, | ||
waterCycle: 7, | ||
}, | ||
}; | ||
|
||
export const Default: Story = { | ||
args: defaultArgs, | ||
}; | ||
|
||
export const LargeContent: Story = { | ||
args: { | ||
...defaultArgs, | ||
dictionaryPlantName: '아스파라거스 풀루모수스', | ||
content: ` | ||
제가 LA에 있을때는 말이죠 정말 제가 꿈에 무대인 메이저리그로 진출해서 가는 식당마다 싸인해달라 기자들은 항상 붙어다니며 취재하고 제가 그 머~ 어~ 대통령이 된 기분이였어요 | ||
그런데 17일만에 17일만에 마이너리그로 떨어졌어요 못던져서 그만두고 그냥 확 한국으로 가버리고 싶었어요 | ||
그래서 집에 가는길에 그 맥주6개 달린거 있잖아요 맥주6개 그걸 사가지고 집으로 갔어요 | ||
그전에는 술먹으면 야구 못하는줄 알았어요 그냥 한국으로 | ||
`, | ||
petPlant: { | ||
...defaultArgs.petPlant, | ||
nickname: '박찬호의 길고길고길고길고길고길고길고긴 식물이름', | ||
}, | ||
}, | ||
}; |
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.
C
해당 함수의 역할이 제가 이해하기로는 show의 상태를
HIDDEN_OVER
를 시키는 함수 같은데 warpperRef라고 명명하신 이유가 있을까요?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.
ref로 instance를 받아야만 해서 이렇게 작성하긴 했습니다!
setInitialShow도 고려해봤어요!
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.
instance로 받는 것이라면, 그 파라마터의 이름이 instanceRef와 같은 식으로 가고, 변수 명은 행동 위주로 가면 더 좋을것 같긴 하네요!