Skip to content

ComponentsMessaging

SourceSource

Reply Preview

A compact "replying to" bar showing the author, a truncated excerpt, or the slash command that was used.

A reply preview keeps the referenced author and excerpt attached to the message that answers it. Compose the avatar, author, text, action and command parts so the compact row still reflects the content being referenced.

Root class newt-reply
import {
  ReplyPreview,
  ReplyPreviewAction,
  ReplyPreviewAuthor,
  ReplyPreviewAvatar,
  ReplyPreviewCommand,
  ReplyPreviewText,
} from "@/registry/bases/newt/ui/reply-preview"

/* Inline so the demo never reaches out to the network for a placeholder. */
const AVATAR =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='8' fill='%235865f2'/%3E%3C/svg%3E"

/* A slash in a square. The chip sizes an icon it is given to 12px. */
const SLASH_ICON = (
  <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
    <path
      fill="currentColor"
      fillRule="evenodd"
      d="M5 3a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2H5Zm9.4 3 1.9.7L9.6 18l-1.9-.7L14.4 6Z"
    />
  </svg>
)

export default function ReplyPreviewDemo() {
  return (
    <div className="flex flex-col gap-3">
      <ReplyPreview>
        <ReplyPreviewAvatar src={AVATAR} />
        <ReplyPreviewAuthor>@username</ReplyPreviewAuthor>
        <ReplyPreviewText>
          original message text being replied to
        </ReplyPreviewText>
      </ReplyPreview>
      <ReplyPreview>
        <ReplyPreviewAvatar src={AVATAR} />
        <ReplyPreviewAuthor>@username</ReplyPreviewAuthor>
        <ReplyPreviewAction>used</ReplyPreviewAction>
        <ReplyPreviewCommand>/ban member</ReplyPreviewCommand>
      </ReplyPreview>
      <ReplyPreview>
        <ReplyPreviewAvatar src={AVATAR} />
        <ReplyPreviewAuthor>@username</ReplyPreviewAuthor>
        <ReplyPreviewAction>used</ReplyPreviewAction>
        <ReplyPreviewCommand icon={SLASH_ICON}>ban member</ReplyPreviewCommand>
      </ReplyPreview>
      {/* No `src`: the children draw an avatar that is an icon. */}
      <ReplyPreview>
        <ReplyPreviewAvatar>
          <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
            <path fill="currentColor" d="M13 2 3 14h7l-1 8 10-12h-7l1-8Z" />
          </svg>
        </ReplyPreviewAvatar>
        <ReplyPreviewAuthor>@relay</ReplyPreviewAuthor>
        <ReplyPreviewText>deploy finished in 42 seconds</ReplyPreviewText>
      </ReplyPreview>
    </div>
  )
}
<script setup lang="ts">
import {
  ReplyPreview,
  ReplyPreviewAction,
  ReplyPreviewAuthor,
  ReplyPreviewAvatar,
  ReplyPreviewCommand,
  ReplyPreviewText,
} from "~~/registry/bases/newt/ui/reply-preview"

/* Inline so the demo never reaches out to the network for a placeholder. */
const AVATAR =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='8' fill='%235865f2'/%3E%3C/svg%3E"
</script>

<template>
  <div class="flex flex-col gap-3">
    <ReplyPreview>
      <ReplyPreviewAvatar :src="AVATAR" />
      <ReplyPreviewAuthor>@username</ReplyPreviewAuthor>
      <ReplyPreviewText
        >original message text being replied to</ReplyPreviewText
      >
    </ReplyPreview>
    <ReplyPreview>
      <ReplyPreviewAvatar :src="AVATAR" />
      <ReplyPreviewAuthor>@username</ReplyPreviewAuthor>
      <ReplyPreviewAction>used</ReplyPreviewAction>
      <ReplyPreviewCommand>/ban member</ReplyPreviewCommand>
    </ReplyPreview>
    <!-- A slash in a square. The chip sizes an icon it is given to 12px. -->
    <ReplyPreview>
      <ReplyPreviewAvatar :src="AVATAR" />
      <ReplyPreviewAuthor>@username</ReplyPreviewAuthor>
      <ReplyPreviewAction>used</ReplyPreviewAction>
      <ReplyPreviewCommand>
        <template #icon>
          <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
            <path
              fill="currentColor"
              fill-rule="evenodd"
              d="M5 3a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2H5Zm9.4 3 1.9.7L9.6 18l-1.9-.7L14.4 6Z"
            />
          </svg>
        </template>
        ban member
      </ReplyPreviewCommand>
    </ReplyPreview>
    <!-- No `src`: the slot draws an avatar that is an icon. -->
    <ReplyPreview>
      <ReplyPreviewAvatar>
        <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
          <path fill="currentColor" d="M13 2 3 14h7l-1 8 10-12h-7l1-8Z" />
        </svg>
      </ReplyPreviewAvatar>
      <ReplyPreviewAuthor>@relay</ReplyPreviewAuthor>
      <ReplyPreviewText>deploy finished in 42 seconds</ReplyPreviewText>
    </ReplyPreview>
  </div>
</template>

Installation

npx newtui@latest add reply-previewnpx shadcn@latest add @newtui/reply-previewnpx shadcn-vue@latest add @newtui/reply-previewpnpm dlx newtui@latest add reply-previewpnpm dlx shadcn@latest add @newtui/reply-previewpnpm dlx shadcn-vue@latest add @newtui/reply-previewyarn dlx newtui@latest add reply-previewyarn dlx shadcn@latest add @newtui/reply-previewyarn dlx shadcn-vue@latest add @newtui/reply-previewbunx newtui@latest add reply-previewbunx shadcn@latest add @newtui/reply-previewbunx shadcn-vue@latest add @newtui/reply-previewdeno run -A npm:newtui@latest add reply-previewdeno run -A npm:shadcn@latest add @newtui/reply-previewdeno run -A npm:shadcn-vue@latest add @newtui/reply-previewvlx newtui@latest add reply-previewvlx shadcn@latest add @newtui/reply-previewvlx shadcn-vue@latest add @newtui/reply-previewvp dlx newtui@latest add reply-previewvp dlx shadcn@latest add @newtui/reply-previewvp dlx shadcn-vue@latest add @newtui/reply-previewnubx newtui@latest add reply-previewnubx shadcn@latest add @newtui/reply-previewnubx shadcn-vue@latest add @newtui/reply-previewnlx newtui@latest add reply-previewnlx shadcn@latest add @newtui/reply-previewnlx shadcn-vue@latest add @newtui/reply-previewupx newtui@latest add reply-previewupx shadcn@latest add @newtui/reply-previewupx shadcn-vue@latest add @newtui/reply-preview

The shadcn CLI needs the @newtui registry in your components.json. Set it up.

Copy the source into your project

import * as React from "react"

import { cn } from "@/lib/utils"

const ReplyPreview = React.forwardRef<
  HTMLDivElement,
  React.ComponentProps<"div">
>(({ className, ...props }, ref) => (
  <div
    ref={ref}
    className={cn(
      "relative mb-1 flex min-w-0 items-center gap-1.5 ps-[18px] text-[13px] leading-4 text-newt-text-muted",
      /* The elbow that hooks the preview back up to the message above it. */
      "before:absolute before:start-0 before:top-1/2 before:h-3 before:w-3 before:-translate-y-full before:rounded-ss-[6px] before:border-s-2 before:border-t-2 before:border-newt-border before:content-['']",
      /*
       * In the reply slot of a message group the preview has no margin and no
       * padding: the row sets the distance to the author line. The reach is
       * the distance from the preview back to the centre of the avatar, from
       * the two properties the group publishes. The fallbacks are the values
       * of a group that does not publish them.
       */
      "[[data-slot=message-reply]_&]:mb-0 [[data-slot=message-reply]_&]:ps-0 [[data-slot=message-reply]_&]:[--newt-reply-spine-reach:calc(var(--newt-message-group-avatar-size,40px)_/_2_+_var(--newt-message-group-gap,16px))]",
      /*
       * There the spine leaves the preview. It starts above the centre of the
       * avatar, half a stroke back so the 2px stroke is centred, and stops
       * 4px before the preview.
       */
      "[[data-slot=message-reply]_&]:before:bottom-0 [[data-slot=message-reply]_&]:before:end-[calc(100%_+_4px)] [[data-slot=message-reply]_&]:before:start-[calc(-1_*_var(--newt-reply-spine-reach)_-_1px)] [[data-slot=message-reply]_&]:before:top-[calc(50%_-_1px)] [[data-slot=message-reply]_&]:before:h-auto [[data-slot=message-reply]_&]:before:w-auto [[data-slot=message-reply]_&]:before:translate-y-0",
      className
    )}
    {...props}
  />
))
ReplyPreview.displayName = "ReplyPreview"

export interface ReplyPreviewAvatarProps extends Omit<
  React.ImgHTMLAttributes<HTMLImageElement>,
  "children"
> {
  /**
   * The fallback, drawn when there is no `src` and no `srcSet`: an icon or
   * initials in a
   * 16px circle. The circle sizes an `svg` to 10px.
   */
  children?: React.ReactNode
}

/*
 * The avatar of the referenced author. With a `src` or a `srcSet` it is an
 * image. Without either it is a circle that holds its children, so an avatar that is an icon
 * can be drawn. An empty `alt` hides either form from a screen reader.
 */
const ReplyPreviewAvatar = React.forwardRef<
  HTMLElement,
  ReplyPreviewAvatarProps
>(({ className, alt = "", src, srcSet, children, ...props }, ref) => {
  const decorative = alt === ""
  if (src !== undefined || srcSet !== undefined) {
    /*
     * `createElement` types the ref by the element it is given here, so the
     * one `HTMLElement` ref serves both forms without an assertion.
     */
    return React.createElement("img", {
      ref,
      src,
      srcSet,
      alt,
      "aria-hidden": decorative ? true : undefined,
      className: cn("h-4 w-4 shrink-0 rounded-full object-cover", className),
      ...props,
    })
  }
  return (
    <span
      ref={ref}
      role={decorative ? undefined : "img"}
      aria-label={decorative ? undefined : alt}
      aria-hidden={decorative ? true : undefined}
      className={cn(
        "inline-flex h-4 w-4 shrink-0 items-center justify-center overflow-hidden rounded-full bg-newt-brand text-[9px] font-semibold text-newt-on-accent [&>svg]:h-2.5 [&>svg]:w-2.5",
        className
      )}
      {...props}
    >
      {children}
    </span>
  )
})
ReplyPreviewAvatar.displayName = "ReplyPreviewAvatar"

const ReplyPreviewAuthor = React.forwardRef<
  HTMLSpanElement,
  React.ComponentProps<"span">
>(({ className, ...props }, ref) => (
  <span
    ref={ref}
    className={cn("shrink-0 font-medium text-newt-text-link", className)}
    {...props}
  />
))
ReplyPreviewAuthor.displayName = "ReplyPreviewAuthor"

const ReplyPreviewText = React.forwardRef<
  HTMLSpanElement,
  React.ComponentProps<"span">
>(({ className, ...props }, ref) => (
  <span
    ref={ref}
    className={cn(
      "min-w-0 max-w-[360px] truncate text-newt-text-muted",
      className
    )}
    {...props}
  />
))
ReplyPreviewText.displayName = "ReplyPreviewText"

/* "used" — the verb between the author and an interaction chip. */
const ReplyPreviewAction = React.forwardRef<
  HTMLSpanElement,
  React.ComponentProps<"span">
>(({ className, ...props }, ref) => (
  <span ref={ref} className={cn("shrink-0", className)} {...props} />
))
ReplyPreviewAction.displayName = "ReplyPreviewAction"

export interface ReplyPreviewCommandProps extends React.ComponentProps<"span"> {
  /**
   * An icon before the command name. It sits outside the truncating label,
   * so the gap of the chip applies and the icon never clips.
   */
  icon?: React.ReactNode
}

/* The command chip shown when the reply is a slash-command interaction. */
const ReplyPreviewCommand = React.forwardRef<
  HTMLSpanElement,
  ReplyPreviewCommandProps
>(({ className, icon, children, ...props }, ref) => (
  <span
    ref={ref}
    className={cn(
      "inline-flex min-w-0 items-center gap-0.5 rounded-[var(--newt-radius-sm)] bg-[color-mix(in_srgb,var(--newt-brand)_15%,transparent)] px-1 font-medium text-newt-mention-text [&>svg]:h-3 [&>svg]:w-3 [&>svg]:shrink-0",
      className
    )}
    {...props}
  >
    {icon}
    <span className="truncate">{children}</span>
  </span>
))
ReplyPreviewCommand.displayName = "ReplyPreviewCommand"

export {
  ReplyPreview,
  ReplyPreviewAvatar,
  ReplyPreviewAuthor,
  ReplyPreviewText,
  ReplyPreviewAction,
  ReplyPreviewCommand,
}
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<template>
  <div
    :class="
      cn(
        'relative mb-1 flex min-w-0 items-center gap-1.5 ps-[18px] text-[13px] leading-4 text-newt-text-muted',
        // The elbow that hooks the preview back up to the message above it.
        `before:absolute before:start-0 before:top-1/2 before:h-3 before:w-3 before:-translate-y-full before:rounded-ss-[6px] before:border-s-2 before:border-t-2 before:border-newt-border before:content-['']`,
        // In the reply slot of a message group the preview has no margin and
        // no padding: the row sets the distance to the author line. The reach
        // is the distance from the preview back to the centre of the avatar,
        // from the two properties the group publishes. The fallbacks are the
        // values of a group that does not publish them.
        '[[data-slot=message-reply]_&]:mb-0 [[data-slot=message-reply]_&]:ps-0 [[data-slot=message-reply]_&]:[--newt-reply-spine-reach:calc(var(--newt-message-group-avatar-size,40px)_/_2_+_var(--newt-message-group-gap,16px))]',
        // There the spine leaves the preview. It starts above the centre of
        // the avatar, half a stroke back so the 2px stroke is centred, and
        // stops 4px before the preview.
        '[[data-slot=message-reply]_&]:before:bottom-0 [[data-slot=message-reply]_&]:before:end-[calc(100%_+_4px)] [[data-slot=message-reply]_&]:before:start-[calc(-1_*_var(--newt-reply-spine-reach)_-_1px)] [[data-slot=message-reply]_&]:before:top-[calc(50%_-_1px)] [[data-slot=message-reply]_&]:before:h-auto [[data-slot=message-reply]_&]:before:w-auto [[data-slot=message-reply]_&]:before:translate-y-0',
        props.class
      )
    "
  >
    <slot />
  </div>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

/*
 * The avatar of the referenced author. With a `src` or a `srcset` it is an
 * image. Without either it is a circle that holds the default slot, so an avatar that is an
 * icon can be drawn; the circle sizes an `svg` to 10px. An empty `alt` hides
 * either form from a screen reader.
 */
const props = withDefaults(
  defineProps<{
    class?: HTMLAttributes["class"]
    src?: string
    srcset?: string
    alt?: string
  }>(),
  { alt: "" }
)
</script>

<template>
  <img
    v-if="props.src !== undefined || props.srcset !== undefined"
    :src="props.src"
    :srcset="props.srcset"
    :alt="props.alt"
    :aria-hidden="props.alt === '' ? true : undefined"
    :class="cn('h-4 w-4 shrink-0 rounded-full object-cover', props.class)"
  />
  <span
    v-else
    :role="props.alt === '' ? undefined : 'img'"
    :aria-label="props.alt === '' ? undefined : props.alt"
    :aria-hidden="props.alt === '' ? true : undefined"
    :class="
      cn(
        'inline-flex h-4 w-4 shrink-0 items-center justify-center overflow-hidden rounded-full bg-newt-brand text-[9px] font-semibold text-newt-on-accent [&>svg]:h-2.5 [&>svg]:w-2.5',
        props.class
      )
    "
  >
    <slot />
  </span>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<template>
  <span :class="cn('shrink-0 font-medium text-newt-text-link', props.class)">
    <slot />
  </span>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<template>
  <span
    :class="
      cn('min-w-0 max-w-[360px] truncate text-newt-text-muted', props.class)
    "
  >
    <slot />
  </span>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<!-- "used" — the verb between the author and an interaction chip. -->
<template>
  <span :class="cn('shrink-0', props.class)"><slot /></span>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<!--
  The command chip shown when the reply is a slash-command interaction. The
  `icon` slot sits outside the truncating label, so the gap of the chip
  applies and the icon never clips.
-->
<template>
  <span
    :class="
      cn(
        'inline-flex min-w-0 items-center gap-0.5 rounded-[var(--newt-radius-sm)] bg-[color-mix(in_srgb,var(--newt-brand)_15%,transparent)] px-1 font-medium text-newt-mention-text [&>svg]:h-3 [&>svg]:w-3 [&>svg]:shrink-0',
        props.class
      )
    "
  >
    <slot name="icon" />
    <span class="truncate"><slot /></span>
  </span>
</template>
export { default as ReplyPreview } from "./ReplyPreview.vue"
export { default as ReplyPreviewAvatar } from "./ReplyPreviewAvatar.vue"
export { default as ReplyPreviewAuthor } from "./ReplyPreviewAuthor.vue"
export { default as ReplyPreviewText } from "./ReplyPreviewText.vue"
export { default as ReplyPreviewAction } from "./ReplyPreviewAction.vue"
export { default as ReplyPreviewCommand } from "./ReplyPreviewCommand.vue"

Update the import paths

The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Reply Preview to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Reply Preview to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

Usage

import { ReplyPreview } from "@/components/ui/reply-preview"

export function Example() {
  return <ReplyPreview />
}
<script setup lang="ts">
import { ReplyPreview, ReplyPreviewAvatar, ReplyPreviewAuthor, ReplyPreviewText, ReplyPreviewAction, ReplyPreviewCommand } from "@/components/ui/reply-preview"
</script>

<template>
  <ReplyPreview />
</template>

In a message group

Put the preview in MessageGroupReply. There it has no margin and no start padding, and the row sets the distance to the author line. Its spine starts above the centre of the avatar and stops 4px before the preview.

The spine reads two custom properties of the row: --newt-message-group-avatar-size and --newt-message-group-gap. If the row does not set them, the spine uses 40px and 16px. Outside a group, the preview keeps its own elbow, its margin and its padding.

API reference

ReplyPreview

PropType
children / default slot?React.ReactNode / Vue slot

The avatar, author and referenced text or command, in reading order.

TypeReact.ReactNode / Vue slot
className / class?string

Additional classes merged with the preview defaults.

Typestring

ReplyPreviewAvatar

PropType
src?string

The image URL. Without it and without `srcSet`, the avatar is a 16px circle that holds its fallback.

Typestring
srcSet (React) / srcset (Vue)?string

Image candidates for each pixel density. It draws the image without `src` too.

Typestring
alt?string

Accessible name. Leave it empty beside the author name, which hides the avatar from a screen reader.

Typestring
Default""
children / default slot?React.ReactNode / Vue slot

The fallback, drawn when there is no `src` and no `srcSet`: an icon or initials. The circle sizes an `svg` to 10px.

TypeReact.ReactNode / Vue slot

ReplyPreviewCommand

PropType
icon (React) / #icon slot (Vue)?React.ReactNode / Vue slot

An icon before the command name. It sits outside the truncating label, so the gap of the chip applies. The chip sizes an `svg` to 12px.

TypeReact.ReactNode / Vue slot

In the plain HTML and CSS distribution, give the icon the class newt-reply__command-icon and put it before newt-reply__command-name. For an avatar with no image, use a <span> with the classes newt-reply__avatar newt-reply__avatar--fallback and put the icon in it.

The registry also exports ReplyPreviewAvatar, ReplyPreviewAuthor, ReplyPreviewText, ReplyPreviewAction and ReplyPreviewCommand. Each part accepts the native attributes of the element it renders.

Accessibility

The avatar is decorative by default; provide alternative text only when it adds information that the adjacent author name does not. Keep the referenced text in DOM order, and use a real button or link outside the preview when the row itself opens the original message.

Tokens

Reply Preview reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-reply.

  • --newt-border
  • --newt-text-muted
  • --newt-radius-full
  • --newt-brand
  • --newt-on-accent
  • --newt-text-link
  • --newt-radius-sm
  • --newt-mention-text