{"id":15388215,"url":"https://github.com/georapbox/clipboard-copy-element","last_synced_at":"2025-04-15T17:33:37.179Z","repository":{"id":57682366,"uuid":"479467555","full_name":"georapbox/clipboard-copy-element","owner":"georapbox","description":"A custom element that implements the Clipboard API to copy text content from elements or input values to the clipboard.","archived":false,"fork":false,"pushed_at":"2024-08-27T15:35:13.000Z","size":745,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T20:01:52.489Z","etag":null,"topics":["custom-elements","web-components"],"latest_commit_sha":null,"homepage":"https://georapbox.github.io/clipboard-copy-element/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/georapbox.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-08T16:42:32.000Z","updated_at":"2024-08-27T15:35:17.000Z","dependencies_parsed_at":"2024-08-22T12:05:52.292Z","dependency_job_id":"54008cce-a05e-4e55-b09c-5eb0a92c21c0","html_url":"https://github.com/georapbox/clipboard-copy-element","commit_stats":{"total_commits":43,"total_committers":1,"mean_commits":43.0,"dds":0.0,"last_synced_commit":"8ee7a94e5d70361d1d16f5f71be996375a8f5755"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georapbox%2Fclipboard-copy-element","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georapbox%2Fclipboard-copy-element/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georapbox%2Fclipboard-copy-element/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georapbox%2Fclipboard-copy-element/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/georapbox","download_url":"https://codeload.github.com/georapbox/clipboard-copy-element/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249119060,"owners_count":21215666,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom-elements","web-components"],"created_at":"2024-10-01T14:55:59.484Z","updated_at":"2025-04-15T17:33:36.867Z","avatar_url":"https://github.com/georapbox.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://img.shields.io/npm/v/@georapbox/clipboard-copy-element.svg)](https://www.npmjs.com/package/@georapbox/clipboard-copy-element)\n[![npm license](https://img.shields.io/npm/l/@georapbox/clipboard-copy-element.svg)](https://www.npmjs.com/package/@georapbox/clipboard-copy-element)\n\n[demo]: https://georapbox.github.io/clipboard-copy-element/\n[license]: https://github.com/georapbox/clipboard-copy-element/blob/main/LICENSE\n[changelog]: https://github.com/georapbox/clipboard-copy-element/blob/main/CHANGELOG.md\n\n# \u0026lt;clipboard-copy\u0026gt;\n\nA custom element that implements the [Clipboard API](https://developer.mozilla.org/docs/Web/API/Clipboard_API) to copy text content from elements or input values to the clipboard.\n\n[API documentation](#api) \u0026bull; [Demo][demo]\n\n## Install\n\n```sh\n$ npm install --save @georapbox/clipboard-copy-element\n```\n\n## Usage\n\n### Script\n\n```js\nimport { ClipboardCopy } from './node_modules/@georapbox/clipboard-copy-element/dist/clipboard-copy.js';\n\n// Manually define the element.\nClipboardCopy.defineCustomElement();\n```\n\nAlternatively, you can import the automatically defined custom element.\n\n```js\nimport './node_modules/@georapbox/clipboard-copy-element/dist/clipboard-copy-defined.js';\n```\n\n### Markup\n\n```html\n\u003cclipboard-copy value=\"Text to copy\"\u003e\u003c/clipboard-copy\u003e\n```\n\n### Style\n\nBy default, the component is style-free to remain as less opinionated as possible. However, you can style the various elements of the component using the `::part()` CSS pseudo-elements provided for this purpose. Below are demonstrated all available parts for styling.\n\n```css\nclipboard-copy::part(button) {\n  /* The button element */\n}\n\nclipboard-copy::part(button--disabled) {\n  /* The button element - disabled state */\n}\n\nclipboard-copy::part(button--success) {\n  /* The button element - success state */\n}\n\nclipboard-copy::part(button--error) {\n  /* The button element - error state */\n}\n```\n\n## API\n\n### Properties\n| Name | Reflects | Type | Default | Description |\n| ---- | -------- | ---- | ------- | ----------- |\n| `value` | ✓ | String | `\"\"` | Optional. The value to be copied to clipboard. |\n| `from` | ✓ | String | `\"\"` | Optional. A valid CSS selector string to target the first element within the document that matches this selector. If the element is `HTMLInputElement` or `HTMLTextAreaElement` the `value` attribute of the element will be copied. If the element is `HTMLAnchorElement` the `href` attribute of the element will be copied. In any other case, the `textContent` of the element will be copied. If both `value` and `from` properties are set, the `value` property will take precedence over the `from` property. |\n| `disabled` | ✓ | Boolean | `false` | Optional. Defines if the copy button is disabled. |\n| `feedbackDuration`\u003cbr\u003e*`feedback-duration`* | ✓ | Number | 1000 | The duration (in milliseconds) that the feedback is displayed before restoring the default button's content. |\n\nAll of the above properties reflect their values as HTML attributes to keep the element's DOM representation in sync with its JavaScript state.\n\n### Slots\n\n| Name | Default | Description |\n| ---- | ------- | ----------- |\n| `copy` | \"Copy\" | Override the button's default content. Example: `\u003cspan slot=\"copy\"\u003eCopy text\u003c/span\u003e` |\n| `success` | \"Copied!\" | Override the button's feedback for success. Example: `\u003cspan slot=\"success\"\u003eCopied successfully!\u003c/span\u003e` |\n| `error` | \"Error\" | Override the button's feedback for error. Example: `\u003cspan slot=\"error\"\u003eCould not copy!\u003c/span\u003e` |\n\n### CSS Parts\n\n| Name | Description |\n| ---- | ----------- |\n| `button` | Represents the button element. |\n| `button--disabled` | Represents the disabled state of the button. |\n| `button--success` | Represents the success state of the button. |\n| `button--error` | Represents the error state of the button. |\n\n### Events\n\n| Name | Description | Event Detail |\n| ---- | ----------- | ------------ |\n| `clipboard-copy-success` | Emitted when copy is successful. | `{ value: String }` |\n| `clipboard-copy-error` | Emitted when copy fails for any reason. | `{ error: DOMException }` |\n\n### Methods\n\n| Name | Type | Description | Arguments |\n| ---- | ---- | ----------- | --------- |\n| `defineCustomElement` | Static | Defines/registers the custom element with the name provided. If no name is provided, the default name is used. The method checks if the element is already defined, hence will skip trying to redefine it. | `elementName='clipboard-copy'` |\n\n## Changelog\n\nFor API updates and breaking changes, check the [CHANGELOG][changelog].\n\n## Development setup\n\n### Prerequisites\n\nThe project requires `Node.js` and `npm` to be installed on your environment. Preferrably, use [nvm](https://github.com/nvm-sh/nvm) Node Version Manager and use the version of Node.js specified in the `.nvmrc` file by running `nvm use`.\n\n### Install dependencies\n\nInstall the project dependencies by running the following command.\n\n```sh\nnpm install\n```\n\n### Build for development\n\nWatch for changes and start a development server by running the following command.\n\n```sh\nnpm start\n```\n\n### Linting\n\nLint the code by running the following command.\n\n```sh\nnpm run lint\n```\n\n### Testing\n\nRun the tests by running any of the following commands.\n\n```sh\nnpm test\nnpm run test:watch # watch mode\n```\n\n### Build for production\n\nCreate a production build by running the following command.\n\n```sh\nnpm run build\n```\n\n## License\n\n[The MIT License (MIT)][license]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorapbox%2Fclipboard-copy-element","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeorapbox%2Fclipboard-copy-element","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorapbox%2Fclipboard-copy-element/lists"}