Skip to content

Commit b4735c2

Browse files
committed
Animate collapsing the side menu
1 parent ae6cde0 commit b4735c2

5 files changed

Lines changed: 258 additions & 252 deletions

File tree

apps/webapp/app/components/navigation/EnvironmentSelector.tsx

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ChevronRightIcon, Cog8ToothIcon } from "@heroicons/react/20/solid";
22
import { useNavigation } from "@remix-run/react";
3+
import { motion } from "framer-motion";
34
import { useEffect, useRef, useState } from "react";
45
import { BranchEnvironmentIconSmall } from "~/assets/icons/EnvironmentIcons";
56
import { useEnvironment } from "~/hooks/useEnvironment";
@@ -9,7 +10,7 @@ import { useOrganization, type MatchedOrganization } from "~/hooks/useOrganizati
910
import { useProject } from "~/hooks/useProject";
1011
import { cn } from "~/utils/cn";
1112
import { branchesPath, docsPath, v3BillingPath } from "~/utils/pathBuilder";
12-
import { EnvironmentCombo, EnvironmentIcon, environmentFullTitle } from "../environments/EnvironmentLabel";
13+
import { EnvironmentCombo, EnvironmentIcon, EnvironmentLabel, environmentFullTitle } from "../environments/EnvironmentLabel";
1314
import { ButtonContent } from "../primitives/Buttons";
1415
import { Header2 } from "../primitives/Headers";
1516
import { Paragraph } from "../primitives/Paragraph";
@@ -51,16 +52,35 @@ export function EnvironmentSelector({
5152

5253
const hasStaging = project.environments.some((env) => env.type === "STAGING");
5354

55+
const trigger = (
56+
<div
57+
className={cn(
58+
"flex h-8 items-center gap-1.5 overflow-hidden rounded px-2 transition-colors hover:bg-charcoal-750",
59+
className
60+
)}
61+
>
62+
<EnvironmentIcon environment={environment} className="size-5 shrink-0" />
63+
<motion.div
64+
className="flex min-w-0 flex-1 items-center overflow-hidden"
65+
initial={false}
66+
animate={{
67+
opacity: isCollapsed ? 0 : 1,
68+
width: isCollapsed ? 0 : "auto",
69+
}}
70+
transition={{ duration: 0.15, ease: "easeOut" }}
71+
>
72+
<EnvironmentLabel environment={environment} className="text-2sm" />
73+
</motion.div>
74+
</div>
75+
);
76+
5477
if (isCollapsed) {
5578
return (
5679
<SimpleTooltip
57-
button={
58-
<div className="flex h-8 w-full items-center justify-center rounded transition-colors hover:bg-charcoal-750">
59-
<EnvironmentIcon environment={environment} className="size-5" />
60-
</div>
61-
}
80+
button={trigger}
6281
content={environmentFullTitle(environment)}
6382
side="right"
83+
buttonClassName="!h-8 block"
6484
/>
6585
);
6686
}
@@ -71,9 +91,22 @@ export function EnvironmentSelector({
7191
isOpen={isMenuOpen}
7292
overflowHidden
7393
fullWidth
74-
className={cn("h-7 overflow-hidden py-1 pl-1.5", className)}
94+
className={cn("h-8 overflow-hidden py-1 pl-0.5", className)}
7595
>
76-
<EnvironmentCombo environment={environment} className="w-full text-2sm" />
96+
<span className="flex items-center gap-1.5 text-sm text-text-bright">
97+
<EnvironmentIcon environment={environment} className="size-5 shrink-0" />
98+
<motion.span
99+
className="flex min-w-0 flex-1 items-center overflow-hidden"
100+
initial={false}
101+
animate={{
102+
opacity: isCollapsed ? 0 : 1,
103+
width: isCollapsed ? 0 : "auto",
104+
}}
105+
transition={{ duration: 0.15, ease: "easeOut" }}
106+
>
107+
<EnvironmentLabel environment={environment} className="text-2sm" />
108+
</motion.span>
109+
</span>
77110
</PopoverArrowTrigger>
78111
<PopoverContent
79112
className="min-w-[14rem] overflow-y-auto p-0 scrollbar-thin scrollbar-track-transparent scrollbar-thumb-charcoal-600"

0 commit comments

Comments
 (0)