Skip to content

Commit

Permalink
Merge pull request #199 from arashsheyda/feat/repo-item-issues-animation
Browse files Browse the repository at this point in the history
feat(ui): add smooth toggle transition for reposity issues list
  • Loading branch information
seanmarcia authored Dec 12, 2024
2 parents 1e4780e + a6c5c19 commit 0cae4a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
19 changes: 16 additions & 3 deletions components/RepositoryItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type RepositoryItemProps = {

export const RepositoryItem = ({ repository }: RepositoryItemProps) => {
const [isIssueOpen, setIsIssueOpen] = useState(false);
const [isIssuesListVisible, setIsIssuesListVisible] = useState(false);

dayjs.extend(relativeTime);
const useLastModified = (date: string) => {
Expand All @@ -25,10 +26,20 @@ export const RepositoryItem = ({ repository }: RepositoryItemProps) => {
};
const lastModified = useLastModified(repository.last_modified);

useEffect(() => {
if (isIssueOpen) {
setIsIssuesListVisible(true);
} else {
// Delay unmounting to allow close animation to complete
const timer = setTimeout(() => setIsIssuesListVisible(false), 300);
return () => clearTimeout(timer);
}
}, [isIssueOpen]);

return (
<div className="repo-item">
<div id={`repo-${repository.id}`} onClick={() => setIsIssueOpen(!isIssueOpen)}>
<div>
<div id={`repo-${repository.id}`}>
<div onClick={() => setIsIssueOpen(!isIssueOpen)}>
<RepositoryItemTopBar
isIssueOpen={isIssueOpen}
repositoryHasNewIssues={repository.has_new_issues}
Expand All @@ -50,7 +61,9 @@ export const RepositoryItem = ({ repository }: RepositoryItemProps) => {
/>
</div>
</div>
{isIssueOpen && <IssuesList issues={repository.issues} />}
<div className={`repo-item__issues-warper ${isIssueOpen ? 'open' : ''}`}>
{isIssuesListVisible && <IssuesList issues={repository.issues} />}
</div>
</div>
</div>
);
Expand Down
13 changes: 13 additions & 0 deletions styles/globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ base, html {
}
}

.repo-item__issues-warper {
overflow: hidden;
transition: all 0.3s ease-in-out;
max-height: 0;
opacity: 0;
visibility: hidden;
&.open {
max-height: 1000px;
opacity: 1;
visibility: visible;
}
}

.repo-item__issue-list {
display: flex;
flex-direction: column;
Expand Down

0 comments on commit 0cae4a4

Please sign in to comment.