|
1 |
| -import React, { useContext, useMemo } from 'react'; |
| 1 | +import React, { useContext, useMemo, useRef } from 'react'; |
2 | 2 | import classnames from 'classnames';
|
3 | 3 | import { ActionBarProps } from './PropsType';
|
4 | 4 | import ActionBarContext from './ActionBarContext';
|
5 | 5 | import ConfigProviderContext from '../config-provider/ConfigProviderContext';
|
| 6 | +import { usePlaceholder } from '../hooks/use-placeholder'; |
6 | 7 |
|
7 | 8 | const ActionBar: React.FC<ActionBarProps> = (props) => {
|
8 | 9 | const { prefixCls, createNamespace } = useContext(ConfigProviderContext);
|
9 | 10 | const [bem] = createNamespace('action-bar', prefixCls);
|
| 11 | + const root = useRef<HTMLDivElement>(null); |
10 | 12 |
|
11 | 13 | const children = useMemo(() => React.Children.toArray(props.children), [props.children]);
|
12 | 14 |
|
13 |
| - return ( |
| 15 | + const renderPlaceholder = usePlaceholder(root, bem); |
| 16 | + |
| 17 | + const renderActionBar = () => ( |
14 | 18 | <ActionBarContext.Provider value={{ parent: { children } }}>
|
15 | 19 | <div
|
| 20 | + ref={root} |
16 | 21 | className={classnames(props.className, bem(), {
|
17 | 22 | 'rc-safe-area-bottom': props.safeAreaInsetBottom,
|
18 | 23 | })}
|
19 | 24 | style={props.style}
|
20 | 25 | >
|
21 | 26 | {React.Children.toArray(props.children)
|
22 | 27 | .filter(Boolean)
|
23 |
| - .map((child: React.ReactFragment, index: number) => { |
24 |
| - // @ts-ignore |
| 28 | + .map((child: React.ReactElement, index: number) => { |
25 | 29 | return React.cloneElement(child, {
|
26 | 30 | index,
|
27 | 31 | });
|
28 | 32 | })}
|
29 | 33 | </div>
|
30 | 34 | </ActionBarContext.Provider>
|
31 | 35 | );
|
| 36 | + |
| 37 | + return props.placeholder ? renderPlaceholder(renderActionBar) : renderActionBar(); |
32 | 38 | };
|
33 | 39 |
|
34 | 40 | ActionBar.defaultProps = {
|
35 | 41 | safeAreaInsetBottom: true,
|
| 42 | + placeholder: false, |
36 | 43 | };
|
37 | 44 |
|
38 | 45 | export default ActionBar;
|
0 commit comments