dify/web/app/components/base/form/components/label.tsx
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

44 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 size-4" popupClassName="w-[200px]">
{tooltip}
</Infotip>
)}
</div>
)
}
export default Label