UNPKG

@uifabric/experiments

Version:

Experimental React components for building experiences for Microsoft 365.

37 lines 1.78 kB
import { __assign } from "tslib"; import * as React from 'react'; // `extends any` to trick the parser into parsing as a type decl instead of a jsx tag export var 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, __assign({}, selectedItemProps, { onCopy: onCopy })); }); }; //# sourceMappingURL=CopyableItem.js.map