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: CelebDropDown, NavButton 컴포넌트 기능 구현 #179

Merged
merged 13 commits into from
Jul 26, 2023
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
2 changes: 1 addition & 1 deletion frontend/src/@types/celeb.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RestaurantData } from './api.types';

export type Celebs = RestaurantData['celebs'];
type Celebs = RestaurantData['celebs'];

export type Celeb = Celebs[number];

Expand Down
14 changes: 14 additions & 0 deletions frontend/src/@types/restaurant.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@ import type { RestaurantData } from './api.types';

export type Restaurant = Omit<RestaurantData, 'celebs'>;
export type RestaurantModalInfo = Omit<Restaurant, 'lat' | 'lng'>;

export type RestaurantCategory =
| '전체'
| '일식당'
| '한식'
| '초밥, 롤'
| '생선회'
| '양식'
| '육류, 고기요리'
| '이자카야'
| '돼지고기구이'
| '요리주점'
| '와인'
| '기타';
1 change: 1 addition & 0 deletions frontend/src/assets/icons/fastFood.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions frontend/src/assets/icons/search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions frontend/src/components/@common/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { styled } from 'styled-components';
import OverlayMarker from './OverlayMarker';
import type { Coordinate } from '~/@types/map.types';
import type { Celebs } from '~/@types/celeb.types';
import type { Celeb } from '~/@types/celeb.types';
import MapContent from './MapContent';
import OverlayMyLocation from './OverlayMyLocation';
import LoadingDots from '../LoadingDots';
Expand All @@ -16,7 +16,7 @@

interface MapProps {
clickMarker: ({ lat, lng }: Coordinate) => void;
markers: { position: Coordinate; celebs: Celebs }[];
markers: { position: Coordinate; celebs: Celeb[] }[];
setData: React.Dispatch<React.SetStateAction<RestaurantData[]>>;
}

Expand All @@ -35,11 +35,11 @@
const { handleFetch } = useFetch('restaurants');

const onClick = (e: google.maps.MapMouseEvent) => {
setClicks([...clicks, e.latLng!]);

Check warning on line 38 in frontend/src/components/@common/Map/Map.tsx

View workflow job for this annotation

GitHub Actions / 🍔테스트 딱 대라 💢👊

Forbidden non-null assertion
};

const onIdle = (m: google.maps.Map) => {
setZoom(m.getZoom()!);

Check warning on line 42 in frontend/src/components/@common/Map/Map.tsx

View workflow job for this annotation

GitHub Actions / 🍔테스트 딱 대라 💢👊

Forbidden non-null assertion

const lowLatitude = String(m.getBounds().getSouthWest().lat());
const highLatitude = String(m.getBounds().getNorthEast().lat());
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/components/@common/NavButton/NavButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Meta, StoryObj } from '@storybook/react';
import NavButton from './NavButton';
import FastFoodIcon from '~/assets/icons/fastFood.svg';

const meta: Meta<typeof NavButton> = {
title: 'NavButton',
component: NavButton,
};

export default meta;

type Story = StoryObj<typeof NavButton>;

export const Default: Story = {
args: {
label: '캠핑장',
icon: <FastFoodIcon />,
isShow: true,
},
};
46 changes: 46 additions & 0 deletions frontend/src/components/@common/NavButton/NavButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { MouseEvent } from 'react';
import styled, { css } from 'styled-components';

import { FONT_SIZE } from '~/styles/common';

interface NavButtonProps {
label: string;
icon: React.ReactNode;
isShow?: boolean;
onClick?: (e?: MouseEvent<HTMLElement>) => void;
}

function NavButton({ icon, label, onClick, isShow = false }: NavButtonProps) {
return (
<StyledNavButton onClick={onClick} isShow={isShow}>
<div>{icon}</div>
<div>{label}</div>
</StyledNavButton>
);
}

export default NavButton;

const StyledNavButton = styled.button<{ isShow: boolean }>`
display: flex;
flex-direction: column;
align-items: center;
gap: 0.6rem;

width: fit-content;
height: 56px;

margin: 1.6rem 0 1rem;

border: none;
background: var(--white);
outline: none;

font-size: ${FONT_SIZE.sm};

${({ isShow }) =>
isShow &&
css`
border-bottom: 3px solid var(--black);
`};
`;
3 changes: 3 additions & 0 deletions frontend/src/components/@common/NavButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import NavButton from '~/components/@common/NavButton/NavButton';

export default NavButton;
67 changes: 67 additions & 0 deletions frontend/src/components/CategoryNavbar/CategoryNavbar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type { Meta, StoryObj } from '@storybook/react';
import CategoryNavbar from './CategoryNavbar';
import FastFood from '~/assets/icons/fastFood.svg';
import { RestaurantCategory } from '~/@types/restaurant.types';

interface Category {
label: RestaurantCategory;
icon: React.ReactNode;
}

const categories: Category[] = [
{
label: '일식당',
icon: <FastFood />,
},
{
label: '한식',
icon: <FastFood />,
},
{
label: '초밥, 롤',
icon: <FastFood />,
},
{
label: '생선회',
icon: <FastFood />,
},
{
label: '양식',
icon: <FastFood />,
},
{
label: '육류, 고기요리',
icon: <FastFood />,
},
{
label: '이자카야',
icon: <FastFood />,
},
{
label: '돼지고기구이',
icon: <FastFood />,
},
{
label: '요리주점',
icon: <FastFood />,
},
{
label: '와인',
icon: <FastFood />,
},
];

const meta: Meta<typeof CategoryNavbar> = {
title: 'Selector/CategoryNavbar',
component: CategoryNavbar,
};

export default meta;

type Story = StoryObj<typeof CategoryNavbar>;

export const Default: Story = {
args: {
categories,
},
};
54 changes: 54 additions & 0 deletions frontend/src/components/CategoryNavbar/CategoryNavbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { MouseEvent, useState } from 'react';
import styled from 'styled-components';
import { RestaurantCategory } from '~/@types/restaurant.types';
import NavButton from '~/components/@common/NavButton';
import isEqual from '~/utils/compare';

interface Category {
label: RestaurantCategory;
icon: React.ReactNode;
}

interface CategoryProps {
categories: Category[];
externalOnClick?: (e?: MouseEvent<HTMLElement>) => void;
}

function CategoryNavbar({ categories, externalOnClick }: CategoryProps) {
const [selected, setSelected] = useState<RestaurantCategory>('전체');

const clickCategory = (value: RestaurantCategory) => (event?: MouseEvent<HTMLElement>) => {
setSelected(value);

if (externalOnClick) externalOnClick(event);
};

return (
<StyledCategoryNavbarWrapper>
{categories.map(({ icon, label }) => (
<NavButton
label={label}
icon={icon}
data-label={label}
isShow={isEqual(selected, label)}
onClick={clickCategory(label)}
/>
))}
</StyledCategoryNavbarWrapper>
);
}

export default CategoryNavbar;

const StyledCategoryNavbarWrapper = styled.ul`
display: flex;
gap: 1.2rem;

width: 100%;
height: 56px;

padding: 1.8rem 0;

border-radius: 10px;
background: transparent;
`;
3 changes: 3 additions & 0 deletions frontend/src/components/CategoryNavbar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CategoryNavbar from '~/components/CategoryNavbar/CategoryNavbar';

export default CategoryNavbar;
53 changes: 53 additions & 0 deletions frontend/src/components/CelebDropDown/CelebDropDown.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Meta, StoryObj } from '@storybook/react';
import CelebDropDown from './CelebDropDown';

const meta: Meta<typeof CelebDropDown> = {
title: 'Selector/CelebDropDown',
component: CelebDropDown,
};

export default meta;

type Story = StoryObj<typeof CelebDropDown>;

export const Default: Story = {
args: {
celebs: [
{
id: 1,
name: '히밥',
youtubeChannelName: '@heebab',
profileImageUrl:
'https://yt3.googleusercontent.com/sL5ugPfl9vvwRwhf6l5APY__BZBw8qWiwgHs-uVsMPFoD5-a4opTJIcRSyrY8aY5LEESOMWJ=s176-c-k-c0x00ffffff-no-rj',
},
{
id: 2,
name: '정찬성',
youtubeChannelName: '@Korean_zzombi',
profileImageUrl:
'https://yt3.googleusercontent.com/sL5ugPfl9vvwRwhf6l5APY__BZBw8qWiwgHs-uVsMPFoD5-a4opTJIcRSyrY8aY5LEESOMWJ=s176-c-k-c0x00ffffff-no-rj',
},
{
id: 3,
name: '정찬',
youtubeChannelName: '@Korean_zzombi',
profileImageUrl:
'https://yt3.googleusercontent.com/sL5ugPfl9vvwRwhf6l5APY__BZBw8qWiwgHs-uVsMPFoD5-a4opTJIcRSyrY8aY5LEESOMWJ=s176-c-k-c0x00ffffff-no-rj',
},
{
id: 4,
name: '정성',
youtubeChannelName: '@Korean_zzombi',
profileImageUrl:
'https://yt3.googleusercontent.com/sL5ugPfl9vvwRwhf6l5APY__BZBw8qWiwgHs-uVsMPFoD5-a4opTJIcRSyrY8aY5LEESOMWJ=s176-c-k-c0x00ffffff-no-rj',
},
{
id: 5,
name: '정찬성1',
youtubeChannelName: '@Korean_zzombi',
profileImageUrl:
'https://yt3.googleusercontent.com/sL5ugPfl9vvwRwhf6l5APY__BZBw8qWiwgHs-uVsMPFoD5-a4opTJIcRSyrY8aY5LEESOMWJ=s176-c-k-c0x00ffffff-no-rj',
},
],
},
};
Loading