Skip to content

Commit 32e726a

Browse files
committed
Add ability to download your Taskfile and improve README
1 parent 4ca7234 commit 32e726a

File tree

9 files changed

+145
-63
lines changed

9 files changed

+145
-63
lines changed

src/components/Generator/GeneredTaskfile/Copy/Copy.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/components/Generator/GeneredTaskfile/Copy/copy.module.css

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/components/Generator/GeneredTaskfile/Copy/index.tsx

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components/Generator/GeneredTaskfile/GeneratedTaskfile.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use client';
22

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';
99

1010
const GeneratedTaskfile = (): ReactElement => {
1111
const form = useFormContext<GeneratorSettings>();
@@ -16,7 +16,7 @@ const GeneratedTaskfile = (): ReactElement => {
1616

1717
return (
1818
<>
19-
<CopyToClipboard onCopy={() => navigator.clipboard.writeText(resultTaskfile)} />
19+
<SaveFile content={resultTaskfile} />
2020
<pre>{highlighter(resultTaskfile)}</pre>
2121
</>
2222
);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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;
Lines changed: 19 additions & 0 deletions
Loading
Lines changed: 33 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './SaveFile';
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

0 commit comments

Comments
 (0)