2023-01-09 10:04:35 +08:00
|
|
|
import React, { useContext } from 'react';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { ConfigConsumerProps } from '.';
|
2023-06-07 11:54:50 +08:00
|
|
|
import { ConfigContext } from '.';
|
2022-06-22 14:57:09 +08:00
|
|
|
import Empty from '../empty';
|
2018-12-26 16:01:00 +08:00
|
|
|
|
2024-06-26 12:40:11 +08:00
|
|
|
type ComponentName =
|
|
|
|
| 'Table'
|
2024-07-03 22:54:21 +08:00
|
|
|
| 'Table.filter' /* 👈 5.20.0+ */
|
2024-06-26 12:40:11 +08:00
|
|
|
| 'List'
|
|
|
|
| 'Select'
|
|
|
|
| 'TreeSelect'
|
|
|
|
| 'Cascader'
|
|
|
|
| 'Transfer'
|
|
|
|
| 'Mentions';
|
|
|
|
|
2023-01-09 10:04:35 +08:00
|
|
|
interface EmptyProps {
|
2024-06-26 12:40:11 +08:00
|
|
|
componentName?: ComponentName;
|
2023-01-09 10:04:35 +08:00
|
|
|
}
|
2018-12-26 16:01:00 +08:00
|
|
|
|
2023-01-09 10:04:35 +08:00
|
|
|
const DefaultRenderEmpty: React.FC<EmptyProps> = (props) => {
|
|
|
|
const { componentName } = props;
|
|
|
|
const { getPrefixCls } = useContext<ConfigConsumerProps>(ConfigContext);
|
|
|
|
const prefix = getPrefixCls('empty');
|
|
|
|
switch (componentName) {
|
|
|
|
case 'Table':
|
|
|
|
case 'List':
|
|
|
|
return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />;
|
|
|
|
case 'Select':
|
|
|
|
case 'TreeSelect':
|
|
|
|
case 'Cascader':
|
|
|
|
case 'Transfer':
|
|
|
|
case 'Mentions':
|
|
|
|
return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} className={`${prefix}-small`} />;
|
2024-07-01 17:47:59 +08:00
|
|
|
/**
|
|
|
|
* This type of component should satisfy the nullish coalescing operator(??) on the left-hand side.
|
|
|
|
* to let the component itself implement the logic.
|
|
|
|
* For example `Table.filter`.
|
|
|
|
*/
|
|
|
|
case 'Table.filter':
|
|
|
|
// why `null`? legacy react16 node type `undefined` is not allowed.
|
|
|
|
return null;
|
2023-01-09 10:04:35 +08:00
|
|
|
default:
|
|
|
|
// Should never hit if we take all the component into consider.
|
|
|
|
return <Empty />;
|
|
|
|
}
|
|
|
|
};
|
2018-12-26 16:01:00 +08:00
|
|
|
|
2024-06-26 12:40:11 +08:00
|
|
|
export type RenderEmptyHandler = (componentName?: ComponentName) => React.ReactNode;
|
2022-05-16 16:34:42 +08:00
|
|
|
|
2023-01-09 10:04:35 +08:00
|
|
|
export default DefaultRenderEmpty;
|