1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
3 | import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
4 | var __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 | };
|
14 | import classNames from 'classnames';
|
15 | import React, { useContext, useMemo } from 'react';
|
16 | import { ConfigContext } from '../config-provider';
|
17 | import useStyle from './style';
|
18 | import Tooltip from '../tooltip';
|
19 | import Content from './FloatButtonContent';
|
20 | import FloatButtonGroupContext from './context';
|
21 | import warning from '../_util/warning';
|
22 | export var floatButtonPrefixCls = 'float-btn';
|
23 | var 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 ? React.createElement(Tooltip, {
|
54 | title: tooltip,
|
55 | placement: "left"
|
56 | }, React.createElement("div", {
|
57 | className: prefixCls + "-body"
|
58 | }, React.createElement(Content, _extends({}, contentProps)))) : React.createElement("div", {
|
59 | className: prefixCls + "-body"
|
60 | }, 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 ? React.createElement("a", _extends({
|
65 | ref: ref
|
66 | }, restProps, {
|
67 | className: classString
|
68 | }), buttonNode) : React.createElement("button", _extends({
|
69 | ref: ref
|
70 | }, restProps, {
|
71 | className: classString,
|
72 | type: "button"
|
73 | }), buttonNode));
|
74 | };
|
75 | if (process.env.NODE_ENV !== 'production') {
|
76 | FloatButton.displayName = 'FloatButton';
|
77 | }
|
78 | var ForwardFloatButton = React.forwardRef(FloatButton);
|
79 | export default ForwardFloatButton; |
\ | No newline at end of file |