import React, { useState } from 'react'; import FocusTrap from 'focus-trap-react'; import { Box, Button, Checkbox, Dialog, Header, Overlay, OverlayBackdrop, OverlayCenter, Text, color, config, } from 'folds'; import type { Capability } from 'matrix-widget-api'; import type { WidgetPermissionRequest } from './widgetUtils'; import { useModalStyle } from '../../../hooks/useModalStyle'; type WidgetPermissionPromptProps = { widgetName: string; /** Hostname the widget is served from โ€” who actually gets the access. */ origin: string; /** Who added the widget to the room, if known. */ addedBy?: string; requests: WidgetPermissionRequest[]; onDone: (allowed: Set, remember: boolean) => void; }; /** * Asks before a room widget may read or send events in this room as you. * Reading is pre-ticked, sending is not; "Deny" (or Escape / clicking away) * grants nothing beyond display-only access. */ export function WidgetPermissionPrompt({ widgetName, origin, addedBy, requests, onDone, }: WidgetPermissionPromptProps) { const modalStyle = useModalStyle(460); const [checked, setChecked] = useState>( () => new Set(requests.filter((r) => !r.sends).map((r) => r.capability)), ); const [remember, setRemember] = useState(true); const toggle = (cap: Capability, on: boolean) => setChecked((prev) => { const next = new Set(prev); if (on) next.add(cap); else next.delete(cap); return next; }); return ( }> onDone(new Set(), false), clickOutsideDeactivates: true, escapeDeactivates: true, }} >
Allow โ€œ{widgetName}โ€ to access this room?
This widget is run by {origin} {addedBy ? `, added to the room by ${addedBy}` : ''}. It is asking to act for you in this room. Only allow what you trust {origin} with. {requests.map((r) => ( ) => toggle(r.capability, e.currentTarget.checked) } /> {r.label} {r.sends && ( {' '} ยท as you )} ))} ) => setRemember(e.currentTarget.checked) } /> Remember my choice for this widget on this device
); }