UNPKG

@pantheon-systems/design-toolkit-react

Version:
61 lines (58 loc) 2.8 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _slicedToArray from '@babel/runtime/helpers/slicedToArray'; import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties'; import PropTypes from 'prop-types'; import useClipboard from '../hooks/useClipboard.js'; import { jsx } from 'react/jsx-runtime'; var _excluded = ["children", "clipboardOptions", "clipboardText", "type"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } var typeStyles = { primary: 'button-primary', secondary: 'button-secondary', subtle: 'button-subtle', tertiary: 'button-tertiary' }; var ClipboardButton = function ClipboardButton(_ref) { var children = _ref.children, clipboardOptions = _ref.clipboardOptions, clipboardText = _ref.clipboardText, type = _ref.type, rest = _objectWithoutProperties(_ref, _excluded); var _useClipboard = useClipboard(clipboardText, clipboardOptions), _useClipboard2 = _slicedToArray(_useClipboard, 2), isCopied = _useClipboard2[0], setIsCopied = _useClipboard2[1]; var getChildContent = function getChildContent() { var props = { isCopied: isCopied }; if (typeof children === 'function') { return children(props); } return children; }; return /*#__PURE__*/jsx("button", _objectSpread(_objectSpread({ className: typeStyles[type] || '', onClick: setIsCopied, type: "button" }, rest), {}, { children: getChildContent() })); }; ClipboardButton.defaultProps = { clipboardOptions: {}, clipboardText: '', type: 'primary' }; ClipboardButton.propTypes = { children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired, clipboardOptions: PropTypes.shape({ duration: PropTypes.number }), clipboardText: PropTypes.string, type: PropTypes.oneOf(['primary', 'secondary', 'subtle', 'tertiary']) }; var ClipboardButton$1 = ClipboardButton; export { ClipboardButton$1 as default }; //# sourceMappingURL=ClipboardButton.js.map