Jon/sky 5452 sidebar improvements (#3098)
This commit is contained in:
@@ -2,6 +2,7 @@ import { useSidebarStore } from "@/store/SidebarStore";
|
|||||||
import { cn } from "@/util/utils";
|
import { cn } from "@/util/utils";
|
||||||
import { NavLink, useMatches } from "react-router-dom";
|
import { NavLink, useMatches } from "react-router-dom";
|
||||||
import { Badge } from "./ui/badge";
|
import { Badge } from "./ui/badge";
|
||||||
|
import { useIsMobile } from "@/hooks/useIsMobile.ts";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -16,6 +17,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function NavLinkGroup({ title, links }: Props) {
|
function NavLinkGroup({ title, links }: Props) {
|
||||||
|
const isMobile = useIsMobile();
|
||||||
const { collapsed } = useSidebarStore();
|
const { collapsed } = useSidebarStore();
|
||||||
const matches = useMatches();
|
const matches = useMatches();
|
||||||
const groupIsActive = matches.some((match) => {
|
const groupIsActive = matches.some((match) => {
|
||||||
@@ -32,6 +34,7 @@ function NavLinkGroup({ title, links }: Props) {
|
|||||||
<div
|
<div
|
||||||
className={cn("py-2 text-slate-400", {
|
className={cn("py-2 text-slate-400", {
|
||||||
"text-primary": groupIsActive,
|
"text-primary": groupIsActive,
|
||||||
|
"mt-2 py-1 text-[0.8rem] font-medium uppercase": isMobile,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -42,7 +45,7 @@ function NavLinkGroup({ title, links }: Props) {
|
|||||||
{title}
|
{title}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-[1px]]">
|
||||||
{links.map((link) => {
|
{links.map((link) => {
|
||||||
return (
|
return (
|
||||||
<NavLink
|
<NavLink
|
||||||
@@ -53,6 +56,7 @@ function NavLinkGroup({ title, links }: Props) {
|
|||||||
className={({ isActive }) => {
|
className={({ isActive }) => {
|
||||||
return cn(
|
return cn(
|
||||||
"block rounded-lg py-2 pl-3 text-slate-400 hover:bg-muted hover:text-primary",
|
"block rounded-lg py-2 pl-3 text-slate-400 hover:bg-muted hover:text-primary",
|
||||||
|
{ "py-1 pl-0 text-[0.8rem]": isMobile },
|
||||||
{
|
{
|
||||||
"bg-muted": isActive,
|
"bg-muted": isActive,
|
||||||
},
|
},
|
||||||
|
|||||||
67
skyvern-frontend/src/hooks/useIsMobile.ts
Normal file
67
skyvern-frontend/src/hooks/useIsMobile.ts
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
function useIsMobile(): boolean {
|
||||||
|
const [isMobile, setIsMobile] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const checkIsMobile = () => {
|
||||||
|
// Check user agent for mobile phones specifically (not tablets)
|
||||||
|
const userAgent = navigator.userAgent.toLowerCase();
|
||||||
|
|
||||||
|
// Mobile phone patterns - exclude tablets
|
||||||
|
const mobilePatterns = [
|
||||||
|
/android.*mobile/, // Android phones (excludes tablets)
|
||||||
|
/iphone/, // iPhone
|
||||||
|
/ipod/, // iPod touch
|
||||||
|
/blackberry/, // BlackBerry
|
||||||
|
/windows phone/, // Windows Phone
|
||||||
|
/opera mini/, // Opera Mini
|
||||||
|
/iemobile/, // IE Mobile
|
||||||
|
/mobile/, // Generic mobile (but will be filtered by screen size)
|
||||||
|
];
|
||||||
|
|
||||||
|
// Check if user agent matches mobile patterns
|
||||||
|
const hasMobileUserAgent = mobilePatterns.some((pattern) =>
|
||||||
|
pattern.test(userAgent),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Additional check: screen width for mobile phones (typically < 768px)
|
||||||
|
// This helps distinguish phones from tablets
|
||||||
|
const hasSmallScreen = window.innerWidth < 768;
|
||||||
|
|
||||||
|
// Exclude tablets by checking for tablet-specific patterns
|
||||||
|
const tabletPatterns = [
|
||||||
|
/ipad/,
|
||||||
|
/android(?!.*mobile)/, // Android tablets (Android without "mobile")
|
||||||
|
/tablet/,
|
||||||
|
/kindle/,
|
||||||
|
];
|
||||||
|
|
||||||
|
const isTablet = tabletPatterns.some((pattern) =>
|
||||||
|
pattern.test(userAgent),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Return true only if it's a mobile device with small screen and not a tablet
|
||||||
|
return hasMobileUserAgent && hasSmallScreen && !isTablet;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleResize = () => {
|
||||||
|
setIsMobile(checkIsMobile());
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initial check
|
||||||
|
setIsMobile(checkIsMobile());
|
||||||
|
|
||||||
|
// Listen for window resize events
|
||||||
|
window.addEventListener("resize", handleResize);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("resize", handleResize);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return isMobile;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { useIsMobile };
|
||||||
@@ -17,7 +17,7 @@ function NavigationHamburgerMenu() {
|
|||||||
<DrawerTrigger asChild>
|
<DrawerTrigger asChild>
|
||||||
<HamburgerMenuIcon className="size-6 cursor-pointer" />
|
<HamburgerMenuIcon className="size-6 cursor-pointer" />
|
||||||
</DrawerTrigger>
|
</DrawerTrigger>
|
||||||
<DrawerContent className="bottom-2 left-2 top-2 mt-0 w-64 rounded border-0 px-6">
|
<DrawerContent className="bottom-2 left-2 top-2 mt-0 h-full w-64 rounded border-0">
|
||||||
<VisuallyHidden.Root>
|
<VisuallyHidden.Root>
|
||||||
<DrawerHeader>
|
<DrawerHeader>
|
||||||
<DrawerTitle>Skyvern</DrawerTitle>
|
<DrawerTitle>Skyvern</DrawerTitle>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function SidebarContent({ useCollapsedState }: Props) {
|
|||||||
const collapsed = useCollapsedState ? collapsedState : false;
|
const collapsed = useCollapsedState ? collapsedState : false;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full flex-col">
|
<div className="flex h-full flex-col overflow-y-auto px-6">
|
||||||
<Link to={window.location.origin}>
|
<Link to={window.location.origin}>
|
||||||
<div className="flex h-24 items-center">
|
<div className="flex h-24 items-center">
|
||||||
{collapsed ? <LogoMinimized /> : <Logo />}
|
{collapsed ? <LogoMinimized /> : <Logo />}
|
||||||
|
|||||||
Reference in New Issue
Block a user