-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d10e31
commit 0c567b1
Showing
2 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
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
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,29 @@ | ||
/** | ||
* 브라우저 클립보드에 Text 를 복사시키는 핸들러, HTTPS || Localhost 에서만 동작 | ||
* @param content 복사시킬 내용 | ||
* @param onError 에러시 사용할 함수 | ||
* @param onSuccess 성공시 사용할 함수 | ||
* @param onSettle 성공/실패 여부에 관계없이 완료후 사용할 함수 | ||
*/ | ||
|
||
interface CopyToClipboardOptions { | ||
onError?: (err: unknown) => void; | ||
onSuccess?: () => void; | ||
onSettle?: () => void; | ||
} | ||
|
||
const copyToClipboard = async ( | ||
content: string, | ||
{ onError, onSettle, onSuccess }: CopyToClipboardOptions | ||
) => { | ||
try { | ||
await navigator.clipboard.writeText(content); | ||
onSuccess && onSuccess(); | ||
} catch (err) { | ||
onError && onError(err); | ||
} finally { | ||
onSettle && onSettle(); | ||
} | ||
}; | ||
|
||
export default copyToClipboard; |