UNPKG

@ant-design/x

Version:

Craft AI-driven interfaces effortlessly

39 lines 1.08 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { Button } from 'antd'; import classNames from 'classnames'; import * as React from 'react'; export const ActionButtonContext = /*#__PURE__*/React.createContext(null); export function ActionButton(props, ref) { const { className, action, onClick: outClick, ...restProps } = props; const context = React.useContext(ActionButtonContext); const { prefixCls, disabled: rootDisabled } = context; const onClick = context[action]; const mergedDisabled = rootDisabled ?? restProps.disabled ?? context[`${action}Disabled`]; return /*#__PURE__*/React.createElement(Button, _extends({ type: "text" }, restProps, { ref: ref, onClick: e => { if (!mergedDisabled) { if (onClick) { onClick(); } if (outClick) { outClick(e); } } }, className: classNames(prefixCls, className, { [`${prefixCls}-disabled`]: mergedDisabled }) })); } export default /*#__PURE__*/React.forwardRef(ActionButton);