Skip to content

ComponentsMessage components

SourceSource

Text Display

A block of message text that keeps its line breaks, with the chat markdown heading and subtext sizes.

A text display is a block of message text, the most common Components V2 part. Put it in a V2Container, in a SectionContent or anywhere a message shows text. It keeps the line breaks of the string it gets (white-space: pre-line), so a bot’s \n is a new line on screen.

Root class newt-text-display
import { Divider } from "@/registry/bases/newt/ui/divider"
import { TextDisplay } from "@/registry/bases/newt/ui/text-display"
import { V2Container } from "@/registry/bases/newt/ui/v2-container"

/* A `\n` in the text is a line break on screen: the part keeps them. */
const RULES =
  "Be kind and keep it on topic.\nRead the pinned messages before asking."

export default function TextDisplayDemo() {
  return (
    <V2Container>
      <TextDisplay size="heading-1">Welcome aboard</TextDisplay>
      <TextDisplay size="heading-2">Server rules</TextDisplay>
      <TextDisplay>{RULES}</TextDisplay>
      <Divider spacing="small" />
      <TextDisplay size="heading-3">Roles</TextDisplay>
      <TextDisplay>Pick a colour in the roles channel.</TextDisplay>
      <TextDisplay size="subtext">Updated by the moderators</TextDisplay>
    </V2Container>
  )
}
<script setup lang="ts">
import { Divider } from "~~/registry/bases/newt/ui/divider"
import { TextDisplay } from "~~/registry/bases/newt/ui/text-display"
import { V2Container } from "~~/registry/bases/newt/ui/v2-container"

/* A `\n` in the text is a line break on screen: the part keeps them. */
const rules =
  "Be kind and keep it on topic.\nRead the pinned messages before asking."
</script>

<template>
  <V2Container>
    <TextDisplay size="heading-1">Welcome aboard</TextDisplay>
    <TextDisplay size="heading-2">Server rules</TextDisplay>
    <TextDisplay>{{ rules }}</TextDisplay>
    <Divider spacing="small" />
    <TextDisplay size="heading-3">Roles</TextDisplay>
    <TextDisplay>Pick a colour in the roles channel.</TextDisplay>
    <TextDisplay size="subtext">Updated by the moderators</TextDisplay>
  </V2Container>
</template>

Installation

npx newtui@latest add text-displaynpx shadcn@latest add @newtui/text-displaynpx shadcn-vue@latest add @newtui/text-displaypnpm dlx newtui@latest add text-displaypnpm dlx shadcn@latest add @newtui/text-displaypnpm dlx shadcn-vue@latest add @newtui/text-displayyarn dlx newtui@latest add text-displayyarn dlx shadcn@latest add @newtui/text-displayyarn dlx shadcn-vue@latest add @newtui/text-displaybunx newtui@latest add text-displaybunx shadcn@latest add @newtui/text-displaybunx shadcn-vue@latest add @newtui/text-displaydeno run -A npm:newtui@latest add text-displaydeno run -A npm:shadcn@latest add @newtui/text-displaydeno run -A npm:shadcn-vue@latest add @newtui/text-displayvlx newtui@latest add text-displayvlx shadcn@latest add @newtui/text-displayvlx shadcn-vue@latest add @newtui/text-displayvp dlx newtui@latest add text-displayvp dlx shadcn@latest add @newtui/text-displayvp dlx shadcn-vue@latest add @newtui/text-displaynubx newtui@latest add text-displaynubx shadcn@latest add @newtui/text-displaynubx shadcn-vue@latest add @newtui/text-displaynlx newtui@latest add text-displaynlx shadcn@latest add @newtui/text-displaynlx shadcn-vue@latest add @newtui/text-displayupx newtui@latest add text-displayupx shadcn@latest add @newtui/text-displayupx shadcn-vue@latest add @newtui/text-display

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

Install the dependencies

npm install class-variance-authoritypnpm add class-variance-authorityyarn add class-variance-authoritybun add class-variance-authoritydeno add npm:class-variance-authorityvlt install class-variance-authorityvp add class-variance-authoritynub add class-variance-authorityni class-variance-authorityupm add class-variance-authority

Copy the source into your project

import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react"

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

/*
 * The sizes are the chat markdown ones, so a text display and a `Markdown`
 * message agree: `#` is 24px, `##` is 20px, `###` is 16px and `-#` subtext
 * is 13px in the muted colour. `default` keeps the size and colour of the
 * container around it.
 */
const textDisplayVariants = cva(
  "m-0 min-w-0 whitespace-pre-line break-words [overflow-wrap:anywhere]",
  {
    variants: {
      size: {
        default: "",
        "heading-1":
          "text-2xl font-bold leading-[1.375] text-newt-text-primary",
        "heading-2": "text-xl font-bold leading-[1.375] text-newt-text-primary",
        "heading-3":
          "text-base font-bold leading-[1.375] text-newt-text-primary",
        subtext: "text-[13px] leading-[1.3] text-newt-text-muted",
      },
    },
    defaultVariants: {
      size: "default",
    },
  }
)

export interface TextDisplayProps
  extends
    React.HTMLAttributes<HTMLElement>,
    VariantProps<typeof textDisplayVariants> {
  /**
   * The element or component to render. Defaults to `div`; pass `h2` or
   * `h3` when a heading size is also a heading of the page.
   */
  as?: React.ElementType
}

/*
 * A block of message text, the most common Components V2 part. Line breaks
 * in the text are kept (`white-space: pre-line`), so a string with `\n`
 * renders the way the message was written.
 */
const TextDisplay = React.forwardRef<HTMLElement, TextDisplayProps>(
  ({ as: Tag = "div", className, size, ...props }, ref) => (
    <Tag
      ref={ref}
      className={cn(textDisplayVariants({ size }), className)}
      {...props}
    />
  )
)
TextDisplay.displayName = "TextDisplay"

export { TextDisplay, textDisplayVariants }
<script setup lang="ts">
import type { Component, HTMLAttributes } from "vue"

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

import { textDisplayVariants, type TextDisplayVariants } from "."

/*
 * A block of message text, the most common Components V2 part. Line breaks
 * in the text are kept (`white-space: pre-line`), so a string with `\n`
 * renders the way the message was written.
 */
const props = withDefaults(
  defineProps<{
    class?: HTMLAttributes["class"]
    size?: TextDisplayVariants["size"]
    /**
     * The element or component to render. Defaults to `div`; pass `h2` or
     * `h3` when a heading size is also a heading of the page.
     */
    as?: string | Component
  }>(),
  { as: "div" }
)
</script>

<template>
  <component
    :is="props.as"
    :class="cn(textDisplayVariants({ size: props.size }), props.class)"
  >
    <slot />
  </component>
</template>
import { cva, type VariantProps } from "class-variance-authority"

export { default as TextDisplay } from "./TextDisplay.vue"

/*
 * The sizes are the chat markdown ones, so a text display and a `Markdown`
 * message agree: `#` is 24px, `##` is 20px, `###` is 16px and `-#` subtext
 * is 13px in the muted colour. `default` keeps the size and colour of the
 * container around it.
 */
export const textDisplayVariants = cva(
  "m-0 min-w-0 whitespace-pre-line break-words [overflow-wrap:anywhere]",
  {
    variants: {
      size: {
        default: "",
        "heading-1":
          "text-2xl font-bold leading-[1.375] text-newt-text-primary",
        "heading-2": "text-xl font-bold leading-[1.375] text-newt-text-primary",
        "heading-3":
          "text-base font-bold leading-[1.375] text-newt-text-primary",
        subtext: "text-[13px] leading-[1.3] text-newt-text-muted",
      },
    },
    defaultVariants: {
      size: "default",
    },
  }
)

export type TextDisplayVariants = VariantProps<typeof textDisplayVariants>

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 Text Display 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 Text Display 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 { TextDisplay } from "@/components/ui/text-display"

export function Example() {
  return <TextDisplay />
}
<script setup lang="ts">
import { TextDisplay } from "@/components/ui/text-display"
</script>

<template>
  <TextDisplay />
</template>

Sizes

size picks one of the chat markdown sizes. They match the Markdown component, so a text display and a rendered message look the same.

size Markdown Text
default none The container’s size
heading-1 # 24px, bold
heading-2 ## 20px, bold, the size of SectionHeading
heading-3 ### 16px, bold
subtext -# 13px, muted colour

Without a size, the text keeps the size and the colour of the container around it. A heading size keeps the font of the container, as a Markdown heading does. SectionHeading uses the display font and a tighter line height.

In Vue, a template collapses its own line breaks before the part sees them. Bind the text as a string, such as {{ content }}, to keep them. In the HTML version, start the text right after the opening tag; a newline there is a line break too.

API reference

TextDisplay

PropType
size?"default" | "heading-1" | "heading-2" | "heading-3" | "subtext"

The chat markdown size: `#`, `##` and `###` headings, or `-#` subtext.

Type"default" | "heading-1" | "heading-2" | "heading-3" | "subtext"
Default"default"
as?React.ElementType (React) / string | Component (Vue)

The element or component to render. Pass `h2` or `h3` when a heading size is also a heading of the page.

TypeReact.ElementType (React) / string | Component (Vue)
Default"div"
children / default slot?React.ReactNode / Vue slot

The text. Line breaks in a string are kept.

TypeReact.ReactNode / Vue slot

The registry exports TextDisplay and textDisplayVariants. TextDisplay accepts the native attributes of the element it renders. React uses className, while Vue uses class and fallthrough attributes.

Accessibility

A heading size only changes the look. If the text is a heading of the page, pass a heading element with as, such as as="h3", so assistive technology can navigate to it. Keep the heading levels in order inside the page. Subtext uses --newt-text-muted; keep it for secondary text, never for the only copy of important information.

Tokens

Text Display 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-text-display.

  • --newt-text-primary
  • --newt-text-muted