|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. |
| 3 | + * Licensed under the MIT License. |
| 4 | + */ |
| 5 | + |
| 6 | +export interface EditElementModalProps { |
| 7 | + isOpen: boolean; |
| 8 | + onClose: () => void; |
| 9 | + onSave: (content: string) => void; |
| 10 | + initialContent: string; |
| 11 | + elementLabel: string; |
| 12 | +} |
| 13 | + |
| 14 | +export function EditElementModal({ isOpen, onClose, onSave, initialContent, elementLabel }: EditElementModalProps) { |
| 15 | + const [content, setContent] = React.useState(initialContent); |
| 16 | + |
| 17 | + React.useEffect(() => { |
| 18 | + setContent(initialContent); |
| 19 | + }, [initialContent, isOpen]); |
| 20 | + |
| 21 | + if (!isOpen) return null; |
| 22 | + |
| 23 | + const handleSave = () => { |
| 24 | + onSave(content); |
| 25 | + onClose(); |
| 26 | + }; |
| 27 | + |
| 28 | + const handleCancel = () => { |
| 29 | + setContent(initialContent); |
| 30 | + onClose(); |
| 31 | + }; |
| 32 | + |
| 33 | + return ( |
| 34 | + <div |
| 35 | + style={{ |
| 36 | + position: 'fixed', |
| 37 | + top: 0, |
| 38 | + left: 0, |
| 39 | + right: 0, |
| 40 | + bottom: 0, |
| 41 | + background: 'rgba(0, 0, 0, 0.5)', |
| 42 | + display: 'flex', |
| 43 | + alignItems: 'center', |
| 44 | + justifyContent: 'center', |
| 45 | + zIndex: 2000 |
| 46 | + }} |
| 47 | + onClick={handleCancel} |
| 48 | + > |
| 49 | + <div |
| 50 | + style={{ |
| 51 | + background: 'white', |
| 52 | + borderRadius: '8px', |
| 53 | + boxShadow: '0 16px 48px rgba(0, 0, 0, 0.3)', |
| 54 | + width: '90%', |
| 55 | + maxWidth: '600px', |
| 56 | + maxHeight: '80vh', |
| 57 | + display: 'flex', |
| 58 | + flexDirection: 'column' |
| 59 | + }} |
| 60 | + onClick={(e) => e.stopPropagation()} |
| 61 | + > |
| 62 | + {/* Modal Header */} |
| 63 | + <div style={{ |
| 64 | + padding: '16px 20px', |
| 65 | + borderBottom: '1px solid #e1e5e9', |
| 66 | + display: 'flex', |
| 67 | + alignItems: 'center', |
| 68 | + justifyContent: 'space-between' |
| 69 | + }}> |
| 70 | + <h3 style={{ |
| 71 | + margin: 0, |
| 72 | + fontSize: '16px', |
| 73 | + fontWeight: '600', |
| 74 | + color: '#24292f' |
| 75 | + }}> |
| 76 | + ✏️ Edit Element: {elementLabel} |
| 77 | + </h3> |
| 78 | + <button |
| 79 | + onClick={handleCancel} |
| 80 | + style={{ |
| 81 | + background: 'transparent', |
| 82 | + border: 'none', |
| 83 | + fontSize: '20px', |
| 84 | + cursor: 'pointer', |
| 85 | + color: '#656d76', |
| 86 | + padding: '4px 8px', |
| 87 | + lineHeight: 1 |
| 88 | + }} |
| 89 | + title="Close" |
| 90 | + > |
| 91 | + ✕ |
| 92 | + </button> |
| 93 | + </div> |
| 94 | + |
| 95 | + {/* Modal Body */} |
| 96 | + <div style={{ |
| 97 | + padding: '20px', |
| 98 | + flex: 1, |
| 99 | + overflow: 'auto' |
| 100 | + }}> |
| 101 | + <textarea |
| 102 | + value={content} |
| 103 | + onChange={(e) => setContent(e.target.value)} |
| 104 | + style={{ |
| 105 | + width: '100%', |
| 106 | + minHeight: '200px', |
| 107 | + padding: '12px', |
| 108 | + border: '1px solid #d1d9e0', |
| 109 | + borderRadius: '6px', |
| 110 | + fontSize: '14px', |
| 111 | + fontFamily: 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace', |
| 112 | + resize: 'vertical', |
| 113 | + background: '#f6f8fa', |
| 114 | + color: '#24292f', |
| 115 | + lineHeight: '1.5', |
| 116 | + boxSizing: 'border-box' |
| 117 | + }} |
| 118 | + autoFocus |
| 119 | + /> |
| 120 | + </div> |
| 121 | + |
| 122 | + {/* Modal Footer */} |
| 123 | + <div style={{ |
| 124 | + padding: '16px 20px', |
| 125 | + borderTop: '1px solid #e1e5e9', |
| 126 | + display: 'flex', |
| 127 | + justifyContent: 'flex-end', |
| 128 | + gap: '12px', |
| 129 | + background: '#f6f8fa' |
| 130 | + }}> |
| 131 | + <button |
| 132 | + onClick={handleCancel} |
| 133 | + style={{ |
| 134 | + padding: '8px 16px', |
| 135 | + border: '1px solid #d1d9e0', |
| 136 | + borderRadius: '6px', |
| 137 | + background: 'white', |
| 138 | + color: '#24292f', |
| 139 | + fontSize: '14px', |
| 140 | + fontWeight: '500', |
| 141 | + cursor: 'pointer' |
| 142 | + }} |
| 143 | + onMouseEnter={(e) => { |
| 144 | + e.currentTarget.style.background = '#f6f8fa'; |
| 145 | + }} |
| 146 | + onMouseLeave={(e) => { |
| 147 | + e.currentTarget.style.background = 'white'; |
| 148 | + }} |
| 149 | + > |
| 150 | + Cancel |
| 151 | + </button> |
| 152 | + <button |
| 153 | + onClick={handleSave} |
| 154 | + style={{ |
| 155 | + padding: '8px 16px', |
| 156 | + border: 'none', |
| 157 | + borderRadius: '6px', |
| 158 | + background: '#2da44e', |
| 159 | + color: 'white', |
| 160 | + fontSize: '14px', |
| 161 | + fontWeight: '500', |
| 162 | + cursor: 'pointer' |
| 163 | + }} |
| 164 | + onMouseEnter={(e) => { |
| 165 | + e.currentTarget.style.background = '#2c974b'; |
| 166 | + }} |
| 167 | + onMouseLeave={(e) => { |
| 168 | + e.currentTarget.style.background = '#2da44e'; |
| 169 | + }} |
| 170 | + > |
| 171 | + Save |
| 172 | + </button> |
| 173 | + </div> |
| 174 | + </div> |
| 175 | + </div> |
| 176 | + ); |
| 177 | +} |
0 commit comments