@wix/design-system
Version:
@wix/design-system
16 lines • 1.4 kB
JavaScript
import React from 'react';
import { Duplicate, DuplicateSmall } from '@wix/wix-ui-icons-common';
import CopyClipboard from '../../CopyClipboard/CopyClipboard';
import Tooltip from '../../Tooltip/Tooltip';
import { st, classes } from './CopyButton.st.css.js';
import { COPY_BUTTON_SIZE, COPY_RESET_TIMEOUT_MS, DEFAULT_TOOLTIP_COPIED, DEFAULT_TOOLTIP_IDLE, } from '../CodeSnippet.constants';
const CopyButton = ({ variant, size = COPY_BUTTON_SIZE.medium, value, copyTooltipText = DEFAULT_TOOLTIP_IDLE, copiedTooltipText = DEFAULT_TOOLTIP_COPIED, tooltipProps, onCopy, describedById, dataHook, }) => (React.createElement(CopyClipboard, { value: value, onCopy: () => onCopy?.(value), resetTimeout: COPY_RESET_TIMEOUT_MS }, ({ isCopied, copyToClipboard }) => {
const tooltipLabel = isCopied ? copiedTooltipText : copyTooltipText;
const Icon = size === COPY_BUTTON_SIZE.small ? DuplicateSmall : Duplicate;
return (React.createElement(Tooltip, { appendTo: "window", ...tooltipProps, content: tooltipLabel, "aria-describedby": describedById },
React.createElement("button", { type: "button", className: st(classes.root, { variant, size }), onClick: copyToClipboard, "aria-label": tooltipLabel, "data-hook": dataHook },
React.createElement(Icon, null))));
}));
CopyButton.displayName = 'CodeSnippet.CopyButton';
export default CopyButton;
//# sourceMappingURL=CopyButton.js.map