1313// limitations under the License.
1414
1515import React , { useState } from "react" ;
16- import { Button , Input , Space , Tooltip } from "antd" ;
16+ import { Button , Input , Tooltip } from "antd" ;
1717import { CheckOutlined , CloseOutlined , EditOutlined } from "@ant-design/icons" ;
1818import i18next from "i18next" ;
1919
20- // Styles for edit components
21- export const editStyles = {
22- // Edit form styles
23- editForm : {
24- width : "100%" ,
25- } ,
26-
27- // TextArea styles in edit form
28- editTextArea : {
29- marginBottom : "8px" ,
30- } ,
31-
32- // Button container in edit form
33- editFormButtons : {
34- display : "flex" ,
35- justifyContent : "flex-end" ,
36- } ,
37- } ;
38-
3920const MessageEdit = ( {
4021 message,
4122 isLastMessage,
4223 disableInput,
24+ hideInput,
4325 index,
4426 onEditMessage,
27+ isDark,
4528} ) => {
4629 const [ isEditing , setIsEditing ] = useState ( false ) ;
4730 const [ editedText , setEditedText ] = useState ( "" ) ;
4831 const [ isHovering , setIsHovering ] = useState ( false ) ;
4932
50- // Edit action handlers
5133 const handleEditActions = {
5234 start : ( ) => {
5335 setIsEditing ( true ) ;
@@ -65,44 +47,99 @@ const MessageEdit = ({
6547 if ( e . key === "Enter" && ! e . shiftKey ) {
6648 e . preventDefault ( ) ;
6749 handleEditActions . save ( ) ;
50+ } else if ( e . key === "Escape" ) {
51+ handleEditActions . cancel ( ) ;
6852 }
6953 } ,
7054 } ;
7155
72- // Edit form component
73- const renderEditForm = ( ) => (
74- < div style = { editStyles . editForm } >
75- < Input . TextArea
76- value = { editedText }
77- onChange = { e => setEditedText ( e . target . value ) }
78- onKeyDown = { handleEditActions . keyDown }
79- autoSize = { { minRows : 1 , maxRows : 6 } }
80- style = { editStyles . editTextArea }
81- autoFocus
82- />
83- < Space style = { editStyles . editFormButtons } >
84- < Button
85- icon = { < CloseOutlined /> }
86- onClick = { handleEditActions . cancel }
87- size = "small"
88- >
89- { i18next . t ( "general:Cancel" ) }
90- </ Button >
91- < Button
92- type = "primary"
93- icon = { < CheckOutlined /> }
94- onClick = { handleEditActions . save }
95- size = "small"
96- >
97- { i18next . t ( "general:Save" ) }
98- </ Button >
99- </ Space >
100- </ div >
101- ) ;
56+ const renderEditForm = ( ) => {
57+ const containerStyle = {
58+ width : "100%" ,
59+ maxWidth : "480px" ,
60+ marginLeft : "auto" ,
61+ background : isDark ? "#1e2130" : "#ffffff" ,
62+ border : isDark ? "1px solid #2e3347" : "1px solid #e2e8f0" ,
63+ borderRadius : "14px 14px 4px 14px" ,
64+ padding : "12px 14px" ,
65+ boxShadow : isDark
66+ ? "0 4px 16px rgba(0,0,0,0.45)"
67+ : "0 4px 16px rgba(0,0,0,0.08)" ,
68+ } ;
69+
70+ const textareaStyle = {
71+ background : isDark ? "#252a3a" : "#f7f9fc" ,
72+ borderColor : isDark ? "#363d52" : "#dde3ed" ,
73+ color : isDark ? "#dde3f0" : "#2d3748" ,
74+ borderRadius : "8px" ,
75+ fontSize : "14px" ,
76+ lineHeight : "1.6" ,
77+ resize : "none" ,
78+ transition : "border-color 0.2s" ,
79+ } ;
80+
81+ return (
82+ < div style = { containerStyle } >
83+ < Input . TextArea
84+ value = { editedText }
85+ onChange = { e => setEditedText ( e . target . value ) }
86+ onKeyDown = { handleEditActions . keyDown }
87+ autoSize = { { minRows : 2 , maxRows : 8 } }
88+ style = { textareaStyle }
89+ autoFocus
90+ />
91+ < div style = { {
92+ display : "flex" ,
93+ justifyContent : "space-between" ,
94+ alignItems : "center" ,
95+ marginTop : "10px" ,
96+ } } >
97+ < span style = { {
98+ fontSize : "11px" ,
99+ color : isDark ? "#5a6480" : "#a0aec0" ,
100+ userSelect : "none" ,
101+ } } >
102+ Enter { i18next . t ( "general:Save" ) } · Esc { i18next . t ( "general:Cancel" ) }
103+ </ span >
104+ < div style = { { display : "flex" , gap : "8px" } } >
105+ < Button
106+ size = "small"
107+ icon = { < CloseOutlined style = { { fontSize : "11px" } } /> }
108+ onClick = { handleEditActions . cancel }
109+ style = { {
110+ borderRadius : "20px" ,
111+ paddingInline : "12px" ,
112+ height : "28px" ,
113+ background : "transparent" ,
114+ borderColor : isDark ? "#3d4560" : "#d1d8e4" ,
115+ color : isDark ? "#8896b0" : "#718096" ,
116+ fontSize : "12px" ,
117+ } }
118+ >
119+ { i18next . t ( "general:Cancel" ) }
120+ </ Button >
121+ < Button
122+ type = "primary"
123+ size = "small"
124+ icon = { < CheckOutlined style = { { fontSize : "11px" } } /> }
125+ onClick = { handleEditActions . save }
126+ style = { {
127+ borderRadius : "20px" ,
128+ paddingInline : "12px" ,
129+ height : "28px" ,
130+ fontSize : "12px" ,
131+ } }
132+ >
133+ { i18next . t ( "general:Save" ) }
134+ </ Button >
135+ </ div >
136+ </ div >
137+ </ div >
138+ ) ;
139+ } ;
102140
103- // Edit button component
104141 const renderEditButton = ( ) => {
105- if ( message . author !== "AI" && ! isEditing && ( disableInput === false || index !== isLastMessage ) ) {
142+ if ( message . author !== "AI" && ! isEditing && ! hideInput && ( disableInput === false || index !== isLastMessage ) ) {
106143 return (
107144 < Tooltip title = { i18next . t ( "general:Edit" ) } arrow = { false } >
108145 < Button
@@ -117,7 +154,6 @@ const MessageEdit = ({
117154 return null ;
118155 } ;
119156
120- // Return the editing state and render functions
121157 return {
122158 isEditing,
123159 isHovering,
0 commit comments