-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from prgrms-web-devcourse-final-project/feature/
#43 feat: LocationPicker 컴포넌트 개발
- Loading branch information
Showing
5 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useState } from "react"; | ||
import { Text, TextButton } from "components/atoms"; | ||
import { Map } from "components/organisms"; | ||
import { LocationPickerWrapper } from "./styled"; | ||
import { ICoord } from "types"; | ||
|
||
interface ILocationPickerProps { | ||
/** 거래희망장소 좌표 (위도, 경도) */ | ||
coord?: ICoord; | ||
/** 거래희망장소 선택 완료 버튼 클릭 이벤트 */ | ||
onLocationSelect: (selectedCoord: ICoord) => void; | ||
} | ||
|
||
export const LocationPicker = ({ | ||
coord, | ||
onLocationSelect | ||
}: ILocationPickerProps) => { | ||
const [centerCoord, setCenterCoord] = useState<any>(null); | ||
|
||
const handleButtonClick = () => { | ||
if (centerCoord) { | ||
const iCoord = { | ||
lat: centerCoord.lat(), | ||
lng: centerCoord.lng() | ||
} as const; | ||
|
||
onLocationSelect(iCoord); | ||
} | ||
}; | ||
|
||
return ( | ||
<LocationPickerWrapper> | ||
<Text | ||
content={`이웃과 만나서 거래하고 싶은 장소를 선택해주세요.`} | ||
variant="h5" | ||
/> | ||
<Text content="만나서 거래할 때는 누구나 찾기 쉬운 공공장소가 좋아요" /> | ||
<Map coord={coord} isCenterMarkerExist setCenterCoord={setCenterCoord} /> | ||
<TextButton text="선택 완료" onClick={handleButtonClick} /> | ||
</LocationPickerWrapper> | ||
); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { NavermapsProvider } from "react-naver-maps"; | ||
import { LocationPicker } from "."; | ||
import { ICoord } from "types"; | ||
|
||
const meta: Meta<typeof LocationPicker> = { | ||
title: "Organisms/LocationPicker", | ||
component: LocationPicker, | ||
tags: ["autodocs"], | ||
argTypes: { | ||
onLocationSelect: { | ||
action: "onSubmitButtonClick", | ||
description: "거래희망장소 선택 완료 버튼 클릭 이벤트" | ||
} | ||
}, | ||
decorators: (story) => ( | ||
<NavermapsProvider ncpClientId={import.meta.env.VITE_NAVER_MAP_CLIENT_ID}> | ||
{story()} | ||
</NavermapsProvider> | ||
) | ||
}; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Register: Story = { | ||
args: { onLocationSelect: (coord: ICoord) => console.log(coord) }, | ||
render: (args) => <LocationPicker {...args} /> | ||
}; | ||
export const Edit: Story = { | ||
args: { | ||
coord: { | ||
lat: 37.5666805, | ||
lng: 126.9784147 | ||
}, | ||
onLocationSelect: (coord: ICoord) => console.log(coord) | ||
}, | ||
render: (args) => <LocationPicker {...args} /> | ||
}; | ||
|
||
export default meta; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import styled from "@emotion/styled"; | ||
|
||
export const LocationPickerWrapper: ReturnType<typeof styled.div> = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
`; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters