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

[#530] FloatingButton 컴포넌트 적용 #536

Merged
merged 10 commits into from
Apr 24, 2024
4 changes: 2 additions & 2 deletions public/icons/book-plus.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 public/icons/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 32 additions & 13 deletions src/app/group/page.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
'use client';

import { useRouter } from 'next/navigation';
import { useEffect } from 'react';
import { useInView } from 'react-intersection-observer';

import SSRSafeSuspense from '@/components/SSRSafeSuspense';
import TopHeader from '@/v1/base/TopHeader';
import SearchGroupInput from '@/v1/bookGroup/SearchGroup';
import SimpleBookGroupCard, {
SimpleBookGroupCardSkeleton,
} from '@/v1/bookGroup/SimpleBookGroupCard';
import DetailBookGroupCard, {
DetailBookGroupCardSkeleton,
} from '@/v1/bookGroup/DetailBookGroupCard';

import useEntireGroupsQuery from '@/queries/group/useEntireGroupsQuery';
import useMyGroupsQuery from '@/queries/group/useMyGroupQuery';
import { useMyProfileId } from '@/queries/user/useMyProfileQuery';
import { checkAuthentication } from '@/utils/helpers';

import useMounted from '@/hooks/useMounted';
import { checkAuthentication } from '@/utils/helpers';
import useToast from '@/v1/base/Toast/useToast';

import FloatingButton from '@/v1/base/FloatingButton';
import Loading from '@/v1/base/Loading';
import TopHeader from '@/v1/base/TopHeader';
import DetailBookGroupCard, {
DetailBookGroupCardSkeleton,
} from '@/v1/bookGroup/DetailBookGroupCard';
import SearchGroupInput from '@/v1/bookGroup/SearchGroup';
import SimpleBookGroupCard, {
SimpleBookGroupCardSkeleton,
} from '@/v1/bookGroup/SimpleBookGroupCard';

const GroupPage = () => {
const router = useRouter();
const { show: showToast } = useToast();

const isAuthenticated = checkAuthentication();

const handleSearchInputClick = () => {
alert('아직 준비 중인 기능이에요.');
};

const handleCreateGroupClick = () => {
if (isAuthenticated) {
router.push('/group/create');
} else {
showToast({ message: '로그인 후에 이용할 수 있어요!', type: 'normal' });
}

return;
};

return (
<>
<TopHeader text="Group" />
Expand All @@ -36,9 +54,10 @@ const GroupPage = () => {
<EntireBookGroupList />
</SSRSafeSuspense>
</div>
{/* <Link href={'/group/create'}>
<FloatingButton position="bottom-right" />
</Link> */}
<FloatingButton
onClick={handleCreateGroupClick}
position="bottom-right"
/>
</>
);
};
Expand Down
39 changes: 24 additions & 15 deletions src/v1/base/FloatingButton.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
import { IconPlus } from '@public/icons';
import { ComponentPropsWithoutRef } from 'react';
import { createPortal } from 'react-dom';

import { IconPlus } from '@public/icons';

import Portal from './Portal';

interface FloatingButtonProps extends ComponentPropsWithoutRef<'button'> {
position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
onClick?: () => void;
}

const getPositionClasses = (position: string) => {
switch (position) {
case 'top-left': {
return 'top-[6.4rem] left-[1.2rem]';
return 'top-[1.3rem] left-[1.7rem]';
}
case 'top-right': {
return 'top-[6.4rem] right-[1.2rem]';
return 'top-[1.3rem] right-[1.7rem]';
}
case 'bottom-left': {
return 'bottom-[7.2rem] left-[1.2rem]';
return 'bottom-[8.3rem] left-[1.7rem]';
}
case 'bottom-right': {
return 'bottom-[7.2rem] right-[1.2rem]';
return 'bottom-[8.3rem] right-[1.7rem]';
}
Comment on lines -12 to +24
Copy link
Member Author

Choose a reason for hiding this comment

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

comment;

바뀐 BottomNavigation에 맞게 포지션 옵션을 수정했습니다

}
};

const FloatingButton = ({ position, ...props }: FloatingButtonProps) => {
const FloatingButton = ({
position,
onClick,
...props
}: FloatingButtonProps) => {
const positionClasses = getPositionClasses(position);

return createPortal(
<button
className={`${positionClasses} fixed left-[50%] top-[50%] flex h-[5.1rem] w-[5.1rem] -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-main-900`}
{...props}
>
<IconPlus />
</button>,
document.body
return (
<Portal id="floating-button-portal">
<button
className={`${positionClasses} absolute flex h-[5.1rem] w-[5.1rem] items-center justify-center rounded-full bg-main-900 shadow-floating-button`}
onClick={onClick}
{...props}
>
<IconPlus className="fill-white" />
</button>
Copy link
Member

Choose a reason for hiding this comment

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

혹시.. 제가 figma에서 floating button 디자인을 조금 수정해봤는데.. 반영해주실 수 있을까요?! 🥹🙇🏻‍♀️

Copy link
Member Author

Choose a reason for hiding this comment

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

comment;

그럼요

</Portal>
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/v1/bookGroup/SearchGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const SearchGroup = ({ onClick }: SearchGroup) => {
return (
<div className="flex">
<div className="rounded-bl-[0.4rem] rounded-tl-[0.4rem] border-[0.1rem] border-r-[0rem] border-solid border-black-100 bg-[#fffff] pl-[1rem] pt-[0.8rem]">
<IconSearch fill="#AFAFAF" />
<IconSearch className="fill-placeholder" />
</div>
<input
id="groupSearching"
Expand Down
2 changes: 2 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ module.exports = {
bookcard: '0px 0px 7px 0px rgba(207, 207, 207, 0.5)',
searchResultItem: '0px 0px 6px 1px rgba(114, 114, 114, 0.10);',
bottomNav: 'rgba(0, 0, 0, 0.05) 0px 0px 10px 1px',
'floating-button':
'0px 0px 2px rgba(0, 0, 0, 0.2), 2px 2px 6px rgba(0, 0, 0, 0.1)',
},
keyframes: {
'page-transition': {
Expand Down
Loading