style: button for empty

This commit is contained in:
jialin
2025-11-27 15:53:23 +08:00
parent 962df859f1
commit d1c1132e6e
9 changed files with 64 additions and 55 deletions
+22 -3
View File
@@ -1,4 +1,4 @@
import { Empty, EmptyProps, Typography } from 'antd';
import { Button, Empty, EmptyProps, Typography } from 'antd';
import _ from 'lodash';
import React, { useMemo } from 'react';
import styled from 'styled-components';
@@ -54,9 +54,19 @@ const NoResult: React.FC<
loading?: boolean;
loadend?: boolean;
dataSource?: any[];
buttonText?: React.ReactNode;
onClick?: () => void;
}
> = (props) => {
const { filters, noFoundText, loadend, loading, dataSource } = props;
const {
filters,
noFoundText,
loadend,
loading,
dataSource,
buttonText,
onClick
} = props;
const hasFilters = useMemo(() => {
const filterValues = _.omit(filters, ['page', 'perPage']);
@@ -70,6 +80,15 @@ const NoResult: React.FC<
});
}, [filters]);
const renderChildren = () => {
if (!buttonText || !onClick) return null;
return (
<Button color="primary" variant="filled" onClick={onClick}>
{buttonText}
</Button>
);
};
return (
<>
{!loading && loadend && !dataSource?.length ? (
@@ -96,7 +115,7 @@ const NoResult: React.FC<
</Description>
}
>
{!hasFilters && props.children}
{!hasFilters && renderChildren()}
</StyledEmpty>
) : (
<span></span>