UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

66 lines (62 loc) 1.82 kB
/** * MSKCC 2021, 2024 */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import PropTypes from 'prop-types'; import React__default from 'react'; import cx from 'classnames'; import { Copy as Copy$1 } from '@carbon/icons-react'; import Copy from '../Copy/Copy.js'; import { LayoutConstraint } from '../Layout/index.js'; import { usePrefix } from '../../internal/usePrefix.js'; function CopyButton(_ref) { let { iconDescription, className, ...other } = _ref; const prefix = usePrefix(); return /*#__PURE__*/React__default.createElement(LayoutConstraint, { size: { default: 'md', max: 'lg' } }, /*#__PURE__*/React__default.createElement(Copy, _extends({ className: cx(className, `${prefix}--copy-btn`), "aria-label": iconDescription }, other), /*#__PURE__*/React__default.createElement(Copy$1, { className: `${prefix}--snippet__icon` }))); } CopyButton.propTypes = { /** * Specify an optional className to be applied to the underlying `<button>` */ className: PropTypes.string, /** * Specify the string that is displayed when the button is clicked and the * content is copied */ feedback: PropTypes.string, /** * Specify the time it takes for the feedback message to timeout */ feedbackTimeout: PropTypes.number, /** * Provide a description for the icon representing the copy action that can * be read by screen readers */ iconDescription: PropTypes.string, /** * Specify an optional `onClick` handler that is called when the underlying * `<button>` is clicked */ onClick: PropTypes.func }; CopyButton.defaultProps = { iconDescription: 'Copy to clipboard', feedback: 'Copied!', feedbackTimeout: 2000, onClick: () => {} }; export { CopyButton as default };