UNPKG

@carbon/react

Version:

React components for the Carbon Design System

91 lines (89 loc) 2.35 kB
/** * Copyright IBM Corp. 2016, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { usePrefix } from "../../internal/usePrefix.js"; import { noopFn } from "../../internal/noopFn.js"; import { deprecateValuesWithin } from "../../prop-types/deprecateValuesWithin.js"; import { mapPopoverAlign } from "../../tools/mapPopoverAlign.js"; import Copy_default from "../Copy/index.js"; import { LayoutConstraint } from "../Layout/index.js"; import classNames from "classnames"; import "react"; import PropTypes from "prop-types"; import { jsx } from "react/jsx-runtime"; import { Copy } from "@carbon/icons-react"; //#region src/components/CopyButton/CopyButton.tsx /** * Copyright IBM Corp. 2016, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ function CopyButton({ align = "bottom", autoAlign = false, feedback = "Copied!", feedbackTimeout = 2e3, iconDescription = "Copy to clipboard", className, onClick = noopFn, ...other }) { const prefix = usePrefix(); return /* @__PURE__ */ jsx(LayoutConstraint, { size: { default: "md", max: "lg" }, children: /* @__PURE__ */ jsx(Copy_default, { feedback, feedbackTimeout, onClick, align, autoAlign, className: classNames(className, `${prefix}--copy-btn`), "aria-label": iconDescription, ...other, children: /* @__PURE__ */ jsx(Copy, { className: `${prefix}--snippet__icon` }) }) }); } CopyButton.propTypes = { align: deprecateValuesWithin(PropTypes.oneOf([ "top", "top-left", "top-right", "bottom", "bottom-left", "bottom-right", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "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), autoAlign: PropTypes.bool, className: PropTypes.string, feedback: PropTypes.string, feedbackTimeout: PropTypes.number, iconDescription: PropTypes.string, onClick: PropTypes.func }; //#endregion export { CopyButton as default };