Skip to content

Commit c1e623c

Browse files
authored
Mobile layout (#3358)
#3178 was meant to redo part of #2087 as a stepping stone to a proper mobile layout, but then we didn't follow up, which means the mobile layout actually got worse — it's really bad! This is an attempt at some quick fixes to make it tolerable without breaking anything for desktop users. As long as nothing on desktop sizes is affected, even if there are flaws it's hard for it to be worse than the status quo. I think it feels really good, and a thorough review by Fable 5.1 didn't turn up any regressions at desktop sizes. ## 🤖 Summary Makes the console usable below 1000px, which is the existing `1000:` breakpoint from the design system. Above that width the layout is unchanged apart from the items called out at the end. ### Navigation - **Sidebar becomes an overlay on small screens.** A hamburger toggle in the top bar opens it over the content with a scrim. It closes on scrim click and on any navigation, including navigations from breadcrumbs or quick actions. Open state lives in a small zustand store (`app/stores/mobile-nav.ts`) so the top bar and sidebar can share it. `PageSkeleton` renders the sidebar closed so there is no flash of an open drawer during load. - **Top bar collapses to a single cell.** The home button cell only exists at desktop width. The shared class strings in `app/layouts/helpers.tsx` are used by both `TopBar` and `PageSkeleton` so the two can't drift. - **Breadcrumbs collapse instead of overflowing.** When the path doesn't fit, leading crumbs are folded into a "…" menu listing the full path, keeping the silo picker and user menu in view. Widths are measured from an invisible copy of the crumbs so the longest complete suffix that fits can be chosen; the current crumb is the last to give way and truncates with an ellipsis as a final fallback. This applies at all widths, so long paths on desktop also collapse rather than pushing the right-side controls off screen. - **User menu shows the username inside the menu** on small screens, where it is hidden from the trigger to save space. ### Components - `Modal`, `SideModal`, `Toast`, and `ErrorPage` are capped to the viewport width with a gutter so they no longer run edge to edge or overflow. - Tab lists scroll horizontally below the breakpoint instead of overflowing the page. - `CardBlock.Header` actions, `DisksTableField` buttons, `Radio` cards, and `DateTimeRangePicker` stack or stretch to full width on small screens. - Serial console terminal uses the full width and hides the scroll buttons on small screens; the footer height becomes content-driven. - Side modal gutter shrinks to 1.5rem below the breakpoint. ### Changes that also affect desktop - `--content-gutter` shrinks below 1000px rather than 768px, so windows between 768 and 999px get the narrower gutter. This aligns the gutter with the layout breakpoint used everywhere else. - `overscroll-behavior-y: none` on `body` prevents pull-to-refresh and scroll chaining behind the sidebar overlay. On macOS this also removes the vertical rubber-band bounce. - `DropdownMenu.Content` defaults `collisionPadding` to 12px (Base UI default is 5px) so menus keep a consistent margin from the viewport edge. ### Tests - New `test/e2e/mobile-layout.e2e.ts` covers the sidebar overlay open/close/navigate flow, the breakpoint transition at 999/1000px, the username in the user menu, and modal/toast bounds at 320px. - `test/e2e/breadcrumbs.e2e.ts` adds cases for collapsed breadcrumbs at 404, 650, 750, and 1024px, including the full-path menu. - The serial console visual regression test is scoped to a role locator because `getByText` now also matches the hidden breadcrumb measurement copy.
1 parent 8b8e83d commit c1e623c

24 files changed

Lines changed: 526 additions & 62 deletions

‎app/components/DocsPopover.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const DocsPopover = ({ heading, icon, summary, links }: DocsPopoverProps)
5555
<PopoverPanel
5656
// popover-panel needed for enter animation
5757
className="popover-panel bg-raise light:bg-default shadow-menu z-10 w-96 rounded-lg"
58-
anchor={{ to: 'bottom end', gap: 12 }}
58+
anchor={{ to: 'bottom end', gap: 12, padding: 16 }}
5959
>
6060
<div className="px-4">
6161
<h2 className="text-sans-md mt-4 flex items-center gap-1">

‎app/components/ErrorPage.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function ErrorPage({ children }: Props) {
4040
</Link>
4141
<SignOutButton className="mt-4 mr-6" />
4242
</div>
43-
<div className="bg-raise! shadow-modal absolute top-1/2 left-1/2 flex w-96 -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center space-y-4 rounded-lg p-8">
43+
<div className="bg-raise! shadow-modal max-1000:w-[calc(100%-var(--content-gutter)*2)] absolute top-1/2 left-1/2 flex w-96 -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center space-y-4 rounded-lg p-8">
4444
<div className="my-2 flex h-12 w-12 items-center justify-center">
4545
<div className="bg-destructive-inverse absolute h-10 w-10 rounded-full opacity-40 motion-safe:animate-[ping_2s_cubic-bezier(0,0,0.2,1)_infinite]" />
4646
<Error12Icon className="text-error light:text-error-secondary relative h-8 w-8" />

‎app/components/PageSkeleton.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ContentPane,
1414
PageContainer,
1515
sidebarWrapperClass,
16+
topBarHomeCellClass,
1617
topBarWrapperClass,
1718
} from '~/layouts/helpers'
1819
import { classed } from '~/util/classed'
@@ -31,7 +32,7 @@ export function PageSkeleton({ skipPaths }: { skipPaths?: RegExp[] }) {
3132
<PageContainer>
3233
{/* TopBar */}
3334
<div className={topBarWrapperClass}>
34-
<div className="border-secondary flex items-center gap-2 border-r p-3">
35+
<div className={cn(topBarHomeCellClass, 'gap-2 p-3')}>
3536
<Block className="h-8 w-8" />
3637
<Block className="h-4 w-24" />
3738
</div>
@@ -44,7 +45,8 @@ export function PageSkeleton({ skipPaths }: { skipPaths?: RegExp[] }) {
4445
</div>
4546
</div>
4647
{/* Sidebar */}
47-
<div className={cn(sidebarWrapperClass, 'p-4')}>
48+
{/* on mobile the sidebar is an overlay, closed (translated off-screen) by default */}
49+
<div className={cn(sidebarWrapperClass, 'p-4 max-1000:-translate-x-full')}>
4850
<Block className="mb-10 h-4 w-full" />
4951
<div className="mb-6 space-y-2">
5052
<Block className="h-4 w-32" />

‎app/components/Sidebar.tsx‎

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
* Copyright Oxide Computer Company
77
*/
88
import cn from 'classnames'
9+
import { useEffect } from 'react'
910
import { Link, useLocation } from 'react-router'
1011

1112
import { Action16Icon, Document16Icon } from '@oxide/design-system/icons/react'
1213

1314
import { useIsActivePath } from '~/hooks/use-is-active-path'
1415
import { openQuickActions } from '~/hooks/use-quick-actions'
1516
import { sidebarWrapperClass } from '~/layouts/helpers'
17+
import { closeMobileNav, useMobileNavStore } from '~/stores/mobile-nav'
1618
import { Button } from '~/ui/lib/Button'
1719
import { Truncate } from '~/ui/lib/Truncate'
1820

1921
const linkStyles = (isActive = false) =>
2022
cn(
21-
'flex h-7 items-center rounded-md px-2 text-sans-md [&>svg]:mr-2',
23+
'flex h-7 items-center rounded-md px-2 text-sans-md pointer-coarse:h-8 [&>svg]:mr-2',
2224
isActive
2325
? 'text-accent bg-accent hover:bg-accent-hover [&>svg]:text-accent-tertiary'
2426
: 'hover:bg-hover [&>svg]:text-quaternary text-default'
@@ -62,18 +64,37 @@ const JumpToButton = () => {
6264
}
6365

6466
export function Sidebar({ children }: { children: React.ReactNode }) {
67+
const mobileNavOpen = useMobileNavStore((state) => state.isOpen)
68+
const { pathname } = useLocation()
69+
70+
// close the mobile nav overlay on any navigation, including ones triggered
71+
// outside the sidebar (breadcrumbs, quick actions)
72+
useEffect(() => closeMobileNav(), [pathname])
73+
6574
return (
66-
<div
67-
className={cn(
68-
sidebarWrapperClass,
69-
'text-sans-md text-raise flex flex-col overflow-y-auto overscroll-none'
75+
<>
76+
{/* scrim behind the mobile nav overlay. covers everything below the top
77+
bar so the toggle button in the top bar stays clickable */}
78+
{mobileNavOpen && (
79+
<div
80+
aria-hidden
81+
onClick={closeMobileNav}
82+
className="bg-scrim 1000:hidden fixed inset-0 top-[calc(var(--top-bar-height)+var(--preview-banner-height))] z-(--z-side-modal-overlay)"
83+
/>
7084
)}
71-
>
72-
<div className="mx-3 mt-4">
73-
<JumpToButton />
85+
<div
86+
className={cn(
87+
sidebarWrapperClass,
88+
'text-sans-md text-raise flex flex-col overflow-y-auto overscroll-none',
89+
!mobileNavOpen && 'max-1000:-translate-x-full'
90+
)}
91+
>
92+
<div className="mx-3 mt-4">
93+
<JumpToButton />
94+
</div>
95+
{children}
7496
</div>
75-
{children}
76-
</div>
97+
</>
7798
)
7899
}
79100

‎app/components/Terminal.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ export function Terminal({ ws }: TerminalProps) {
126126
<>
127127
<div
128128
role="application"
129-
className="text-mono-code h-full w-[calc(100%-3rem)]"
129+
className="text-mono-code 1000:w-[calc(100%-3rem)] h-full w-full"
130130
ref={terminalRef}
131131
/>
132-
<div className="text-default absolute top-0 right-0 space-y-2">
132+
<div className="text-default max-1000:hidden absolute top-0 right-0 space-y-2">
133133
<ScrollButton onClick={() => term?.scrollToTop()} aria-label="Scroll to top">
134134
<DirectionUpIcon aria-hidden />
135135
</ScrollButton>

0 commit comments

Comments
 (0)