SelectionActions
The host supplies the selected passage, edit state and result. The toolbar anchors to that passage; actions and custom instructions only request work. Keep/Discard callbacks leave persistence to the host. Busy, error and cancelled states never rewrite the original.
The host supplies the selected passage, edit state and result. The toolbar anchors to that passage; actions and custom instructions only request work. Keep/Discard callbacks leave persistence to the host. Busy, error and cancelled states never rewrite the original.
Import
import { SelectionActions } from "@yuhuanowo/yunui/ai";Interactive example
The controls below explicitly simulate host responses; no request is sent. All labels and accessibility copy can be overridden. Missing callbacks disable the corresponding request controls.
SelectionActions
Integration note: Use the library controls directly rather than rebuilding each control.
The original passage remains until the host accepts a result.
Composition
import { SelectionActions } from "@yuhuanowo/yunui/ai";
<SelectionActions selectedText="Use the public components." state="idle" />Props
| Prop | Type | Default | Description |
|---|---|---|---|
| actions | readonly SelectionAction[] | [ { id: "Explain", action: "Explain", icon: <CircleHelp {...iconProps} /> }, { id: "Improve", action: "Improve", busyLabel: "Improving", icon: <Sparkles {...iconProps} /> }, { id: "Shorten", action: "Shorten", busyLabel: "Shortening", icon: <Scissors {...iconProps} /> }, { id: "Tone", action: "Change tone", busyLabel: "Changing tone", icon: <ThumbsUp {...iconProps} /> }, { id: "Grammar", action: "Fix grammar", icon: <Type {...iconProps} /> }, ] | Host-owned actions. Omitting this uses the general-purpose default action set. |
| busyLabel | ReactNode | — | Current host activity label; used only while `state="busy"`. |
| className | string | — | |
| disabled | boolean | false | |
| labels | SelectionActionsLabels | — | |
| lead | ReactNode | — | Optional prose immediately before the selected passage. |
| onAccept | ((result: string) => void) | — | |
| onAction | ((action: string, instruction?: string) => void) | — | |
| onDismiss | (() => void) | — | |
| onRetry | (() => void) | — | |
| resultText | string | — | Host-provided rewrite. It is never generated by this component. |
| selectedText* | string | — | |
| state | "idle" | "busy" | "result" | "error" | "cancelled" | idle | Host owns all request state; no internal request timer or optimistic result. |