CommandChip
Show a slash command invocation as a badge followed by its arguments, with the description in a tooltip. Pass commands to MessageList or UserMessage and user messages that start with a known command render this chip automatically.
Getting Started
$pnpm add @sinups/ai-kit @mantine/core @mantine/hooks @tabler/icons-reactExamples
Sizes
Source
The component source as it ships in the package. Useful as a reference, or as a starting point if you want to fork a piece.
message-actions/CommandChip/CommandChip.tsx
import React, { memo } from 'react';
import { Badge, Group, Text, Tooltip, type MantineSize } from '@mantine/core';
import { IconSlash } from '@tabler/icons-react';
import classes from './CommandChip.module.css';
export interface CommandChipProps {
/** Command name with or without the leading slash, for example `review` */
name: string;
/** Arguments typed after the command */
args?: string;
/** Command description shown in a tooltip */
description?: string;
/** Icon rendered in the badge instead of the slash */
icon?: React.ReactNode;
/** Badge and text size, `sm` by default */
size?: Extract<MantineSize, 'xs' | 'sm' | 'md'>;
/** Class name added to the root element */
className?: string;
/** Inline styles added to the root element */
style?: React.CSSProperties;
}
/** Slash command invocation: the command as a badge followed by its arguments */
export const CommandChip = memo(function CommandChip({
name,
args,
description,
icon,
size = 'sm',
className,
style,
}: CommandChipProps) {
const commandName = name.replace(/^\//, '');
const badge = (
<Badge
variant="light"
radius="sm"
size={size}
tt="none"
ff="monospace"
leftSection={icon ?? <IconSlash size={12} aria-hidden />}
data-command={commandName}
>
{commandName}
</Badge>
);
return (
<Group gap={6} wrap="wrap" align="baseline" className={className} style={style}>
{description ? (
<Tooltip label={description} withArrow openDelay={300}>
{badge}
</Tooltip>
) : (
badge
)}
{args && (
<Text component="span" size={size} className={classes.args}>
{args}
</Text>
)}
</Group>
);
});
CommandChip.displayName = 'CommandChip';
API reference
Prop
Type
Required
name
string
Yes
Command name with or without the leading slash, for example `review`
args
string
No
Arguments typed after the command
description
string
No
Command description shown in a tooltip
icon
React.ReactNode
No
Icon rendered in the badge instead of the slash
size
Extract<MantineSize, 'xs' | 'sm' | 'md'>
No
Badge and text size, `sm` by default
className
string
No
Class name added to the root element
style
React.CSSProperties
No
Inline styles added to the root element