UNPKG

3.58 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4var __rest = this && this.__rest || function (s, e) {
5 var t = {};
6 for (var p in s) {
7 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
8 }
9 if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
10 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
11 }
12 return t;
13};
14import classNames from 'classnames';
15import React, { useContext, useMemo } from 'react';
16import { ConfigContext } from '../config-provider';
17import useStyle from './style';
18import Tooltip from '../tooltip';
19import Content from './FloatButtonContent';
20import FloatButtonGroupContext from './context';
21import warning from '../_util/warning';
22export var floatButtonPrefixCls = 'float-btn';
23var FloatButton = function FloatButton(props, ref) {
24 var customizePrefixCls = props.prefixCls,
25 className = props.className,
26 _props$type = props.type,
27 type = _props$type === void 0 ? 'default' : _props$type,
28 _props$shape = props.shape,
29 shape = _props$shape === void 0 ? 'circle' : _props$shape,
30 icon = props.icon,
31 description = props.description,
32 tooltip = props.tooltip,
33 restProps = __rest(props, ["prefixCls", "className", "type", "shape", "icon", "description", "tooltip"]);
34 var _useContext = useContext(ConfigContext),
35 getPrefixCls = _useContext.getPrefixCls,
36 direction = _useContext.direction;
37 var groupShape = useContext(FloatButtonGroupContext);
38 var prefixCls = getPrefixCls(floatButtonPrefixCls, customizePrefixCls);
39 var _useStyle = useStyle(prefixCls),
40 _useStyle2 = _slicedToArray(_useStyle, 2),
41 wrapSSR = _useStyle2[0],
42 hashId = _useStyle2[1];
43 var mergeShape = groupShape || shape;
44 var classString = classNames(hashId, prefixCls, className, prefixCls + "-" + type, prefixCls + "-" + mergeShape, _defineProperty({}, prefixCls + "-rtl", direction === 'rtl'));
45 var contentProps = useMemo(function () {
46 return {
47 prefixCls: prefixCls,
48 description: description,
49 icon: icon,
50 type: type
51 };
52 }, [prefixCls, description, icon, type]);
53 var buttonNode = tooltip ? /*#__PURE__*/React.createElement(Tooltip, {
54 title: tooltip,
55 placement: "left"
56 }, /*#__PURE__*/React.createElement("div", {
57 className: prefixCls + "-body"
58 }, /*#__PURE__*/React.createElement(Content, _extends({}, contentProps)))) : /*#__PURE__*/React.createElement("div", {
59 className: prefixCls + "-body"
60 }, /*#__PURE__*/React.createElement(Content, _extends({}, contentProps)));
61 if (process.env.NODE_ENV !== 'production') {
62 process.env.NODE_ENV !== "production" ? warning(!(shape === 'circle' && description), 'FloatButton', 'supported only when `shape` is `square`. Due to narrow space for text, short sentence is recommended.') : void 0;
63 }
64 return wrapSSR(props.href ? /*#__PURE__*/React.createElement("a", _extends({
65 ref: ref
66 }, restProps, {
67 className: classString
68 }), buttonNode) : /*#__PURE__*/React.createElement("button", _extends({
69 ref: ref
70 }, restProps, {
71 className: classString,
72 type: "button"
73 }), buttonNode));
74};
75if (process.env.NODE_ENV !== 'production') {
76 FloatButton.displayName = 'FloatButton';
77}
78var ForwardFloatButton = /*#__PURE__*/React.forwardRef(FloatButton);
79export default ForwardFloatButton;
\No newline at end of file