-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathAddModModal.tsx
More file actions
112 lines (101 loc) · 2.85 KB
/
Copy pathAddModModal.tsx
File metadata and controls
112 lines (101 loc) · 2.85 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import React, { useState, useCallback, useRef, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { Modal } from "../../../tailwind/components/modal";
import { Typography } from "../../../tailwind/components/next/typography";
import { Button } from "../../../tailwind/components/next/button";
import { Input } from "../../../tailwind/components/next/form/input";
interface AddModModalProps {
isOpen: boolean;
onClose: () => void;
onConfirm: (modName: string) => void;
}
/**
* Modal dialog for creating a new empty mod
* Uses the modern Tailwind/Headless UI styling
*/
export const AddModModal = ({
isOpen,
onClose,
onConfirm,
}: AddModModalProps) => {
const { t } = useTranslation(["common"]);
const [modName, setModName] = useState("");
const inputRef = useRef<HTMLInputElement>(null);
// Reset mod name when dialog opens
useEffect(() => {
if (isOpen) {
// This is intentional - reset state when modal opens
// eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
setModName("");
}
}, [isOpen]);
const handleConfirm = useCallback(() => {
const trimmedName = modName.trim();
if (trimmedName) {
onConfirm(trimmedName);
setModName("");
onClose();
}
}, [modName, onConfirm, onClose]);
const handleKeyDown = useCallback(
(e: React.KeyboardEvent) => {
if (e.key === "Enter" && modName.trim()) {
handleConfirm();
}
},
[handleConfirm, modName],
);
const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
setModName(e.target.value);
}, []);
return (
<Modal
isOpen={isOpen}
title={t("Create New Mod")}
onClose={onClose}
initialFocusRef={inputRef}
>
<Typography
as="div"
appearance="subdued"
className="mb-4"
typographyType="body-sm"
>
{t(
"Enter a name for your new mod. This will create an empty mod folder in your staging directory where you can add files manually.",
)}
</Typography>
<Input
id="add-mod-name-input"
ref={inputRef}
label={t("Mod Name")}
value={modName}
onChange={handleChange}
onKeyDown={handleKeyDown}
placeholder={t("My Custom Mod")}
className="w-full"
/>
<div className="grid grid-cols-2 gap-x-2 mt-4">
<Button
buttonType="tertiary"
className="w-full"
filled="weak"
size="sm"
onClick={onClose}
>
{t("Cancel")}
</Button>
<Button
buttonType="primary"
className="w-full"
size="sm"
onClick={handleConfirm}
disabled={!modName.trim()}
>
{t("Create Mod")}
</Button>
</div>
</Modal>
);
};
export default AddModModal;