Skip to content

ComponentsMessage components

SourceSource

Section

A block of text with one accessory beside it — a thumbnail, or a button.

A block of text with one accessory beside it — a thumbnail, or a button. Compose it from the exported registry parts so local content and behaviour stay in the application while the visual contract stays token-driven.

import {
  Section,
  SectionAccessory,
  SectionContent,
  SectionHeading,
  SectionThumbnail,
} from "@/registry/bases/newt/ui/section"

/*
 * Drawn as a data URI rather than fetched: a demo that needs the network is a
 * demo that fails offline, and the thumbnail only has to be a thumbnail.
 */
const COVER =
  "data:image/svg+xml;utf8," +
  encodeURIComponent(
    `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 85 85">
      <defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stop-color="#5865f2"/><stop offset="1" stop-color="#eb459e"/>
      </linearGradient></defs>
      <rect width="85" height="85" fill="url(#g)"/>
    </svg>`
  )

export default function SectionDemo() {
  return (
    <Section className="max-w-[520px]">
      <SectionContent>
        <SectionHeading>Release 7.3</SectionHeading>
        <p>
          The update is out. Chests open on the first try, the servers hold at
          peak hours, and gravity only changes on Thursdays.
        </p>
      </SectionContent>
      <SectionAccessory>
        <SectionThumbnail src={COVER} alt="Release artwork" />
      </SectionAccessory>
    </Section>
  )
}
<script setup lang="ts">
import {
  Section,
  SectionAccessory,
  SectionContent,
  SectionHeading,
  SectionThumbnail,
} from "~~/registry/bases/newt/ui/section"

/*
 * Drawn as a data URI rather than fetched: a demo that needs the network is a
 * demo that fails offline, and the thumbnail only has to be a thumbnail.
 */
const cover =
  "data:image/svg+xml;utf8," +
  encodeURIComponent(
    `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 85 85">
      <defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stop-color="#5865f2"/><stop offset="1" stop-color="#eb459e"/>
      </linearGradient></defs>
      <rect width="85" height="85" fill="url(#g)"/>
    </svg>`
  )
</script>

<template>
  <Section class="max-w-[520px]">
    <SectionContent>
      <SectionHeading>Release 7.3</SectionHeading>
      <p>
        The update is out. Chests open on the first try, the servers hold at
        peak hours, and gravity only changes on Thursdays.
      </p>
    </SectionContent>
    <SectionAccessory>
      <SectionThumbnail :src="cover" alt="Release artwork" />
    </SectionAccessory>
  </Section>
</template>

Installation

npx newtui@latest add sectionnpx shadcn@latest add @newtui/sectionnpx shadcn-vue@latest add @newtui/sectionpnpm dlx newtui@latest add sectionpnpm dlx shadcn@latest add @newtui/sectionpnpm dlx shadcn-vue@latest add @newtui/sectionyarn dlx newtui@latest add sectionyarn dlx shadcn@latest add @newtui/sectionyarn dlx shadcn-vue@latest add @newtui/sectionbunx newtui@latest add sectionbunx shadcn@latest add @newtui/sectionbunx shadcn-vue@latest add @newtui/sectiondeno run -A npm:newtui@latest add sectiondeno run -A npm:shadcn@latest add @newtui/sectiondeno run -A npm:shadcn-vue@latest add @newtui/sectionvlx newtui@latest add sectionvlx shadcn@latest add @newtui/sectionvlx shadcn-vue@latest add @newtui/sectionvp dlx newtui@latest add sectionvp dlx shadcn@latest add @newtui/sectionvp dlx shadcn-vue@latest add @newtui/sectionnubx newtui@latest add sectionnubx shadcn@latest add @newtui/sectionnubx shadcn-vue@latest add @newtui/sectionnlx newtui@latest add sectionnlx shadcn@latest add @newtui/sectionnlx shadcn-vue@latest add @newtui/sectionupx newtui@latest add sectionupx shadcn@latest add @newtui/sectionupx shadcn-vue@latest add @newtui/section

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"

/*
 * A block of text with one thing beside it: a thumbnail, or a button. That
 * pairing is the whole component — the text column takes the space that is
 * left, and the accessory keeps its own width whatever the text does.
 */
const Section = React.forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
  <div
    ref={ref}
    className={cn("flex w-full items-start gap-4", className)}
    {...props}
  />
))
Section.displayName = "Section"

const SectionContent = React.forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
  <div
    ref={ref}
    className={cn(
      "flex min-w-0 flex-1 flex-col gap-2 text-[15px] leading-[1.375] text-newt-text-secondary",
      className
    )}
    {...props}
  />
))
SectionContent.displayName = "SectionContent"

const SectionHeading = React.forwardRef<
  HTMLParagraphElement,
  React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
  <p
    ref={ref}
    className={cn(
      "font-display text-xl font-bold leading-tight text-newt-text-primary",
      className
    )}
    {...props}
  />
))
SectionHeading.displayName = "SectionHeading"

/*
 * The accessory never shrinks and never stretches: it is the fixed side of
 * the pair, which is what keeps a long paragraph from squeezing a thumbnail
 * into a sliver.
 */
const SectionAccessory = React.forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
  <div
    ref={ref}
    className={cn("flex shrink-0 items-start", className)}
    {...props}
  />
))
SectionAccessory.displayName = "SectionAccessory"

/*
 * The props of the element or component `as` names, so a custom image
 * component's own props type-check.
 */
export type SectionThumbnailProps<E extends React.ElementType = "img"> = {
  /**
   * The image element or component to render. Defaults to `img`; pass your
   * framework's image component for optimised sources. It receives `src`,
   * `alt`, `className` and the spoiler attributes and handlers.
   */
  as?: E
  /**
   * Marks the image as a spoiler: blurred until clicked, the same treatment
   * a spoilered attachment gets.
   */
  spoiler?: boolean
  /** Accessible name of a hidden spoiler, read in place of the image. */
  spoilerLabel?: string
} & Omit<React.ComponentPropsWithRef<E>, "as" | "spoiler">

type SectionThumbnailComponent = {
  <E extends React.ElementType = "img">(
    props: SectionThumbnailProps<E>
  ): React.ReactNode
  displayName?: string
}

/*
 * SAFETY: `forwardRef` drops the generic signature. The render hands every
 * prop it does not set itself to `as` unchanged, so the props of `as` are
 * the props the part receives.
 */
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- see SAFETY
const SectionThumbnail = React.forwardRef<
  HTMLImageElement,
  SectionThumbnailProps
>(
  (
    {
      as: Tag = "img",
      className,
      spoiler = false,
      spoilerLabel = "Spoiler, click to reveal",
      alt = "",
      ...props
    },
    ref
  ) => {
    const [revealed, setRevealed] = React.useState(false)
    const hidden = spoiler && !revealed

    return (
      <Tag
        ref={ref}
        alt={alt}
        data-spoiler={hidden || undefined}
        /*
         * A spoilered thumbnail is a button until it is opened: it takes a
         * click and a key, and says what it is to a screen reader.
         */
        role={hidden ? "button" : undefined}
        tabIndex={hidden ? 0 : undefined}
        aria-label={hidden ? spoilerLabel : undefined}
        onClick={() => setRevealed(true)}
        onKeyDown={(event: React.KeyboardEvent<HTMLImageElement>) => {
          if (!hidden) return
          if (event.key === "Enter" || event.key === " ") {
            event.preventDefault()
            setRevealed(true)
          }
        }}
        className={cn(
          "h-[85px] w-[85px] rounded-[var(--newt-radius-lg)] object-cover",
          hidden && "cursor-pointer blur-lg",
          className
        )}
        {...props}
      />
    )
  }
) as SectionThumbnailComponent
SectionThumbnail.displayName = "SectionThumbnail"

export {
  Section,
  SectionAccessory,
  SectionContent,
  SectionHeading,
  SectionThumbnail,
}
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

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

/*
 * A block of text with one thing beside it: a thumbnail, or a button. That
 * pairing is the whole component — the text column takes the space that is
 * left, and the accessory keeps its own width whatever the text does.
 */
const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<template>
  <div :class="cn('flex w-full items-start gap-4', props.class)">
    <slot />
  </div>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

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

/*
 * The accessory never shrinks and never stretches: it is the fixed side of
 * the pair, which is what keeps a long paragraph from squeezing a thumbnail
 * into a sliver.
 */
const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<template>
  <div :class="cn('flex shrink-0 items-start', props.class)">
    <slot />
  </div>
</template>
<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(
        'flex min-w-0 flex-1 flex-col gap-2 text-[15px] leading-[1.375] text-newt-text-secondary',
        props.class
      )
    "
  >
    <slot />
  </div>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

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

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

<template>
  <p
    :class="
      cn(
        'font-display text-xl font-bold leading-tight text-newt-text-primary',
        props.class
      )
    "
  >
    <slot />
  </p>
</template>
<script setup lang="ts">
import { ref, type Component, type HTMLAttributes } from "vue"

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

const props = withDefaults(
  defineProps<{
    class?: HTMLAttributes["class"]
    /**
     * The image element or component to render. Defaults to `img`; pass
     * `NuxtImg` or another image component for optimised sources. It
     * receives `src`, `alt`, `class` and the spoiler attributes and handlers.
     */
    as?: string | Component
    src: string
    alt?: string
    /**
     * Marks the image as a spoiler: blurred until clicked, the same treatment
     * a spoilered attachment gets.
     */
    spoiler?: boolean
    /** Accessible name of a hidden spoiler, read in place of the image. */
    spoilerLabel?: string
  }>(),
  {
    as: "img",
    alt: "",
    spoiler: false,
    spoilerLabel: "Spoiler, click to reveal",
  }
)

const revealed = ref(false)

function reveal() {
  revealed.value = true
}

function onKeydown(event: KeyboardEvent) {
  if (revealed.value || !props.spoiler) return
  if (event.key === "Enter" || event.key === " ") {
    event.preventDefault()
    reveal()
  }
}
</script>

<template>
  <component
    :is="props.as"
    :src="props.src"
    :alt="props.alt"
    :data-spoiler="props.spoiler && !revealed ? true : undefined"
    :role="props.spoiler && !revealed ? 'button' : undefined"
    :tabindex="props.spoiler && !revealed ? 0 : undefined"
    :aria-label="props.spoiler && !revealed ? props.spoilerLabel : undefined"
    :class="
      cn(
        'h-[85px] w-[85px] rounded-[var(--newt-radius-lg)] object-cover',
        props.spoiler && !revealed && 'cursor-pointer blur-lg',
        props.class
      )
    "
    @click="reveal"
    @keydown="onKeydown"
  />
</template>
export { default as Section } from "./Section.vue"
export { default as SectionAccessory } from "./SectionAccessory.vue"
export { default as SectionContent } from "./SectionContent.vue"
export { default as SectionHeading } from "./SectionHeading.vue"
export { default as SectionThumbnail } from "./SectionThumbnail.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 Section 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 Section 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 { Section } from "@/components/ui/section"

export function Example() {
  return <Section />
}
<script setup lang="ts">
import { Section, SectionAccessory, SectionContent, SectionHeading, SectionThumbnail } from "@/components/ui/section"
</script>

<template>
  <Section />
</template>

API reference

Section

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

Content rendered inside the component.

TypeReact.ReactNode / Vue slot
className / class?string

Additional classes merged with the component defaults.

Typestring

SectionThumbnail

PropType
as?React.ElementType (React) / string | Component (Vue)

The image element or component to render, such as `NuxtImg`. It gets `src`, `alt`, the classes and the spoiler attributes and handlers, so the spoiler still works.

TypeReact.ElementType (React) / string | Component (Vue)
Default"img"
spoiler?boolean

Blurs the thumbnail until it is clicked or activated with `Enter` or `Space`.

Typeboolean
Defaultfalse
spoilerLabel?string

Accessible name of a hidden spoiler, read in place of the image.

Typestring
Default"Spoiler, click to reveal"

The thumbnail is 85px square. Use TextDisplay in SectionContent for the text beside it. SectionHeading has the size of TextDisplay size="heading-2".

Accessibility

Preserve the native semantics of the rendered elements and pass through ARIA attributes when the surrounding context needs a label or description. Any interactive child needs a visible focus indicator, and meaning must not rely on colour alone.

A spoilered thumbnail takes its name from spoilerLabel. Translating labels lists every English default.

Tokens

Section 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.

  • --newt-text-secondary
  • --newt-font-display
  • --newt-text-primary
  • --newt-radius-lg