Skip to content

Commit ae6abd7

Browse files
committed
Fixes width issue with environment selector
1 parent aa6f192 commit ae6abd7

File tree

1 file changed

+38
-54
lines changed

1 file changed

+38
-54
lines changed

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

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ChevronRightIcon, Cog8ToothIcon } from "@heroicons/react/20/solid";
2+
import { DropdownIcon } from "~/assets/icons/DropdownIcon";
23
import { useNavigation } from "@remix-run/react";
3-
import { motion } from "framer-motion";
44
import { useEffect, useRef, useState } from "react";
55
import { BranchEnvironmentIconSmall } from "~/assets/icons/EnvironmentIcons";
66
import { useEnvironment } from "~/hooks/useEnvironment";
@@ -16,7 +16,6 @@ import { Header2 } from "../primitives/Headers";
1616
import { Paragraph } from "../primitives/Paragraph";
1717
import {
1818
Popover,
19-
PopoverArrowTrigger,
2019
PopoverContent,
2120
PopoverMenuItem,
2221
PopoverSectionHeader,
@@ -52,64 +51,49 @@ export function EnvironmentSelector({
5251

5352
const hasStaging = project.environments.some((env) => env.type === "STAGING");
5453

55-
const trigger = (
56-
<div
57-
className={cn(
58-
"flex h-8 w-full items-center gap-1.5 overflow-hidden rounded pl-1.5 pr-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-
77-
if (isCollapsed) {
78-
return (
54+
return (
55+
<Popover onOpenChange={(open) => setIsMenuOpen(open)} open={isMenuOpen}>
7956
<SimpleTooltip
80-
button={trigger}
57+
button={
58+
<PopoverTrigger
59+
className={cn(
60+
"group flex h-8 w-full items-center rounded pl-[0.4375rem] transition-colors hover:bg-charcoal-750",
61+
isCollapsed ? "justify-center pr-0.5" : "justify-between pr-1",
62+
className
63+
)}
64+
>
65+
<span className="flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden">
66+
<EnvironmentIcon environment={environment} className="size-5 shrink-0" />
67+
<span
68+
className={cn(
69+
"flex min-w-0 items-center overflow-hidden transition-all duration-200",
70+
isCollapsed ? "max-w-0 opacity-0" : "max-w-[200px] opacity-100"
71+
)}
72+
>
73+
<EnvironmentLabel environment={environment} className="text-2sm" />
74+
</span>
75+
</span>
76+
<span
77+
className={cn(
78+
"overflow-hidden transition-all duration-200",
79+
isCollapsed ? "max-w-0 opacity-0" : "max-w-[16px] opacity-100"
80+
)}
81+
>
82+
<DropdownIcon className="size-4 min-w-4 text-text-dimmed transition group-hover:text-text-bright" />
83+
</span>
84+
</PopoverTrigger>
85+
}
8186
content={environmentFullTitle(environment)}
8287
side="right"
83-
buttonClassName="!h-8 block"
88+
sideOffset={8}
89+
hidden={!isCollapsed}
90+
buttonClassName="!h-8 w-full"
91+
asChild
8492
/>
85-
);
86-
}
87-
88-
return (
89-
<Popover onOpenChange={(open) => setIsMenuOpen(open)} open={isMenuOpen}>
90-
<PopoverArrowTrigger
91-
isOpen={isMenuOpen}
92-
overflowHidden
93-
fullWidth
94-
className={cn("h-8 overflow-hidden py-1 pl-1.5", className)}
95-
>
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>
110-
</PopoverArrowTrigger>
11193
<PopoverContent
11294
className="min-w-[14rem] overflow-y-auto p-0 scrollbar-thin scrollbar-track-transparent scrollbar-thumb-charcoal-600"
95+
side={isCollapsed ? "right" : "bottom"}
96+
sideOffset={isCollapsed ? 8 : 4}
11397
align="start"
11498
style={{ maxHeight: `calc(var(--radix-popover-content-available-height) - 10vh)` }}
11599
>

0 commit comments

Comments
 (0)