mirror of
https://github.com/czhu12/canine.git
synced 2025-12-31 00:10:14 -06:00
35 lines
805 B
JavaScript
35 lines
805 B
JavaScript
import { Controller } from "@hotwired/stimulus"
|
|
import ClipboardJS from "clipboard"
|
|
import tippy from "tippy.js";
|
|
|
|
export default class extends Controller {
|
|
static values = {
|
|
successMessage: String,
|
|
errorMessage: String
|
|
}
|
|
|
|
connect() {
|
|
this.clipboard = new ClipboardJS(this.element)
|
|
this.clipboard.on("success", (e) => this.tooltip(this.successMessage))
|
|
this.clipboard.on("error", (e) => this.tooltip(this.errorMessage))
|
|
}
|
|
|
|
tooltip(message) {
|
|
tippy(this.element, {
|
|
theme: "light",
|
|
content: message,
|
|
showOnCreate: true,
|
|
onHidden: (instance) => {
|
|
instance.destroy()
|
|
}
|
|
})
|
|
}
|
|
|
|
get successMessage() {
|
|
return this.successMessageValue || "Copied!"
|
|
}
|
|
|
|
get errorMessage() {
|
|
return this.errorMessageValue || "Failed!"
|
|
}
|
|
} |