@coveops/copy-to-clipboard
v1.2.5
Published
Allows the user to copy a value to their clipboard.
Downloads
206
Maintainers
Keywords
Readme
CopyToClipboard
Disclaimer: This component was built by the community at large and is not an official Coveo JSUI Component. Use this component at your own risk.
The CopyToClipboard component allows the user to copy a value specified to their clipboard.
Getting Started
- Install the component into your project
npm i @coveops/copy-to-clipboard
- Use the Component or extend it
Typescript:
import { CopyToClipboard, ICopyToClipboardOptions } from '@coveops/copy-to-clipboard';
Javascript
const CopyToClipboard = require('@coveops/copy-to-clipboard').CopyToClipboard;
- You can also expose the component alongside other components being built in your project.
export * from '@coveops/copy-to-clipboard'
- Or for quick testing, you can add the script from unpkg
<script src="https://unpkg.com/@coveops/copy-to-clipboard@latest/dist/index.min.js"></script>
Disclaimer: Unpkg should be used for testing but not for production.
- Include the component in your template as follows:
<div class="CoveoCopyToClipboard"></div>
Options
The following options can be configured:
| Option | Required | Type | Default | Notes |
| --- | --- | --- | --- | --- |
| hasCaption
| No | boolean | true
| Do we show a caption on the component? |
| caption
| No | string | Copy
| The caption shown on the component. |
| copiedCaption
| No | string | Copied!
| The caption shown when you successfully copied the field. |
| resetTimeout
| No | string | 3000
| The amount of milliseconds before the caption reverts from copiedCaption
to caption
. |
| field
| No | IFieldOption | @clickUri
| The field whose value will be copied to the clipboard. The field name must be prefixed with @
. |
| altTitle
| No | string | Copy
| The alternate title displayed for accessibility purposes. |
| hasIcon
| No | string | false
| Do we display an icon on the component? |
| icon
| No | string | clipboard
| The icon displayed on the component. The component offers a couple of icons. If none of them fit your needs, you can inject an SVG element. |
| iconWidth
| No | number | 18
| The icon width. |
| iconHeight
| No | string | 18
| The icon height. |
These icons are available:
| Icon | Preview |
| --- | --- |
| clipboard
| |
| copy
| |
If none of these icons serve your purpose, you may use your own SVG icon like so:
<span class="CoveoCopyToClipboard" data-field="@uri" data-caption="Copy" data-has-icon="true"
data-icon="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><path d='M458.4 64.3C400.6 15.7 311.3 23 256 79.3 200.7 23 111.4 15.6 53.6 64.3-21.6 127.6-10.6 230.8 43 285.5l175.4 178.7c10 10.2 23.4 15.9 37.6 15.9 14.3 0 27.6-5.6 37.6-15.8L469 285.6c53.5-54.7 64.7-157.9-10.6-221.3zm-23.6 187.5L259.4 430.5c-2.4 2.4-4.4 2.4-6.8 0L77.2 251.8c-36.5-37.2-43.9-107.6 7.3-150.7 38.9-32.7 98.9-27.8 136.5 10.5l35 35.7 35-35.7c37.8-38.5 97.8-43.2 136.5-10.6 51.1 43.1 43.5 113.9 7.3 150.8z'></path></svg>"
data-icon-height="20" data-icon-width="20"></span>
Avoid self-closing tags for maximum compatibility.
Regarding Salesforce
If you wish to use this component in Salesforce, please use the equivalent CoveoSalesforceCopyToClipboard
component embedded in this package.
<div class="CoveoSalesforceCopyToClipboard"></div>
Extending
Extending the component can be done as follows:
import { CopyToClipboard, ICopyToClipboardOptions } from "@coveops/copy-to-clipboard";
export interface IExtendedCopyToClipboardOptions extends ICopyToClipboardOptions {}
export class ExtendedCopyToClipboard extends CopyToClipboard {}
Contribute
- Clone the project
- Copy
.env.dist
to.env
and update the COVEO_ORG_ID and COVEO_TOKEN fields in the.env
file to use your Coveo credentials and SERVER_PORT to configure the port of the sandbox - it will use 8080 by default. - Build the code base:
npm run build
- Serve the sandbox for live development
npm run serve