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

Feat/map #10

Merged
merged 13 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 41 additions & 0 deletions components/LayoutMap/LayoutMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";
import {HeaderBar} from "components/HeaderBar";
import {SearchBar} from "components/SearchBar";
import {Stack} from "components/Stack";

type LayoutMapProps = {
children: React.ReactNode;
};

const LayoutMap = ({children}: LayoutMapProps) => {
return (
<div
css={{
display: "flex",
flexDirection: "column",
width: "100%",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

홍빈님 말씀대로 이 부분의 영향이 있었어요. 확인해보니, SearchBar 안에 들어있는 컴포넌트의 margin, padding을 설정해주지 않아서 마음대로 움직이고 있는 거였어요.

height: "100vh",
}}
>
<HeaderBar />
<SearchBar />
<div css={{flex: 1, height: 10}}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이 부분 해결했습니다!

해결방식

  1. stack을 감싸는 div에 height를 준다.
  • 홍빈님 말씀대로 해봤는데 아직 의문인 것은 height를 몇으로 주든 원하는 대로 동작은 되는데 height: 10px로 고정되지는 않는다는 것입니다.
  1. stack 안에 들어가는 게시글 하나에 div를 만든다.
  • 따로 감쌀 필요가 없을 거 같아서 <></>로 했더니 안 되더군요.

화면 기록 2022-05-01 오전 9 33 27

<Stack
spacing="29px"
divider={<hr css={{width: "88%", color: "#DDDDDD"}} />}
>
<div css={{height: 200}}>item2</div>
<div css={{height: 200}}>item2</div>
<div css={{height: 200}}>item2</div>
<div css={{height: 200}}>item2</div>
<div css={{height: 200}}>item2</div>
</Stack>

{/* naver map */}
<div css={{width: "100%"}}>{children}</div>
</div>
</div>
);
};

export default LayoutMap;
1 change: 1 addition & 0 deletions components/LayoutMap/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./LayoutMap"
27 changes: 27 additions & 0 deletions components/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import {Select} from "components/Select";

export const SearchBar = () => {
const hrColor = "#DDDDDD";

return (
<section
css={{
height: 68,
padding: 12,
display: "flex",
alignItems: "center",
}}
>
<input
type="text"
placeholder="검색어를 입력해 주세요"
css={{marginRight: 24}}
/>
<hr css={{height: 24, color: hrColor, marginRight: 16, marginLeft: 24}} />
<Select id="distance" name="거리순"></Select>
<Select id="distance" name="동물 선택"></Select>
<Select id="distance" name="혈액형 선택"></Select>
</section>
);
};
1 change: 1 addition & 0 deletions components/SearchBar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./SearchBar"
16 changes: 16 additions & 0 deletions components/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {ComponentMeta, ComponentStory} from "@storybook/react";
import {Select} from "./Select";

export default {
title: "atoms/Select",
component: Select,
argTypes: {},
args: {
id: "id",
name: "name",
},
} as ComponentMeta<typeof Select>;

const Template: ComponentStory<typeof Select> = (args) => <Select {...args} />;

export const Default = Template.bind({});
44 changes: 44 additions & 0 deletions components/Select/Select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {ChangeEventHandler, ReactNode, useCallback} from "react";
import {Css, CssObject} from "styles/theme";

export type SelectProps = {
children?: ReactNode;
id: string;
name: string;
onChange?: ChangeEventHandler<HTMLSelectElement>;
};

export const Select = ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

색상 값이 사실 컬러시스템에서 가져오지 않고 hex 값을 사용하는 등
디자인팀에서 아직 와이어프레임 단계이다보니깐 아직 디자인이 미완성인거 같아요.
지금은 당장 이렇게 나두고 나중에 디자인 팀이 컴포넌트로 작업해주시면 그때 수정하는 PR 올릴게요!

children,
id,
name,
onChange,
...rest
}: SelectProps) => {
return (
<div
css={{
borderWidth: 1,
borderStyle: "solid",
borderRadius: "22px",
borderColor: "#E6E7E9",
paddingTop: 12,
paddingRight: 11,
paddingBottom: 13,
paddingLeft: 12,
marginLeft: 8,
marginRight: 8,
}}
>
<select
id={id}
onChange={onChange}
{...rest}
css={{border: 0, color: "#393939", fontSize: 13, paddingRight: 4}}
>
{children}
<option value="">{name}</option>
</select>
</div>
);
};
1 change: 1 addition & 0 deletions components/Select/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Select"
59 changes: 59 additions & 0 deletions components/Stack/Stack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, {ReactNode} from "react";

// ref: https://stackoverflow.com/questions/62432985/typescript-saying-a-string-is-invalid-even-though-its-in-the-union
type FlexDirection =
| "column"
| "inherit"
| "-moz-initial"
| "initial"
| "revert"
| "unset"
| "column-reverse"
| "row"
| "row-reverse"
| undefined;

export type StackProps = {
children: ReactNode;
direction?: FlexDirection;
divider?: ReactNode;
spacing: number | string;
};

// ref: https://stackoverflow.com/questions/49496906/react-mapping-children-of-a-parent-component
export const Stack = ({
children,
direction = "column",
divider,
spacing,
}: StackProps) => {
return (
<>
{children && (
<div
css={{
display: "flex",
flexDirection: direction,
width: 400,
padding: 24,
overflowY: "scroll",
}}
>
{React.Children.map(children, (child) => {
return (
<div
css={{
display: "flex",
flexDirection: "column",
}}
>
{child}
{divider}
</div>
);
})}
</div>
)}
</>
);
};
1 change: 1 addition & 0 deletions components/Stack/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Stack"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@storybook/react": "^6.4.22",
"@storybook/testing-library": "^0.0.9",
"@svgr/webpack": "5.5.0",
"@types/navermaps": "^3.0.13",
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

"@types/node": "17.0.23",
"@types/react": "18.0.1",
"@types/react-dom": "18.0.0",
Expand Down
92 changes: 92 additions & 0 deletions pages/request/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import type {NextPage} from "next";
import Script from "next/script";
import {useEffect, useState} from "react";
import LayoutMap from "components/LayoutMap/LayoutMap";

type Location = {
latitude: number;
longitude: number;
};

const Request: NextPage = () => {
// 초기 위치: 건국대학교 동물병원
const [userLocation, setUserLocation] = useState<Location>({
latitude: 37.5390908,
longitude: 127.0747238,
});

useEffect(() => {
// 현재 위치 반영
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
setUserLocation({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
});
});
}
}, []);

useEffect(() => {
// userLocation으로 이동
const map = new naver.maps.Map("map", {
center: new naver.maps.LatLng(
userLocation.latitude,
userLocation.longitude
),
zoom: 14,
zoomControl: true,
zoomControlOptions: {
style: naver.maps.ZoomControlStyle.SMALL,
position: naver.maps.Position.BOTTOM_RIGHT,
},
});

const locationBtn = "현재 위치 추적하는 아이콘, 추가 예정";

const getUserLocation = new naver.maps.CustomControl(locationBtn, {
position: naver.maps.Position.BOTTOM_RIGHT,
});

// 마커로 위치 표시
const marker = new naver.maps.Marker({
position: new naver.maps.LatLng(
userLocation.latitude,
userLocation.longitude
),
map,
// icon: {
// url: ZoopiMarker,
// size: new naver.maps.Size(25, 34),
// scaledSize: new naver.maps.Size(25, 34),
// origin: new naver.maps.Point(0, 0),
// anchor: new naver.maps.Point(12, 34),
// },
});

naver.maps.Event.once(map, "init", function () {
getUserLocation.setMap(map);
});
}, [userLocation]);

const mapStyle = {
width: "100%",
height: "100%",
};

return (
<>
<LayoutMap>
<div id="map" style={mapStyle}></div>
</LayoutMap>
<Script
src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=w4dthat1j6"
strategy="beforeInteractive"
/>
</>
);
};

// ref: https://nextjs.org/docs/basic-features/script

export default Request;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2709,6 +2709,11 @@
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
integrity sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==

"@types/navermaps@^3.0.13":
version "3.0.13"
resolved "https://registry.yarnpkg.com/@types/navermaps/-/navermaps-3.0.13.tgz#eb06d733652e99a2e0f5699fdbbb875274d9e893"
integrity sha512-kA9Ss2FWm91IojmV8M6M3wtMcRjvVf4z0iAmoZD1xUqn3iJNoq2THvbOiQdbcO6Iu06a/bmXrXH7nKIlShmOZg==

"@types/node-fetch@^2.5.7":
version "2.6.1"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.1.tgz#8f127c50481db65886800ef496f20bbf15518975"
Expand Down