2022-09-23 14:31:16 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
2023-08-08 19:48:41 +08:00
|
|
|
|
group: 通用
|
2022-09-23 14:31:16 +08:00
|
|
|
|
title: FloatButton
|
2024-03-22 14:22:42 +08:00
|
|
|
|
subtitle: 悬浮按钮
|
|
|
|
|
description: 悬浮于页面上方的按钮。
|
2024-01-29 14:50:36 +08:00
|
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*tXAoQqyr-ioAAAAAAAAAAAAADrJ8AQ/original
|
|
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*hSAwR7cnabwAAAAAAAAAAAAADrJ8AQ/original
|
2022-11-09 12:28:04 +08:00
|
|
|
|
demo:
|
|
|
|
|
cols: 2
|
2024-04-02 14:05:03 +08:00
|
|
|
|
tag: 5.0.0
|
2022-09-23 14:31:16 +08:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 何时使用
|
|
|
|
|
|
|
|
|
|
- 用于网站上的全局功能;
|
|
|
|
|
- 无论浏览到何处都可以看见的按钮。
|
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
|
## 代码演示
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
<!-- prettier-ignore -->
|
2022-11-17 11:30:20 +08:00
|
|
|
|
<code src="./demo/basic.tsx" iframe="360">基本</code>
|
|
|
|
|
<code src="./demo/type.tsx" iframe="360">类型</code>
|
|
|
|
|
<code src="./demo/shape.tsx" iframe="360">形状</code>
|
|
|
|
|
<code src="./demo/description.tsx" iframe="360">描述</code>
|
|
|
|
|
<code src="./demo/tooltip.tsx" iframe="360">含有气泡卡片的悬浮按钮</code>
|
|
|
|
|
<code src="./demo/group.tsx" iframe="360">浮动按钮组</code>
|
|
|
|
|
<code src="./demo/group-menu.tsx" iframe="360">菜单模式</code>
|
2023-06-12 17:20:55 +08:00
|
|
|
|
<code src="./demo/controlled.tsx" iframe="360">受控模式</code>
|
2022-11-17 11:30:20 +08:00
|
|
|
|
<code src="./demo/back-top.tsx" iframe="360">回到顶部</code>
|
2023-03-20 10:28:20 +08:00
|
|
|
|
<code src="./demo/badge.tsx" iframe="360">徽标数</code>
|
|
|
|
|
<code src="./demo/badge-debug.tsx" iframe="360" debug>调试小圆点使用</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/render-panel.tsx" debug>\_InternalPanelDoNotUseOrYouWillBeFired</code>
|
|
|
|
|
|
2022-09-23 14:31:16 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2023-08-08 18:27:48 +08:00
|
|
|
|
通用属性参考:[通用属性](/docs/react/common-props)
|
|
|
|
|
|
2022-11-27 17:39:35 +08:00
|
|
|
|
> 自 `antd@5.0.0` 版本开始提供该组件。
|
|
|
|
|
|
2022-09-23 14:31:16 +08:00
|
|
|
|
### 共同的 API
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| icon | 自定义图标 | ReactNode | - | |
|
|
|
|
|
| description | 文字及其它内容 | ReactNode | - | |
|
|
|
|
|
| tooltip | 气泡卡片的内容 | ReactNode \| () => ReactNode | - | |
|
|
|
|
|
| type | 设置按钮类型 | `default` \| `primary` | `default` | |
|
|
|
|
|
| shape | 设置按钮形状 | `circle` \| `square` | `circle` | |
|
|
|
|
|
| onClick | 点击按钮时的回调 | (event) => void | - | |
|
|
|
|
|
| href | 点击跳转的地址,指定此属性 button 的行为和 a 链接一致 | string | - | |
|
|
|
|
|
| target | 相当于 a 标签的 target 属性,href 存在时生效 | string | - | |
|
2023-03-21 14:11:39 +08:00
|
|
|
|
| badge | 带徽标数字的悬浮按钮(不支持 `status` 以及相关属性) | [BadgeProps](/components/badge-cn#api) | - | 5.4.0 |
|
2022-09-23 14:31:16 +08:00
|
|
|
|
|
|
|
|
|
### FloatButton.Group
|
|
|
|
|
|
2023-06-12 17:20:55 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| shape | 设置包含的 FloatButton 按钮形状 | `circle` \| `square` | `circle` | |
|
|
|
|
|
| trigger | 触发方式(有触发方式为菜单模式) | `click` \| `hover` | - | |
|
|
|
|
|
| open | 受控展开,需配合 trigger 一起使用 | boolean | - | |
|
2024-01-31 10:01:54 +08:00
|
|
|
|
| closeIcon | 自定义关闭按钮 | React.ReactNode | `<CloseOutlined />` | |
|
2023-06-12 17:20:55 +08:00
|
|
|
|
| onOpenChange | 展开收起时的回调,需配合 trigger 一起使用 | (open: boolean) => void | - | |
|
2022-09-23 14:31:16 +08:00
|
|
|
|
|
|
|
|
|
### FloatButton.BackTop
|
|
|
|
|
|
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| ---------------- | ---------------------------------- | ----------------- | ------------ | ---- |
|
|
|
|
|
| duration | 回到顶部所需时间(ms) | number | 450 | |
|
|
|
|
|
| target | 设置需要监听其滚动事件的元素 | () => HTMLElement | () => window | |
|
|
|
|
|
| visibilityHeight | 滚动高度达到此参数值才出现 BackTop | number | 400 | |
|
|
|
|
|
| onClick | 点击按钮的回调函数 | () => void | - | |
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
2023-08-30 23:02:35 +08:00
|
|
|
|
## 主题变量(Design Token)
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="FloatButton"></ComponentTokenTable>
|