Skip to content

Commit dc22fd1

Browse files
authored
feat(ActionBar): 新增 placeholder 属性 (#62)
* feat(ActionBar): 增加 placeholder 属性 * feat: 将renderPlaceholder抽象为hook
1 parent 7eb59c5 commit dc22fd1

File tree

7 files changed

+406
-939
lines changed

7 files changed

+406
-939
lines changed
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,45 @@
1-
import React, { useContext, useMemo } from 'react';
1+
import React, { useContext, useMemo, useRef } from 'react';
22
import classnames from 'classnames';
33
import { ActionBarProps } from './PropsType';
44
import ActionBarContext from './ActionBarContext';
55
import ConfigProviderContext from '../config-provider/ConfigProviderContext';
6+
import { usePlaceholder } from '../hooks/use-placeholder';
67

78
const ActionBar: React.FC<ActionBarProps> = (props) => {
89
const { prefixCls, createNamespace } = useContext(ConfigProviderContext);
910
const [bem] = createNamespace('action-bar', prefixCls);
11+
const root = useRef<HTMLDivElement>(null);
1012

1113
const children = useMemo(() => React.Children.toArray(props.children), [props.children]);
1214

13-
return (
15+
const renderPlaceholder = usePlaceholder(root, bem);
16+
17+
const renderActionBar = () => (
1418
<ActionBarContext.Provider value={{ parent: { children } }}>
1519
<div
20+
ref={root}
1621
className={classnames(props.className, bem(), {
1722
'rc-safe-area-bottom': props.safeAreaInsetBottom,
1823
})}
1924
style={props.style}
2025
>
2126
{React.Children.toArray(props.children)
2227
.filter(Boolean)
23-
.map((child: React.ReactFragment, index: number) => {
24-
// @ts-ignore
28+
.map((child: React.ReactElement, index: number) => {
2529
return React.cloneElement(child, {
2630
index,
2731
});
2832
})}
2933
</div>
3034
</ActionBarContext.Provider>
3135
);
36+
37+
return props.placeholder ? renderPlaceholder(renderActionBar) : renderActionBar();
3238
};
3339

3440
ActionBar.defaultProps = {
3541
safeAreaInsetBottom: true,
42+
placeholder: false,
3643
};
3744

3845
export default ActionBar;

packages/rc-ui-lib/src/action-bar/PropsType.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { BaseTypeProps } from '../utils';
66
export interface ActionBarProps extends BaseTypeProps {
77
/** 是否开启底部安全区适配 */
88
safeAreaInsetBottom?: boolean;
9+
/** 是否在标签位置生成一个等高的占位元素 */
10+
placeholder?: boolean;
911
/** 自元素 */
1012
children?: React.ReactNode;
1113
}

packages/rc-ui-lib/src/action-bar/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default () => {
7878
| 参数 | 说明 | 类型 | 默认值 |
7979
| --- | --- | --- | --- |
8080
| safeAreaInsetBottom | 是否开启[底部安全区适配](#/zh-CN/advanced-usage#di-bu-an-quan-qu-gua-pei) | _boolean_ | `true` |
81+
| placeholder | 是否在标签位置生成一个等高的占位元素 | _boolean_ | `false` |
8182

8283
### ActionBarIcon Props
8384

@@ -87,7 +88,7 @@ export default () => {
8788
| icon | 图标 | _string\|ReactNode_ | - |
8889
| color | 图标颜色 | _string_ | `#323233` |
8990
| iconClass | 图标额外类名 | _string_ | - |
90-
| icoPrefix | 图标类名前缀,等同于 Icon 组件的 [classPrefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
91+
| iconPrefix | 图标类名前缀,等同于 Icon 组件的 [classPrefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
9192
| badge | 图标右上角徽标设置 | _BadgeProps_ | - |
9293
| onClick | 点击事件 | _(event) => void_ | - |
9394

@@ -96,7 +97,7 @@ export default () => {
9697
| 参数 | 说明 | 类型 | 默认值 |
9798
| --- | --- | --- | --- |
9899
| text | 按钮文字 | _ReactNode_ | - |
99-
| type | 按钮类型,可选值为 `primary` `info` `warning` `danger` | _string_ | `default` |
100+
| type | 按钮类型,可选值为 `default` `primary` `info` `warning` `danger` | _string_ | `default` |
100101
| color | 按钮颜色,支持传入 `linear-gradient` 渐变色 | _string_ | - |
101102
| icon | 左侧[图标名称](#/zh-CN/icon)或图片链接 | _string_ | - |
102103
| disabled | 是否禁用按钮 | _boolean_ | `false` |

0 commit comments

Comments
 (0)