56 lines
2.1 KiB
TypeScript
56 lines
2.1 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
|
|
sourceName: string
|
|
defaultCloneName: string
|
|
onCancel: () => void
|
|
onConfirm: (cloneName: string) => void
|
|
}
|
|
|
|
export const CloneDialog: React.FC<Props> = ({ locale, sourceName, defaultCloneName, onCancel, onConfirm }) => {
|
|
const [cloneName, setCloneName] = useState(defaultCloneName)
|
|
const trimmed = cloneName.trim()
|
|
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, 'cloneTitle', { name: sourceName })}</Alert.Title>
|
|
<Alert.Description className="dialog-desc">
|
|
{t(locale, 'cloneDesc')}
|
|
</Alert.Description>
|
|
<div className="field field-spaced">
|
|
<label className="field-label" htmlFor="clone-name">{t(locale, 'cloneNameLabel')}</label>
|
|
<input
|
|
id="clone-name"
|
|
className="input rg-p-input mono"
|
|
value={cloneName}
|
|
spellCheck={false}
|
|
autoComplete="off"
|
|
onChange={(e) => setCloneName(e.target.value)}
|
|
onKeyDown={(e) => { if (e.key === 'Enter' && trimmed) onConfirm(trimmed) }}
|
|
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={!trimmed} onClick={() => onConfirm(trimmed)}>
|
|
{t(locale, 'cloneConfirm')}
|
|
</button>
|
|
</Alert.Action>
|
|
</div>
|
|
</Alert.Content>
|
|
</Alert.Portal>
|
|
</Alert.Root>
|
|
)
|
|
}
|