diff --git a/web/src/components/common/ui/SelectableButtonGroup.jsx b/web/src/components/common/ui/SelectableButtonGroup.jsx index ebc900f13..8637c8210 100644 --- a/web/src/components/common/ui/SelectableButtonGroup.jsx +++ b/web/src/components/common/ui/SelectableButtonGroup.jsx @@ -20,6 +20,7 @@ For commercial licensing, please contact support@quantumnous.com import React, { useState } from 'react'; import { useIsMobile } from '../../../hooks/common/useIsMobile'; import { useMinimumLoadingTime } from '../../../hooks/common/useMinimumLoadingTime'; +import { useContainerWidth } from '../../../hooks/common/useContainerWidth'; import { Divider, Button, Tag, Row, Col, Collapsible, Checkbox, Skeleton, Tooltip } from '@douyinfe/semi-ui'; import { IconChevronDown, IconChevronUp } from '@douyinfe/semi-icons'; @@ -52,11 +53,29 @@ const SelectableButtonGroup = ({ const [isOpen, setIsOpen] = useState(false); const [skeletonCount] = useState(6); const isMobile = useIsMobile(); - const perRow = 3; + const [containerRef, containerWidth] = useContainerWidth(); + + // 基于容器宽度计算响应式列数和标签显示策略 + const getResponsiveConfig = () => { + if (containerWidth <= 280) return { columns: 1, showTags: true }; // 极窄:1列+标签 + if (containerWidth <= 380) return { columns: 2, showTags: true }; // 窄屏:2列+标签 + if (containerWidth <= 460) return { columns: 3, showTags: false }; // 中等:3列不加标签 + return { columns: 3, showTags: true }; // 最宽:3列+标签 + }; + + const { columns: perRow, showTags: shouldShowTags } = getResponsiveConfig(); const maxVisibleRows = Math.max(1, Math.floor(collapseHeight / 32)); // Approx row height 32 const needCollapse = collapsible && items.length > perRow * maxVisibleRows; const showSkeleton = useMinimumLoadingTime(loading); + // 统一使用紧凑的网格间距 + const gutterSize = [4, 4]; + + // 计算 Semi UI Col 的 span 值 + const getColSpan = () => { + return Math.floor(24 / perRow); + }; + const maskStyle = isOpen ? {} : { @@ -87,13 +106,10 @@ const SelectableButtonGroup = ({ const renderSkeletonButtons = () => { const placeholder = ( - + {Array.from({ length: skeletonCount }).map((_, index) => (
{withCheckbox && ( @@ -129,7 +145,7 @@ const SelectableButtonGroup = ({ }; const contentElement = showSkeleton ? renderSkeletonButtons() : ( - + {items.map((item) => { const isDisabled = item.disabled || (typeof item.tagCount === 'number' && item.tagCount === 0); const isActive = Array.isArray(activeValue) @@ -139,10 +155,7 @@ const SelectableButtonGroup = ({ if (withCheckbox) { return (
@@ -177,10 +190,7 @@ const SelectableButtonGroup = ({ return (