feat(SubTabContainer): 新增 rightElement prop 支持自定义右侧内容

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
zdl
2025-12-16 19:59:00 +08:00
parent 2eb2a22495
commit c34aa37731

View File

@@ -28,6 +28,7 @@ import {
Icon, Icon,
HStack, HStack,
Text, Text,
Spacer,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import type { ComponentType } from 'react'; import type { ComponentType } from 'react';
import type { IconType } from 'react-icons'; import type { IconType } from 'react-icons';
@@ -95,6 +96,8 @@ export interface SubTabContainerProps {
contentPadding?: number; contentPadding?: number;
/** 是否懒加载 */ /** 是否懒加载 */
isLazy?: boolean; isLazy?: boolean;
/** TabList 右侧自定义内容 */
rightElement?: React.ReactNode;
} }
const SubTabContainer: React.FC<SubTabContainerProps> = memo(({ const SubTabContainer: React.FC<SubTabContainerProps> = memo(({
@@ -107,6 +110,7 @@ const SubTabContainer: React.FC<SubTabContainerProps> = memo(({
theme: customTheme, theme: customTheme,
contentPadding = 4, contentPadding = 4,
isLazy = true, isLazy = true,
rightElement,
}) => { }) => {
// 内部状态(非受控模式) // 内部状态(非受控模式)
const [internalIndex, setInternalIndex] = useState(defaultIndex); const [internalIndex, setInternalIndex] = useState(defaultIndex);
@@ -148,19 +152,27 @@ const SubTabContainer: React.FC<SubTabContainerProps> = memo(({
borderBottom="1px solid" borderBottom="1px solid"
borderColor={theme.borderColor} borderColor={theme.borderColor}
pl={0} pl={0}
pr={4} pr={2}
py={2} py={1.5}
flexWrap="wrap" flexWrap="nowrap"
gap={2} gap={1}
alignItems="center"
overflowX="auto"
css={{
'&::-webkit-scrollbar': { display: 'none' },
scrollbarWidth: 'none',
}}
> >
{tabs.map((tab) => ( {tabs.map((tab) => (
<Tab <Tab
key={tab.key} key={tab.key}
color={theme.tabUnselectedColor} color={theme.tabUnselectedColor}
borderRadius="full" borderRadius="full"
px={4} px={2.5}
py={2} py={1.5}
fontSize="sm" fontSize="xs"
whiteSpace="nowrap"
flexShrink={0}
_selected={{ _selected={{
bg: theme.tabSelectedBg, bg: theme.tabSelectedBg,
color: theme.tabSelectedColor, color: theme.tabSelectedColor,
@@ -170,12 +182,18 @@ const SubTabContainer: React.FC<SubTabContainerProps> = memo(({
bg: theme.tabHoverBg, bg: theme.tabHoverBg,
}} }}
> >
<HStack spacing={2}> <HStack spacing={1}>
{tab.icon && <Icon as={tab.icon} boxSize={4} />} {tab.icon && <Icon as={tab.icon} boxSize={3} />}
<Text>{tab.name}</Text> <Text>{tab.name}</Text>
</HStack> </HStack>
</Tab> </Tab>
))} ))}
{rightElement && (
<>
<Spacer />
<Box flexShrink={0}>{rightElement}</Box>
</>
)}
</TabList> </TabList>
<TabPanels p={contentPadding}> <TabPanels p={contentPadding}>