dify/web/app/components/base/form/components/label.tsx
yyh 2bb1f0906b
refactor(web): migrate legacy tooltip callers (#35961)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-05-09 05:26:21 +00:00

45 lines
1.1 KiB
TypeScript

import { cn } from '@langgenius/dify-ui/cn'
import { useTranslation } from 'react-i18next'
import { Infotip } from '../../infotip'
export type LabelProps = {
htmlFor: string
label: string
isRequired?: boolean
showOptional?: boolean
tooltip?: string
className?: string
}
const Label = ({
htmlFor,
label,
isRequired,
showOptional,
tooltip,
className,
}: LabelProps) => {
const { t } = useTranslation()
return (
<div className="flex h-6 items-center">
<label
data-testid="label"
htmlFor={htmlFor}
className={cn('system-sm-medium text-text-secondary', className)}
>
{label}
</label>
{!isRequired && showOptional && <div className="ml-1 system-xs-regular text-text-tertiary">{t('label.optional', { ns: 'common' })}</div>}
{isRequired && <div className="ml-1 system-xs-regular text-text-destructive-secondary">*</div>}
{tooltip && (
<Infotip aria-label={tooltip} className="ml-0.5 h-4 w-4" popupClassName="w-[200px]">
{tooltip}
</Infotip>
)}
</div>
)
}
export default Label