From f4f5983168829f6e607e5162235f850bc17797c2 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sat, 28 Feb 2026 15:51:39 +0800 Subject: [PATCH] Use custom close and save button --- src/components/Icon.tsx | 8 +++-- src/manage/qd/ChapterEditor.module.css | 48 +++++++++++++++++++++++--- src/manage/qd/ChapterEditor.tsx | 48 +++++++++++++++++++------- 3 files changed, 85 insertions(+), 19 deletions(-) diff --git a/src/components/Icon.tsx b/src/components/Icon.tsx index bfc35b4..dfd47a0 100644 --- a/src/components/Icon.tsx +++ b/src/components/Icon.tsx @@ -1,8 +1,12 @@ import { HTMLProps } from "react"; import styles from "./Icon.module.css"; -export default function Icon(props: HTMLProps) { +export interface IconProps extends HTMLProps { + cls?: string; +} + +export default function Icon(props: IconProps) { return ( - {props.children} + {props.children} ) } diff --git a/src/manage/qd/ChapterEditor.module.css b/src/manage/qd/ChapterEditor.module.css index 8080a13..9a4b67f 100644 --- a/src/manage/qd/ChapterEditor.module.css +++ b/src/manage/qd/ChapterEditor.module.css @@ -9,16 +9,54 @@ .name { align-items: center; display: flex; - margin-top: 8px; - margin-left: 16px; + margin: 8px!important; } -.name .save { +.nameContainer.editing .name { + width: 100%; + left: 0; + top: 0; +} + +.nameContainer.editing .name textarea:global(.ant-input) { + padding-right: 40px; + width: 100%; +} + +.nameSave { + position: absolute; + right: 14px; + cursor: pointer; + color: gray; +} + +.nameSave:hover { + color: #4096ff; +} + +.nameClose { + position: absolute; + right: 34px; + cursor: pointer; + color: gray; +} + +.nameClose:hover { + color: #4096ff; +} + +.nameContainer { position: relative; - top: 3px; + align-items: center; } -.editorWrapper { +.nameContainer.editing { + min-width: 200px; + width: calc(100% - 200px); + max-width: 500px; +} + +.editor { flex: 1; overflow: hidden; position: relative; diff --git a/src/manage/qd/ChapterEditor.tsx b/src/manage/qd/ChapterEditor.tsx index 4e75261..fbd109f 100644 --- a/src/manage/qd/ChapterEditor.tsx +++ b/src/manage/qd/ChapterEditor.tsx @@ -6,6 +6,7 @@ import { Flex, Typography } from "antd"; import Icon from "../../components/Icon"; import EditOutlined from "../../../node_modules/@material-icons/svg/svg/edit/outline.svg"; import SaveOutlined from "../../../node_modules/@material-icons/svg/svg/save/outline.svg"; +import CloseOutlined from "../../../node_modules/@material-icons/svg/svg/close/outline.svg"; const { Text } = Typography; @@ -16,6 +17,8 @@ export interface ChapterEditorProps { export interface ChapterEditorState { content: string; chapterName: string; + editingChapterName: boolean; + eChapterName?: string; } export default class ChapterEditor extends Component { @@ -26,6 +29,7 @@ export default class ChapterEditor extends Component, _prevState: Readonly, _snapshot?: unknown): void { @@ -33,6 +37,8 @@ export default class ChapterEditor extends Component - this.setState({ chapterName: value }), - icon: , - enterIcon: , - tooltip: "编辑章节名称", - }} - > - {this.state.chapterName} - + + this.setState({ eChapterName: value }), + icon: , + tooltip: "编辑章节名称", + onStart: () => this.setState({ editingChapterName: true }), + enterIcon: null, + onEnd: () => this.setState({ editingChapterName: false, chapterName: this.state.eChapterName ?? this.state.chapterName, eChapterName: undefined }), + onCancel: () => this.setState({ editingChapterName: false, eChapterName: undefined }), + }} + > + {this.state.editingChapterName ? (this.state.eChapterName ?? this.state.chapterName) : this.state.chapterName} + + {this.state.editingChapterName && { + this.setState({ editingChapterName: false, eChapterName: undefined }); + }} />} + {this.state.editingChapterName && { + this.setState({ editingChapterName: false, chapterName: this.state.eChapterName ?? this.state.chapterName, eChapterName: undefined }); + }} />} + -
+