Skip to content

Commit b1ee4eb

Browse files
committed
新增 FloatButton 可自定义位置属性 position
1 parent ddf4ee8 commit b1ee4eb

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

@types/floatButton.d.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
import {ComponentClass} from "react";
2-
import {bgColorMoreType, bgColorType, iconType, lightBgColorType, normalSizeType} from "./baseType";
1+
import { ComponentClass } from "react";
2+
import { bgColorMoreType, bgColorType, iconType, lightBgColorType, normalSizeType } from "./baseType";
33

44
export interface IProps {
5+
/**
6+
* 初始化时 Button 的位置
7+
*
8+
* 默认 top: `auto`, right: `50`, bottom: `200`, left: `auto`
9+
*/
10+
position?: {
11+
top?: number | 'auto';
12+
right?: number | 'auto';
13+
bottom?: number | 'auto';
14+
left?: number | 'auto';
15+
}
516
/**
617
* 点击阴影关闭
718
*

src/components/floatButton/index.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Taro, { useState, useEffect } from '@tarojs/taro';
1+
import Taro, { useState, useEffect, pxTransform } from '@tarojs/taro';
22
import { View } from '@tarojs/components';
33
import utils, { generateId } from '../utils/index';
44
import { IProps } from '../../../@types/floatButton';
@@ -33,7 +33,7 @@ export default function ClFloatButton(props: IProps) {
3333
closeWithShadow
3434
} = props;
3535
useEffect(() => {
36-
const list = props.actionList || []
36+
const list = actionList || []
3737
setActionListState(list.map((item: any) => {
3838
item.cu_float_button_id = generateId()
3939
return item
@@ -97,6 +97,12 @@ export default function ClFloatButton(props: IProps) {
9797
>
9898
<View
9999
className='float_button__fixed'
100+
style={{
101+
top: props.position.top && props.position.top !== 'auto' ? pxTransform(props.position.top) : 'auto',
102+
right: props.position.right && props.position.right !== 'auto' ? pxTransform(props.position.right) : 'auto',
103+
bottom: props.position.bottom && props.position.bottom !== 'auto' ? pxTransform(props.position.bottom) : 'auto',
104+
left: props.position.left && props.position.left !== 'auto' ? pxTransform(props.position.left) : 'auto',
105+
}}
100106
animation={animation}
101107
onTouchStart={e => {
102108
if (!move) return;
@@ -163,9 +169,15 @@ ClFloatButton.defaultProps = {
163169
direction: 'vertical',
164170
onClick: () => { },
165171
shadow: true,
166-
onActionClick: (index: number) => { },
172+
onActionClick: () => { },
167173
actionList: [],
168174
size: 'normal',
169175
shape: 'round',
170-
closeWithShadow: false
176+
closeWithShadow: false,
177+
position: {
178+
top: 'auto',
179+
right: 50,
180+
bottom: 200,
181+
left: 'auto'
182+
}
171183
} as IProps;

0 commit comments

Comments
 (0)