-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add points remaining and copy to talents
- Loading branch information
1 parent
85f3887
commit 6ffe47e
Showing
10 changed files
with
195 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Tooltip } from 'bootstrap'; | ||
// eslint-disable-next-line unused-imports/no-unused-imports | ||
import { element, ref } from 'tsx-vanilla'; | ||
|
||
import { Component } from "./component"; | ||
|
||
export interface CopyButtonConfig { | ||
getContent: () => string, | ||
extraCssClasses?: string[], | ||
text?: string, | ||
tooltip?: string, | ||
} | ||
|
||
export class CopyButton extends Component { | ||
private readonly config: CopyButtonConfig; | ||
|
||
constructor(parent: HTMLElement, config: CopyButtonConfig) { | ||
const btnRef = ref<HTMLButtonElement>(); | ||
const buttonElem = ( | ||
<button | ||
className={`btn ${config.extraCssClasses?.join(' ') ?? ''}`} | ||
ref={btnRef} | ||
> | ||
<i className="fas fa-copy me-1" />{config.text ?? 'Copy to Clipboard'} | ||
</button> | ||
) | ||
|
||
super(parent, 'copy-button', buttonElem as HTMLElement); | ||
this.config = config; | ||
|
||
const button = btnRef.value! | ||
let clicked = false | ||
button.addEventListener('click', _event => { | ||
if (clicked) return | ||
|
||
const data = this.config.getContent() | ||
if (navigator.clipboard == undefined) { | ||
alert(data); | ||
} else { | ||
clicked = true | ||
navigator.clipboard.writeText(data); | ||
const originalContent = button.innerHTML; | ||
button.innerHTML = '<i class="fas fa-check me-1"></i>Copied'; | ||
setTimeout(() => { | ||
button.innerHTML = originalContent; | ||
clicked = false | ||
}, 1500); | ||
} | ||
}); | ||
|
||
if (config.tooltip) { | ||
Tooltip.getOrCreateInstance(button, {title: config.tooltip}); | ||
} | ||
} | ||
}; |
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
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
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
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
Oops, something went wrong.