tdesign-react
Version:
TDesign Component for React
115 lines (111 loc) • 5.65 kB
JavaScript
/**
* tdesign v1.15.1
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _defineProperty } from '../_chunks/dep-cb0a3966.js';
import { _ as _slicedToArray } from '../_chunks/dep-48805ab8.js';
import { _ as _objectWithoutProperties } from '../_chunks/dep-6b660ef0.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-eca3a3de.js';
import '../_chunks/dep-026a4c6b.js';
import '../config-provider/ConfigContext.js';
import 'lodash-es';
import '../locale/zh_CN.js';
import '../_chunks/dep-e29214cb.js';
import 'dayjs';
import '../_chunks/dep-3c9ab31a.js';
import '../_chunks/dep-c48e2ca1.js';
import '../hooks/useAnimation.js';
import '../_chunks/dep-3a09424a.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 '../_chunks/dep-f53c91cd.js';
import '../_chunks/dep-b908e1fe.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