refactor: improve modal ux

This commit is contained in:
Yidadaa 2023-07-04 22:08:41 +08:00
parent cda074fe24
commit f2d748cfe4
3 changed files with 8 additions and 3 deletions

View File

@ -911,6 +911,7 @@ export function Chat() {
const newMessage = await showPrompt( const newMessage = await showPrompt(
Locale.Chat.Actions.Edit, Locale.Chat.Actions.Edit,
message.content, message.content,
10,
); );
chatStore.updateCurrentSession((session) => { chatStore.updateCurrentSession((session) => {
const m = session.messages.find( const m = session.messages.find(

View File

@ -72,7 +72,9 @@
box-shadow: var(--card-shadow); box-shadow: var(--card-shadow);
background-color: var(--white); background-color: var(--white);
border-radius: 12px; border-radius: 12px;
width: 60vw; width: 80vw;
max-width: 900px;
min-width: 300px;
animation: slide-in ease 0.3s; animation: slide-in ease 0.3s;
--modal-padding: 20px; --modal-padding: 20px;
@ -242,7 +244,6 @@
resize: none; resize: none;
outline: none; outline: none;
box-sizing: border-box; box-sizing: border-box;
min-height: 30vh;
&:focus { &:focus {
border: 1px solid var(--primary); border: 1px solid var(--primary);

View File

@ -321,6 +321,7 @@ export function showConfirm(content: any) {
function PromptInput(props: { function PromptInput(props: {
value: string; value: string;
onChange: (value: string) => void; onChange: (value: string) => void;
rows?: number;
}) { }) {
const [input, setInput] = useState(props.value); const [input, setInput] = useState(props.value);
const onInput = (value: string) => { const onInput = (value: string) => {
@ -334,11 +335,12 @@ function PromptInput(props: {
autoFocus autoFocus
value={input} value={input}
onInput={(e) => onInput(e.currentTarget.value)} onInput={(e) => onInput(e.currentTarget.value)}
rows={props.rows ?? 3}
></textarea> ></textarea>
); );
} }
export function showPrompt(content: any, value = "") { export function showPrompt(content: any, value = "", rows = 3) {
const div = document.createElement("div"); const div = document.createElement("div");
div.className = "modal-mask"; div.className = "modal-mask";
document.body.appendChild(div); document.body.appendChild(div);
@ -386,6 +388,7 @@ export function showPrompt(content: any, value = "") {
<PromptInput <PromptInput
onChange={(val) => (userInput = val)} onChange={(val) => (userInput = val)}
value={value} value={value}
rows={rows}
></PromptInput> ></PromptInput>
</Modal>, </Modal>,
); );