-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to download your Taskfile and improve README
- Loading branch information
Showing
9 changed files
with
145 additions
and
63 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
src/components/Generator/GeneredTaskfile/Copy/copy.module.css
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/components/Generator/GeneredTaskfile/SaveFile/SaveFile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use client'; | ||
|
||
import {ReactElement, useState} from 'react'; | ||
|
||
import styles from './save-file.module.scss'; | ||
|
||
type CopyProps = { | ||
content: string; | ||
}; | ||
|
||
const CopyToClipboard = ({ content }: CopyProps): ReactElement => { | ||
const [isCopied, setCopied] = useState(false); | ||
|
||
const onClick = (): void => { | ||
setCopied(true); | ||
navigator.clipboard.writeText(content); | ||
|
||
setTimeout(() => setCopied(false), 1000); | ||
}; | ||
|
||
const download = (): void => { | ||
const blob = new Blob([content], {type: 'text/x-shellscript'}); | ||
const elem = window.document.createElement('a'); | ||
elem.href = window.URL.createObjectURL(blob); | ||
elem.download = 'Taskfile'; | ||
document.body.appendChild(elem); | ||
elem.click(); | ||
document.body.removeChild(elem); | ||
}; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<button type="button" className={`${styles.download}`} onClick={download} title="Download Taskfile" /> | ||
<button type="button" className={`${styles.copy} ${isCopied && styles.copied}`} onClick={onClick} title="Copy Taskfile content" /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CopyToClipboard; |
19 changes: 19 additions & 0 deletions
19
src/components/Generator/GeneredTaskfile/SaveFile/clipboard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions
33
src/components/Generator/GeneredTaskfile/SaveFile/download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './SaveFile'; |
46 changes: 46 additions & 0 deletions
46
src/components/Generator/GeneredTaskfile/SaveFile/save-file.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
.container { | ||
position: sticky; | ||
top: 0; | ||
float: right; | ||
transform: translateY(-1rem); | ||
display: flex; | ||
flex-direction: row; | ||
gap: 0.5rem; | ||
} | ||
|
||
.copy, | ||
.download { | ||
background-color: #10001fc2; | ||
color: rgb(255 255 255 / 0.5); | ||
border: 0.1rem solid rgb(255 255 255 / 0.5); | ||
border-radius: 0.2rem; | ||
height: 2.6rem; | ||
width: 2.6rem; | ||
cursor: pointer; | ||
font-size: 1rem; | ||
background-size: 1.2rem; | ||
background-repeat: no-repeat; | ||
background-position: center; | ||
border-radius: 0.2rem; | ||
transition: | ||
background-color 200ms ease-in-out; | ||
} | ||
|
||
.download { | ||
background-image: url('./download.svg'); | ||
} | ||
|
||
.copy { | ||
background-image: url('./clipboard.svg'); | ||
background-size: 1.0rem; | ||
} | ||
|
||
.copy:hover, .download:hover { | ||
color: #fff; | ||
border-color: #fff; | ||
} | ||
|
||
.copy.copied, | ||
.copy:hover.copied { | ||
background-color: #2ac93faa; | ||
} |