Channel Header
The bar above the message list, with the channel name, topic and channel actions.
The bar above the message list, with the channel name, topic and channel actions. Compose it from the exported registry parts so local content and behaviour stay in the application while the visual contract stays token-driven.
newt-channel-header"use client"
import * as React from "react"
import {
ChannelHeader,
ChannelHeaderAction,
ChannelHeaderDivider,
ChannelHeaderIcon,
ChannelHeaderInfo,
ChannelHeaderName,
ChannelHeaderSearch,
ChannelHeaderToolbar,
ChannelHeaderTopic,
} from "@/registry/bases/newt/ui/channel-header"
export default function ChannelHeaderDemo() {
const [members, setMembers] = React.useState(true)
return (
<ChannelHeader className="w-full">
<ChannelHeaderInfo>
<ChannelHeaderIcon />
<ChannelHeaderName>general</ChannelHeaderName>
<ChannelHeaderDivider />
<ChannelHeaderTopic>
Say hello and tell us what you are building.
</ChannelHeaderTopic>
</ChannelHeaderInfo>
<ChannelHeaderToolbar>
<ChannelHeaderAction aria-label="Pinned messages">
<svg viewBox="0 0 24 24" className="h-6 w-6" fill="currentColor">
<path d="M14 3v6l3 3v2h-4v6l-1 1-1-1v-6H7v-2l3-3V3h4Z" />
</svg>
</ChannelHeaderAction>
<ChannelHeaderAction
active={members}
aria-label="Member list"
onClick={() => setMembers((shown) => !shown)}
>
<svg viewBox="0 0 24 24" className="h-6 w-6" fill="currentColor">
<path d="M9 11a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Zm7 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM2 19a7 7 0 0 1 14 0v1H2v-1Zm15.5-6a5.5 5.5 0 0 1 4.5 5.4V20h-4v-1a8.9 8.9 0 0 0-1.6-5.1c.35-.06.72-.09 1.1-.09Z" />
</svg>
</ChannelHeaderAction>
<ChannelHeaderSearch className="hidden sm:flex" />
</ChannelHeaderToolbar>
</ChannelHeader>
)
}<script setup lang="ts">
import { ref } from "vue"
import {
ChannelHeader,
ChannelHeaderAction,
ChannelHeaderDivider,
ChannelHeaderIcon,
ChannelHeaderInfo,
ChannelHeaderName,
ChannelHeaderSearch,
ChannelHeaderToolbar,
ChannelHeaderTopic,
} from "~~/registry/bases/newt/ui/channel-header"
const members = ref(true)
</script>
<template>
<ChannelHeader class="w-full">
<ChannelHeaderInfo>
<ChannelHeaderIcon />
<ChannelHeaderName>general</ChannelHeaderName>
<ChannelHeaderDivider />
<ChannelHeaderTopic>
Say hello and tell us what you are building.
</ChannelHeaderTopic>
</ChannelHeaderInfo>
<ChannelHeaderToolbar>
<ChannelHeaderAction aria-label="Pinned messages">
<svg viewBox="0 0 24 24" class="h-6 w-6" fill="currentColor">
<path d="M14 3v6l3 3v2h-4v6l-1 1-1-1v-6H7v-2l3-3V3h4Z" />
</svg>
</ChannelHeaderAction>
<ChannelHeaderAction
:active="members"
aria-label="Member list"
@click="members = !members"
>
<svg viewBox="0 0 24 24" class="h-6 w-6" fill="currentColor">
<path
d="M9 11a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Zm7 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM2 19a7 7 0 0 1 14 0v1H2v-1Zm15.5-6a5.5 5.5 0 0 1 4.5 5.4V20h-4v-1a8.9 8.9 0 0 0-1.6-5.1c.35-.06.72-.09 1.1-.09Z"
/>
</svg>
</ChannelHeaderAction>
<ChannelHeaderSearch class="hidden sm:flex" />
</ChannelHeaderToolbar>
</ChannelHeader>
</template>Installation
npx newtui@latest add channel-headernpx shadcn@latest add @newtui/channel-headernpx shadcn-vue@latest add @newtui/channel-headerpnpm dlx newtui@latest add channel-headerpnpm dlx shadcn@latest add @newtui/channel-headerpnpm dlx shadcn-vue@latest add @newtui/channel-headeryarn dlx newtui@latest add channel-headeryarn dlx shadcn@latest add @newtui/channel-headeryarn dlx shadcn-vue@latest add @newtui/channel-headerbunx newtui@latest add channel-headerbunx shadcn@latest add @newtui/channel-headerbunx shadcn-vue@latest add @newtui/channel-headerdeno run -A npm:newtui@latest add channel-headerdeno run -A npm:shadcn@latest add @newtui/channel-headerdeno run -A npm:shadcn-vue@latest add @newtui/channel-headervlx newtui@latest add channel-headervlx shadcn@latest add @newtui/channel-headervlx shadcn-vue@latest add @newtui/channel-headervp dlx newtui@latest add channel-headervp dlx shadcn@latest add @newtui/channel-headervp dlx shadcn-vue@latest add @newtui/channel-headernubx newtui@latest add channel-headernubx shadcn@latest add @newtui/channel-headernubx shadcn-vue@latest add @newtui/channel-headernlx newtui@latest add channel-headernlx shadcn@latest add @newtui/channel-headernlx shadcn-vue@latest add @newtui/channel-headerupx newtui@latest add channel-headerupx shadcn@latest add @newtui/channel-headerupx shadcn-vue@latest add @newtui/channel-header- newtui
- shadcn
- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
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"
export interface ChannelHeaderProps extends React.HTMLAttributes<HTMLElement> {
/**
* The element to render. `div` by default, because a `header` outside
* `main`, `article`, `aside`, `nav` or `section` is a second banner
* landmark. Pass `header` when the bar sits inside one of those.
*/
as?: React.ElementType
}
/* The bar above the message list: channel name, topic, and channel actions. */
const ChannelHeader = React.forwardRef<HTMLElement, ChannelHeaderProps>(
({ as: Tag = "div", className, ...props }, ref) => (
<Tag
ref={ref}
className={cn(
"flex min-h-12 items-center justify-between gap-3 border-b border-newt-border bg-newt-bg-surface ps-4 pe-3 text-newt-text-primary",
className
)}
{...props}
/>
)
)
ChannelHeader.displayName = "ChannelHeader"
const ChannelHeaderInfo = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex min-w-0 items-center gap-2", className)}
{...props}
/>
))
ChannelHeaderInfo.displayName = "ChannelHeaderInfo"
const ChannelHeaderIcon = React.forwardRef<
HTMLSpanElement,
React.ComponentProps<"span">
>(({ className, children = "#", ...props }, ref) => (
<span
ref={ref}
aria-hidden="true"
className={cn(
"shrink-0 text-xl font-bold leading-none text-newt-text-muted",
className
)}
{...props}
>
{children}
</span>
))
ChannelHeaderIcon.displayName = "ChannelHeaderIcon"
const ChannelHeaderName = React.forwardRef<
HTMLSpanElement,
React.ComponentProps<"span">
>(({ className, ...props }, ref) => (
<span
ref={ref}
className={cn(
"min-w-0 truncate text-base font-semibold text-newt-text-primary",
className
)}
{...props}
/>
))
ChannelHeaderName.displayName = "ChannelHeaderName"
/* Round dot that sets the topic apart from the channel name. */
const ChannelHeaderDivider = React.forwardRef<
HTMLSpanElement,
React.ComponentProps<"span">
>(({ className, ...props }, ref) => (
<span
ref={ref}
aria-hidden="true"
className={cn(
"h-1 w-1 shrink-0 rounded-full bg-newt-text-muted opacity-70",
className
)}
{...props}
/>
))
ChannelHeaderDivider.displayName = "ChannelHeaderDivider"
/*
* The shrink factor is what makes the topic give way before the name: the
* name only starts to truncate once the topic has no width left.
*/
const ChannelHeaderTopic = React.forwardRef<
HTMLSpanElement,
React.ComponentProps<"span">
>(({ className, ...props }, ref) => (
<span
ref={ref}
className={cn(
"min-w-0 shrink-[99999] truncate text-[13px] font-medium text-newt-text-muted",
className
)}
{...props}
/>
))
ChannelHeaderTopic.displayName = "ChannelHeaderTopic"
const ChannelHeaderToolbar = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex shrink-0 items-center gap-4", className)}
{...props}
/>
))
ChannelHeaderToolbar.displayName = "ChannelHeaderToolbar"
/* What every control of the header adds to its resting look. */
const interactiveClassName =
"cursor-pointer transition-colors duration-fast ease-newt focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link disabled:cursor-not-allowed disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:cursor-not-allowed aria-disabled:opacity-50"
interface ChannelHeaderControlProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
/**
* The element or component to render. Defaults to `button`, or to `a` when
* `href` is set; pass a router link component to keep client navigation.
* `span` renders the decorative form: hidden from assistive technology, out
* of the tab order, with no pointer and no hover.
* Its event handlers do not run.
*/
as?: React.ElementType
/** Render a link to this URL. */
href?: string
/**
* Turns the control off. A link loses its URL, which takes it out of the
* tab order, and says so with `aria-disabled`.
*/
disabled?: boolean
/** Link target, with `href`. */
target?: React.AnchorHTMLAttributes<HTMLAnchorElement>["target"]
/** Link relationship, with `href`. */
rel?: string
}
/* The element a control renders, and whether it is the decorative form. */
function resolveControl(
as: React.ElementType | undefined,
href: string | undefined
) {
const Tag: React.ElementType = as ?? (href === undefined ? "button" : "a")
return { Tag, isButton: Tag === "button", decorative: Tag === "span" }
}
/*
* The `span` form runs nothing: it drops every event handler, so a click
* cannot start an action that the keyboard and assistive technology miss.
*/
function withoutHandlers(
props: React.HTMLAttributes<HTMLElement>
): React.HTMLAttributes<HTMLElement> {
return Object.fromEntries(
Object.entries(props).filter(([name]) => !/^on[A-Z]/.test(name))
)
}
export interface ChannelHeaderActionProps extends ChannelHeaderControlProps {
/**
* Makes the action a toggle and keeps it lit up while `true`. A button
* reports the value as `aria-pressed`; leave it unset for a plain action.
*/
active?: boolean
}
const ChannelHeaderAction = React.forwardRef<
HTMLElement,
ChannelHeaderActionProps
>(
(
{ as, href, disabled, className, active, type = "button", ...props },
ref
) => {
const { Tag, isButton, decorative } = resolveControl(as, href)
return (
<Tag
ref={ref}
type={isButton ? type : undefined}
href={decorative || disabled ? undefined : href}
disabled={isButton ? disabled : undefined}
aria-disabled={!isButton && !decorative && disabled ? true : undefined}
aria-hidden={decorative ? true : undefined}
aria-pressed={isButton ? active : undefined}
data-state={active ? "active" : "inactive"}
className={cn(
"inline-flex h-6 w-6 shrink-0 items-center justify-center border-0 bg-transparent p-0 text-newt-text-muted data-[state=active]:text-newt-text-primary",
!decorative && [interactiveClassName, "hover:text-newt-text-primary"],
className
)}
{...(decorative ? withoutHandlers(props) : props)}
/>
)
}
)
ChannelHeaderAction.displayName = "ChannelHeaderAction"
const SearchIcon = ({ className }: { className: string }) => (
<svg
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth="1.75"
strokeLinecap="round"
aria-hidden="true"
className={cn("shrink-0", className)}
>
<circle cx="7" cy="7" r="4.5" />
<path d="M10.5 10.5 14 14" />
</svg>
)
export interface ChannelHeaderSearchProps extends ChannelHeaderControlProps {
/** The text shown when the control has no children. */
placeholder?: string
/**
* Icon-only form for the narrow header. The text stays in the control for
* assistive technology, so it is still the accessible name.
*/
compact?: boolean
}
/* Its text is its accessible name: what a user sees is what they can say. */
const ChannelHeaderSearch = React.forwardRef<
HTMLElement,
ChannelHeaderSearchProps
>(
(
{
as,
href,
disabled,
className,
placeholder = "Search",
compact = false,
type = "button",
children,
...props
},
ref
) => {
const { Tag, isButton, decorative } = resolveControl(as, href)
return (
<Tag
ref={ref}
type={isButton ? type : undefined}
href={decorative || disabled ? undefined : href}
disabled={isButton ? disabled : undefined}
aria-disabled={!isButton && !decorative && disabled ? true : undefined}
aria-hidden={decorative ? true : undefined}
className={cn(
"flex shrink-0 items-center text-newt-text-muted no-underline",
compact
? "h-6 w-6 justify-center border-0 bg-transparent p-0"
: "h-7 w-60 justify-between gap-3 rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-bg-input px-2",
!decorative && [
interactiveClassName,
compact
? "hover:text-newt-text-primary"
: "hover:border-newt-text-muted",
],
className
)}
{...(decorative ? withoutHandlers(props) : props)}
>
<span
className={
compact
? "sr-only"
: "min-w-0 flex-1 truncate text-start text-sm font-medium leading-none"
}
>
{children ?? placeholder}
</span>
<SearchIcon className={compact ? "h-5 w-5" : "h-4 w-4"} />
</Tag>
)
}
)
ChannelHeaderSearch.displayName = "ChannelHeaderSearch"
export interface ChannelHeaderBackProps extends ChannelHeaderControlProps {
/** The unread count drawn beside the arrow. Leave it unset for no badge. */
badge?: React.ReactNode
}
/*
* The control that leaves the channel in the narrow header. It has no text,
* so it needs an `aria-label`; put the unread count in that label too,
* because the label replaces the badge for assistive technology.
*/
const ChannelHeaderBack = React.forwardRef<HTMLElement, ChannelHeaderBackProps>(
(
{
as,
href,
disabled,
className,
badge,
type = "button",
children,
...props
},
ref
) => {
const { Tag, isButton, decorative } = resolveControl(as, href)
return (
<Tag
ref={ref}
type={isButton ? type : undefined}
href={decorative || disabled ? undefined : href}
disabled={isButton ? disabled : undefined}
aria-disabled={!isButton && !decorative && disabled ? true : undefined}
aria-hidden={decorative ? true : undefined}
className={cn(
"inline-flex h-6 min-w-6 shrink-0 items-center justify-center gap-1 border-0 bg-transparent p-0 text-newt-text-muted no-underline",
!decorative && [interactiveClassName, "hover:text-newt-text-primary"],
className
)}
{...(decorative ? withoutHandlers(props) : props)}
>
{children ?? (
<svg
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
className="h-5 w-5 shrink-0 rtl:-scale-x-100"
>
<path d="M8.7 3.3 2 10l6.7 6.7 1.4-1.4L5.8 11H18V9H5.8l4.3-4.3-1.4-1.4Z" />
</svg>
)}
{badge == null || badge === false ? null : (
<span className="inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-newt-dnd px-1 text-[11px] font-bold leading-none text-newt-on-accent">
{badge}
</span>
)}
</Tag>
)
}
)
ChannelHeaderBack.displayName = "ChannelHeaderBack"
/*
* The channel name as a control, for the narrow header where a press on the
* title opens the channel details. Put `ChannelHeaderIcon` and
* `ChannelHeaderName` inside it: the name is its accessible name. `span`
* renders it as plain text, still readable by assistive technology. Its
* event handlers do not run.
*/
const ChannelHeaderTitle = React.forwardRef<
HTMLElement,
ChannelHeaderControlProps
>(
(
{ as, href, disabled, className, type = "button", children, ...props },
ref
) => {
const { Tag, isButton, decorative: plain } = resolveControl(as, href)
return (
<Tag
ref={ref}
type={isButton ? type : undefined}
href={plain || disabled ? undefined : href}
disabled={isButton ? disabled : undefined}
aria-disabled={!isButton && !plain && disabled ? true : undefined}
className={cn(
"inline-flex min-w-0 items-center gap-2 rounded-[var(--newt-radius-sm)] border-0 bg-transparent px-1.5 py-1 text-start text-newt-text-primary no-underline",
!plain && [interactiveClassName, "hover:bg-newt-bg-hover"],
className
)}
{...(plain ? withoutHandlers(props) : props)}
>
{children}
{plain ? null : (
<svg
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth="1.75"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
className="h-4 w-4 shrink-0 text-newt-text-muted rtl:-scale-x-100"
>
<path d="m6 3.5 4.5 4.5L6 12.5" />
</svg>
)}
</Tag>
)
}
)
ChannelHeaderTitle.displayName = "ChannelHeaderTitle"
/* Compact "N Online" readout used by the narrow layout of the header. */
const ChannelHeaderOnline = React.forwardRef<
HTMLSpanElement,
React.ComponentProps<"span">
>(({ className, children, ...props }, ref) => (
<span
ref={ref}
className={cn(
"inline-flex shrink-0 items-center gap-1.5 text-xs text-newt-text-muted",
className
)}
{...props}
>
<span
aria-hidden="true"
className="h-2 w-2 shrink-0 rounded-full bg-newt-online"
/>
{children}
</span>
))
ChannelHeaderOnline.displayName = "ChannelHeaderOnline"
export {
ChannelHeader,
ChannelHeaderInfo,
ChannelHeaderIcon,
ChannelHeaderName,
ChannelHeaderDivider,
ChannelHeaderTopic,
ChannelHeaderToolbar,
ChannelHeaderAction,
ChannelHeaderSearch,
ChannelHeaderBack,
ChannelHeaderTitle,
ChannelHeaderOnline,
}<script setup lang="ts">
import type { Component, HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const props = withDefaults(
defineProps<{
/**
* The element to render. `div` by default, because a `header` outside
* `main`, `article`, `aside`, `nav` or `section` is a second banner
* landmark. Pass `header` when the bar sits inside one of those.
*/
as?: string | Component
class?: HTMLAttributes["class"]
}>(),
{ as: "div" }
)
</script>
<template>
<!-- The bar above the message list: channel name, topic, channel actions. -->
<component
:is="props.as"
:class="
cn(
'flex min-h-12 items-center justify-between gap-3 border-b border-newt-border bg-newt-bg-surface ps-4 pe-3 text-newt-text-primary',
props.class
)
"
>
<slot />
</component>
</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 items-center gap-2', 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>
<span
aria-hidden="true"
:class="
cn(
'shrink-0 text-xl font-bold leading-none text-newt-text-muted',
props.class
)
"
>
<slot>#</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 truncate text-base font-semibold text-newt-text-primary',
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>
<!-- Round dot that sets the topic apart from the channel name. -->
<span
aria-hidden="true"
:class="
cn(
'h-1 w-1 shrink-0 rounded-full bg-newt-text-muted opacity-70',
props.class
)
"
/>
</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 shrink-[99999] truncate text-[13px] font-medium 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>
<template>
<div :class="cn('flex shrink-0 items-center gap-4', props.class)">
<slot />
</div>
</template><script setup lang="ts">
import type { Component, HTMLAttributes } from "vue"
import { computed } from "vue"
import { cn } from "@/lib/utils"
defineOptions({ inheritAttrs: false })
/*
* The `span` form runs nothing: it drops every listener, so a click cannot
* start an action that the keyboard and assistive technology miss.
*/
function withoutListeners(attrs: HTMLAttributes): HTMLAttributes {
return Object.fromEntries(
Object.entries(attrs).filter(([name]) => !/^on[A-Z]/.test(name))
)
}
const props = withDefaults(
defineProps<{
/**
* The element or component to render. Defaults to `button`, or to `a`
* when `href` is set; pass `NuxtLink` or `RouterLink` to keep client
* navigation. `span` renders the decorative form: hidden from assistive
* technology, out of the tab order, with no pointer and no hover.
* Its event handlers do not run.
*/
as?: string | Component
/** Render a link to this URL. */
href?: string
/**
* Turns the control off. A link loses its URL, which takes it out of the
* tab order, and says so with `aria-disabled`.
*/
disabled?: boolean
class?: HTMLAttributes["class"]
/**
* Makes the action a toggle and keeps it lit up while `true`. A button
* reports the value as `aria-pressed`; leave it unset for a plain action.
*/
active?: boolean
}>(),
/*
* Vue casts an absent `boolean` prop to `false` unless it has a `default`
* key. `undefined` here is what tells a plain action from a toggle that is
* off.
*/
{ active: undefined }
)
const tag = computed(
() => props.as ?? (props.href === undefined ? "button" : "a")
)
const isButton = computed(() => tag.value === "button")
const decorative = computed(() => tag.value === "span")
</script>
<template>
<component
:is="tag"
:type="isButton ? 'button' : undefined"
:href="decorative || props.disabled ? undefined : props.href"
:disabled="isButton ? props.disabled : undefined"
:aria-disabled="
!isButton && !decorative && props.disabled ? true : undefined
"
:aria-hidden="decorative ? true : undefined"
:aria-pressed="isButton ? props.active : undefined"
:data-state="props.active ? 'active' : 'inactive'"
:class="
cn(
'inline-flex h-6 w-6 shrink-0 items-center justify-center border-0 bg-transparent p-0 text-newt-text-muted data-[state=active]:text-newt-text-primary',
!decorative &&
'cursor-pointer transition-colors duration-fast ease-newt hover:text-newt-text-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link disabled:cursor-not-allowed disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:cursor-not-allowed aria-disabled:opacity-50',
props.class
)
"
v-bind="decorative ? withoutListeners($attrs) : $attrs"
>
<slot />
</component>
</template><script setup lang="ts">
import type { Component, HTMLAttributes } from "vue"
import { computed } from "vue"
import { cn } from "@/lib/utils"
defineOptions({ inheritAttrs: false })
/*
* The `span` form runs nothing: it drops every listener, so a click cannot
* start an action that the keyboard and assistive technology miss.
*/
function withoutListeners(attrs: HTMLAttributes): HTMLAttributes {
return Object.fromEntries(
Object.entries(attrs).filter(([name]) => !/^on[A-Z]/.test(name))
)
}
const props = withDefaults(
defineProps<{
/**
* The element or component to render. Defaults to `button`, or to `a`
* when `href` is set; pass `NuxtLink` or `RouterLink` to keep client
* navigation. `span` renders the decorative form: hidden from assistive
* technology, out of the tab order, with no pointer and no hover.
* Its event handlers do not run.
*/
as?: string | Component
/** Render a link to this URL. */
href?: string
/**
* Turns the control off. A link loses its URL, which takes it out of the
* tab order, and says so with `aria-disabled`.
*/
disabled?: boolean
class?: HTMLAttributes["class"]
/** The text shown when the default slot is empty. */
placeholder?: string
/**
* Icon-only form for the narrow header. The text stays in the control for
* assistive technology, so it is still the accessible name.
*/
compact?: boolean
}>(),
{ placeholder: "Search", compact: false }
)
const tag = computed(
() => props.as ?? (props.href === undefined ? "button" : "a")
)
const isButton = computed(() => tag.value === "button")
const decorative = computed(() => tag.value === "span")
</script>
<template>
<!-- Its text is its accessible name: what a user sees is what they can say. -->
<component
:is="tag"
:type="isButton ? 'button' : undefined"
:href="decorative || props.disabled ? undefined : props.href"
:disabled="isButton ? props.disabled : undefined"
:aria-disabled="
!isButton && !decorative && props.disabled ? true : undefined
"
:aria-hidden="decorative ? true : undefined"
:class="
cn(
'flex shrink-0 items-center text-newt-text-muted no-underline',
props.compact
? 'h-6 w-6 justify-center border-0 bg-transparent p-0'
: 'h-7 w-60 justify-between gap-3 rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-bg-input px-2',
!decorative &&
'cursor-pointer transition-colors duration-fast ease-newt focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link disabled:cursor-not-allowed disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:cursor-not-allowed aria-disabled:opacity-50',
!decorative &&
(props.compact
? 'hover:text-newt-text-primary'
: 'hover:border-newt-text-muted'),
props.class
)
"
v-bind="decorative ? withoutListeners($attrs) : $attrs"
>
<span
:class="
props.compact
? 'sr-only'
: 'min-w-0 flex-1 truncate text-start text-sm font-medium leading-none'
"
>
<slot>{{ props.placeholder }}</slot>
</span>
<svg
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
aria-hidden="true"
:class="cn('shrink-0', props.compact ? 'h-5 w-5' : 'h-4 w-4')"
>
<circle cx="7" cy="7" r="4.5" />
<path d="M10.5 10.5 14 14" />
</svg>
</component>
</template><script setup lang="ts">
import type { Component, HTMLAttributes } from "vue"
import { computed } from "vue"
import { cn } from "@/lib/utils"
defineOptions({ inheritAttrs: false })
/*
* The `span` form runs nothing: it drops every listener, so a click cannot
* start an action that the keyboard and assistive technology miss.
*/
function withoutListeners(attrs: HTMLAttributes): HTMLAttributes {
return Object.fromEntries(
Object.entries(attrs).filter(([name]) => !/^on[A-Z]/.test(name))
)
}
const props = defineProps<{
/**
* The element or component to render. Defaults to `button`, or to `a`
* when `href` is set; pass `NuxtLink` or `RouterLink` to keep client
* navigation. `span` renders the decorative form: hidden from assistive
* technology, out of the tab order, with no pointer and no hover.
* Its event handlers do not run.
*/
as?: string | Component
/** Render a link to this URL. */
href?: string
/**
* Turns the control off. A link loses its URL, which takes it out of the
* tab order, and says so with `aria-disabled`.
*/
disabled?: boolean
class?: HTMLAttributes["class"]
/** The unread count drawn beside the arrow. Leave it unset for no badge. */
badge?: string | number
}>()
const tag = computed(
() => props.as ?? (props.href === undefined ? "button" : "a")
)
const isButton = computed(() => tag.value === "button")
const decorative = computed(() => tag.value === "span")
</script>
<template>
<!--
The control that leaves the channel in the narrow header. It has no text,
so it needs an `aria-label`; put the unread count in that label too,
because the label replaces the badge for assistive technology.
-->
<component
:is="tag"
:type="isButton ? 'button' : undefined"
:href="decorative || props.disabled ? undefined : props.href"
:disabled="isButton ? props.disabled : undefined"
:aria-disabled="
!isButton && !decorative && props.disabled ? true : undefined
"
:aria-hidden="decorative ? true : undefined"
:class="
cn(
'inline-flex h-6 min-w-6 shrink-0 items-center justify-center gap-1 border-0 bg-transparent p-0 text-newt-text-muted no-underline',
!decorative &&
'cursor-pointer transition-colors duration-fast ease-newt hover:text-newt-text-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link disabled:cursor-not-allowed disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:cursor-not-allowed aria-disabled:opacity-50',
props.class
)
"
v-bind="decorative ? withoutListeners($attrs) : $attrs"
>
<slot>
<svg
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
class="h-5 w-5 shrink-0 rtl:-scale-x-100"
>
<path
d="M8.7 3.3 2 10l6.7 6.7 1.4-1.4L5.8 11H18V9H5.8l4.3-4.3-1.4-1.4Z"
/>
</svg>
</slot>
<span
v-if="props.badge !== undefined"
class="inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-newt-dnd px-1 text-[11px] font-bold leading-none text-newt-on-accent"
>
{{ props.badge }}
</span>
</component>
</template><script setup lang="ts">
import type { Component, HTMLAttributes } from "vue"
import { computed } from "vue"
import { cn } from "@/lib/utils"
defineOptions({ inheritAttrs: false })
/*
* The `span` form runs nothing: it drops every listener, so a click cannot
* start an action that the keyboard and assistive technology miss.
*/
function withoutListeners(attrs: HTMLAttributes): HTMLAttributes {
return Object.fromEntries(
Object.entries(attrs).filter(([name]) => !/^on[A-Z]/.test(name))
)
}
const props = defineProps<{
/**
* The element or component to render. Defaults to `button`, or to `a`
* when `href` is set; pass `NuxtLink` or `RouterLink` to keep client
* navigation. `span` renders plain text: no pointer, no hover and no
* chevron, and assistive technology still reads it. Its event handlers
* do not run.
*/
as?: string | Component
/** Render a link to this URL. */
href?: string
/**
* Turns the control off. A link loses its URL, which takes it out of the
* tab order, and says so with `aria-disabled`.
*/
disabled?: boolean
class?: HTMLAttributes["class"]
}>()
const tag = computed(
() => props.as ?? (props.href === undefined ? "button" : "a")
)
const isButton = computed(() => tag.value === "button")
const plain = computed(() => tag.value === "span")
</script>
<template>
<!--
The channel name as a control, for the narrow header where a press on the
title opens the channel details. Put `ChannelHeaderIcon` and
`ChannelHeaderName` inside it: the name is its accessible name.
-->
<component
:is="tag"
:type="isButton ? 'button' : undefined"
:href="plain || props.disabled ? undefined : props.href"
:disabled="isButton ? props.disabled : undefined"
:aria-disabled="!isButton && !plain && props.disabled ? true : undefined"
:class="
cn(
'inline-flex min-w-0 items-center gap-2 rounded-[var(--newt-radius-sm)] border-0 bg-transparent px-1.5 py-1 text-start text-newt-text-primary no-underline',
!plain &&
'cursor-pointer transition-colors duration-fast ease-newt hover:bg-newt-bg-hover focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link disabled:cursor-not-allowed disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:cursor-not-allowed aria-disabled:opacity-50',
props.class
)
"
v-bind="plain ? withoutListeners($attrs) : $attrs"
>
<slot />
<svg
v-if="!plain"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
stroke-width="1.75"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
class="h-4 w-4 shrink-0 text-newt-text-muted rtl:-scale-x-100"
>
<path d="m6 3.5 4.5 4.5L6 12.5" />
</svg>
</component>
</template><script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>
<template>
<!-- Compact "N Online" readout used by the narrow layout of the header. -->
<span
:class="
cn(
'inline-flex shrink-0 items-center gap-1.5 text-xs text-newt-text-muted',
props.class
)
"
>
<span
aria-hidden="true"
class="h-2 w-2 shrink-0 rounded-full bg-newt-online"
/>
<slot />
</span>
</template>export { default as ChannelHeader } from "./ChannelHeader.vue"
export { default as ChannelHeaderInfo } from "./ChannelHeaderInfo.vue"
export { default as ChannelHeaderIcon } from "./ChannelHeaderIcon.vue"
export { default as ChannelHeaderName } from "./ChannelHeaderName.vue"
export { default as ChannelHeaderDivider } from "./ChannelHeaderDivider.vue"
export { default as ChannelHeaderTopic } from "./ChannelHeaderTopic.vue"
export { default as ChannelHeaderToolbar } from "./ChannelHeaderToolbar.vue"
export { default as ChannelHeaderAction } from "./ChannelHeaderAction.vue"
export { default as ChannelHeaderSearch } from "./ChannelHeaderSearch.vue"
export { default as ChannelHeaderBack } from "./ChannelHeaderBack.vue"
export { default as ChannelHeaderTitle } from "./ChannelHeaderTitle.vue"
export { default as ChannelHeaderOnline } from "./ChannelHeaderOnline.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 Channel Header 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 Channel Header 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 { ChannelHeader } from "@/components/ui/channel-header"
export function Example() {
return <ChannelHeader />
}<script setup lang="ts">
import { ChannelHeader, ChannelHeaderInfo, ChannelHeaderIcon, ChannelHeaderName, ChannelHeaderDivider, ChannelHeaderTopic, ChannelHeaderToolbar, ChannelHeaderAction, ChannelHeaderSearch, ChannelHeaderBack, ChannelHeaderTitle, ChannelHeaderOnline } from "@/components/ui/channel-header"
</script>
<template>
<ChannelHeader />
</template>Put the name and the topic in ChannelHeaderInfo, and the actions in ChannelHeaderToolbar. When the bar runs out of room, the topic shrinks first. The name truncates only after the topic has no width left.
Examples
Narrow layout
On a narrow screen, the bar holds three controls. ChannelHeaderBack leaves the channel and shows the unread count in badge. ChannelHeaderTitle makes the name a button that opens the channel details. ChannelHeaderSearch with compact draws only the icon. ChannelHeaderOnline shows the member count.
newt-channel-headerimport {
ChannelHeader,
ChannelHeaderBack,
ChannelHeaderIcon,
ChannelHeaderInfo,
ChannelHeaderName,
ChannelHeaderOnline,
ChannelHeaderSearch,
ChannelHeaderTitle,
ChannelHeaderToolbar,
} from "@/registry/bases/newt/ui/channel-header"
export default function ChannelHeaderNarrowDemo() {
return (
<ChannelHeader className="w-full max-w-[360px]">
<ChannelHeaderInfo>
<ChannelHeaderBack aria-label="Back to channels, 3 unread" badge={3} />
<ChannelHeaderTitle>
<ChannelHeaderIcon />
<ChannelHeaderName>general</ChannelHeaderName>
</ChannelHeaderTitle>
</ChannelHeaderInfo>
<ChannelHeaderToolbar className="gap-3">
<ChannelHeaderOnline>128 Online</ChannelHeaderOnline>
<ChannelHeaderSearch compact />
</ChannelHeaderToolbar>
</ChannelHeader>
)
}<script setup lang="ts">
import {
ChannelHeader,
ChannelHeaderBack,
ChannelHeaderIcon,
ChannelHeaderInfo,
ChannelHeaderName,
ChannelHeaderOnline,
ChannelHeaderSearch,
ChannelHeaderTitle,
ChannelHeaderToolbar,
} from "~~/registry/bases/newt/ui/channel-header"
</script>
<template>
<ChannelHeader class="w-full max-w-[360px]">
<ChannelHeaderInfo>
<ChannelHeaderBack aria-label="Back to channels, 3 unread" :badge="3" />
<ChannelHeaderTitle>
<ChannelHeaderIcon />
<ChannelHeaderName>general</ChannelHeaderName>
</ChannelHeaderTitle>
</ChannelHeaderInfo>
<ChannelHeaderToolbar class="gap-3">
<ChannelHeaderOnline>128 Online</ChannelHeaderOnline>
<ChannelHeaderSearch compact />
</ChannelHeaderToolbar>
</ChannelHeader>
</template>The bar has a minimum height, so a title with two lines makes it taller. Show one layout or the other with your own breakpoint classes.
Decorative actions
A showcase or a read-only view draws the actions and does nothing with them. Pass as="span" to an action or to the search. The part keeps its look and loses its pointer, its hover and its place in the tab order. It also takes aria-hidden, so assistive technology skips it.
newt-channel-headerimport {
ChannelHeader,
ChannelHeaderAction,
ChannelHeaderDivider,
ChannelHeaderIcon,
ChannelHeaderInfo,
ChannelHeaderName,
ChannelHeaderSearch,
ChannelHeaderToolbar,
ChannelHeaderTopic,
} from "@/registry/bases/newt/ui/channel-header"
export default function ChannelHeaderDecorativeDemo() {
return (
<ChannelHeader className="w-full">
<ChannelHeaderInfo>
<ChannelHeaderIcon />
<ChannelHeaderName>general</ChannelHeaderName>
<ChannelHeaderDivider />
<ChannelHeaderTopic>
Say hello and tell us what you are building.
</ChannelHeaderTopic>
</ChannelHeaderInfo>
<ChannelHeaderToolbar>
<ChannelHeaderAction as="span">
<svg viewBox="0 0 24 24" className="h-6 w-6" fill="currentColor">
<path d="M14 3v6l3 3v2h-4v6l-1 1-1-1v-6H7v-2l3-3V3h4Z" />
</svg>
</ChannelHeaderAction>
<ChannelHeaderAction as="span" active>
<svg viewBox="0 0 24 24" className="h-6 w-6" fill="currentColor">
<path d="M9 11a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Zm7 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM2 19a7 7 0 0 1 14 0v1H2v-1Zm15.5-6a5.5 5.5 0 0 1 4.5 5.4V20h-4v-1a8.9 8.9 0 0 0-1.6-5.1c.35-.06.72-.09 1.1-.09Z" />
</svg>
</ChannelHeaderAction>
<ChannelHeaderSearch as="span" className="hidden sm:flex" />
</ChannelHeaderToolbar>
</ChannelHeader>
)
}<script setup lang="ts">
import {
ChannelHeader,
ChannelHeaderAction,
ChannelHeaderDivider,
ChannelHeaderIcon,
ChannelHeaderInfo,
ChannelHeaderName,
ChannelHeaderSearch,
ChannelHeaderToolbar,
ChannelHeaderTopic,
} from "~~/registry/bases/newt/ui/channel-header"
</script>
<template>
<ChannelHeader class="w-full">
<ChannelHeaderInfo>
<ChannelHeaderIcon />
<ChannelHeaderName>general</ChannelHeaderName>
<ChannelHeaderDivider />
<ChannelHeaderTopic>
Say hello and tell us what you are building.
</ChannelHeaderTopic>
</ChannelHeaderInfo>
<ChannelHeaderToolbar>
<ChannelHeaderAction as="span">
<svg viewBox="0 0 24 24" class="h-6 w-6" fill="currentColor">
<path d="M14 3v6l3 3v2h-4v6l-1 1-1-1v-6H7v-2l3-3V3h4Z" />
</svg>
</ChannelHeaderAction>
<ChannelHeaderAction as="span" active>
<svg viewBox="0 0 24 24" class="h-6 w-6" fill="currentColor">
<path
d="M9 11a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Zm7 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM2 19a7 7 0 0 1 14 0v1H2v-1Zm15.5-6a5.5 5.5 0 0 1 4.5 5.4V20h-4v-1a8.9 8.9 0 0 0-1.6-5.1c.35-.06.72-.09 1.1-.09Z"
/>
</svg>
</ChannelHeaderAction>
<ChannelHeaderSearch as="span" class="hidden sm:flex" />
</ChannelHeaderToolbar>
</ChannelHeader>
</template>API reference
ChannelHeader
as?string | Component
The element to render. Pass `header` when the bar sits inside `main`, `article`, `aside`, `nav` or `section`.
string | Component"div"ChannelHeaderAction, ChannelHeaderSearch, ChannelHeaderBack and ChannelHeaderTitle are the controls. Each one takes these two props.
ChannelHeaderAction, ChannelHeaderSearch, ChannelHeaderBack, ChannelHeaderTitle
as?string | Component
The element or component to render. Defaults to `button`, or to `a` when `href` is set. Pass a router link component to keep client navigation. `span` renders the decorative form, which runs no event handlers.
string | Componenthref?string | undefined
Render a link to this URL.
string | undefineddisabled?boolean | undefined
Turns the control off. A link loses its URL, which takes it out of the tab order, and says so with `aria-disabled`. A disabled control fades to half opacity.
boolean | undefinedChannelHeaderAction
active?boolean | undefined
Makes the action a toggle and keeps it lit up while `true`. A button reports the value as `aria-pressed`. Leave it unset for a plain action.
boolean | undefinedChannelHeaderSearch
placeholder?string | undefined
The text shown when the control has no children. Children, or the default slot in Vue, replace it.
string | undefined"Search"compact?boolean | undefined
Icon-only form for the narrow layout. The text stays in the control for assistive technology.
boolean | undefinedfalseChannelHeaderBack
badge?React.ReactNode / string | number
The unread count drawn beside the arrow. Leave it unset for no badge.
React.ReactNode / string | numberchildren / default slot?React.ReactNode / Vue slot
An icon of your own in place of the arrow.
React.ReactNode / Vue slotChannelHeaderTitle takes ChannelHeaderIcon and ChannelHeaderName as children and adds a chevron after them. With as="span" it renders plain text with no chevron, and assistive technology still reads it.
The registry exports ChannelHeader, ChannelHeaderInfo, ChannelHeaderIcon, ChannelHeaderName, ChannelHeaderDivider, ChannelHeaderTopic, ChannelHeaderToolbar, ChannelHeaderAction, ChannelHeaderSearch, ChannelHeaderBack, ChannelHeaderTitle, ChannelHeaderOnline. Parts without a table accept the native attributes for the element they render; React uses className, while Vue uses class and fallthrough attributes.
Accessibility
The bar is a div. A header element outside main, article, aside, nav or section is a banner landmark, and a page must have only one. Pass as="header" when the bar sits inside one of those elements.
The search control’s text, and so its name, comes from placeholder. Translating labels lists every English default.
Every icon-only action needs an aria-label. ChannelHeaderBack has no text either. Put the unread count in its label, for example “Back to channels, 3 unread”, because the label replaces the badge for assistive technology.
Set active on an action that turns something on and off. The button then reports its state with aria-pressed. Keep the label the same in both states, for example “Member list”.
ChannelHeaderSearch takes its accessible name from its text, so the name always matches what a user sees. The same holds for ChannelHeaderTitle, whose name is the channel name.
Do not hide an interactive action with aria-hidden alone. It stays in the tab order, and a keyboard user lands on a control that a screen reader cannot announce. Use the decorative form.
Tokens
Channel Header 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-channel-header.
--newt-border--newt-bg-surface--newt-text-primary--newt-text-muted--newt-radius-full--newt-duration-fast--newt-ease--newt-text-link--newt-radius-sm--newt-bg-input--newt-dir--newt-dnd--newt-on-accent--newt-bg-hover--newt-online