Inline action buttons for assistant and user messages.
Inline action buttons for assistant and user messages.
import { ChatMessageActions } from 'heroui-native-pro';<ChatMessageActions>
<ChatMessageActions.Copy />
<ChatMessageActions.ThumbsUp />
<ChatMessageActions.ThumbsDown />
<ChatMessageActions.Regenerate />
<ChatMessageActions.Menu />
<ChatMessageActions.Action accessibilityLabel="...">...</ChatMessageActions.Action>
</ChatMessageActions>ChatMessage.Actions is an alias of it, so ChatMessage.Actions.Copy works too.ChatMessage.Action): a compact 32px ghost icon button.isCopied is true. It does not touch the clipboard.Menu or Popover.isSelected fills the icon.isSelected fills the icon.size and color, or a custom icon as children.Each preset is a ChatMessage.Action, so it accepts every heroui-native Button prop.
Place the row in a ChatMessage.Body, under the content.
<ChatMessage.Assistant>
<ChatMessage.Avatar alt="Assistant" fallback="AI" />
<ChatMessage.Body>
<ChatMessage.Content>...</ChatMessage.Content>
<ChatMessageActions>
<ChatMessageActions.Copy onPress={() => Clipboard.setStringAsync(text)} />
<ChatMessageActions.ThumbsUp onPress={() => rate('up')} />
<ChatMessageActions.ThumbsDown onPress={() => rate('down')} />
<ChatMessageActions.Regenerate onPress={regenerate} />
</ChatMessageActions>
</ChatMessage.Body>
</ChatMessage.Assistant>Add your own buttons with ChatMessageActions.Action. It is icon-only with no visible label, so always pass an accessibilityLabel.
<ChatMessageActions>
<ChatMessageActions.Copy onPress={copyMessage} />
<ChatMessageActions.Action accessibilityLabel="Share" onPress={onShare}>
<ShareIcon size={16} color={mutedColor} />
</ChatMessageActions.Action>
</ChatMessageActions>The button does not touch the clipboard. Copy the message in onPress, for example with expo-clipboard. By default each press shows the copied icon for 2 seconds. Pass isCopied to control the state yourself, for example to show it only after the clipboard write succeeds.
const [isCopied, setIsCopied] = useState(false);
<ChatMessageActions.Copy
isCopied={isCopied}
onPress={async () => {
await Clipboard.setStringAsync(text);
setIsCopied(true);
}}
/>Pass isSelected to show which feedback the user gave. The selected button draws a filled glyph in the theme foreground color and is announced as selected. A ThumbsUpIcon / ThumbsDownIcon passed as children follows it, so a custom color keeps the filled glyph.
<ChatMessageActions.ThumbsUp
isSelected={feedback === 'up'}
onPress={() => setFeedback('up')}
/>
<ChatMessageActions.ThumbsDown
isSelected={feedback === 'down'}
onPress={() => setFeedback('down')}
>
<ChatMessageActions.ThumbsDownIcon color={feedback === 'down' ? dangerColor : undefined} />
</ChatMessageActions.ThumbsDown>Each preset ships an English accessibilityLabel: "Copy" (or "Copied" while copied), "Good response", "Bad response", "Regenerate", and "More actions". Pass your own labels to localize them.
<ChatMessageActions.Copy
accessibilityLabel={t`Copy`}
copiedAccessibilityLabel={t`Copied`}
/>
<ChatMessageActions.ThumbsUp accessibilityLabel={t`Good response`} />Menu is a plain button. Wrap it in a heroui-native Menu or Popover trigger to open more actions.
<Menu>
<Menu.Trigger asChild>
<ChatMessageActions.Menu />
</Menu.Trigger>
<Menu.Portal>
<Menu.Overlay />
<Menu.Content presentation="popover">
<Menu.Item onPress={share}>
<Menu.ItemTitle>Share</Menu.ItemTitle>
</Menu.Item>
</Menu.Content>
</Menu.Portal>
</Menu>Pass size or color to a default glyph, or pass your own icon as its children. A valid element passed directly to a preset replaces its icon too. On Copy, children replaces the copy glyph and copiedIcon replaces the check mark.
<ChatMessageActions.ThumbsUp>
<ChatMessageActions.ThumbsUpIcon color={successColor} />
</ChatMessageActions.ThumbsUp>
<ChatMessageActions.Copy copiedIcon={<ChatMessageActions.CopiedIcon color={successColor} />} />
<ChatMessageActions.Regenerate>
<RefreshCw size={16} color={mutedColor} />
</ChatMessageActions.Regenerate>The copy and check icons swap with a scale and fade. Customize it with iconAnimation. animation still configures the button's press feedback, as on every other preset.
<ChatMessageActions.Copy iconAnimation={{ scale: { value: [0.5, 1] } }} />
<ChatMessageActions.Copy iconAnimation="disabled" />With the system "Reduce Motion" setting on, the swap becomes a 120ms crossfade without scaling. animation="disable-all" on the ChatMessageActions root turns off the press feedback of every preset and the icon swap.
<ChatMessageActions animation="disable-all">...</ChatMessageActions>import { Menu, useThemeColor } from 'heroui-native';
import { ChatMessage, ChatMessageActions } from 'heroui-native-pro';
import { useEffect, useRef, useState } from 'react';
type Feedback = 'up' | 'down' | null;
export default function ChatMessageActionsExample() {
const [themeColorSuccess, themeColorDanger] = useThemeColor([
'success',
'danger',
]);
const [isCopied, setIsCopied] = useState(false);
const [feedback, setFeedback] = useState<Feedback>(null);
const copyTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
useEffect(() => {
return () => {
if (copyTimeoutRef.current !== null) {
clearTimeout(copyTimeoutRef.current);
}
};
}, []);
const handleCopy = () => {
if (copyTimeoutRef.current !== null) {
clearTimeout(copyTimeoutRef.current);
}
setIsCopied(true);
copyTimeoutRef.current = setTimeout(() => {
setIsCopied(false);
copyTimeoutRef.current = null;
}, 3000);
};
const toggleFeedback = (value: Exclude<Feedback, null>) => {
setFeedback((current) => (current === value ? null : value));
};
return (
<ChatMessage.Assistant>
<ChatMessage.Avatar alt="Assistant" fallback="AI" />
<ChatMessage.Body>
<ChatMessage.Content>
Copy stays checked for 3 seconds, and the feedback buttons remember your choice.
</ChatMessage.Content>
<ChatMessageActions>
<ChatMessageActions.Copy isCopied={isCopied} onPress={handleCopy} />
<ChatMessageActions.ThumbsUp
isSelected={feedback === 'up'}
onPress={() => toggleFeedback('up')}
>
<ChatMessageActions.ThumbsUpIcon
color={feedback === 'up' ? themeColorSuccess : undefined}
/>
</ChatMessageActions.ThumbsUp>
<ChatMessageActions.ThumbsDown
isSelected={feedback === 'down'}
onPress={() => toggleFeedback('down')}
>
<ChatMessageActions.ThumbsDownIcon
color={feedback === 'down' ? themeColorDanger : undefined}
/>
</ChatMessageActions.ThumbsDown>
<Menu>
<Menu.Trigger asChild>
<ChatMessageActions.Menu />
</Menu.Trigger>
<Menu.Portal>
<Menu.Overlay />
<Menu.Content presentation="popover" width={220}>
<Menu.Item>
<Menu.ItemTitle>Share</Menu.ItemTitle>
</Menu.Item>
<Menu.Item>
<Menu.ItemTitle>Edit</Menu.ItemTitle>
</Menu.Item>
<Menu.Item variant="danger">
<Menu.ItemTitle>Delete</Menu.ItemTitle>
</Menu.Item>
</Menu.Content>
</Menu.Portal>
</Menu>
</ChatMessageActions>
</ChatMessage.Body>
</ChatMessage.Assistant>
);
}ChatMessage.Actions is an alias of this component.
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Preset or custom action buttons |
className | string | - | Additional CSS classes for the row |
animation | ChatMessageRootAnimation | - | Animation configuration of the row |
...ViewProps | ViewProps | - | All standard React Native View props are supported |
The row animates nothing itself. Can be:
"disable-all": Disable all animations of descendants (press feedback of every preset and the copy icon swap)undefined: Use default animationsSame component as ChatMessage.Action.
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Icon of the button |
isIconOnly | boolean | true | Icon-only layout |
hitSlop | Insets | { top: 6, bottom: 6 } | Extra touch area. Makes the 32px button a 44pt tall target |
variant | ButtonVariant | 'ghost' | heroui-native Button variant |
size | ButtonSize | 'sm' | heroui-native Button size |
className | string | - | Additional CSS classes for the button |
accessibilityLabel | string | - | Label announced by screen readers. Always set it |
...ButtonRootProps | ButtonRootProps | - | All heroui-native Button props (onPress, animation, …) |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Custom copy icon. Replaces the default copy glyph |
isCopied | boolean | - | Controlled copied state. When set, presses no longer toggle it |
copiedIcon | ReactNode | - | Custom icon shown while copied. Replaces the default check glyph |
accessibilityLabel | string | 'Copy' | Label announced while not copied |
copiedAccessibilityLabel | string | 'Copied' | Label announced while copied |
onPress | (event: GestureResponderEvent) => void | - | Called on press. Copy to the clipboard here |
iconAnimation | ChatMessageActionsCopyIconAnimation | - | Animation configuration of the icon swap |
...ChatMessageActionProps | ChatMessageActionProps | - | All ChatMessage.Action props (animation sets the press feedback) |
Animation configuration of the copy / copied icon swap. Can be:
false or "disabled": Instant swaptrue or undefined: Default swapobject: Custom animation configuration| prop | type | default | description |
|---|---|---|---|
state | 'disabled' | boolean | - | Disable animations while customizing properties |
scale.value | [number, number] | [0.25, 1] | Scale as [hidden, visible] |
scale.springConfig | WithSpringConfig | { duration: 300, dampingRatio: 1 } | Spring configuration of the scale |
opacity.value | [number, number] | [0, 1] | Opacity as [hidden, visible] |
opacity.timingConfig | WithTimingConfig | { duration: 300, easing: Easing.out(Easing.quad) } | Timing configuration of the opacity |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Custom icon |
accessibilityLabel | string | 'Regenerate' / 'More actions' | Label announced by screen readers |
...ChatMessageActionProps | ChatMessageActionProps | - | All ChatMessage.Action props |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Custom icon |
isSelected | boolean | false | Fills the icon in the theme foreground color and sets accessibilityState.selected |
accessibilityLabel | string | 'Good response' / 'Bad response' | Label announced by screen readers |
...ChatMessageActionProps | ChatMessageActionProps | - | All ChatMessage.Action props |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Custom icon element. Replaces the glyph, and size and color are ignored |
size | number | 16 | Width and height of the glyph |
isSelected | boolean | false | ThumbsUpIcon / ThumbsDownIcon only: draws the filled glyph. Inside a feedback preset it follows the button's isSelected |
color | string | theme muted | Fill color of the glyph (theme foreground while selected) |