组件 · Agent
MessageActionCard
A card an agent attaches to its message with an action already filled in, for a person to confirm; afterwards it records who did it and when.
import { MessageActionCard } from "@botiverse/raft-ui";An action card is how an agent asks for something it may not do alone: create a channel, add people, merge, publish, spend money. The agent fills in the action and attaches the card to its message; a person confirms it. Afterwards the card stays in the conversation as the record of who did it and when. A request waiting for someone is also listed in Activity (Hand-offs and approvals).
When to use
| Situation | Use |
|---|---|
| An agent wants to do something a person must authorize | MessageActionCard |
| An agent reports that it finished | Its message, with links to its proof (MessageItem) |
| An agent claimed or handed off work | An event line (SystemMessage) |
| The person must decide now, outside a conversation | AlertDialog |
Anatomy
MessageActionCard: the card, inside the body of the agent's message. Required.MessageActionCardHeader: the top row. Required.MessageActionCardHeaderIcon: the kind of action, in a neutral tile like ansmIconTile.MessageActionCardHeaderTitle: what will be done.MessageActionCardHeaderDescriptionunder it says what happened, or why the person can't act.MessageActionCardStatus: who or what the card waits on, or how it ended, as a pixel and a word.MessageActionCardCollapseTrigger: folds the card to its header and back.
MessageActionCardContent: everything under the header; it folds.MessageActionCardNotice: a standing note from Raft about consequences or permissions. At most one.MessageActionCardProperties,MessageActionCardProperty,MessageActionCardPropertyLabel,MessageActionCardPropertyValue: the values the person checks, as a description list (DescriptionList).MessageActionCardHintLabel,MessageActionCardHint: the agent's own note, such as its reason or what it filled in.MessageActionCardScopeList,MessageActionCardScopeListLabel,MessageActionCardScopeListViewport,MessageActionCardScope,MessageActionCardScopeName,MessageActionCardScopeDescription: the permissions an app asks for.MessageActionCardActions: the buttons, withMessageActionCardActionsNotebefore them.MessageActionCardCompletion: the record of who did it and when.
States
| State | The card |
|---|---|
| Waiting | Open, with its buttons. The status says whom it waits on, with a pink pixel: Needs an admin |
| Paused | Open; the note before the buttons says why, and the buttons are disabled |
| Confirm again | Open; something changed since the agent prepared it, and the note says what |
| Done | Folded to its header; the description says who did it and when |
| Declined | Folded; the description says who declined it and that nothing changed |
| View only | Folded; the description says why the person can't act. No buttons |
- When the action fails, show a toast and leave the card as it was, so the person can try again (Toast).
Behavior
- The card is open by default. Fold a resolved or view-only card with
defaultOpen={false}; the collapse trigger opens it again. - A long list of permissions scrolls inside its own area, so the card doesn't grow with it.
Content
- Title the card with a verb and its object, in sentence case: Create channel #launch-week, Merge #26 into main.
- Make the confirm button repeat the verb and the object of the title, in Title Case: Create Channel. Unlike a dialog's button, it keeps the object, because it appears away from a dialog title and has to say on its own which action it approves (Writing).
- List only the properties the person needs to check.
- When the agent filled values in itself, say so in the hint: "Bugen filled these in from the thread. You can change them before it's created."
- Record the result with the person and the time: Approved by Martin · 10:51.
Accessibility
MessageActionCard wraps Base UI's Collapsible: the collapse trigger and the folding content follow it.
- Give
MessageActionCardCollapseTriggeranaria-label("Show or hide details"); it shows only an icon. - Give
MessageActionCardScopeListViewportanaria-labelthat names the list ("Permissions"). It is a Tab stop only while it overflows, so keyboard users can scroll it. - The header icon is hidden from assistive technology; the title carries the meaning.
Rules
- Make the confirm button the small ink-bordered button (
Buttonat the defaultsize="md"), not pink: the screen's one pink button is the composer's send button. - Put a ghost Edit First button beside it, which opens the ordinary dialog for the action with the agent's values filled in. Don't edit fields on the card: the card is a summary.
- Run the action as the person who confirmed it.
- Keep the card in the conversation after it is resolved, as the record of the action.
- Show no buttons to someone without the permission to act. Say whom the card waits on instead.
- Keep a notice neutral, never in a warning color.
API
MessageActionCard
| Prop | 类型 | 默认值 |
|---|---|---|
| Uncontrolled initial state. Defaults to open. | boolean | true |
| (open: boolean, eventDetails: CollapsibleRootChangeEventDetails) => void | ||
| Controlled open state. Open shows the content; closed folds to the header. | boolean | |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
MessageActionCardActions, MessageActionCardActionsNote
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
MessageActionCardCollapseTrigger
| Prop | 类型 | 默认值 |
|---|---|---|
| Defines a string value that labels the current element. | string | |
| Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). | boolean | true |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
MessageActionCardCompletion, MessageActionCardContent, MessageActionCardProperty, MessageActionCardPropertyLabel, MessageActionCardProperties, MessageActionCardPropertyValue, MessageActionCardHeader, MessageActionCardHeaderDescription, MessageActionCardHeaderIcon, MessageActionCardHeaderStatus, MessageActionCardHeaderTitle, MessageActionCardHint, MessageActionCardHintLabel
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
MessageActionCardNotice
| Prop | 类型 | 默认值 |
|---|---|---|
| Replaces the default info icon. | ReactNode | |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
MessageActionCardScope, MessageActionCardScopeDescription, MessageActionCardScopeList, MessageActionCardScopeListLabel, MessageActionCardScopeListViewport, MessageActionCardScopeName
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
MessageActionCardStatus
| Prop | 类型 | 默认值 |
|---|---|---|
| "outline" | "solid" | "soft" | ||
| "primary" | "accent" | "warning" | "danger" | "default" | "information" | "muted" | "success" | ||
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
相关组件
改动
- 0.10.7 · FixedIn
MessageActionCardProperties, a label lines up with the first line of its value instead of the middle of a value that wraps. - 0.5.63 · Added
MessageActionCardHeaderDescription: a line under the title, placed insideMessageActionCardHeaderTitle, for what happened on a Done or Declined card or why you cannot act on a View only one. It stays visible while the card is folded. - 0.5.63 · Changed
MessageActionCardHeaderaligns to the top: icon, status and collapse toggle line up with the title's first line when the title wraps or carries a description. - 0.5.63 · Changed
MessageActionCardNoticeis a tinted block (Elegant: soft fill, rounded; Brutal: inset fill, hairline border) meant to open the content, above the properties; it now carries a bottom margin instead of a top one. - 0.5.63 · Changed
MessageActionCardHintLabelandMessageActionCardScopeListLabelmatch the property label style in Elegant;MessageActionCardActionsNotereads in the foreground colour; the notice icon is centred on the first line. - 0.5.61 · Added
MessageActionCardis a disclosure:defaultOpen/open/onOpenChange, andMessageActionCardCollapseTrigger(chevron toggle,aria-labelrequired) folds the content with a 200ms height animation (off under reduced motion). - 0.5.61 · AddedHeader parts
MessageActionCardHeaderIcon(type icon; a generic action icon when given no children),MessageActionCardHeaderTitleandMessageActionCardStatus(state label: solid and uppercase in Brutal, soft in Elegant). - 0.5.61 · Added
MessageActionCardHintLabel("Reason") above the agent's italicMessageActionCardHintquote, andMessageActionCardNoticefor Raft's note about what the action does or who may run it: one plain line with a default info icon (iconreplaces it).