import React, { forwardRef } from 'react'; import { Box, BoxProps, Flex, Stack, Skeleton } from '@chakra-ui/react'; import { Header, CardSection } from './components'; export interface CardProps extends Omit { /** 标题 */ title?: React.ReactNode; /** 副标题 */ subTitle?: React.ReactNode; subdued?: boolean; /** 加载中 */ loading?: boolean; /** 是否有边框 */ bordered?: boolean; /** 是否有阴影 */ boxShadow?: boolean; /** 右上角内容 */ extra?: React.ReactNode; /** 是否有 padding */ sectioned?: boolean; /** 页脚内容 */ footer?: React.ReactNode; /** 页脚位置 */ footerAlignment?: 'left' | 'right'; headerProps?: BoxProps; bodyProps?: BoxProps; footerProps?: BoxProps; } // 添加 ref,ApolloTable、ProTable 获取宽度要用到 export const Card = forwardRef( ( { subdued, children, title, subTitle, extra, loading, sectioned, footer, bordered = true, boxShadow, footerAlignment = 'right', bodyProps, headerProps, footerProps, ...rest }, ref, ) => { const headerMarkup = !loading && (title || extra) ? (
) : null; const footerMarkup = footer && !loading ? ( {footer} ) : null; const loadingBlock = ( ); const content = sectioned ? ( {loading ? loadingBlock : children} ) : ( <>{loading ? {loadingBlock} : children} ); return ( {headerMarkup} {content} {footerMarkup} ); }, );