UNPKG

@kisstar/rc-ui

Version:

UI component library built with React Hooks.

51 lines (50 loc) 2.33 kB
/* eslint-disable react/button-has-type */ var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { useContext } from 'react'; import classNames from 'classnames'; import { ConfigContext } from '../config-provider'; import { isUndef } from '../../lib/utils'; /** * 按钮用于开始一个即时操作。 * * 在 Rc-UI 中提供了三种按钮:主按钮、默认按钮、链接按钮,以及危险、禁用两种状态。 */ export var Button = function (props) { var _a; var htmlType = props.htmlType, type = props.type, size = props.size, href = props.href, danger = props.danger, className = props.className, children = props.children, customizePrefixCls = props.prefixCls, restProps = __rest(props, ["htmlType", "type", "size", "href", "danger", "className", "children", "prefixCls"]); var getPrefixCls = useContext(ConfigContext).getPrefixCls; var prefixCls = getPrefixCls('btn', customizePrefixCls); var classes = classNames(prefixCls, className, (_a = {}, _a[prefixCls + "-" + type] = type, _a[prefixCls + "-" + size] = size, _a[prefixCls + "-danger"] = danger, _a)); var linkNode = (React.createElement("a", __assign({ className: classes, href: href }, restProps), children)); var buttonNode = (React.createElement("button", __assign({ type: htmlType, className: classes }, restProps), children)); return isUndef(href) ? buttonNode : linkNode; }; Button.defaultProps = { htmlType: 'button', }; export default Button;