Skip to content

Commit

Permalink
Merge pull request #92 from team-offonoff/feat/better-bottomsheet
Browse files Browse the repository at this point in the history
feat: better bottomsheet
  • Loading branch information
Jinho1011 authored Dec 14, 2023
2 parents ead4928 + 90bf060 commit 6de4177
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/components/Home/TopicCard/TopicCard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState } from 'react';

import BottomSheet from '@components/commons/BottomSheet/BottomSheet';
import Text from '@components/commons/Text/Text';
import ChoiceSlider from '@components/Home/ChoiceSlider/ChoiceSlider';
import CommentBox from '@components/Home/CommentBox/CommentBox';
import Timer from '@components/Home/Timer/Timer';
import useBottomSheet from '@hooks/useBottomSheet/useBottomSheet';
import { TopicResponse } from '@interfaces/api/topic';

import { colors } from '@styles/theme';
Expand All @@ -23,7 +23,7 @@ import {

const TopicCard = () => {
const [hasVoted, setHasVoted] = useState(false);
const [isCommentOpen, setIsCommentOpen] = useState(false);
const { BottomSheet: CommentSheet, toggleSheet } = useBottomSheet({});

const data: TopicResponse = {
topicId: 1,
Expand Down Expand Up @@ -72,7 +72,7 @@ const TopicCard = () => {

const handleOnClickCommentBox = () => {
if (hasVoted) {
setIsCommentOpen(true);
toggleSheet();
}
};

Expand Down Expand Up @@ -120,11 +120,9 @@ const TopicCard = () => {
onClick={handleOnClickCommentBox}
/>
</TopicCardContainer>
{isCommentOpen && (
<BottomSheet open={isCommentOpen} setIsOpen={setIsCommentOpen}>
<div style={{ height: '100%', backgroundColor: 'white' }}>hi</div>
</BottomSheet>
)}
<CommentSheet>
<div style={{ height: '100%', backgroundColor: 'white' }}>hi</div>
</CommentSheet>
</React.Fragment>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/commons/BottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const Backdrop = styled(motion.div)`
position: fixed;
top: 0;
left: 0;
z-index: 1;
z-index: ${(props) => props.theme.zIndex.sheet};
width: 100%;
height: 100%;
Expand Down
32 changes: 32 additions & 0 deletions src/hooks/useBottomSheet/useBottomSheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useCallback, useState } from 'react';

import BottomSheet from '@components/commons/BottomSheet/BottomSheet';

interface UseBottomSheetProps {
snapPoints?: number[];
initialSnap?: number;
}

const useBottomSheet = (props: UseBottomSheetProps) => {
const { snapPoints = [0.9, 0.7, 0], initialSnap = 0.7 } = props;
const [isOpen, setIsOpen] = useState(false);

const toggleSheet = useCallback(() => {
setIsOpen((prev) => !prev);
}, []);

const Sheet = ({ children }: { children: React.ReactNode }) => (
<BottomSheet
open={isOpen}
setIsOpen={setIsOpen}
snapPoints={snapPoints}
initialSnap={initialSnap}
>
{children}
</BottomSheet>
);

return { BottomSheet: isOpen ? Sheet : () => null, toggleSheet };
};

export default useBottomSheet;

0 comments on commit 6de4177

Please sign in to comment.