FloatButton.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { createVNode as _createVNode, resolveDirective as _resolveDirective } from "vue";
  3. var __rest = this && this.__rest || function (s, e) {
  4. var t = {};
  5. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  6. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  7. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  8. }
  9. return t;
  10. };
  11. import classNames from '../_util/classNames';
  12. import { defineComponent, computed, ref } from 'vue';
  13. import Tooltip from '../tooltip';
  14. import Badge from '../badge';
  15. import Content from './FloatButtonContent';
  16. import useConfigInject from '../config-provider/hooks/useConfigInject';
  17. import { useInjectFloatButtonGroupContext } from './context';
  18. import warning from '../_util/warning';
  19. import { initDefaultProps } from '../_util/props-util';
  20. import { floatButtonProps } from './interface';
  21. // import { useCompactItemContext } from '../space/Compact';
  22. // CSSINJS
  23. import useStyle from './style';
  24. export const floatButtonPrefixCls = 'float-btn';
  25. const FloatButton = defineComponent({
  26. compatConfig: {
  27. MODE: 3
  28. },
  29. name: 'AFloatButton',
  30. inheritAttrs: false,
  31. props: initDefaultProps(floatButtonProps(), {
  32. type: 'default',
  33. shape: 'circle'
  34. }),
  35. setup(props, _ref) {
  36. let {
  37. attrs,
  38. slots
  39. } = _ref;
  40. const {
  41. prefixCls,
  42. direction
  43. } = useConfigInject(floatButtonPrefixCls, props);
  44. const [wrapSSR, hashId] = useStyle(prefixCls);
  45. const {
  46. shape: groupShape
  47. } = useInjectFloatButtonGroupContext();
  48. const floatButtonRef = ref(null);
  49. const mergeShape = computed(() => {
  50. return (groupShape === null || groupShape === void 0 ? void 0 : groupShape.value) || props.shape;
  51. });
  52. return () => {
  53. var _a;
  54. const {
  55. prefixCls: customPrefixCls,
  56. type = 'default',
  57. shape = 'circle',
  58. description = (_a = slots.description) === null || _a === void 0 ? void 0 : _a.call(slots),
  59. tooltip,
  60. badge = {}
  61. } = props,
  62. restProps = __rest(props, ["prefixCls", "type", "shape", "description", "tooltip", "badge"]);
  63. const classString = classNames(prefixCls.value, `${prefixCls.value}-${type}`, `${prefixCls.value}-${mergeShape.value}`, {
  64. [`${prefixCls.value}-rtl`]: direction.value === 'rtl'
  65. }, attrs.class, hashId.value);
  66. const buttonNode = _createVNode(Tooltip, {
  67. "placement": "left"
  68. }, {
  69. title: slots.tooltip || tooltip ? () => slots.tooltip && slots.tooltip() || tooltip : undefined,
  70. default: () => _createVNode(Badge, badge, {
  71. default: () => [_createVNode("div", {
  72. "class": `${prefixCls.value}-body`
  73. }, [_createVNode(Content, {
  74. "prefixCls": prefixCls.value
  75. }, {
  76. icon: slots.icon,
  77. description: () => description
  78. })])]
  79. })
  80. });
  81. if (process.env.NODE_ENV !== 'production') {
  82. warning(!(shape === 'circle' && description), 'FloatButton', 'supported only when `shape` is `square`. Due to narrow space for text, short sentence is recommended.');
  83. }
  84. return wrapSSR(props.href ? _createVNode("a", _objectSpread(_objectSpread(_objectSpread({
  85. "ref": floatButtonRef
  86. }, attrs), restProps), {}, {
  87. "class": classString
  88. }), [buttonNode]) : _createVNode("button", _objectSpread(_objectSpread(_objectSpread({
  89. "ref": floatButtonRef
  90. }, attrs), restProps), {}, {
  91. "class": classString,
  92. "type": "button"
  93. }), [buttonNode]));
  94. };
  95. }
  96. });
  97. export default FloatButton;