| 1 |
/** @odoo-module */ |
| 2 |
|
| 3 |
import { Component, useState, xml } from "@odoo/owl"; |
| 4 |
import { copy, hasClipboard } from "../hoot_utils"; |
| 5 |
|
| 6 |
/** |
| 7 |
* @typedef {{ |
| 8 |
* altText?: string; |
| 9 |
* text: string; |
| 10 |
* }} HootCopyButtonProps |
| 11 |
*/ |
| 12 |
|
| 13 |
/** @extends {Component<HootCopyButtonProps, import("../hoot").Environment>} */ |
| 14 |
export class HootCopyButton extends Component { |
| 15 |
static props = { |
| 16 |
altText: { type: String, optional: true }, |
| 17 |
text: String, |
| 18 |
}; |
| 19 |
|
| 20 |
static template = xml` |
| 21 |
<t t-if="hasClipboard()"> |
| 22 |
<button |
| 23 |
type="button" |
| 24 |
class="text-gray-400 hover:text-gray-500" |
| 25 |
t-att-class="{ 'text-emerald': state.copied }" |
| 26 |
title="copy to clipboard" |
| 27 |
t-on-click.stop="onClick" |
| 28 |
> |
| 29 |
<i class="fa fa-clipboard" /> |
| 30 |
</button> |
| 31 |
</t> |
| 32 |
`; |
| 33 |
|
| 34 |
hasClipboard = hasClipboard; |
| 35 |
|
| 36 |
setup() { |
| 37 |
this.state = useState({ copied: false }); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* @param {PointerEvent} ev |
| 42 |
*/ |
| 43 |
async onClick(ev) { |
| 44 |
const text = ev.altKey && this.props.altText ? this.props.altText : this.props.text; |
| 45 |
await copy(text); |
| 46 |
this.state.copied = true; |
| 47 |
} |
| 48 |
} |