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: (
+ <>
+
+ {children}
+ >
+ ),
+ },
+ ref: ref ? [ref, pageRef] : pageRef,
+ });
+};
+
+/**
+ * Wraps the page so bottom drawers (and any drawer with `indent`) shrink it behind
+ * them: the page scales down around the visible screen, gets rounded top
+ * corners over a black backdrop and grows back as the drawer is swiped away.
+ * Fixed elements inside the page are positioned against the scaled page
+ * while it is indented; pin them to `--page-indent-bottom` /
+ * `--page-indent-top` under `group-data-active/indent:` (see the mobile tab
+ * bar). Skipped under reduced motion. Universal.
+ */
+function DrawerIndent({ children }: { children: React.ReactNode }) {
+ return (
+
+
+ (
+
+ )}
+ >
+ {children}
+
+
+ );
}
/**
@@ -101,13 +177,21 @@ function DrawerOverlay({
/**
* The drawer panel, rendered in a portal over a scrim, with a decorative drag
- * handle.
+ * handle on bottom drawers.
*/
function DrawerContent({
className,
children,
+ handle = true,
...props
-}: DrawerPrimitive.Popup.Props) {
+}: DrawerPrimitive.Popup.Props & {
+ /**
+ * Renders the drag handle row above `children` on bottom drawers. Turn it
+ * off to let content such as a cover image reach the top edge and draw your
+ * own handle over it. Defaults to `true`.
+ */
+ handle?: boolean;
+}) {
return (
@@ -124,10 +208,12 @@ function DrawerContent({
data-slot="drawer-content"
{...props}
>
-
+ {handle ? (
+
+ ) : null}
{children}
@@ -192,6 +278,7 @@ export {
DrawerDescription,
DrawerFooter,
DrawerHeader,
+ DrawerIndent,
DrawerOverlay,
DrawerPortal,
DrawerTitle,
diff --git a/packages/vitnode/src/components/ui/hover-card.tsx b/packages/vitnode/src/components/ui/hover-card.tsx
index 8c99c23c4..d42a10bb7 100644
--- a/packages/vitnode/src/components/ui/hover-card.tsx
+++ b/packages/vitnode/src/components/ui/hover-card.tsx
@@ -47,7 +47,7 @@ function HoverCardContent({
>
- `/users/${encodeURIComponent(nameCode)}`;
+const FALLBACK_AVATAR_COLOR = "64748b";
/**
* A user's name, optionally styled by their role, led by their avatar and
* linked to their profile. Shows `user.fullName` in place of the nickname when
- * the API sends one.
+ * the API sends one. A linked name previews the member's profile - a hover
+ * card with a mouse, a bottom sheet on touch screens - which fetches its own
+ * data.
*/
export const UserFormat = ({
user,
@@ -22,6 +24,7 @@ export const UserFormat = ({
avatarSize = 20,
format,
link,
+ preview = true,
className,
style,
...props
@@ -38,6 +41,13 @@ export const UserFormat = ({
format?: boolean;
/** Links to the profile page; needs `user.nameCode`. */
link?: boolean;
+ /**
+ * With `link`, previews the member's profile: a hover card when the link is
+ * hovered or focused, a bottom sheet when it is tapped on a touch screen
+ * (the tap then opens the sheet instead of the profile). Turn it off inside
+ * another hover card. Defaults to `true`.
+ */
+ preview?: boolean;
user: {
/** The letter avatar's background, a hex color without `#`. */
avatarColor?: string;
@@ -83,6 +93,19 @@ export const UserFormat = ({
>
);
+ if (link && user.nameCode && preview) {
+ return (
+
+ {content}
+
+ );
+ }
+
if (link && user.nameCode) {
return (
{
+ const seconds = Math.max(
+ 0,
+ (now.getTime() - new Date(date).getTime()) / 1000,
+ );
+ const [unit, size] = ELAPSED_UNITS.find(
+ ([, length]) => seconds >= length,
+ ) ?? ["minute", 60];
+
+ return new Intl.NumberFormat(locale, {
+ style: "unit",
+ unit,
+ unitDisplay: "short",
+ }).format(Math.max(1, Math.floor(seconds / size)));
+};
+
+const PresenceAvatar = ({
+ presence,
+ user,
+}: {
+ presence: undefined | UserPresence;
+ user: UserProfile;
+}) => {
+ const t = useTranslations("core.global.presence");
+ const format = useFormatter();
+ const now = useNow({ updateInterval: 60_000 });
+
+ let label: null | string = null;
+ if (presence?.status === "online") {
+ label = t("online_now");
+ } else if (presence?.status === "offline") {
+ label = presence.lastSeenAt
+ ? t("last_seen", {
+ time: format.relativeTime(new Date(presence.lastSeenAt), now),
+ })
+ : t("offline");
+ }
+ const offset = Math.round(
+ AVATAR_SIZE * CIRCLE_EDGE_INSET_AT_45_DEG - PRESENCE_DOT_SIZE / 2,
+ );
+
+ return (
+
+
+ {label ? (
+
+ ) : null}
+
+ );
+};
+
+const Stat = ({
+ children,
+ label,
+}: {
+ children: React.ReactNode;
+ label: string;
+}) => (
+