import React, { useState } from 'react'; import { Card } from 'antd'; import { useLocalStorageState } from 'ahooks'; import { CardProps, CardTabListType } from 'antd/es/card'; import styles from './index.less'; export interface TabsCardProps extends CardProps { tabList: CardTabListType[]; contentList: Record | Function; tabLocalStorageKey?: string; } const TabsCard: React.FC = props => { const { tabList, onTabChange, activeTabKey, contentList, defaultActiveTabKey = '', tabLocalStorageKey = 'lins-government-tabs', ...rest } = props; const [state, setState] = useLocalStorageState( tabLocalStorageKey, defaultActiveTabKey, ); const realActiveTabKey = activeTabKey ? activeTabKey : state; const handleTabChange = (key: string) => { setState(key); onTabChange?.(key); }; const renderContent = () => { if (typeof contentList === 'function') { return contentList(realActiveTabKey); } else { return contentList[realActiveTabKey]; } }; return (
{renderContent()}
); }; TabsCard.defaultProps = {}; export default TabsCard;