nandi/oripublic Fork 0
3017563d783a895a85f8f8ad162b58bb5d944946
Commits
Clone
git clone https://git.rickub.com/nandi/ori.git
git clone ssh://git@rickub.com/nandi/ori.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

forked from bots-garden/ori

PermissionPrompt.tsx · 49 lines · 1.3 KBTypeScript Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
 * PermissionPrompt asks the user to approve or reject a sensitive agent
 * action, offering exactly the options the agent proposed (allow once,
 * always, reject, ...), like Zed's permission bar.
 *
 * @example
 * <PermissionPrompt
 *   request={{ requestId: "perm-1", title: "Run `make test`", options: [
 *     { optionId: "allow", name: "Allow", kind: "allow_once" }] }}
 *   onRespond={(requestId, optionId) => console.log(requestId, optionId)}
 * />
 */

import type { PermissionRequestState } from "../reducer";
import { InlineText } from "./InlineText";

interface PermissionPromptProps {
	request: PermissionRequestState;
	onRespond: (requestId: string, optionId: string) => void;
}

export function PermissionPrompt({
	request,
	onRespond,
}: PermissionPromptProps) {
	return (
		<div
			className="permission"
			role="alertdialog"
			aria-label="permission request"
		>
			<p className="permission-title">
				🔐 <InlineText text={request.title} />
			</p>
			<div className="permission-options">
				{request.options.map((option) => (
					<button
						key={option.optionId}
						type="button"
						className={`permission-option permission-${option.kind}`}
						onClick={() => onRespond(request.requestId, option.optionId)}
					>
						{option.name}
					</button>
				))}
			</div>
		</div>
	);
}