UNPKG

@uifabric/experiments

Version:

Experimental React components for building experiences for Microsoft 365.

39 lines 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); // `extends any` to trick the parser into parsing as a type decl instead of a jsx tag exports.CopyableItem = function (copyableItemProps) { return React.memo(function (selectedItemProps) { var onCopy = React.useCallback(function (item) { var copyText = copyableItemProps.getCopyItemText([item]); var copyInput = document.createElement('input'); document.body.appendChild(copyInput); try { // Try to copy the text directly to the clipboard copyInput.value = copyText; copyInput.select(); if (!document.execCommand('copy')) { // The command failed. Fallback to the method below. throw new Error(); } } catch (err) { // no op } finally { document.body.removeChild(copyInput); } }, // TODO: evaluate whether anything should be changed here based on warning: // "React Hook React.useCallback has an unnecessary dependency: 'copyableItemProps.getCopyItemText'. // Either exclude it or remove the dependency array. Outer scope values like // 'copyableItemProps.getCopyItemText' aren't valid dependencies because mutating them // doesn't re-render the component." // eslint-disable-next-line react-hooks/exhaustive-deps [copyableItemProps.getCopyItemText]); var ItemComponent = copyableItemProps.itemComponent; return React.createElement(ItemComponent, tslib_1.__assign({}, selectedItemProps, { onCopy: onCopy })); }); }; //# sourceMappingURL=CopyableItem.js.map