mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-05-12 02:20:28 +08:00
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import React, { useState, useEffect } from 'react';
|
|
import { Modal, Input } from 'antd';
|
|
import { useI18n } from '../../../../i18n';
|
|
import type { VfsEntry } from '../../../../api/client';
|
|
|
|
interface RenameModalProps {
|
|
entry: VfsEntry | null;
|
|
onOk: (entry: VfsEntry, newName: string) => void;
|
|
onCancel: () => void;
|
|
}
|
|
|
|
export const RenameModal: React.FC<RenameModalProps> = ({ entry, onOk, onCancel }) => {
|
|
const [name, setName] = useState('');
|
|
const { t } = useI18n();
|
|
|
|
useEffect(() => {
|
|
if (entry) {
|
|
setName(entry.name);
|
|
}
|
|
}, [entry]);
|
|
|
|
const handleOk = () => {
|
|
if (entry) {
|
|
onOk(entry, name);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Modal
|
|
title={t('Rename')}
|
|
open={!!entry}
|
|
onOk={handleOk}
|
|
onCancel={onCancel}
|
|
okButtonProps={{ disabled: !name.trim() || name.trim() === entry?.name }}
|
|
destroyOnHidden
|
|
>
|
|
<Input
|
|
placeholder={t('New Name')}
|
|
value={name}
|
|
onChange={e => setName(e.target.value)}
|
|
onPressEnter={handleOk}
|
|
autoFocus
|
|
/>
|
|
</Modal>
|
|
);
|
|
};
|