fix: tune transition and collapsing conditions

This commit is contained in:
Saumya Pandey committed 2022-02-14 01:09:04 +05:30
1 parent aa7ab3f23b
commit 32886aa8d7
3 files changed
+32 -23

No files matched your search

@@ -13,6 +13,7 @@ import DocumentReparent from "~/scenes/DocumentReparent";
import CollectionIcon from "~/components/CollectionIcon";
import Modal from "~/components/Modal";
import useBoolean from "~/hooks/useBoolean";
import usePrevious from "~/hooks/usePrevious";
import useStores from "~/hooks/useStores";
import CollectionMenu from "~/menus/CollectionMenu";
import CollectionSortMenu from "~/menus/CollectionSortMenu";
@@ -71,8 +72,9 @@ function CollectionLink({
const [expanded, setExpanded] = React.useState(
collection.id === ui.activeCollectionId
);
const [expandedViaDisclosure, setExpandedViaDisclosure] = React.useState(
false
const prevActiveCollectionId = usePrevious<string | undefined>(
ui.activeCollectionId
);
const manualSort = collection.sort.field === "index";
@@ -209,13 +211,20 @@ function CollectionLink({
return;
}
if (isDraggingAnyCollection) {
const wasUIActiveCollection =
collection.id === prevActiveCollectionId &&
collection.id !== ui.activeCollectionId;
if (isDraggingAnyCollection || wasUIActiveCollection) {
setExpanded(false);
setExpandedViaDisclosure(false);
} else {
setExpanded(collection.id === ui.activeCollectionId);
}
}, [isDraggingAnyCollection, collection.id, ui.activeCollectionId, search]);
}, [
isDraggingAnyCollection,
collection.id,
ui.activeCollectionId,
search,
prevActiveCollectionId,
]);
return (
<>
@@ -237,10 +246,10 @@ function CollectionLink({
icon={
<>
<Disclosure
expanded={expandedViaDisclosure}
expanded={expanded}
onClick={(event) => {
event.preventDefault();
setExpandedViaDisclosure((prev) => !prev);
setExpanded((prev) => !prev);
}}
/>
<CollectionIcon collection={collection} expanded={expanded} />
@@ -290,12 +299,10 @@ function CollectionLink({
)}
</div>
<Transition
style={{
maxHeight:
expanded || expandedViaDisclosure
? (collection?.documentIds?.length ?? 1) * 80 + "px"
: "0px",
}}
$expanded={expanded}
$maxHeight={
expanded ? (collection?.documentIds?.length ?? 1) * 80 + "px" : "0px"
}
>
{collectionDocuments.map((node, index) => (
<DocumentLink
@@ -353,12 +353,12 @@ function DocumentLink(
)}
</Relative>
<Transition
style={{
maxHeight:
expanded && !isDragging
? (collection?.documentIds?.length ?? 1) * 80 + "px"
: "0px",
}}
$expanded={expanded && !isDragging}
$maxHeight={
expanded && !isDragging
? (collection?.documentIds?.length ?? 1) * 80 + "px"
: "0px"
}
>
{nodeChildren.map((childNode, index) => (
<ObservedDocumentLink
@@ -1,7 +1,9 @@
import styled from "styled-components";
const Transition = styled.div`
transition: max-height 400ms cubic-bezier(0.08, 0.17, 0.14, 0.87);
const Transition = styled.div<{ $expanded: boolean; $maxHeight: string }>`
max-height: ${(props) => props.$maxHeight};
transition: ${(props) =>
props.$expanded ? "max-height 300ms ease-in" : "max-height 400ms ease-out"};
overflow: hidden;
`;