1
- import { ChevronDownIcon , ChevronRightIcon } from "@heroicons/react/24/outline" ;
1
+ import {
2
+ ChevronDownIcon ,
3
+ ChevronRightIcon ,
4
+ QuestionMarkCircleIcon ,
5
+ } from "@heroicons/react/24/outline" ;
2
6
import { useState , useEffect } from "react" ;
3
7
import { FileInfo } from "@/components/common" ;
4
8
@@ -10,8 +14,17 @@ export default function FileDirectiveComponent({
10
14
onChange : ( file : FileInfo ) => void ;
11
15
} ) {
12
16
const [ isExpanded , setIsExpanded ] = useState ( true ) ;
17
+ const [ isDocExpanded , setIsDocExpanded ] = useState ( false ) ;
13
18
const [ fileContent , setFileContent ] = useState ( file . contents || "" ) ;
14
- const inputType = file . contents !== undefined ? "content" : "filename" ;
19
+
20
+ // Determine input type based on file properties
21
+ const getInputType = ( ) => {
22
+ if ( file . contents !== undefined ) return "content" ;
23
+ if ( file . url !== undefined ) return "url" ;
24
+ return "filename" ;
25
+ } ;
26
+
27
+ const inputType = getInputType ( ) ;
15
28
16
29
useEffect ( ( ) => {
17
30
// Update local state when file changes externally
@@ -23,21 +36,57 @@ export default function FileDirectiveComponent({
23
36
} ;
24
37
25
38
const updateFilename = ( value : string ) => {
26
- onChange ( { ...file , filename : value , contents : undefined } ) ;
39
+ onChange ( {
40
+ ...file ,
41
+ filename : value ,
42
+ contents : undefined ,
43
+ url : undefined ,
44
+ } ) ;
27
45
} ;
28
46
29
47
const updateContents = ( value : string ) => {
30
48
setFileContent ( value ) ;
31
- onChange ( { ...file , contents : value , filename : undefined } ) ;
49
+ onChange ( {
50
+ ...file ,
51
+ contents : value ,
52
+ filename : undefined ,
53
+ url : undefined ,
54
+ } ) ;
55
+ } ;
56
+
57
+ const updateUrl = ( value : string ) => {
58
+ onChange ( {
59
+ ...file ,
60
+ url : value ,
61
+ contents : undefined ,
62
+ filename : undefined ,
63
+ } ) ;
32
64
} ;
33
65
34
- const toggleInputType = ( type : "content" | "filename" ) => {
66
+ const toggleInputType = ( type : "content" | "filename" | "url" ) => {
35
67
if ( type === inputType ) return ;
36
68
37
69
if ( type === "content" ) {
38
- onChange ( { ...file , contents : fileContent , filename : undefined } ) ;
39
- } else {
40
- onChange ( { ...file , contents : undefined , filename : file . filename || "" } ) ;
70
+ onChange ( {
71
+ ...file ,
72
+ contents : fileContent ,
73
+ filename : undefined ,
74
+ url : undefined ,
75
+ } ) ;
76
+ } else if ( type === "filename" ) {
77
+ onChange ( {
78
+ ...file ,
79
+ contents : undefined ,
80
+ filename : file . filename || "" ,
81
+ url : undefined ,
82
+ } ) ;
83
+ } else if ( type === "url" ) {
84
+ onChange ( {
85
+ ...file ,
86
+ contents : undefined ,
87
+ filename : undefined ,
88
+ url : file . url || "" ,
89
+ } ) ;
41
90
}
42
91
} ;
43
92
@@ -54,11 +103,43 @@ export default function FileDirectiveComponent({
54
103
< ChevronRightIcon className = "h-5 w-5" />
55
104
) }
56
105
</ button >
57
- < h2 className = "text-[#0c0e0a] font-medium" >
106
+ < h2 className = "text-[#0c0e0a] font-medium flex-1 " >
58
107
File: < span className = "font-mono" > { file . name } </ span >
59
108
</ h2 >
109
+ < button
110
+ onClick = { ( e ) => {
111
+ e . stopPropagation ( ) ;
112
+ setIsDocExpanded ( ! isDocExpanded ) ;
113
+ } }
114
+ className = "ml-2 text-[#4f7b38] hover:text-[#6aa329] transition-colors"
115
+ title = "Show documentation"
116
+ >
117
+ < QuestionMarkCircleIcon className = "h-5 w-5" />
118
+ </ button >
60
119
</ div >
61
120
121
+ { isDocExpanded && (
122
+ < div className = "px-4 py-3 bg-blue-50 border-t border-[#e6f1d6] text-sm" >
123
+ < h3 className = "font-medium text-blue-900 mb-2" > File Options</ h3 >
124
+ < div className = "space-y-2 text-blue-800" >
125
+ < div >
126
+ < strong > Enter Content:</ strong > Directly input the file content
127
+ into a text area. Use this when you want to provide the exact
128
+ content inline.
129
+ </ div >
130
+ < div >
131
+ < strong > Provide Filename:</ strong > Reference an existing file by
132
+ its path. The system will read the file from the specified
133
+ location.
134
+ </ div >
135
+ < div >
136
+ < strong > Provide URL:</ strong > Reference a file by its URL. The
137
+ system will fetch the content from the specified web address.
138
+ </ div >
139
+ </ div >
140
+ </ div >
141
+ ) }
142
+
62
143
{ isExpanded && (
63
144
< div className = "p-4 border-t border-[#e6f1d6]" >
64
145
< div className = "mb-4" >
@@ -81,8 +162,8 @@ export default function FileDirectiveComponent({
81
162
type = "button"
82
163
onClick = { ( ) => toggleInputType ( "content" ) }
83
164
className = { `px-4 py-2 text-sm rounded-md transition-colors ${ inputType === "content"
84
- ? "bg-white shadow-sm text-[#4f7b38] font-medium"
85
- : "text-gray-600 hover:text-[#4f7b38]"
165
+ ? "bg-white shadow-sm text-[#4f7b38] font-medium"
166
+ : "text-gray-600 hover:text-[#4f7b38]"
86
167
} `}
87
168
>
88
169
Enter Content
@@ -91,12 +172,22 @@ export default function FileDirectiveComponent({
91
172
type = "button"
92
173
onClick = { ( ) => toggleInputType ( "filename" ) }
93
174
className = { `px-4 py-2 text-sm rounded-md transition-colors ${ inputType === "filename"
94
- ? "bg-white shadow-sm text-[#4f7b38] font-medium"
95
- : "text-gray-600 hover:text-[#4f7b38]"
175
+ ? "bg-white shadow-sm text-[#4f7b38] font-medium"
176
+ : "text-gray-600 hover:text-[#4f7b38]"
96
177
} `}
97
178
>
98
179
Provide Filename
99
180
</ button >
181
+ < button
182
+ type = "button"
183
+ onClick = { ( ) => toggleInputType ( "url" ) }
184
+ className = { `px-4 py-2 text-sm rounded-md transition-colors ${ inputType === "url"
185
+ ? "bg-white shadow-sm text-[#4f7b38] font-medium"
186
+ : "text-gray-600 hover:text-[#4f7b38]"
187
+ } `}
188
+ >
189
+ Provide URL
190
+ </ button >
100
191
</ div >
101
192
</ div >
102
193
@@ -112,7 +203,7 @@ export default function FileDirectiveComponent({
112
203
placeholder = "Enter file contents here..."
113
204
/>
114
205
</ div >
115
- ) : (
206
+ ) : inputType === "filename" ? (
116
207
< div >
117
208
< label className = "block mb-1 font-medium text-sm text-[#1e2a16]" >
118
209
Filename
@@ -127,9 +218,24 @@ export default function FileDirectiveComponent({
127
218
Enter the path to an existing file
128
219
</ p >
129
220
</ div >
221
+ ) : (
222
+ < div >
223
+ < label className = "block mb-1 font-medium text-sm text-[#1e2a16]" >
224
+ URL
225
+ </ label >
226
+ < input
227
+ className = "w-full px-3 py-2 border border-gray-200 rounded-md text-[#0c0e0a] focus:outline-none focus:ring-1 focus:ring-[#6aa329] focus:border-[#6aa329]"
228
+ value = { file . url || "" }
229
+ onChange = { ( e ) => updateUrl ( e . target . value ) }
230
+ placeholder = "https://example.com/file.txt"
231
+ />
232
+ < p className = "mt-2 text-sm text-gray-500" >
233
+ Enter a URL to reference a file from the web
234
+ </ p >
235
+ </ div >
130
236
) }
131
237
</ div >
132
238
) }
133
239
</ div >
134
240
) ;
135
- }
241
+ }
0 commit comments