Skip to content

Commit 1a2b75f

Browse files
committed
chore(proto): 🧪 open the user preview card as a bottom sheet on touch screens
Prototype only: on devices without hover, tapping a name or avatar opens the card in the swipeable bottom drawer instead of a hover card. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFbA6iCLzpJ2F55jPdT
1 parent 1782ba9 commit 1a2b75f

2 files changed

Lines changed: 97 additions & 4 deletions

File tree

‎apps/web/src/proto/user-preview/harness.tsx‎

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import './picker.css'
33

44
import { Link } from '@tanstack/react-router'
55
import { Avatar } from '@vitnode/core/components/avatar'
6+
import {
7+
Drawer,
8+
DrawerContent,
9+
DrawerTitle,
10+
DrawerTrigger,
11+
} from '@vitnode/core/components/ui/drawer'
612
import {
713
HoverCard,
814
HoverCardContent,
@@ -77,7 +83,80 @@ const POSTS = [
7783
},
7884
]
7985

80-
const PreviewTrigger = ({
86+
// Touch screens have no hover: there the card opens as a bottom sheet on tap.
87+
const COARSE_QUERY = '(hover: none) and (pointer: coarse)'
88+
89+
const subscribeCoarse = (onChange: () => void) => {
90+
const query = window.matchMedia(COARSE_QUERY)
91+
query.addEventListener('change', onChange)
92+
93+
return () => query.removeEventListener('change', onChange)
94+
}
95+
96+
const useCoarsePointer = () =>
97+
React.useSyncExternalStore(
98+
subscribeCoarse,
99+
() => window.matchMedia(COARSE_QUERY).matches,
100+
() => false,
101+
)
102+
103+
const PreviewSheet = ({
104+
children,
105+
decorative,
106+
defaultOpen,
107+
nameCode,
108+
variant,
109+
}: {
110+
children: React.ReactNode
111+
decorative?: boolean
112+
defaultOpen?: boolean
113+
nameCode: string
114+
variant: Variant
115+
}) => {
116+
const [open, setOpen] = React.useState(defaultOpen ?? false)
117+
// Stays mounted after the first open, so the sheet keeps its content while it slides away.
118+
const [opened, setOpened] = React.useState(defaultOpen ?? false)
119+
const Content = variant.Content
120+
121+
return (
122+
<Drawer
123+
onOpenChange={(next) => {
124+
setOpen(next)
125+
if (next) setOpened(true)
126+
}}
127+
open={open}
128+
>
129+
<DrawerTrigger asChild>
130+
<button
131+
aria-haspopup="dialog"
132+
aria-hidden={decorative ? true : undefined}
133+
className="focus-visible:ring-ring/50 inline-flex min-w-0 cursor-pointer touch-manipulation rounded-sm text-start outline-none focus-visible:ring-3"
134+
tabIndex={decorative ? -1 : undefined}
135+
type="button"
136+
>
137+
{children}
138+
</button>
139+
</DrawerTrigger>
140+
<DrawerContent
141+
aria-describedby={undefined}
142+
style={{ paddingBottom: 'env(safe-area-inset-bottom)' }}
143+
>
144+
<DrawerTitle className="sr-only">Profile of @{nameCode}</DrawerTitle>
145+
<div className="mx-auto w-full max-w-md overflow-y-auto">
146+
{opened ? (
147+
<React.Suspense fallback={<UserPreviewSkeleton />}>
148+
<RouteMessages namespaces={['core.global', 'core.profile']}>
149+
<Content nameCode={nameCode} />
150+
</RouteMessages>
151+
</React.Suspense>
152+
) : null}
153+
</div>
154+
</DrawerContent>
155+
</Drawer>
156+
)
157+
}
158+
159+
const PreviewHoverCard = ({
81160
children,
82161
decorative,
83162
defaultOpen,
@@ -126,6 +205,13 @@ const PreviewTrigger = ({
126205
)
127206
}
128207

208+
const PreviewTrigger = (props: React.ComponentProps<typeof PreviewHoverCard>) =>
209+
useCoarsePointer() ? (
210+
<PreviewSheet {...props} />
211+
) : (
212+
<PreviewHoverCard {...props} />
213+
)
214+
129215
const Thread = ({ variant }: { variant: Variant }) => (
130216
<main className="container mx-auto flex max-w-3xl flex-col gap-6 p-4 pb-32 sm:p-8 sm:pb-32">
131217
<header className="flex flex-col gap-2">
@@ -137,7 +223,8 @@ const Thread = ({ variant }: { variant: Variant }) => (
137223
Which switches for a first mechanical keyboard?
138224
</h1>
139225
<p className="text-muted-foreground text-sm leading-relaxed">
140-
Hover a name or an avatar. The first card opens on load.
226+
Hover a name or an avatar (tap on touch screens). The first card opens
227+
on load.
141228
</p>
142229
</header>
143230

@@ -183,6 +270,7 @@ const Picker = ({
183270
onReplay: () => void
184271
onSelect: (index: number) => void
185272
}) => {
273+
const coarse = useCoarsePointer()
186274
const navRef = React.useRef<HTMLElement>(null)
187275
const highlightRef = React.useRef<HTMLSpanElement>(null)
188276
const itemRefs = React.useRef<(HTMLButtonElement | null)[]>([])
@@ -212,7 +300,12 @@ const Picker = ({
212300
}, [])
213301

214302
return (
215-
<nav aria-label="Prototype variants" className="proto-picker" ref={navRef}>
303+
<nav
304+
aria-label="Prototype variants"
305+
className="proto-picker"
306+
data-position={coarse ? 'top' : undefined}
307+
ref={navRef}
308+
>
216309
<span
217310
aria-hidden="true"
218311
className="proto-picker-highlight"

‎apps/web/src/proto/user-preview/sheet.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const Body = ({ nameCode }: { nameCode: string }) => {
113113
}
114114

115115
export const sheet: Variant = {
116-
name: 'Round 3',
116+
name: 'Before',
117117
contentClassName: 'w-80 overflow-hidden p-0',
118118
Content: Body,
119119
}

0 commit comments

Comments
 (0)