Slash Command Suggestions
The command picker that opens above the composer, with an app rail, grouped options and a matched-command preview.
The command picker that opens above the composer, with an app rail, grouped options and a matched-command preview. Compose it from the exported registry parts so local content and behaviour stay in the application while the visual contract stays token-driven.
newt-slash-suggestionsimport { SlashCommand } from "@/registry/bases/newt/ui/slash-command"
import {
SlashCommandAppIcon,
SlashCommandSuggestion,
SlashCommandSuggestionGroup,
SlashCommandSuggestionMatched,
SlashCommandSuggestions,
SlashCommandSuggestionsFooter,
SlashCommandSuggestionsHeader,
SlashCommandSuggestionsList,
SlashCommandSuggestionsRail,
SlashCommandSuggestionsRailItem,
} from "@/registry/bases/newt/ui/slash-command-suggestions"
const ShieldIcon = () => (
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2 4 5v7c0 5 3.4 8.4 8 10 4.6-1.6 8-5 8-10V5l-8-3Z" />
</svg>
)
export default function SlashCommandSuggestionsDemo() {
return (
<SlashCommandSuggestions>
<SlashCommandSuggestionsRail aria-label="Filter commands by app">
<SlashCommandSuggestionsRailItem active aria-label="Frequently used">
<svg viewBox="0 0 24 24" className="h-5 w-5" fill="currentColor">
<path d="M12 3a9 9 0 1 0 9 9h-2a7 7 0 1 1-7-7v4l5-4-5-4v2Z" />
<path d="M11 7h2v5l4 2-1 1.7L11 13V7Z" />
</svg>
</SlashCommandSuggestionsRailItem>
<SlashCommandSuggestionsRailItem aria-label="Moderation commands">
<SlashCommandAppIcon size="rail">
<ShieldIcon />
</SlashCommandAppIcon>
</SlashCommandSuggestionsRailItem>
</SlashCommandSuggestionsRail>
<SlashCommandSuggestionsList aria-label="Slash commands">
<SlashCommandSuggestionsHeader>
Frequently Used
</SlashCommandSuggestionsHeader>
<SlashCommandSuggestionGroup aria-label="Moderation">
<SlashCommandSuggestion
active
name="ban"
description="Ban a member from the server."
appLabel="Moderation"
icon={
<SlashCommandAppIcon>
<ShieldIcon />
</SlashCommandAppIcon>
}
/>
<SlashCommandSuggestion
name="timeout"
description="Mute a member for a set amount of time."
appLabel="Moderation"
icon={
<SlashCommandAppIcon>
<ShieldIcon />
</SlashCommandAppIcon>
}
/>
<SlashCommandSuggestion
disabled
name="verify"
description="Only available to server administrators."
appLabel="Moderation"
icon={
<SlashCommandAppIcon>
<ShieldIcon />
</SlashCommandAppIcon>
}
/>
</SlashCommandSuggestionGroup>
<SlashCommandSuggestionMatched>
<SlashCommand
name="ban"
options={[{ name: "user", value: "@username" }]}
/>
</SlashCommandSuggestionMatched>
</SlashCommandSuggestionsList>
<SlashCommandSuggestionsFooter>
<SlashCommand
name="ban"
options={[
{ name: "user", description: "the member to ban", focused: true },
]}
/>
</SlashCommandSuggestionsFooter>
</SlashCommandSuggestions>
)
}<script setup lang="ts">
import { SlashCommand } from "~~/registry/bases/newt/ui/slash-command"
import {
SlashCommandAppIcon,
SlashCommandSuggestion,
SlashCommandSuggestionGroup,
SlashCommandSuggestionMatched,
SlashCommandSuggestions,
SlashCommandSuggestionsFooter,
SlashCommandSuggestionsHeader,
SlashCommandSuggestionsList,
SlashCommandSuggestionsRail,
SlashCommandSuggestionsRailItem,
} from "~~/registry/bases/newt/ui/slash-command-suggestions"
const shieldPath = "M12 2 4 5v7c0 5 3.4 8.4 8 10 4.6-1.6 8-5 8-10V5l-8-3Z"
</script>
<template>
<SlashCommandSuggestions>
<SlashCommandSuggestionsRail aria-label="Filter commands by app">
<SlashCommandSuggestionsRailItem active aria-label="Frequently used">
<svg viewBox="0 0 24 24" class="h-5 w-5" fill="currentColor">
<path d="M12 3a9 9 0 1 0 9 9h-2a7 7 0 1 1-7-7v4l5-4-5-4v2Z" />
<path d="M11 7h2v5l4 2-1 1.7L11 13V7Z" />
</svg>
</SlashCommandSuggestionsRailItem>
<SlashCommandSuggestionsRailItem aria-label="Moderation commands">
<SlashCommandAppIcon size="rail">
<svg viewBox="0 0 24 24" fill="currentColor">
<path :d="shieldPath" />
</svg>
</SlashCommandAppIcon>
</SlashCommandSuggestionsRailItem>
</SlashCommandSuggestionsRail>
<SlashCommandSuggestionsList aria-label="Slash commands">
<SlashCommandSuggestionsHeader>
Frequently Used
</SlashCommandSuggestionsHeader>
<SlashCommandSuggestionGroup aria-label="Moderation">
<SlashCommandSuggestion
active
name="ban"
description="Ban a member from the server."
app-label="Moderation"
>
<template #icon>
<SlashCommandAppIcon>
<svg viewBox="0 0 24 24" fill="currentColor">
<path :d="shieldPath" />
</svg>
</SlashCommandAppIcon>
</template>
</SlashCommandSuggestion>
<SlashCommandSuggestion
name="timeout"
description="Mute a member for a set amount of time."
app-label="Moderation"
>
<template #icon>
<SlashCommandAppIcon>
<svg viewBox="0 0 24 24" fill="currentColor">
<path :d="shieldPath" />
</svg>
</SlashCommandAppIcon>
</template>
</SlashCommandSuggestion>
<SlashCommandSuggestion
disabled
name="verify"
description="Only available to server administrators."
app-label="Moderation"
>
<template #icon>
<SlashCommandAppIcon>
<svg viewBox="0 0 24 24" fill="currentColor">
<path :d="shieldPath" />
</svg>
</SlashCommandAppIcon>
</template>
</SlashCommandSuggestion>
</SlashCommandSuggestionGroup>
<SlashCommandSuggestionMatched>
<SlashCommand
name="ban"
:options="[{ name: 'user', value: '@username' }]"
/>
</SlashCommandSuggestionMatched>
</SlashCommandSuggestionsList>
<SlashCommandSuggestionsFooter>
<SlashCommand
name="ban"
:options="[
{ name: 'user', description: 'the member to ban', focused: true },
]"
/>
</SlashCommandSuggestionsFooter>
</SlashCommandSuggestions>
</template>Installation
npx newtui@latest add slash-command-suggestionsnpx shadcn@latest add @newtui/slash-command-suggestionsnpx shadcn-vue@latest add @newtui/slash-command-suggestionspnpm dlx newtui@latest add slash-command-suggestionspnpm dlx shadcn@latest add @newtui/slash-command-suggestionspnpm dlx shadcn-vue@latest add @newtui/slash-command-suggestionsyarn dlx newtui@latest add slash-command-suggestionsyarn dlx shadcn@latest add @newtui/slash-command-suggestionsyarn dlx shadcn-vue@latest add @newtui/slash-command-suggestionsbunx newtui@latest add slash-command-suggestionsbunx shadcn@latest add @newtui/slash-command-suggestionsbunx shadcn-vue@latest add @newtui/slash-command-suggestionsdeno run -A npm:newtui@latest add slash-command-suggestionsdeno run -A npm:shadcn@latest add @newtui/slash-command-suggestionsdeno run -A npm:shadcn-vue@latest add @newtui/slash-command-suggestionsvlx newtui@latest add slash-command-suggestionsvlx shadcn@latest add @newtui/slash-command-suggestionsvlx shadcn-vue@latest add @newtui/slash-command-suggestionsvp dlx newtui@latest add slash-command-suggestionsvp dlx shadcn@latest add @newtui/slash-command-suggestionsvp dlx shadcn-vue@latest add @newtui/slash-command-suggestionsnubx newtui@latest add slash-command-suggestionsnubx shadcn@latest add @newtui/slash-command-suggestionsnubx shadcn-vue@latest add @newtui/slash-command-suggestionsnlx newtui@latest add slash-command-suggestionsnlx shadcn@latest add @newtui/slash-command-suggestionsnlx shadcn-vue@latest add @newtui/slash-command-suggestionsupx newtui@latest add slash-command-suggestionsupx shadcn@latest add @newtui/slash-command-suggestionsupx shadcn-vue@latest add @newtui/slash-command-suggestions- 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.
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- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
Add the components it builds on
Copy the source into your project
import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react"
import { cn } from "@/lib/utils"
import { scrollbarClassName } from "@/registry/bases/newt/ui/scrollbar"
/*
* The picker that opens above the composer once a message starts with `/`.
* Focus stays in the composer: wire `aria-activedescendant` on the input to
* the id of the active option rather than moving focus into the list.
*
* A grid, so the parts need no wrapper: the rail and the list share the first
* row, the footer takes the second, and a rail laid as a row takes the third.
* The picker is a size container: its parts change layout from its own width,
* not from the viewport. Set `--newt-slash-suggestions-max-width` to change
* the 640px cap, or to `none` to fill the composer.
*/
const SlashCommandSuggestions = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"grid max-h-80 w-full max-w-[var(--newt-slash-suggestions-max-width,640px)] grid-cols-[auto_minmax(0,1fr)] grid-rows-[minmax(0,1fr)_auto_auto] overflow-hidden rounded-[var(--newt-radius-lg)] bg-newt-bg-floating text-newt-text-primary shadow-elevation-high [container-type:inline-size]",
className
)}
{...props}
/>
))
SlashCommandSuggestions.displayName = "SlashCommandSuggestions"
const railOrientations = {
vertical: "col-start-1 row-start-1 flex-col overflow-y-auto border-e",
horizontal:
"col-span-full row-start-3 flex-row overflow-x-auto overflow-y-hidden border-t",
}
/* The horizontal layout again, for a picker narrower than 480px. */
const railNarrow =
"[@container_(max-width:480px)]:col-span-full [@container_(max-width:480px)]:row-start-3 [@container_(max-width:480px)]:flex-row [@container_(max-width:480px)]:overflow-x-auto [@container_(max-width:480px)]:overflow-y-hidden [@container_(max-width:480px)]:border-e-0 [@container_(max-width:480px)]:border-t"
export interface SlashCommandSuggestionsRailProps extends React.ComponentProps<"nav"> {
/**
* Lays the rail as a column beside the list, or as a row under it. Without
* it, the rail is a column, and a row when the picker is narrower than 480px.
*/
orientation?: "vertical" | "horizontal"
}
/* Strip of app icons that filters the list by app. */
const SlashCommandSuggestionsRail = React.forwardRef<
HTMLElement,
SlashCommandSuggestionsRailProps
>(({ className, orientation, ...props }, ref) => (
<nav
ref={ref}
data-orientation={orientation}
className={cn(
"flex items-center gap-2 border-newt-border bg-newt-bg-base p-2",
railOrientations[orientation ?? "vertical"],
orientation === undefined && railNarrow,
className
)}
{...props}
/>
))
SlashCommandSuggestionsRail.displayName = "SlashCommandSuggestionsRail"
export interface SlashCommandSuggestionsRailItemProps extends React.ComponentProps<"button"> {
active?: boolean
}
const SlashCommandSuggestionsRailItem = React.forwardRef<
HTMLButtonElement,
SlashCommandSuggestionsRailItemProps
>(({ className, active = false, type = "button", ...props }, ref) => (
<button
ref={ref}
type={type}
aria-pressed={active}
data-state={active ? "active" : "inactive"}
className={cn(
"inline-flex h-9 w-9 shrink-0 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent p-0 text-newt-text-muted transition-colors duration-fast ease-newt",
"hover:bg-newt-bg-hover hover:text-newt-text-primary",
"data-[state=active]:bg-newt-bg-active data-[state=active]:text-newt-text-primary",
"focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link",
className
)}
{...props}
/>
))
SlashCommandSuggestionsRailItem.displayName = "SlashCommandSuggestionsRailItem"
const SlashCommandSuggestionsList = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, role = "listbox", ...props }, ref) => (
<div
ref={ref}
role={role}
className={cn(
"col-start-2 row-start-1 min-w-0 overflow-y-auto p-2",
scrollbarClassName,
className
)}
{...props}
/>
))
SlashCommandSuggestionsList.displayName = "SlashCommandSuggestionsList"
/* Sticky section header, as used by the "Frequently Used" block. */
const SlashCommandSuggestionsHeader = React.forwardRef<
HTMLParagraphElement,
React.ComponentProps<"p">
>(({ className, ...props }, ref) => (
<p
ref={ref}
role="presentation"
className={cn(
"sticky top-0 z-[1] m-0 flex items-center gap-1.5 bg-newt-bg-floating px-2 py-1.5 text-sm font-semibold text-newt-text-primary",
className
)}
{...props}
/>
))
SlashCommandSuggestionsHeader.displayName = "SlashCommandSuggestionsHeader"
/* Bar under the rail and the list, for the command being typed. */
const SlashCommandSuggestionsFooter = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"col-span-full row-start-2 flex min-w-0 items-center gap-2 border-t border-newt-border px-3 py-2 text-[13px] leading-snug text-newt-text-secondary",
className
)}
{...props}
/>
))
SlashCommandSuggestionsFooter.displayName = "SlashCommandSuggestionsFooter"
const SlashCommandSuggestionGroup = React.forwardRef<
HTMLElement,
React.ComponentProps<"section">
>(({ className, role = "group", ...props }, ref) => (
<section
ref={ref}
role={role}
className={cn("min-w-0", className)}
{...props}
/>
))
SlashCommandSuggestionGroup.displayName = "SlashCommandSuggestionGroup"
/*
* An image fills the circle. Anything else is a glyph at half its size: an
* inline SVG, or the element an icon component renders, which is often a
* `<span>`.
*/
const appIconVariants = cva(
"inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full bg-newt-bg-elevated text-newt-text-muted [&>img]:h-full [&>img]:w-full [&>img]:object-cover [&>svg]:h-1/2 [&>svg]:w-1/2 [&>:first-child:not(img)]:h-1/2 [&>:first-child:not(img)]:w-1/2",
{
variants: {
size: {
header: "h-4 w-4",
row: "h-6 w-6",
rail: "h-8 w-8",
},
},
defaultVariants: { size: "row" },
}
)
export interface SlashCommandAppIconProps
extends React.ComponentProps<"span">, VariantProps<typeof appIconVariants> {}
const SlashCommandAppIcon = React.forwardRef<
HTMLSpanElement,
SlashCommandAppIconProps
>(({ className, size, ...props }, ref) => (
<span
ref={ref}
aria-hidden="true"
className={cn(appIconVariants({ size }), className)}
{...props}
/>
))
SlashCommandAppIcon.displayName = "SlashCommandAppIcon"
export interface SlashCommandSuggestionProps extends Omit<
React.ComponentProps<"div">,
"children"
> {
/** Command path without the leading slash, e.g. `moderation ban`. */
name: string
description?: string
/** Name of the app the command belongs to, shown on the right. */
appLabel?: string
/** Icon for the owning app; pair with `<SlashCommandAppIcon>`. */
icon?: React.ReactNode
active?: boolean
disabled?: boolean
}
/*
* In a picker narrower than 480px, the app name moves beside the command
* name, and the description takes the full width under them, on up to two
* lines.
*/
const SlashCommandSuggestion = React.forwardRef<
HTMLDivElement,
SlashCommandSuggestionProps
>(
(
{
className,
name,
description,
appLabel,
icon,
active = false,
disabled = false,
...props
},
ref
) => (
<div
ref={ref}
role="option"
aria-selected={active}
aria-disabled={disabled || undefined}
data-state={active ? "active" : "inactive"}
className={cn(
"grid min-h-12 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-[var(--newt-radius-md)] px-2 py-1.5",
"[@container_(max-width:480px)]:gap-x-2 [@container_(max-width:480px)]:gap-y-0.5",
disabled
? "cursor-default opacity-60"
: "cursor-pointer hover:bg-newt-bg-hover",
"data-[state=active]:bg-newt-bg-active",
className
)}
{...props}
>
{icon}
<div className="flex min-w-0 flex-col gap-0.5 [@container_(max-width:480px)]:contents">
<span className="text-[15px] font-semibold leading-tight text-newt-text-primary [@container_(max-width:480px)]:col-start-2 [@container_(max-width:480px)]:row-start-1">
{/* The slash stands off the command path. A margin keeps the text `/ban`. */}
<span className="me-1">/</span>
{name}
</span>
{description ? (
<span className="truncate text-[13px] leading-snug text-newt-text-secondary [@container_(max-width:480px)]:col-[2/-1] [@container_(max-width:480px)]:row-start-2 [@container_(max-width:480px)]:line-clamp-2 [@container_(max-width:480px)]:whitespace-normal">
{description}
</span>
) : null}
</div>
{appLabel ? (
<span className="shrink-0 text-[13px] text-newt-text-secondary [@container_(max-width:480px)]:col-start-3 [@container_(max-width:480px)]:row-start-1">
{appLabel}
</span>
) : null}
</div>
)
)
SlashCommandSuggestion.displayName = "SlashCommandSuggestion"
export interface SlashCommandSuggestionMatchedProps extends React.ComponentProps<"div"> {
active?: boolean
}
/* Row that previews the command already typed, rendered with `<SlashCommand>`. */
const SlashCommandSuggestionMatched = React.forwardRef<
HTMLDivElement,
SlashCommandSuggestionMatchedProps
>(({ className, active = false, ...props }, ref) => (
<div
ref={ref}
role="option"
aria-selected={active}
data-state={active ? "active" : "inactive"}
className={cn(
"min-h-11 cursor-pointer rounded-[var(--newt-radius-md)] px-3 py-2 hover:bg-newt-bg-hover",
"data-[state=active]:bg-newt-bg-active",
className
)}
{...props}
/>
))
SlashCommandSuggestionMatched.displayName = "SlashCommandSuggestionMatched"
export {
SlashCommandSuggestions,
SlashCommandSuggestionsRail,
SlashCommandSuggestionsRailItem,
SlashCommandSuggestionsList,
SlashCommandSuggestionsHeader,
SlashCommandSuggestionsFooter,
SlashCommandSuggestionGroup,
SlashCommandAppIcon,
SlashCommandSuggestion,
SlashCommandSuggestionMatched,
}<script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>
<template>
<!--
The picker that opens above the composer once a message starts with `/`.
Focus stays in the composer: wire `aria-activedescendant` on the input to
the id of the active option rather than moving focus into the list.
A grid, so the parts need no wrapper: the rail and the list share the first
row, the footer takes the second, and a rail laid as a row takes the third.
The picker is a size container: its parts change layout from its own width,
not from the viewport. Set `--newt-slash-suggestions-max-width` to change
the 640px cap, or to `none` to fill the composer.
-->
<div
:class="
cn(
'grid max-h-80 w-full max-w-[var(--newt-slash-suggestions-max-width,640px)] grid-cols-[auto_minmax(0,1fr)] grid-rows-[minmax(0,1fr)_auto_auto] overflow-hidden rounded-[var(--newt-radius-lg)] bg-newt-bg-floating text-newt-text-primary shadow-elevation-high [container-type:inline-size]',
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"]
/**
* Lays the rail as a column beside the list, or as a row under it. Without
* it, the rail is a column, and a row when the picker is narrower than 480px.
*/
orientation?: "vertical" | "horizontal"
}>()
const railOrientations = {
vertical: "col-start-1 row-start-1 flex-col overflow-y-auto border-e",
horizontal:
"col-span-full row-start-3 flex-row overflow-x-auto overflow-y-hidden border-t",
}
/* The horizontal layout again, for a picker narrower than 480px. */
const railNarrow =
"[@container_(max-width:480px)]:col-span-full [@container_(max-width:480px)]:row-start-3 [@container_(max-width:480px)]:flex-row [@container_(max-width:480px)]:overflow-x-auto [@container_(max-width:480px)]:overflow-y-hidden [@container_(max-width:480px)]:border-e-0 [@container_(max-width:480px)]:border-t"
</script>
<template>
<!-- Strip of app icons that filters the list by app. -->
<nav
:data-orientation="props.orientation"
:class="
cn(
'flex items-center gap-2 border-newt-border bg-newt-bg-base p-2',
railOrientations[props.orientation ?? 'vertical'],
props.orientation === undefined && railNarrow,
props.class
)
"
>
<slot />
</nav>
</template><script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const props = withDefaults(
defineProps<{ class?: HTMLAttributes["class"]; active?: boolean }>(),
{ active: false }
)
</script>
<template>
<button
type="button"
:aria-pressed="props.active"
:data-state="props.active ? 'active' : 'inactive'"
:class="
cn(
'inline-flex h-9 w-9 shrink-0 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent p-0 text-newt-text-muted transition-colors duration-fast ease-newt',
'hover:bg-newt-bg-hover hover:text-newt-text-primary',
'data-[state=active]:bg-newt-bg-active data-[state=active]:text-newt-text-primary',
'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link',
props.class
)
"
>
<slot />
</button>
</template><script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { scrollbarClassName } from "~~/registry/bases/newt/ui/scrollbar"
import { cn } from "@/lib/utils"
const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>
<template>
<div
role="listbox"
:class="
cn(
'col-start-2 row-start-1 min-w-0 overflow-y-auto p-2',
scrollbarClassName,
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>
<!-- Sticky section header, as used by the "Frequently Used" block. -->
<p
role="presentation"
:class="
cn(
'sticky top-0 z-[1] m-0 flex items-center gap-1.5 bg-newt-bg-floating px-2 py-1.5 text-sm font-semibold text-newt-text-primary',
props.class
)
"
>
<slot />
</p>
</template><script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>
<template>
<!-- Bar under the rail and the list, for the command being typed. -->
<div
:class="
cn(
'col-span-full row-start-2 flex min-w-0 items-center gap-2 border-t border-newt-border px-3 py-2 text-[13px] leading-snug 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>
<section role="group" :class="cn('min-w-0', props.class)">
<slot />
</section>
</template><script setup lang="ts">
import { cva } from "class-variance-authority"
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
/*
* An image fills the circle. Anything else is a glyph at half its size: an
* inline SVG, or the element an icon component renders, which is often a
* `<span>`.
*/
const appIconVariants = cva(
"inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full bg-newt-bg-elevated text-newt-text-muted [&>img]:h-full [&>img]:w-full [&>img]:object-cover [&>svg]:h-1/2 [&>svg]:w-1/2 [&>:first-child:not(img)]:h-1/2 [&>:first-child:not(img)]:w-1/2",
{
variants: {
size: {
header: "h-4 w-4",
row: "h-6 w-6",
rail: "h-8 w-8",
},
},
defaultVariants: { size: "row" },
}
)
const props = withDefaults(
defineProps<{
class?: HTMLAttributes["class"]
size?: "header" | "row" | "rail"
}>(),
{ size: "row" }
)
</script>
<template>
<span
aria-hidden="true"
:class="cn(appIconVariants({ size: props.size }), props.class)"
>
<slot />
</span>
</template><script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const props = withDefaults(
defineProps<{
class?: HTMLAttributes["class"]
/** Command path without the leading slash, e.g. `moderation ban`. */
name: string
description?: string
/** Name of the app the command belongs to, shown on the right. */
appLabel?: string
active?: boolean
disabled?: boolean
}>(),
{ active: false, disabled: false }
)
</script>
<template>
<!--
In a picker narrower than 480px, the app name moves beside the command
name, and the description takes the full width under them, on up to two
lines.
-->
<div
role="option"
:aria-selected="props.active"
:aria-disabled="props.disabled || undefined"
:data-state="props.active ? 'active' : 'inactive'"
:class="
cn(
'grid min-h-12 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-[var(--newt-radius-md)] px-2 py-1.5',
'[@container_(max-width:480px)]:gap-x-2 [@container_(max-width:480px)]:gap-y-0.5',
props.disabled
? 'cursor-default opacity-60'
: 'cursor-pointer hover:bg-newt-bg-hover',
'data-[state=active]:bg-newt-bg-active',
props.class
)
"
>
<slot name="icon" />
<div
class="flex min-w-0 flex-col gap-0.5 [@container_(max-width:480px)]:contents"
>
<span
class="text-[15px] font-semibold leading-tight text-newt-text-primary [@container_(max-width:480px)]:col-start-2 [@container_(max-width:480px)]:row-start-1"
>
<!-- The slash stands off the command path. A margin keeps the text `/ban`. -->
<span class="me-1">/</span>{{ props.name }}
</span>
<span
v-if="props.description"
class="truncate text-[13px] leading-snug text-newt-text-secondary [@container_(max-width:480px)]:col-[2/-1] [@container_(max-width:480px)]:row-start-2 [@container_(max-width:480px)]:line-clamp-2 [@container_(max-width:480px)]:whitespace-normal"
>
{{ props.description }}
</span>
</div>
<span
v-if="props.appLabel"
class="shrink-0 text-[13px] text-newt-text-secondary [@container_(max-width:480px)]:col-start-3 [@container_(max-width:480px)]:row-start-1"
>
{{ props.appLabel }}
</span>
</div>
</template><script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const props = withDefaults(
defineProps<{ class?: HTMLAttributes["class"]; active?: boolean }>(),
{ active: false }
)
</script>
<template>
<!-- Row that previews the command already typed, rendered with `<SlashCommand>`. -->
<div
role="option"
:aria-selected="props.active"
:data-state="props.active ? 'active' : 'inactive'"
:class="
cn(
'min-h-11 cursor-pointer rounded-[var(--newt-radius-md)] px-3 py-2 hover:bg-newt-bg-hover',
'data-[state=active]:bg-newt-bg-active',
props.class
)
"
>
<slot />
</div>
</template>export { default as SlashCommandSuggestions } from "./SlashCommandSuggestions.vue"
export { default as SlashCommandSuggestionsRail } from "./SlashCommandSuggestionsRail.vue"
export { default as SlashCommandSuggestionsRailItem } from "./SlashCommandSuggestionsRailItem.vue"
export { default as SlashCommandSuggestionsList } from "./SlashCommandSuggestionsList.vue"
export { default as SlashCommandSuggestionsHeader } from "./SlashCommandSuggestionsHeader.vue"
export { default as SlashCommandSuggestionsFooter } from "./SlashCommandSuggestionsFooter.vue"
export { default as SlashCommandSuggestionGroup } from "./SlashCommandSuggestionGroup.vue"
export { default as SlashCommandAppIcon } from "./SlashCommandAppIcon.vue"
export { default as SlashCommandSuggestion } from "./SlashCommandSuggestion.vue"
export { default as SlashCommandSuggestionMatched } from "./SlashCommandSuggestionMatched.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 Slash Command Suggestions 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 Slash Command Suggestions 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 { SlashCommandSuggestions } from "@/components/ui/slash-command-suggestions"
export function Example() {
return <SlashCommandSuggestions />
}<script setup lang="ts">
import { SlashCommandSuggestions, SlashCommandSuggestionsRail, SlashCommandSuggestionsRailItem, SlashCommandSuggestionsList, SlashCommandSuggestionsHeader, SlashCommandSuggestionsFooter, SlashCommandSuggestionGroup, SlashCommandAppIcon, SlashCommandSuggestion, SlashCommandSuggestionMatched } from "@/components/ui/slash-command-suggestions"
</script>
<template>
<SlashCommandSuggestions />
</template>Put the rail, the list and the footer directly inside SlashCommandSuggestions, in any order. The picker is a grid: the rail and the list share the first row, and the footer takes the row under them. Each of the three is optional.
Width
The picker fills its container up to 640px. Set --newt-slash-suggestions-max-width on the picker or on an ancestor to change the cap. Set it to none to make the picker as wide as the composer.
.composer {
--newt-slash-suggestions-max-width: none;
}
The picker is a size container, so its parts follow its own width. Its width must not depend on its content. Keep w-full on it, or give it a width.
Footer
SlashCommandSuggestionsFooter is a bar under the rail and the list. It takes any content. The preview shows the command being typed, with the option the caret sits in.
App icon
SlashCommandAppIcon is a circle in three sizes: header, row and rail. An <img> inside it fills the circle. Any other first child is drawn at half the size of the circle: an inline SVG, or the <span> that an icon component renders.
Examples
Narrow picker
The parts follow the width of the picker, not the width of the viewport. In a picker narrower than 480px, the rail becomes a row under the list and the footer. In each suggestion, the app name moves beside the command name. The description takes the full width under them, on up to two lines.
orientation on SlashCommandSuggestionsRail fixes the rail as "vertical" or "horizontal" at every width.
The app icons of the rows here hold a <span> with a mask, as an icon component in CSS mode renders it.
newt-slash-suggestionsimport { SlashCommand } from "@/registry/bases/newt/ui/slash-command"
import {
SlashCommandAppIcon,
SlashCommandSuggestion,
SlashCommandSuggestionGroup,
SlashCommandSuggestions,
SlashCommandSuggestionsFooter,
SlashCommandSuggestionsList,
SlashCommandSuggestionsRail,
SlashCommandSuggestionsRailItem,
} from "@/registry/bases/newt/ui/slash-command-suggestions"
const shieldPath = "M12 2 4 5v7c0 5 3.4 8.4 8 10 4.6-1.6 8-5 8-10V5l-8-3Z"
/* What an icon component in CSS mode renders: a `<span>` with a mask. */
const shieldMask = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='${shieldPath}'/%3E%3C/svg%3E") center / contain no-repeat`
const MaskIcon = () => (
<span className="bg-current" style={{ mask: shieldMask }} />
)
/* A picker 360px wide, the width it has on a phone. */
export default function SlashCommandSuggestionsNarrowDemo() {
return (
<div className="w-full max-w-[360px]">
<SlashCommandSuggestions>
<SlashCommandSuggestionsRail aria-label="Filter commands by app">
<SlashCommandSuggestionsRailItem active aria-label="Frequently used">
<svg viewBox="0 0 24 24" className="h-5 w-5" fill="currentColor">
<path d="M12 3a9 9 0 1 0 9 9h-2a7 7 0 1 1-7-7v4l5-4-5-4v2Z" />
<path d="M11 7h2v5l4 2-1 1.7L11 13V7Z" />
</svg>
</SlashCommandSuggestionsRailItem>
<SlashCommandSuggestionsRailItem aria-label="Moderation commands">
<SlashCommandAppIcon size="rail">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d={shieldPath} />
</svg>
</SlashCommandAppIcon>
</SlashCommandSuggestionsRailItem>
</SlashCommandSuggestionsRail>
<SlashCommandSuggestionsList aria-label="Slash commands">
<SlashCommandSuggestionGroup aria-label="Moderation">
<SlashCommandSuggestion
active
name="ban"
description="Ban a member from the server and delete their recent messages."
appLabel="Moderation"
icon={
<SlashCommandAppIcon>
<MaskIcon />
</SlashCommandAppIcon>
}
/>
<SlashCommandSuggestion
name="timeout"
description="Mute a member for a set amount of time."
appLabel="Moderation"
icon={
<SlashCommandAppIcon>
<MaskIcon />
</SlashCommandAppIcon>
}
/>
</SlashCommandSuggestionGroup>
</SlashCommandSuggestionsList>
<SlashCommandSuggestionsFooter>
<SlashCommand
name="ban"
options={[
{ name: "user", description: "the member to ban", focused: true },
]}
/>
</SlashCommandSuggestionsFooter>
</SlashCommandSuggestions>
</div>
)
}<script setup lang="ts">
import { SlashCommand } from "~~/registry/bases/newt/ui/slash-command"
import {
SlashCommandAppIcon,
SlashCommandSuggestion,
SlashCommandSuggestionGroup,
SlashCommandSuggestions,
SlashCommandSuggestionsFooter,
SlashCommandSuggestionsList,
SlashCommandSuggestionsRail,
SlashCommandSuggestionsRailItem,
} from "~~/registry/bases/newt/ui/slash-command-suggestions"
const shieldPath = "M12 2 4 5v7c0 5 3.4 8.4 8 10 4.6-1.6 8-5 8-10V5l-8-3Z"
/* What an icon component in CSS mode renders: a `<span>` with a mask. */
const shieldMask = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='${shieldPath}'/%3E%3C/svg%3E") center / contain no-repeat`
</script>
<template>
<!-- A picker 360px wide, the width it has on a phone. -->
<div class="w-full max-w-[360px]">
<SlashCommandSuggestions>
<SlashCommandSuggestionsRail aria-label="Filter commands by app">
<SlashCommandSuggestionsRailItem active aria-label="Frequently used">
<svg viewBox="0 0 24 24" class="h-5 w-5" fill="currentColor">
<path d="M12 3a9 9 0 1 0 9 9h-2a7 7 0 1 1-7-7v4l5-4-5-4v2Z" />
<path d="M11 7h2v5l4 2-1 1.7L11 13V7Z" />
</svg>
</SlashCommandSuggestionsRailItem>
<SlashCommandSuggestionsRailItem aria-label="Moderation commands">
<SlashCommandAppIcon size="rail">
<svg viewBox="0 0 24 24" fill="currentColor">
<path :d="shieldPath" />
</svg>
</SlashCommandAppIcon>
</SlashCommandSuggestionsRailItem>
</SlashCommandSuggestionsRail>
<SlashCommandSuggestionsList aria-label="Slash commands">
<SlashCommandSuggestionGroup aria-label="Moderation">
<SlashCommandSuggestion
active
name="ban"
description="Ban a member from the server and delete their recent messages."
app-label="Moderation"
>
<template #icon>
<SlashCommandAppIcon>
<span class="bg-current" :style="{ mask: shieldMask }" />
</SlashCommandAppIcon>
</template>
</SlashCommandSuggestion>
<SlashCommandSuggestion
name="timeout"
description="Mute a member for a set amount of time."
app-label="Moderation"
>
<template #icon>
<SlashCommandAppIcon>
<span class="bg-current" :style="{ mask: shieldMask }" />
</SlashCommandAppIcon>
</template>
</SlashCommandSuggestion>
</SlashCommandSuggestionGroup>
</SlashCommandSuggestionsList>
<SlashCommandSuggestionsFooter>
<SlashCommand
name="ban"
:options="[
{ name: 'user', description: 'the member to ban', focused: true },
]"
/>
</SlashCommandSuggestionsFooter>
</SlashCommandSuggestions>
</div>
</template>API reference
SlashCommandSuggestionsRail
orientation?"vertical" | "horizontal" | undefined
Lays the rail as a column beside the list, or as a row under it. Without it, the rail is a column, and a row when the picker is narrower than 480px.
"vertical" | "horizontal" | undefinedSlashCommandSuggestionsRailItem
active?boolean | undefined
Optional active value.
boolean | undefinedSlashCommandAppIcon
size?"header" | "row" | "rail" | undefined
Diameter of the circle: 16px in a header, 24px in a row, 32px in the rail.
"header" | "row" | "rail" | undefined"row"SlashCommandSuggestion
name?string
Command path without the leading slash, e.g. `moderation ban`.
stringdescription?string | undefined
Optional description value.
string | undefinedappLabel?string | undefined
Name of the app the command belongs to, shown on the right.
string | undefinedicon / #icon?React.ReactNode / Vue slot
Icon for the owning app; pair with `<SlashCommandAppIcon>`.
React.ReactNode / Vue slotactive?boolean | undefined
Optional active value.
boolean | undefineddisabled?boolean | undefined
Optional disabled value.
boolean | undefinedSlashCommandSuggestionMatched
active?boolean | undefined
Optional active value.
boolean | undefinedThe registry exports SlashCommandSuggestions, SlashCommandSuggestionsRail, SlashCommandSuggestionsRailItem, SlashCommandSuggestionsList, SlashCommandSuggestionsHeader, SlashCommandSuggestionsFooter, SlashCommandSuggestionGroup, SlashCommandAppIcon, SlashCommandSuggestion, SlashCommandSuggestionMatched. Parts without a table accept the native attributes for the element they render; React uses className, while Vue uses class and fallthrough attributes.
The text of a suggestion is the slash and the name with nothing between them: /ban. A margin on the slash draws the gap.
HTML and CSS
Load tokens.css, scrollbar.css, slash-command.css and slash-command-suggestions.css with the markup. Set data-orientation="vertical" or data-orientation="horizontal" on newt-slash-suggestions__rail to fix its direction. Add a newt-slash-suggestions__footer element inside the picker for the footer.
Wrap the slash of a suggestion in newt-slash-suggestions__option-slash, with no space after it.
Accessibility
Keep focus in the composer and point aria-activedescendant at the active option. Announce disabled options and label both the app rail and command list.
The footer is outside the list, so it is not an option. Give it aria-live="polite" when its content changes as the user types and a screen reader must announce it.
The rail comes first in the markup at every width. Its buttons keep the same place in the tab order when the rail is drawn under the list.
Tokens
Slash Command Suggestions 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-slash-suggestions.
--newt-radius-lg--newt-bg-floating--newt-shadow-elevation-high--newt-text-primary--newt-border--newt-bg-base--newt-radius-full--newt-text-muted--newt-duration-fast--newt-ease--newt-bg-hover--newt-bg-active--newt-text-link--newt-bg-elevated--newt-radius-md--newt-text-secondary