60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
import * as Alert from '@radix-ui/react-alert-dialog'
|
|
import React, { useState } from 'react'
|
|
import { t } from '../i18n'
|
|
import { Locale } from '../types'
|
|
|
|
interface Props {
|
|
locale: Locale
|
|
vmName: string
|
|
guestToolsConnected: boolean
|
|
onCancel: () => void
|
|
onConfirm: (text: string) => void
|
|
}
|
|
|
|
export const SendTextDialog: React.FC<Props> = ({ locale, vmName, guestToolsConnected, onCancel, onConfirm }) => {
|
|
const [text, setText] = useState('')
|
|
const canSend = text.length > 0
|
|
|
|
return (
|
|
<Alert.Root open onOpenChange={(open) => { if (!open) onCancel() }}>
|
|
<Alert.Portal>
|
|
<Alert.Overlay className="overlay" />
|
|
<Alert.Content className="dialog rg-p-dialog sm" data-tone="neutral">
|
|
<div className="dialog-body">
|
|
<Alert.Title className="dialog-title">{t(locale, 'sendTextTitle', { name: vmName })}</Alert.Title>
|
|
<Alert.Description className="dialog-desc">
|
|
{t(locale, guestToolsConnected ? 'sendTextDesc' : 'sendTextDescNoGT')}
|
|
</Alert.Description>
|
|
<div className="field field-spaced">
|
|
<textarea
|
|
className="input rg-p-input textarea"
|
|
rows={4}
|
|
placeholder={t(locale, 'sendTextPlaceholder')}
|
|
value={text}
|
|
onChange={(e) => setText(e.target.value)}
|
|
onKeyDown={(e) => {
|
|
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey) && canSend) {
|
|
e.preventDefault()
|
|
onConfirm(text)
|
|
}
|
|
}}
|
|
autoFocus
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className="dialog-foot">
|
|
<Alert.Cancel asChild>
|
|
<button type="button" className="btn rg-p-button">{t(locale, 'cancel')}</button>
|
|
</Alert.Cancel>
|
|
<Alert.Action asChild>
|
|
<button type="button" className="btn rg-p-button btn-primary" disabled={!canSend} onClick={() => onConfirm(text)}>
|
|
{t(locale, 'sendTextConfirm')}
|
|
</button>
|
|
</Alert.Action>
|
|
</div>
|
|
</Alert.Content>
|
|
</Alert.Portal>
|
|
</Alert.Root>
|
|
)
|
|
}
|