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

✨ 미션 선택 Bottom Sheet 연결 #118

Merged
merged 8 commits into from
Dec 22, 2023
Binary file added public/images/category/etc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/category/exercise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/category/laptop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/category/play-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/category/reading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/category/study.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/category/writting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 98 additions & 0 deletions src/app/select/CategoryBottomSheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { type ComponentProps } from 'react';
import Image from 'next/image';
import BottomSheet from '@/components/BottomSheet/BottomSheet';
import Header from '@/components/Header';
import Icon from '@/components/Icon';
import { css } from '@/styled-system/css';

const CATEGORY = [
{
name: '운동',
image: '/images/category/exercise.png',
},
{
name: '공부',
image: '/images/category/study.png',
},
{
name: '글 읽기',
image: '/images/category/reading.png',
},
{
name: '글 쓰기',
image: '/images/category/writting.png',
},
{
name: '프로젝트 / 작업',
image: '/images/category/laptop.png',
},
{
name: '영상 보기 / 팟캐스트 듣기',
image: '/images/category/play-button.png',
},
{
name: '기타',
image: '/images/category/exercise.png',
},
];

interface Props extends Omit<ComponentProps<typeof BottomSheet>, 'headerElement'> {
select: string | null;
onSelect: (category: string) => void;
}

function CategoryBottomSheet(props: Props) {
const onClick = (name: string) => {
props.onSelect(name);
props.onClickOutside?.();
};

return (
<BottomSheet headerElement={<Header.None title="카테고리" />} {...props}>
<ul className={categoryListCss}>
{CATEGORY.map((item) => (
<li key={item.name} className={categoryItemCss} onClick={() => onClick(item.name)}>
<div>
<div className={imageWrapperCss}>
<Image src={item.image} alt={item.name} fill />
</div>
<div>{item.name}</div>
</div>
<div>{props.select === item.name && <Icon name="check-circle" color="purple.purple700" />}</div>
</li>
))}
</ul>
</BottomSheet>
);
}

export default CategoryBottomSheet;

const categoryListCss = css({
width: '100%',
});

const categoryItemCss = css({
position: 'relative',
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
padding: '12px 16px',
color: 'text.secondary',
textStyle: 'subtitle3',
height: '46px',
cursor: 'pointer',

'& div': {
display: 'flex',
gap: '8px',
alignItems: 'center',
},
});

const imageWrapperCss = css({
position: 'relative',
width: '28px',
height: '28px',
});
30 changes: 28 additions & 2 deletions src/app/select/MissionRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

import { useState } from 'react';
import Link from 'next/link';
import CategoryBottomSheet from '@/app/select/CategoryBottomSheet';
import PublicBottomSheet from '@/app/select/PublicBottomSheet';
import Button from '@/components/Button/Button';
import Icon from '@/components/Icon';
import Input from '@/components/Input/Input';
import useToggle from '@/hooks/useToggle';
import { css } from '@/styled-system/css';

export default function MissionRegistration() {
const [missionTitleInput, setMissionTitleInput] = useState('');
const [missionContentInput, setMissionContentInput] = useState('');

const [isCategoryShowing, toggleCategoryShowing] = useToggle();
const [missionCategory, setMissionCategory] = useState<string | null>(null);

const [isPublicShowing, togglePublicShowing] = useToggle();
const [missionPublicSetting, setMissionPublicSetting] = useState<string>('팔로워에게 공개');

// 미션 명
const handleMissionTitleInput = (value: string) => {
setMissionTitleInput(value);
Expand Down Expand Up @@ -58,16 +67,32 @@ export default function MissionRegistration() {
<span className={asterisk}>*</span>

<div className={categoryWrapperCss}>
<p className={categoryTextCss}>카테고리를 선택해주세요.</p>
<p className={categoryTextCss} onClick={toggleCategoryShowing}>
{missionCategory ?? '카테고리를 선택해주세요.'}
</p>
<Icon name={'arrow-down'} color={'icon.secondary'} className={iconCss} />
<CategoryBottomSheet
isShowing={isCategoryShowing}
onClickOutside={toggleCategoryShowing}
select={missionCategory}
onSelect={setMissionCategory}
/>
</div>

{/* 공개설정 */}
<span className={publicSettingTitleCss}>공개설정</span>

<div className={publicSettingWrapperCss}>
<p className={publicSettingTextCss}>팔로워에게 공개</p>
<p className={publicSettingTextCss} onClick={togglePublicShowing}>
{missionPublicSetting}
</p>
<Icon name={'arrow-down'} color={'icon.secondary'} className={iconCss} />
<PublicBottomSheet
isShowing={isPublicShowing}
onClickOutside={togglePublicShowing}
select={missionPublicSetting}
onSelect={setMissionPublicSetting}
/>
</div>

<div className={buttonContainerCss}>
Expand All @@ -80,6 +105,7 @@ export default function MissionRegistration() {
</section>
);
}

const buttonContainerCss = css({
display: 'flex',
justifyContent: 'flex-end',
Expand Down
56 changes: 56 additions & 0 deletions src/app/select/PublicBottomSheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { type ComponentProps } from 'react';
import BottomSheet from '@/components/BottomSheet/BottomSheet';
import Header from '@/components/Header';
import Icon from '@/components/Icon';
import { css } from '@/styled-system/css';

interface Props extends Omit<ComponentProps<typeof BottomSheet>, 'headerElement'> {
select: string | null;
onSelect: (name: string) => void;
}

const PUBLIC_LIST = [{ name: '팔로워에게 공개' }, { name: '전체 공개' }, { name: '비공개' }];

function PublicBottomSheet(props: Props) {
const onClick = (name: string) => {
props.onSelect(name);
};

return (
<BottomSheet headerElement={<Header.TextButton title="카테고리" onButtonClick={props.onClickOutside} />} {...props}>
<ul className={listCss}>
{PUBLIC_LIST.map((item) => (
<li key={item.name} className={itemCss} onClick={() => onClick(item.name)}>
<div>{item.name}</div>
<div>{props.select === item.name && <Icon name="check-circle" color="purple.purple700" />}</div>
</li>
))}
</ul>
</BottomSheet>
);
}

export default PublicBottomSheet;

const listCss = css({
width: '100%',
});

const itemCss = css({
position: 'relative',
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
padding: '12px 16px',
color: 'text.secondary',
textStyle: 'subtitle3',
height: '46px',
cursor: 'pointer',

'& div': {
display: 'flex',
gap: '8px',
alignItems: 'center',
},
});
13 changes: 10 additions & 3 deletions src/components/BottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,21 @@ const headerWrapperCss = css({
paddingTop: '16px',
paddingBottom: '12px',
'& header': {
position: 'static',
position: 'relative',
'& .back-button': {
// TODO : 수정 필요, 중간 발표를 위한 임시방편
display: 'none',
},
},
'& section': {
gap: '0px',
},
'& h2': {
width: '100%',
textAlign: 'center',
position: 'absolute',
left: 0,
right: 0,
margin: '0 auto',
width: 'fit-content',
textStyle: 'subtitle1',
color: 'text.primary',
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Header({ title, rightElement, onBackAction }: Props) {
<>
<header className={wrapperCss}>
<section className={leftSectionCss}>
<button className={backButtonCss} type="button" onClick={handleBackIconClick}>
<button className={`${backButtonCss} back-button`} type="button" onClick={handleBackIconClick}>
<Icon name={'arrow-back'} color={'icon.secondary'} width={20} height={20} />
</button>
<h2 className={headingCss}>{title}</h2>
Expand Down
5 changes: 3 additions & 2 deletions src/components/Header/TextButtonHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import Header from '@/components/Header/Header';

interface Props extends Omit<ComponentProps<typeof Header>, 'rightElement'> {
rightButtonText?: string;
onButtonClick?: () => void;
}

function TextButtonHeader({ rightButtonText = '완료', ...props }: Props) {
function TextButtonHeader({ rightButtonText = '완료', onButtonClick, ...props }: Props) {
return (
<Header
rightElement={
<Button variant="ghost" size="medium">
<Button variant="ghost" size="medium" onClick={onButtonClick}>
{rightButtonText}
</Button>
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function Input({ iconName, value, onChange, iconColor, onIconClic
<p className={subTitleCss}>
{/* 인풋타이틀 */}
{name}
{required && <span className={asterisk}>*</span>}
{required && <span className={asterisk}> *</span>}
Copy link
Member

Choose a reason for hiding this comment

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

이 부분은 오타인거겠죠?? 제가 뷰 구현하다 실수한 부분같아요 죄송합니다ㅠ_ㅠ

</p>

<div className={inputWrapperCss}>
Expand Down
29 changes: 29 additions & 0 deletions src/hooks/useToggle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useCallback, useState } from 'react';

type Return = readonly [boolean, VoidFunction, VoidFunction, VoidFunction];

/**
* boolean을 쉽게 다룰 수 있는 hook 입니다
*
* @param initialValue - 기본 boolean 값
* @returns [boolean state, toggle func, set true func, set false func]
*/
const useToggle = (initialValue?: boolean): Return => {
const [value, setValue] = useState(initialValue ?? false);

const setTrue = useCallback(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

혹시 useCallback으로 하지 않아도 될것 같은데
설정해주신 이유가 궁금해요!

Copy link
Member Author

@sumi-0011 sumi-0011 Dec 22, 2023

Choose a reason for hiding this comment

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

복붙했어요..
뻴까요?

setValue(true);
}, []);

const setFalse = useCallback(() => {
setValue(false);
}, []);

const toggle = useCallback(() => {
setValue((prev) => !prev);
}, []);

return [value, toggle, setTrue, setFalse];
};

export default useToggle;
Loading