File tree Expand file tree Collapse file tree 9 files changed +145
-63
lines changed
src/components/Generator/GeneredTaskfile Expand file tree Collapse file tree 9 files changed +145
-63
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
'use client' ;
2
2
3
- import { ReactElement } from 'react' ;
4
- import { taskfile } from '@/components/Generator/GeneredTaskfile/taskfile' ;
5
- import { useFormContext } from 'react-hook-form' ;
6
- import { GeneratorSettings } from '@/components/Generator/Generator' ;
7
- import CopyToClipboard from '@/components/Generator/GeneredTaskfile/Copy ' ;
8
- import { highlighter } from './Highlighter' ;
3
+ import { ReactElement } from 'react' ;
4
+ import { taskfile } from '@/components/Generator/GeneredTaskfile/taskfile' ;
5
+ import { useFormContext } from 'react-hook-form' ;
6
+ import { GeneratorSettings } from '@/components/Generator/Generator' ;
7
+ import SaveFile from './SaveFile ' ;
8
+ import { highlighter } from './Highlighter' ;
9
9
10
10
const GeneratedTaskfile = ( ) : ReactElement => {
11
11
const form = useFormContext < GeneratorSettings > ( ) ;
@@ -16,7 +16,7 @@ const GeneratedTaskfile = (): ReactElement => {
16
16
17
17
return (
18
18
< >
19
- < CopyToClipboard onCopy = { ( ) => navigator . clipboard . writeText ( resultTaskfile ) } />
19
+ < SaveFile content = { resultTaskfile } />
20
20
< pre > { highlighter ( resultTaskfile ) } </ pre >
21
21
</ >
22
22
) ;
Original file line number Diff line number Diff line change
1
+ 'use client' ;
2
+
3
+ import { ReactElement , useState } from 'react' ;
4
+
5
+ import styles from './save-file.module.scss' ;
6
+
7
+ type CopyProps = {
8
+ content : string ;
9
+ } ;
10
+
11
+ const CopyToClipboard = ( { content } : CopyProps ) : ReactElement => {
12
+ const [ isCopied , setCopied ] = useState ( false ) ;
13
+
14
+ const onClick = ( ) : void => {
15
+ setCopied ( true ) ;
16
+ navigator . clipboard . writeText ( content ) ;
17
+
18
+ setTimeout ( ( ) => setCopied ( false ) , 1000 ) ;
19
+ } ;
20
+
21
+ const download = ( ) : void => {
22
+ const blob = new Blob ( [ content ] , { type : 'text/x-shellscript' } ) ;
23
+ const elem = window . document . createElement ( 'a' ) ;
24
+ elem . href = window . URL . createObjectURL ( blob ) ;
25
+ elem . download = 'Taskfile' ;
26
+ document . body . appendChild ( elem ) ;
27
+ elem . click ( ) ;
28
+ document . body . removeChild ( elem ) ;
29
+ } ;
30
+
31
+ return (
32
+ < div className = { styles . container } >
33
+ < button type = "button" className = { `${ styles . download } ` } onClick = { download } title = "Download Taskfile" />
34
+ < button type = "button" className = { `${ styles . copy } ${ isCopied && styles . copied } ` } onClick = { onClick } title = "Copy Taskfile content" />
35
+ </ div >
36
+ ) ;
37
+ } ;
38
+
39
+ export default CopyToClipboard ;
Original file line number Diff line number Diff line change
1
+ export { default } from './SaveFile' ;
Original file line number Diff line number Diff line change
1
+ .container {
2
+ position : sticky ;
3
+ top : 0 ;
4
+ float : right ;
5
+ transform : translateY (-1rem );
6
+ display : flex ;
7
+ flex-direction : row ;
8
+ gap : 0.5rem ;
9
+ }
10
+
11
+ .copy ,
12
+ .download {
13
+ background-color : #10001fc2 ;
14
+ color : rgb (255 255 255 / 0.5 );
15
+ border : 0.1rem solid rgb (255 255 255 / 0.5 );
16
+ border-radius : 0.2rem ;
17
+ height : 2.6rem ;
18
+ width : 2.6rem ;
19
+ cursor : pointer ;
20
+ font-size : 1rem ;
21
+ background-size : 1.2rem ;
22
+ background-repeat : no-repeat ;
23
+ background-position : center ;
24
+ border-radius : 0.2rem ;
25
+ transition :
26
+ background-color 200ms ease-in-out ;
27
+ }
28
+
29
+ .download {
30
+ background-image : url (' ./download.svg' );
31
+ }
32
+
33
+ .copy {
34
+ background-image : url (' ./clipboard.svg' );
35
+ background-size : 1.0rem ;
36
+ }
37
+
38
+ .copy :hover , .download :hover {
39
+ color : #fff ;
40
+ border-color : #fff ;
41
+ }
42
+
43
+ .copy.copied ,
44
+ .copy :hover .copied {
45
+ background-color : #2ac93faa ;
46
+ }
You can’t perform that action at this time.
0 commit comments