diff --git a/apps/web/content/docs/ui/user-format-preview-sheet.webp b/apps/web/content/docs/ui/user-format-preview-sheet.webp new file mode 100644 index 000000000..1e32cdfeb Binary files /dev/null and b/apps/web/content/docs/ui/user-format-preview-sheet.webp differ diff --git a/apps/web/content/docs/ui/user-format-preview.webp b/apps/web/content/docs/ui/user-format-preview.webp new file mode 100644 index 000000000..57596847f Binary files /dev/null and b/apps/web/content/docs/ui/user-format-preview.webp differ diff --git a/apps/web/content/docs/ui/user-format.mdx b/apps/web/content/docs/ui/user-format.mdx index 334fca5c8..2c8c296c7 100644 --- a/apps/web/content/docs/ui/user-format.mdx +++ b/apps/web/content/docs/ui/user-format.mdx @@ -4,6 +4,10 @@ description: Show a member's name in their role color, with the role's icon or e icon: UserCheck --- +import { ImgDocs } from "@/components/fumadocs/img"; +import previewCard from "./user-format-preview.webp"; +import previewSheet from "./user-format-preview-sheet.webp"; + `UserFormat` prints a member's name the way the rest of the site does. Use it anywhere a name shows up: article bylines, tables, comments, notifications. @@ -89,6 +93,57 @@ Leave `link` off when the name sits inside another link or a button, such as a table row that already opens something. Nested links are invalid HTML and confuse screen readers. +## Profile preview + +A linked name opens a profile preview when someone rests the pointer on it or +tabs to it. The card shows the member's cover, avatar with an online dot, name, +`@nameCode` and primary role, then their reputation, how long ago they joined +and when they were last here, with a **View profile** button at the bottom. + + + +Phones and tablets have no hover, so there a tap opens the same preview as a +bottom sheet. Swipe it down to close it, or tap **View profile** to go on to +the profile. + + + +Moderators also see the member's warnings in the preview: their active warning +points, how many warnings are active and in total, and a **Review** link to the +member's warnings in the ModCP. Everyone else never loads them. + +You don't pass the preview any data. When it opens, it loads the member's +public profile from `GET /users/profile/{nameCode}` and shows a skeleton until +the answer arrives. The preview shares its cache with the profile page, so +opening it and then going to the profile renders the page right away. Nothing +is fetched for names nobody opens. + +The preview is on by default for every `UserFormat` with `link`. Turn it off +with `preview={false}` when the name already sits inside another hover card: + +```tsx + +``` + +### Preview on an avatar + +Wrap any element in `UserPreview` to give it the same preview. It renders a +link to the profile (a button that opens the sheet on touch screens), so only +pass the `nameCode`: + +```tsx +import { Avatar } from '@vitnode/core/components/avatar' +import { UserPreview } from '@vitnode/core/components/user-preview' + + + + +``` + +Add `decorative` when a linked name sits right next to the avatar. It keeps the +duplicate link out of the tab order and away from screen readers, while mouse +and touch users still get the preview. + ## Names inside a sentence `UserFormat` is an `inline-flex` row, which keeps the icon centered on the @@ -111,6 +166,7 @@ words around it: | `avatarSize` | `number` | No | `20` | The avatar's width and height in pixels | | `format` | `boolean` | No | `false` | Adds the role color and prefix | | `link` | `boolean` | No | `false` | Links to `/users/` when it is set | +| `preview` | `boolean` | No | `true` | With `link`, opens the profile preview (hover card, or bottom sheet on touch) | | `className` | `string` | No | - | Extra classes on the outer element | Other `` props go to the outer ``. With `link`, only `className`, diff --git a/packages/vitnode/src/components/ui/drawer.tsx b/packages/vitnode/src/components/ui/drawer.tsx index ad0e313eb..553ac7759 100644 --- a/packages/vitnode/src/components/ui/drawer.tsx +++ b/packages/vitnode/src/components/ui/drawer.tsx @@ -1,4 +1,5 @@ import { Drawer as DrawerPrimitive } from "@base-ui/react/drawer"; +import { useRender } from "@base-ui/react/use-render"; import { cn } from "cn"; import React from "react"; @@ -30,16 +31,91 @@ const asChildProps = ( */ function Drawer({ direction = "bottom", + indent = direction === "bottom", ...props }: Omit & { direction?: DrawerDirection; + /** + * Shrinks the page behind the drawer while it is open, following the + * swipe, like an iOS sheet. Needs a `DrawerIndent` around the page (the + * public theme layout has one); without it nothing changes. Defaults to + * `true` for bottom drawers and `false` for the other directions. + */ + indent?: boolean; }) { - return ( + const root = ( ); + + return indent ? ( + root + ) : ( + {root} + ); +} + +const IndentedPage = ({ + active, + children, + ref, + ...props +}: React.ComponentProps<"div"> & { active: boolean }) => { + const pageRef = React.useRef(null); + + React.useLayoutEffect(() => { + const page = pageRef.current; + if (!active || !page) return; + + page.style.setProperty( + "--page-indent-bottom", + `${window.scrollY + window.innerHeight}px`, + ); + page.style.setProperty("--page-indent-top", `${window.scrollY}px`); + }, [active]); + + return useRender({ + props: { + ...props, + children: ( + <> +