Mentions List
Mentions inbox card listing where you were tagged: each timeline row shows the actor and location, the quoted line in a bordered blockquote, and Open and Reply buttons beneath every mention.
"use client"
import { useState } from "react"
import { LinkButton } from "@/components/link-button/link-button"
import {
Timeline,
TimelineContent,
TimelineIndicator,
TimelineItem,
TimelineLabel,
TimelineTitle,
} from "@/components/timeline/timeline"
import { Button } from "@/components/ui/button"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import { Textarea } from "@/components/ui/textarea"
// The copy: change text here, not in the markup.
const COPY = {
title: "Mentions",
body: "Where you were tagged this week.",
open: "Open",
reply: "Reply",
replyLabel: "Your reply",
replyPlaceholder: "Write a reply",
send: "Send reply",
cancel: "Cancel",
replied: (text: string) => `You replied: ${text}`,
} as const
const MENTIONS = [
{
actor: "Alexei Leonov",
where: "#482 · Rate limiter",
time: "1h",
quote: "@lena can you confirm the retry window is 30s and not 60s?",
},
{
actor: "Sian Proctor",
where: "#311 · Checkout flash",
time: "4h",
quote: "Fixed by the latest deploy, @lena please verify on staging.",
},
{
actor: "Raja Chari",
where: "Design review notes",
time: "Yesterday",
quote: "@lena owns the stepper rail decision.",
},
{
actor: "Luca Parmitano",
where: "Launch brief",
time: "2 days",
quote: "Audience section rewritten, @lena take a look.",
},
] as const
// The quoted line is the point: the mention sits in a quiet quote block under
// the actor line, with Open and Reply on the row.
export default function MentionsList01() {
const [replying, setReplying] = useState<number | null>(null)
const [draft, setDraft] = useState("")
const [replies, setReplies] = useState<Record<number, string[]>>({})
function send(i: number) {
const text = draft.trim()
if (!text) return
setReplies((cur) => ({ ...cur, [i]: [...(cur[i] ?? []), text] }))
setDraft("")
setReplying(null)
}
return (
<Card className="mx-auto w-full max-w-md">
<CardHeader>
<CardTitle>{COPY.title}</CardTitle>
<CardDescription>{COPY.body}</CardDescription>
</CardHeader>
<CardContent>
<Timeline className="[--timeline-lh:1.25rem]">
{MENTIONS.map((m, i) => (
<TimelineItem key={m.actor + m.time}>
<TimelineIndicator variant="plain" />
<TimelineContent className="pb-6">
<div className="flex items-baseline justify-between gap-3">
<TimelineTitle className="text-sm/5 font-normal">
<span className="font-medium">{m.actor}</span>{" "}
<span className="text-muted-foreground">in {m.where}</span>
</TimelineTitle>
<TimelineLabel className="shrink-0">{m.time}</TimelineLabel>
</div>
<blockquote className="mt-2 text-sm text-foreground/90">
{m.quote}
</blockquote>
<div className="mt-2 flex gap-1">
<LinkButton href="#" variant="outline" size="xs">
{COPY.open}
</LinkButton>
<Button
size="xs"
variant="ghost"
aria-expanded={replying === i}
onClick={() => {
setDraft("")
setReplying(replying === i ? null : i)
}}
>
{COPY.reply}
</Button>
</div>
{replying === i && (
<div className="mt-2 flex flex-col items-start gap-2">
<Textarea
aria-label={COPY.replyLabel}
placeholder={COPY.replyPlaceholder}
value={draft}
onChange={(e) => setDraft(e.target.value)}
/>
<div className="flex gap-1">
<Button
size="xs"
disabled={!draft.trim()}
onClick={() => send(i)}
>
{COPY.send}
</Button>
<Button
size="xs"
variant="ghost"
onClick={() => setReplying(null)}
>
{COPY.cancel}
</Button>
</div>
</div>
)}
{(replies[i] ?? []).map((text, n) => (
<p
key={n}
role="status"
className="mt-2 text-sm text-muted-foreground"
>
{COPY.replied(text)}
</p>
))}
</TimelineContent>
</TimelineItem>
))}
</Timeline>
</CardContent>
</Card>
)
}
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import { buttonVariants } from "@/components/ui/button"
/**
* The classes of a link that looks like a button: stock `buttonVariants`,
* plus LinkButton's own sizes (`lg` sets a 16px label). For an element that
* can't be a LinkButton.
*/
function linkButtonVariants({
variant,
size,
className,
}: VariantProps<typeof buttonVariants> & { className?: string } = {}) {
return cn(
buttonVariants({ variant, size }),
// Every size is stock's except lg, which takes a 16px label. Stock stays
// untouched in ui/button.tsx, so a shadcn re-download never undoes it.
size === "lg" && "text-base",
className
)
}
/**
* A link that looks like a button: an `<a>` with the button's look, never a
* button. Base UI's `Button` gives any element `role="button"`, so navigation
* uses this instead.
*
* `variant` and `size` are stock Button's; `lg` sets a 16px label. Pass
* `render` to use your framework's link, such as
* `render={<Link href="/pricing" />}` with Next.js, or change the default
* here once and every block follows.
*/
function LinkButton({
className,
variant = "default",
size = "default",
render,
...props
}: useRender.ComponentProps<"a"> & VariantProps<typeof buttonVariants>) {
return useRender({
defaultTagName: "a",
render,
// Written as data-slot="button" on the link, so styles that dress a
// button's slot dress this too.
state: { slot: "button", variant, size },
props: mergeProps<"a">(
{ className: linkButtonVariants({ variant, size, className }) },
props
),
})
}
export { LinkButton, linkButtonVariants }
import type { ComponentProps } from "react"
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cn } from "cn"
/**
* A vertical timeline, as an ordered list. Holds `TimelineItem` entries,
* each with a mark and a line down to the next.
*
* Three CSS variables, set on it through `className` or `style`, tune the
* marks. `--timeline-lh` is the line height of the first line in
* `TimelineContent`, so the mark lines up with it: the default 1rem suits a
* leading `TimelineLabel`; set 1.5rem when a title or body text comes first.
* `--timeline-dot` is the mark's diameter (1rem). `--timeline-nudge` (1px)
* lowers the mark slightly, because a mark centered on a line of text looks
* high.
*/
function Timeline({ className, ...props }: ComponentProps<"ol">) {
return (
<ol
role="list"
data-slot="timeline"
className={cn(
"relative [--timeline-dot:1rem] [--timeline-lh:1rem] [--timeline-nudge:1px]",
"[--timeline-shift:calc((var(--timeline-lh)-var(--timeline-dot))/2+var(--timeline-nudge))]",
className
)}
{...props}
/>
)
}
/**
* One entry, an `li` by default. Put a `TimelineIndicator` and a
* `TimelineContent` inside it. It draws the line from under its mark to the
* next entry's mark; the last entry has none. A `Timeline` nested inside
* `TimelineContent` keeps its own lines.
*/
function TimelineItem({
className,
children,
render,
...props
}: useRender.ComponentProps<"li">) {
return useRender({
defaultTagName: "li",
render,
state: { slot: "timeline-item" },
props: mergeProps<"li">(
{
className: cn(
"group/timeline-item relative flex items-start gap-3",
className
),
children: (
<>
<div
aria-hidden
data-slot="timeline-line"
className={cn(
// Runs from under this mark to the top of the next, never through it. The
// last-item check looks at the direct parent only, so a Timeline nested in
// TimelineContent keeps its own rails.
"pointer-events-none absolute top-[calc(var(--timeline-shift)+var(--timeline-dot))]",
"left-[calc(var(--timeline-dot)/2)] w-px -translate-x-1/2",
"h-[calc(100%-var(--timeline-dot))]",
// A 1px rail can't get thinner, so it is lighter than the type.
"bg-muted-foreground/45 [[data-slot=timeline-item]:last-child>&]:hidden"
)}
/>
{children}
</>
),
},
props
),
})
}
const indicatorVariants = {
default: { ring: "", dot: "bg-foreground" },
muted: { ring: "border-border", dot: "bg-muted-foreground/60" },
plain: { ring: "border-0", dot: "bg-muted-foreground/60" },
faint: { ring: "border-0", dot: "bg-border" },
line: { ring: "border-border", dot: "bg-border" },
empty: { ring: "border-border bg-transparent", dot: "hidden" },
solid: { ring: "border-0 bg-muted-foreground/60", dot: "hidden" },
inverted: { ring: "border-0 bg-foreground", dot: "bg-background" },
primary: { ring: "border-primary", dot: "bg-primary" },
}
/**
* The mark beside an entry. With no children it shows a small dot in a ring.
* Pass an element, such as an icon, to show your own mark instead; the ring
* and fill are then removed. Bare text and `false` are not supported.
*
* `variant` picks how the default mark looks, so a finished, current or
* upcoming entry can read differently without overriding the dot:
* `default` is a foreground ring and dot (the current entry); `muted` a
* soft ring with a muted dot; `plain` a muted dot with no ring; `faint` a
* pale dot with no ring; `line` a soft ring with a pale dot; `empty` an
* empty soft ring (upcoming); `solid` a filled muted disc; `inverted` a
* foreground disc with a background-colored dot; `primary` a primary ring
* and dot. It has no effect on a custom child.
*/
function TimelineIndicator({
className,
children,
variant = "default",
...props
}: ComponentProps<"div"> & {
/** Which look the default mark takes. See the part's description. */
variant?: keyof typeof indicatorVariants
}) {
const look = indicatorVariants[variant]
return (
<div
data-slot="timeline-indicator"
data-variant={variant}
className={cn(
"relative z-10 mt-(--timeline-shift) flex shrink-0",
"size-(--timeline-dot) items-center justify-center rounded-full",
// No children: the default dot in its ring. An element child: your mark,
// no ring. false, [] and bare text are not supported forms.
"border-[1.5px] border-foreground bg-background",
"has-[*:not([data-slot=timeline-dot])]:border-0",
"has-[*:not([data-slot=timeline-dot])]:bg-transparent",
look.ring,
className
)}
{...props}
>
{children ?? (
<div
data-slot="timeline-dot"
className={cn("size-1.5 rounded-full", look.dot)}
/>
)}
</div>
)
}
/**
* The text of an entry, beside its mark. It leaves 32px of space before the
* next entry, and none after the last.
*/
function TimelineContent({ className, ...props }: ComponentProps<"div">) {
return (
<div
data-slot="timeline-content"
className={cn(
"min-w-0 flex-1 pb-8 [[data-slot=timeline-item]:last-child>&]:pb-0",
className
)}
{...props}
/>
)
}
/** The entry's title, in medium weight. It renders a `div`, not a heading. */
function TimelineTitle({ className, ...props }: ComponentProps<"div">) {
return (
<div
data-slot="timeline-title"
className={cn("font-medium", className)}
{...props}
/>
)
}
/** Supporting text for an entry, small and muted, under the title. */
function TimelineDescription({ className, ...props }: ComponentProps<"p">) {
return (
<p
data-slot="timeline-description"
className={cn("mt-1 text-sm text-muted-foreground", className)}
{...props}
/>
)
}
/**
* A small muted line for an entry, such as a date. Its line height matches
* the default `--timeline-lh`, so a label that comes first lines up with the
* mark.
*/
function TimelineLabel({ className, ...props }: ComponentProps<"p">) {
return (
<p
data-slot="timeline-label"
className={cn("text-xs/4 text-muted-foreground", className)}
{...props}
/>
)
}
export {
Timeline,
TimelineItem,
TimelineIndicator,
TimelineContent,
TimelineTitle,
TimelineDescription,
TimelineLabel,
}
Installation
npx shadcn@latest add @01orbital/mentions-list-01Make it yours
- Its words are in
COPYat the top ofcomponents/blocks/notifications/mentions-list-01/index.tsx: change them there, not in the markup. MENTIONS, also at the top of the file, holds its lists and settings.
Built from
Built from these parts. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.
Last updated on