UNPKG

@flatbiz/antd

Version:
99 lines (95 loc) 3.06 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import _CopyOutlined from '@ant-design/icons/es/icons/CopyOutlined.js'; import _CheckOutlined from '@ant-design/icons/es/icons/CheckOutlined.js'; import { a as _slicedToArray, b as _objectSpread2 } from './_rollupPluginBabelHelpers-BspM60Sw.js'; import { useState, useEffect, useMemo, Fragment } from 'react'; import { Flex, message } from 'antd'; import copy from 'copy-to-clipboard'; import { I as IconWrapper } from './icon-wrapper-DE97bI14.js'; import { jsx, jsxs } from 'react/jsx-runtime'; var CopyWrapper = function CopyWrapper(props) { var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), trigger = _useState2[0], setTrigger = _useState2[1]; var onClick = function onClick() { if (trigger) return; setTrigger(true); var copyText = typeof props.copyText === 'function' ? props.copyText() : props.copyText; copy(copyText); if (props.copyAfterMsg) { message.success(props.copyAfterMsg); } }; useEffect(function () { if (trigger) { setTimeout(function () { setTrigger(false); }, 1000); } }, [trigger]); var hoverTips = useMemo(function () { if (props.hiddenTips) return undefined; if (typeof props.hoverTips === 'function') { return props.hoverTips(trigger); } if (props.hoverTips) return props.hoverTips; return '复制'; }, [props, trigger]); if (!props.text) { return /*#__PURE__*/jsx(IconWrapper, { hoverTips: hoverTips, wrapperStyle: { display: 'inline-flex' }, text: trigger ? /*#__PURE__*/jsx(_CheckOutlined, { style: _objectSpread2({ color: 'var(--color-primary)' }, props.iconStyle) }) : props.icon ? /*#__PURE__*/jsx(Fragment, { children: props.icon }) : /*#__PURE__*/jsx(_CopyOutlined, { style: _objectSpread2({ color: 'var(--color-primary)' }, props.iconStyle) }), size: "small", onClick: onClick }); } return /*#__PURE__*/jsxs(Flex, { align: "center", gap: 5, style: { alignItems: 'center' }, children: [props.iconPosition !== 'left' ? /*#__PURE__*/jsx("div", { children: props.text }) : null, /*#__PURE__*/jsx(IconWrapper, { hoverTips: hoverTips, wrapperStyle: { display: 'inline-flex' }, text: trigger ? /*#__PURE__*/jsx(_CheckOutlined, { style: _objectSpread2({ color: 'var(--color-primary)' }, props.iconStyle) }) : props.icon ? /*#__PURE__*/jsx(Fragment, { children: props.icon }) : /*#__PURE__*/jsx(_CopyOutlined, { style: _objectSpread2({ color: 'var(--color-primary)' }, props.iconStyle) }), size: "small", onClick: onClick }), props.iconPosition === 'left' ? /*#__PURE__*/jsx("div", { children: props.text }) : null] }); }; CopyWrapper.copy = function (text) { copy(text); }; export { CopyWrapper as C }; //# sourceMappingURL=copy-BSlIwnwz.js.map