cb9d836227
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
40 lines
1.1 KiB
React
40 lines
1.1 KiB
React
import React from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import OptionGroup from './OptionGroup';
|
|
import { optionValue } from './constraints';
|
|
import { optionLabel, paramLabel } from './labels';
|
|
|
|
/**
|
|
* 分段选择(schema type = 'segmented'),主要用于时长,按 unit 显示"5s"。
|
|
* props: { param, value, onChange(value), optionDisabledReasons?, disabledReason? }
|
|
*/
|
|
const DurationSegmented = ({
|
|
param,
|
|
value,
|
|
onChange,
|
|
optionDisabledReasons,
|
|
disabledReason,
|
|
}) => {
|
|
const { t } = useTranslation();
|
|
const unitWord = param?.unit === 's' ? t('秒') : param?.unit || '';
|
|
return (
|
|
<OptionGroup
|
|
variant='segmented'
|
|
options={param?.options || []}
|
|
value={value}
|
|
onChange={onChange}
|
|
ariaLabel={paramLabel(t, param)}
|
|
optionDisabledReasons={optionDisabledReasons}
|
|
disabledReason={disabledReason}
|
|
getOptionAriaLabel={(opt) => `${optionValue(opt)} ${unitWord}`.trim()}
|
|
renderOption={(opt) => (
|
|
<span className='cp-option-label tabular-nums'>
|
|
{optionLabel(t, param, opt)}
|
|
</span>
|
|
)}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default DurationSegmented;
|