# Selection actions

Select text inside a reply and act on just that part: ask a follow-up about it, have it explained, or quote it into the composer. The toolbar appears above the selection and only for selections inside this container; Escape or clicking away dismisses it.

- Registry name: `selection-actions` (`@candor/selection-actions`)
- Tier: Pro. Installing it needs a Pro, Premium or Team licence key: the person runs `npx candor-ui key <key>` themselves; never ask for the key in chat or write it to a file.
- Docs: https://candor.themethodic.com/docs/selection-actions

## Install

```bash
npx candor-ui add selection-actions
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/selection-actions`.
It brings in: locale, utils.
npm packages: lucide-react@^1.67.0.

## Example

```tsx
"use client"

import * as React from "react"
import { SelectionActions, type SelectionAction } from "@/components/selection-actions"

export default function Example() {
  const [last, setLast] = React.useState<{ action: SelectionAction; text: string } | null>(null)
  return (
    <div className="flex max-w-lg flex-col gap-3">
      <SelectionActions onAction={(action, text) => setLast({ action, text })}>
        <p className="text-sm leading-relaxed">
          The checkout flag is on in Staging but off in Production. Turning it on adds a write to the payments table on every order, so watch the
          replication lag for the first hour.
        </p>
      </SelectionActions>
      <p className="text-xs text-muted-foreground">
        {last ? `${last.action}: “${last.text}”` : "Select some of the text above to act on it."}
      </p>
    </div>
  )
}
```

## <SelectionActions>

Props:

- `onAction: (action: SelectionAction, text: string) => void`: Called with the action picked and the selected text.
- `children: React.ReactNode`
- `className?: string | undefined`

## Strings (`selectionActions`)

The fixed words, English by default. Override any of them under `selectionActions` in `<LocaleProvider strings={{ selectionActions: { … } }}>`; the table is exported as `selectionActionsStrings`.

- `ask`: Ask about this
- `explain`: Explain
- `quote`: Quote
- `toolbar`: Selected text

## Types

### SelectionAction

```ts
"ask" | "explain" | "quote"
```

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
