@carbon/react
Version:
React components for the Carbon Design System
114 lines (102 loc) • 3.94 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var PropTypes = require('prop-types');
var React = require('react');
var cx = require('classnames');
var iconsReact = require('@carbon/icons-react');
var Copy = require('../Copy/Copy.js');
var index = require('../Layout/index.js');
var usePrefix = require('../../internal/usePrefix.js');
var noopFn = require('../../internal/noopFn.js');
var deprecateValuesWithin = require('../../prop-types/deprecateValuesWithin.js');
var mapPopoverAlign = require('../../tools/mapPopoverAlign.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
function CopyButton({
align = 'bottom',
autoAlign = false,
feedback = 'Copied!',
feedbackTimeout = 2000,
iconDescription = 'Copy to clipboard',
className,
onClick = noopFn.noopFn,
...other
}) {
const prefix = usePrefix.usePrefix();
return /*#__PURE__*/React__default["default"].createElement(index.LayoutConstraint, {
size: {
default: 'md',
max: 'lg'
}
}, /*#__PURE__*/React__default["default"].createElement(Copy["default"], _rollupPluginBabelHelpers["extends"]({
feedback: feedback,
feedbackTimeout: feedbackTimeout,
onClick: onClick,
align: align,
autoAlign: autoAlign,
className: cx__default["default"](className, `${prefix}--copy-btn`),
"aria-label": iconDescription
}, other), /*#__PURE__*/React__default["default"].createElement(iconsReact.Copy, {
className: `${prefix}--snippet__icon`
})));
}
CopyButton.propTypes = {
/**
* Specify how the trigger should align with the tooltip
*/
align: deprecateValuesWithin["default"](PropTypes__default["default"].oneOf(['top', 'top-left',
// deprecated use top-start instead
'top-right',
// deprecated use top-end instead
'bottom', 'bottom-left',
// deprecated use bottom-start instead
'bottom-right',
// deprecated use bottom-end instead
'left', 'left-bottom',
// deprecated use left-end instead
'left-top',
// deprecated use left-start instead
'right', 'right-bottom',
// deprecated use right-end instead
'right-top',
// deprecated use right-start instead
// new values to match floating-ui
'top-start', 'top-end', 'bottom-start', 'bottom-end', 'left-end', 'left-start', 'right-end', 'right-start']), ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end'], mapPopoverAlign.mapPopoverAlign),
/**
* **Experimental**: Will attempt to automatically align the tooltip
*/
autoAlign: PropTypes__default["default"].bool,
/**
* Specify an optional className to be applied to the underlying `<button>`
*/
className: PropTypes__default["default"].string,
/**
* Specify the string that is displayed when the button is clicked and the
* content is copied
*/
feedback: PropTypes__default["default"].string,
/**
* Specify the time it takes for the feedback message to timeout
*/
feedbackTimeout: PropTypes__default["default"].number,
/**
* Provide a description for the icon representing the copy action that can
* be read by screen readers
*/
iconDescription: PropTypes__default["default"].string,
/**
* Specify an optional `onClick` handler that is called when the underlying
* `<button>` is clicked
*/
onClick: PropTypes__default["default"].func
};
exports["default"] = CopyButton;