UNPKG

tdesign-react

Version:
207 lines (203 loc) 9.37 kB
/** * tdesign v1.15.1 * (c) 2025 tdesign * @license MIT */ import { _ as _defineProperty } from '../_chunks/dep-cb0a3966.js'; import { _ as _objectWithoutProperties } from '../_chunks/dep-6b660ef0.js'; import { _ as _slicedToArray } from '../_chunks/dep-48805ab8.js'; import React, { forwardRef, useRef, useState } from 'react'; import classNames from 'classnames'; import { CheckIcon, CopyIcon } from 'tdesign-icons-react'; import Ellipsis from './ellipsis/Ellipsis.js'; import useConfig from '../hooks/useConfig.js'; import useEllipsis from './ellipsis/useEllipsis.js'; import Button from '../button/Button.js'; import { Tooltip } from '../tooltip/index.js'; import { useLocaleReceiver } from '../locale/LocalReceiver.js'; import useDefaultProps from '../hooks/useDefaultProps.js'; import { textDefaultProps } from './defaultProps.js'; import copyText from '../_util/copyText.js'; import '../_chunks/dep-eca3a3de.js'; import '../_chunks/dep-026a4c6b.js'; import './ellipsis/Truncate.js'; import '../_chunks/dep-83726008.js'; import 'lodash-es'; import '../_chunks/dep-e29214cb.js'; import 'react-is'; import '../config-provider/ConfigContext.js'; import '../locale/zh_CN.js'; import 'dayjs'; import '../_chunks/dep-3c9ab31a.js'; import '../hooks/useDomRefCallback.js'; import '../hooks/useRipple.js'; import '../_chunks/dep-c48e2ca1.js'; import '../hooks/useAnimation.js'; import '../_chunks/dep-3a09424a.js'; import '../loading/index.js'; import '../loading/Loading.js'; import '../common/Portal.js'; import 'react-dom'; import '../hooks/useLayoutEffect.js'; import '../loading/gradient.js'; import '../_chunks/dep-1630b9b4.js'; import '../_chunks/dep-87d110df.js'; import '../loading/defaultProps.js'; import '../loading/plugin.js'; import '../_util/react-render.js'; import '../_chunks/dep-a74cc5e4.js'; import '../common/PluginContainer.js'; import '../config-provider/index.js'; import '../config-provider/ConfigProvider.js'; import '../config-provider/type.js'; import '../loading/style/css.js'; import '../loading/type.js'; import '../button/defaultProps.js'; import '../_util/parseTNode.js'; import '../_chunks/dep-f53c91cd.js'; import '../_chunks/dep-b908e1fe.js'; import '../tooltip/Tooltip.js'; import '../popup/index.js'; import '../popup/Popup.js'; import 'react-transition-group'; import '../_util/ref.js'; import '../_util/isFragment.js'; import '../hooks/useAttach.js'; import '../hooks/useControlled.js'; import '../_util/noop.js'; import '../hooks/useMutationObserver.js'; import '../hooks/useLatest.js'; import '../hooks/usePopper.js'; import '@popperjs/core'; import 'react-fast-compare'; import '../hooks/useWindowSize.js'; import '../popup/defaultProps.js'; import '../popup/hooks/useTrigger.js'; import '../_util/composeRefs.js'; import '../_util/listener.js'; import '../popup/utils/transition.js'; import '../popup/PopupPlugin.js'; import '../popup/style/css.js'; import '../popup/type.js'; import '../tooltip/defaultProps.js'; import '../tooltip/TooltipLite.js'; import '../hooks/useSwitch.js'; import '../hooks/usePersistFn.js'; import '../tooltip/style/css.js'; import '../tooltip/type.js'; var _excluded = ["theme", "disabled", "className", "copyable", "strong", "mark", "code", "keyboard", "underline", "delete", "italic", "children", "ellipsis"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var Text = /*#__PURE__*/forwardRef(function (originalProps, ref) { var _copyable$onCopy, _copyable$tooltipProp; var _useConfig = useConfig(), classPrefix = _useConfig.classPrefix; var props = useDefaultProps(originalProps, textDefaultProps); var prefixCls = "".concat(classPrefix, "-typography"); var _useLocaleReceiver = useLocaleReceiver("typography"), _useLocaleReceiver2 = _slicedToArray(_useLocaleReceiver, 2), local = _useLocaleReceiver2[0], t = _useLocaleReceiver2[1]; var copiedText = t(local.copiedText); var theme = props.theme, disabled = props.disabled, className = props.className, copyable = props.copyable, strong = props.strong, mark = props.mark, code = props.code, keyboard = props.keyboard, underline = props.underline, deleteProp = props["delete"], italic = props.italic, children = props.children, ellipsis = props.ellipsis, rest = _objectWithoutProperties(props, _excluded); var getComponent = function getComponent() { var _Object$entries$find; var componentMap = { strong: !!strong, mark: !!mark, code: !!code, kbd: !!keyboard, u: !!underline, del: !!deleteProp, i: !!italic }; return (_Object$entries$find = Object.entries(componentMap).find(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), condition = _ref2[1]; return !!condition; })) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[0]; }; var currentRef = useRef(null); var _useEllipsis = useEllipsis(ellipsis), ellipsisProps = _useEllipsis.ellipsisProps; var Component = getComponent(); var textEllipsisProps = _objectSpread({}, ellipsisProps); var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), isCopied = _useState2[0], setIsCopied = _useState2[1]; var copyProps = typeof copyable === "boolean" ? { text: children.toString(), onCopy: Function.prototype, tooltipProps: isCopied ? { content: copiedText } : null } : { text: (copyable === null || copyable === void 0 ? void 0 : copyable.text) || children.toString(), onCopy: copyable === null || copyable === void 0 || (_copyable$onCopy = copyable.onCopy) === null || _copyable$onCopy === void 0 ? void 0 : _copyable$onCopy.call(copyable), tooltipProps: _objectSpread(_objectSpread({}, copyable === null || copyable === void 0 ? void 0 : copyable.tooltipProps), {}, { content: isCopied ? copiedText : copyable === null || copyable === void 0 || (_copyable$tooltipProp = copyable.tooltipProps) === null || _copyable$tooltipProp === void 0 ? void 0 : _copyable$tooltipProp.content }), suffix: copyable === null || copyable === void 0 ? void 0 : copyable.suffix }; var handleCopy = function handleCopy() { copyText(copyProps === null || copyProps === void 0 ? void 0 : copyProps.text); setIsCopied(true); setTimeout(function () { setIsCopied(false); }, 1500); if (typeof copyProps.onCopy === "function") copyProps.onCopy(); }; var renderContent = function renderContent(withChildren) { var tooltipProps = copyProps.tooltipProps; var wrapWithTooltip = function wrapWithTooltip(wrapContent) { return tooltipProps ? /* @__PURE__ */React.createElement(Tooltip, _objectSpread({}, tooltipProps), wrapContent) : wrapContent; }; var getSuffix = function getSuffix() { if (typeof (copyProps === null || copyProps === void 0 ? void 0 : copyProps.suffix) === "function") { return copyProps.suffix({ copied: isCopied }); } return isCopied ? /* @__PURE__ */React.createElement(CheckIcon, null) : /* @__PURE__ */React.createElement(CopyIcon, null); }; return /* @__PURE__ */React.createElement(React.Fragment, null, withChildren ? children : null, copyable ? wrapWithTooltip(/* @__PURE__ */React.createElement(Button, { shape: "square", theme: "primary", variant: "text", icon: getSuffix(), onClick: handleCopy })) : null); }; if (!ellipsis) { return Component ? /* @__PURE__ */React.createElement("span", _objectSpread({ className: classNames(className, prefixCls), ref: ref || currentRef }, rest), /* @__PURE__ */React.createElement(Component, null, renderContent(true))) : /* @__PURE__ */React.createElement("span", _objectSpread({ className: classNames(className, _defineProperty(_defineProperty({}, "".concat(prefixCls, "--").concat(theme), theme), "".concat(prefixCls, "--disabled"), disabled)) }, rest), renderContent(true)); } return /* @__PURE__ */React.createElement(React.Fragment, null, Component ? /* @__PURE__ */React.createElement("span", _objectSpread({ className: classNames(className, prefixCls), ref: ref || currentRef }, rest), /* @__PURE__ */React.createElement(Ellipsis, _objectSpread(_objectSpread({}, textEllipsisProps), {}, { component: Component }), children)) : /* @__PURE__ */React.createElement(Ellipsis, _objectSpread(_objectSpread({}, textEllipsisProps), {}, { className: classNames(className, _defineProperty(_defineProperty({}, "".concat(prefixCls, "--").concat(theme), theme), "".concat(prefixCls, "--disabled"), disabled)) }, rest), children), renderContent(false)); }); export { Text as default }; //# sourceMappingURL=Text.js.map