11"use client" ;
2-
32import { useState } from 'react' ;
43import copy from 'copy-to-clipboard' ;
4+ import 'react-toastify/dist/ReactToastify.css' ;
55
6- export function EnvVariableConfig ( { variableNames, format } : { variableNames : { key : string ; name : string ; defaultVal ?: string } [ ] ; format ?: "yaml" | "env" } ) {
6+ export function EnvVariableConfig ( { variableNames, format } : { variableNames : { key : string ; name : string ; defaultVal ?: string } [ ] ; format ?: "yaml" | "env" } ) {
77 const [ values , setValues ] = useState ( variableNames . map ( ( name ) => name . defaultVal || '' ) ) ;
8+ const [ copyButtonText , setCopyButtonText ] = useState ( '复制' ) ; // 新增状态用于控制按钮文本
89
910 const handleCopy = ( ) => {
1011 if ( format === 'yaml' ) {
1112 const yamlContent = variableNames . map ( ( name , index ) => `- ${ name . key } =${ values [ index ] } ` ) . join ( '\n' ) ;
1213 copy ( yamlContent ) ;
13- return ;
14+ } else {
15+ const envContent = variableNames . map ( ( name , index ) => `${ name . key } =${ values [ index ] } ` ) . join ( '\n' ) ;
16+ copy ( envContent ) ;
1417 }
15- const envContent = variableNames . map ( ( name , index ) => `${ name . key } =${ values [ index ] } ` ) . join ( '\n' ) ;
16- copy ( envContent ) ;
18+ setCopyButtonText ( '复制成功' ) ;
19+ setTimeout ( ( ) => {
20+ setCopyButtonText ( '复制' ) ;
21+ } , 3000 ) ;
1722 } ;
1823
1924 const handleChange = ( index : number , value : string ) => {
@@ -23,50 +28,50 @@ export function EnvVariableConfig({ variableNames, format }: { variableNames: {
2328 } ;
2429
2530 return (
26- < div className = "p-4 mt-2 rounded-lg border dark:bg-gray-900 dark:border-gray-800" >
27- { variableNames . map ( ( name , index ) => (
28- < div key = { `${ name . key } ` } className = "flex items-center space-x-4 mb-4" >
29- < input
30- type = "text"
31- className = "border rounded-lg px-2 py-2 w-1/2 bg-transparent focus:outline-none focus:border-black hover:border-white-400 transition duration-300 font-[400] font-sans text-sm cursor-not-allowed dark:border-gray-700 dark:text-gray-300 dark:bg-gray-800"
32- value = { name . name || name . key }
33- data-tip = { name . key }
34- onMouseOver = { ( e : any ) => {
35- e . target . style . color = 'transparent' ;
36- setTimeout ( ( ) => {
37- e . target . style . color = 'inherit' ;
38- e . target . value = e . target . dataset . tip ;
39- } , 300 ) ;
40- } }
41- onMouseLeave = { ( e : any ) => {
42- e . target . style . color = 'transparent' ;
43- setTimeout ( ( ) => {
44- e . target . style . color = 'inherit' ;
45- e . target . value = name . name || name . key ;
46- } , 300 ) ;
47- } }
48- disabled
49- />
50- < input
51- type = "text"
52- className = "border rounded-lg px-2 py-2 w-1/2 focus:outline-none focus:border-black hover:border-gray-400 transition duration-300 font-[400] font-sans text-sm dark:border-gray-700 dark:text-gray-300 dark:bg-gray-800"
53- style = { { outline : "none" , boxShadow : "none" } }
54- placeholder = { `Enter value...` }
55- value = { values [ index ] }
56- onChange = { ( e ) => handleChange ( index , e . target . value ) }
57- />
31+ < div className = "p-4 mt-2 rounded-lg border dark:bg-gray-900 dark:border-gray-800" >
32+ { variableNames . map ( ( name , index ) => (
33+ < div key = { `${ name . key } ` } className = "flex items-center space-x-4 mb-4" >
34+ < input
35+ type = "text"
36+ className = "border rounded-lg px-2 py-2 w-1/2 bg-transparent focus:outline-none focus:border-black hover:border-white-400 transition duration-300 font-[400] font-sans text-sm cursor-not-allowed dark:border-gray-700 dark:text-gray-300 dark:bg-gray-800"
37+ value = { name . name || name . key }
38+ data-tip = { name . key }
39+ onMouseOver = { ( e : any ) => {
40+ e . target . style . color = 'transparent' ;
41+ setTimeout ( ( ) => {
42+ e . target . style . color = 'inherit' ;
43+ e . target . value = e . target . dataset . tip ;
44+ } , 300 ) ;
45+ } }
46+ onMouseLeave = { ( e : any ) => {
47+ e . target . style . color = 'transparent' ;
48+ setTimeout ( ( ) => {
49+ e . target . style . color = 'inherit' ;
50+ e . target . value = name . name || name . key ;
51+ } , 300 ) ;
52+ } }
53+ disabled
54+ />
55+ < input
56+ type = "text"
57+ className = "border rounded-lg px-2 py-2 w-1/2 focus:outline-none focus:border-black hover:border-gray-400 transition duration-300 font-[400] font-sans text-sm dark:border-gray-700 dark:text-gray-300 dark:bg-gray-800"
58+ style = { { outline : "none" , boxShadow : "none" } }
59+ placeholder = { `Enter value...` }
60+ value = { values [ index ] }
61+ onChange = { ( e ) => handleChange ( index , e . target . value ) }
62+ />
63+ </ div >
64+ ) ) }
65+ < div className = "flex items-center justify-between mb-4" >
66+ < h2 className = "sr-only" > 环境变量配置</ h2 >
67+ < button
68+ type = "button"
69+ className = "border bg-black w-full text-white px-4 py-2 rounded-lg text-sm transform transition-all duration-300 focus:outline-none hover:bg-gray-700 dark:border-gray-700 dark:bg-gray-800"
70+ onClick = { handleCopy }
71+ >
72+ { copyButtonText }
73+ </ button >
5874 </ div >
59- ) ) }
60- < div className = "flex items-center justify-between mb-4" >
61- < h2 className = "sr-only" > 环境变量配置</ h2 >
62- < button
63- type = "button"
64- className = "border bg-black w-full text-white px-4 py-2 rounded-lg text-sm transform transition-all duration-300 focus:outline-none hover:bg-gray-700 dark:border-gray-700 dark:bg-gray-800"
65- onClick = { handleCopy }
66- >
67- 复制
68- </ button >
6975 </ div >
70- </ div >
7176 ) ;
72- }
77+ }
0 commit comments