From 6d06cb8fb3ddb3f1f063825c87cedac3615c6df3 Mon Sep 17 00:00:00 2001 From: t0ng7u Date: Wed, 23 Jul 2025 04:10:44 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20enhance=20SelectableButtonG?= =?UTF-8?q?roup=20with=20checkbox=20support=20and=20refactor=20pricing=20d?= =?UTF-8?q?isplay=20settings=20(#1365)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add withCheckbox prop to SelectableButtonGroup component for checkbox-prefixed buttons - Support both single value and array activeValue for multi-selection scenarios - Refactor PricingDisplaySettings to use consistent SelectableButtonGroup styling - Replace Switch components with checkbox-enabled SelectableButtonGroup - Replace Select dropdown with SelectableButtonGroup for currency selection - Maintain unified UI/UX across all pricing filter components - Add proper JSDoc documentation for new withCheckbox functionality This improves visual consistency and provides a more cohesive user experience in the model pricing filter interface. --- .../common/ui/SelectableButtonGroup.jsx | 55 ++++++++- .../filter/PricingDisplaySettings.jsx | 109 ++++++++++-------- 2 files changed, 115 insertions(+), 49 deletions(-) diff --git a/web/src/components/common/ui/SelectableButtonGroup.jsx b/web/src/components/common/ui/SelectableButtonGroup.jsx index 159dde73..a75c537e 100644 --- a/web/src/components/common/ui/SelectableButtonGroup.jsx +++ b/web/src/components/common/ui/SelectableButtonGroup.jsx @@ -19,7 +19,7 @@ For commercial licensing, please contact support@quantumnous.com import React, { useState, useRef } from 'react'; import { useIsMobile } from '../../../hooks/common/useIsMobile'; -import { Divider, Button, Tag, Row, Col, Collapsible } from '@douyinfe/semi-ui'; +import { Divider, Button, Tag, Row, Col, Collapsible, Checkbox } from '@douyinfe/semi-ui'; import { IconChevronDown, IconChevronUp } from '@douyinfe/semi-icons'; /** @@ -27,12 +27,13 @@ import { IconChevronDown, IconChevronUp } from '@douyinfe/semi-icons'; * * @param {string} title 标题 * @param {Array<{value:any,label:string,icon?:React.ReactNode,tagCount?:number}>} items 按钮项 - * @param {*} activeValue 当前激活的值 + * @param {*|Array} activeValue 当前激活的值,可以是单个值或数组(多选) * @param {(value:any)=>void} onChange 选择改变回调 * @param {function} t i18n * @param {object} style 额外样式 * @param {boolean} collapsible 是否支持折叠,默认true * @param {number} collapseHeight 折叠时的高度,默认200 + * @param {boolean} withCheckbox 是否启用前缀 Checkbox 来控制激活状态 */ const SelectableButtonGroup = ({ title, @@ -42,7 +43,8 @@ const SelectableButtonGroup = ({ t = (v) => v, style = {}, collapsible = true, - collapseHeight = 200 + collapseHeight = 200, + withCheckbox = false }) => { const [isOpen, setIsOpen] = useState(false); const isMobile = useIsMobile(); @@ -82,7 +84,52 @@ const SelectableButtonGroup = ({ const contentElement = ( {items.map((item) => { - const isActive = activeValue === item.value; + const isActive = Array.isArray(activeValue) + ? activeValue.includes(item.value) + : activeValue === item.value; + + // 当启用前缀 Checkbox 时,按钮本身不可点击,仅 Checkbox 可控制状态切换 + if (withCheckbox) { + return ( + + + + ); + } + + // 默认行为 return ( { - return ( -
- - {t('显示设置')} - -
-
- {t('以充值价格显示')} - -
- {showWithRecharge && ( -
-
{t('货币单位')}
- -
- )} -
-
- {t('显示倍率')} - - - -
- -
-
+ style={{ color: 'var(--semi-color-text-2)', cursor: 'help' }} + /> + + + ), + } + ]; + + const currencyItems = [ + { value: 'USD', label: 'USD ($)' }, + { value: 'CNY', label: 'CNY (¥)' } + ]; + + const handleChange = (value) => { + if (value === 'recharge') { + setShowWithRecharge(!showWithRecharge); + } else if (value === 'ratio') { + setShowRatio(!showRatio); + } + }; + + const getActiveValues = () => { + const activeValues = []; + if (showWithRecharge) activeValues.push('recharge'); + if (showRatio) activeValues.push('ratio'); + return activeValues; + }; + + return ( +
+ + + {showWithRecharge && ( + + )}
); };