UNPKG

tdesign-react

Version:
109 lines (105 loc) 5.45 kB
/** * tdesign v1.13.2 * (c) 2025 tdesign * @license MIT */ import { _ as _defineProperty } from '../_chunks/dep-8618a2f1.js'; import { _ as _slicedToArray } from '../_chunks/dep-118954e6.js'; import { _ as _objectWithoutProperties } from '../_chunks/dep-30ed04a0.js'; import React, { forwardRef, useMemo } from 'react'; import classNames from 'classnames'; import useConfig from '../hooks/useConfig.js'; import useDomRefCallback from '../hooks/useDomRefCallback.js'; import useRipple from '../hooks/useRipple.js'; import { Loading } from '../loading/index.js'; import { buttonDefaultProps } from './defaultProps.js'; import parseTNode from '../_util/parseTNode.js'; import useDefaultProps from '../hooks/useDefaultProps.js'; import '../_chunks/dep-c37cc2fd.js'; import '../_chunks/dep-61f5e3d1.js'; import '../config-provider/ConfigContext.js'; import 'lodash-es'; import '../_chunks/dep-698f8ddd.js'; import '../_chunks/dep-09955460.js'; import 'dayjs'; import '../_chunks/dep-fab491d8.js'; import '../hooks/useAnimation.js'; import '../_chunks/dep-82b8abc2.js'; import '../loading/Loading.js'; import '../common/Portal.js'; import 'react-dom'; import '../hooks/useLayoutEffect.js'; import '../loading/gradient.js'; import '../_chunks/dep-ce8ef9b5.js'; import '../_chunks/dep-132961ab.js'; import '../loading/defaultProps.js'; import '../loading/plugin.js'; import '../_util/react-render.js'; import '../_chunks/dep-e78f641d.js'; import '../common/PluginContainer.js'; import '../config-provider/ConfigProvider.js'; import '../_chunks/dep-d104053f.js'; var _excluded = ["type", "theme", "variant", "icon", "disabled", "loading", "size", "block", "ghost", "shape", "children", "content", "className", "suffix", "href", "tag", "onClick"]; 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 Button = /*#__PURE__*/forwardRef(function (originProps, ref) { var props = useDefaultProps(originProps, buttonDefaultProps); var type = props.type, theme = props.theme, variant = props.variant, icon = props.icon, disabled = props.disabled, loading = props.loading, size = props.size, block = props.block, ghost = props.ghost, shape = props.shape, children = props.children, content = props.content, className = props.className, suffix = props.suffix, href = props.href, tag = props.tag, onClick = props.onClick, buttonProps = _objectWithoutProperties(props, _excluded); var _useConfig = useConfig(), classPrefix = _useConfig.classPrefix; var _useDomRefCallback = useDomRefCallback(), _useDomRefCallback2 = _slicedToArray(_useDomRefCallback, 2), btnDom = _useDomRefCallback2[0], setRefCurrent = _useDomRefCallback2[1]; useRipple((ref === null || ref === void 0 ? void 0 : ref.current) || btnDom); var renderChildren = content !== null && content !== void 0 ? content : children; var iconNode = icon; if (loading) iconNode = /* @__PURE__ */React.createElement(Loading, { loading: loading, inheritColor: true }); var renderTheme = useMemo(function () { if (!theme) { if (variant === "base") return "primary"; return "default"; } return theme; }, [theme, variant]); var renderTag = useMemo(function () { if (!tag && href && !disabled) return "a"; if (!tag && disabled) return "div"; return tag || "button"; }, [tag, href, disabled]); return /*#__PURE__*/React.createElement(renderTag, _objectSpread(_objectSpread({}, buttonProps), {}, { href: href, type: type, ref: ref || setRefCurrent, disabled: disabled || loading, className: classNames(className, ["".concat(classPrefix, "-button"), "".concat(classPrefix, "-button--theme-").concat(renderTheme), "".concat(classPrefix, "-button--variant-").concat(variant)], _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(classPrefix, "-button--shape-").concat(shape), shape !== "rectangle"), "".concat(classPrefix, "-button--ghost"), ghost), "".concat(classPrefix, "-is-loading"), loading), "".concat(classPrefix, "-is-disabled"), disabled), "".concat(classPrefix, "-size-s"), size === "small"), "".concat(classPrefix, "-size-l"), size === "large"), "".concat(classPrefix, "-size-full-width"), block)), onClick: !disabled && !loading ? onClick : void 0 }), /* @__PURE__ */React.createElement(React.Fragment, null, iconNode, renderChildren && /* @__PURE__ */React.createElement("span", { className: "".concat(classPrefix, "-button__text") }, renderChildren), suffix && /* @__PURE__ */React.createElement("span", { className: "".concat(classPrefix, "-button__suffix") }, parseTNode(suffix)))); }); Button.displayName = "Button"; export { Button as default }; //# sourceMappingURL=Button.js.map