(
props: HelpTextProps & {
descriptionRef?: DOMRef<HTMLDivElement>;
errorRef?: DOMRef<HTMLDivElement>;
}
)
| 405 | }); |
| 406 | |
| 407 | export function HelpText( |
| 408 | props: HelpTextProps & { |
| 409 | descriptionRef?: DOMRef<HTMLDivElement>; |
| 410 | errorRef?: DOMRef<HTMLDivElement>; |
| 411 | } |
| 412 | ): ReactNode { |
| 413 | let domDescriptionRef = useDOMRef(props.descriptionRef || null); |
| 414 | let domErrorRef = useDOMRef(props.errorRef || null); |
| 415 | |
| 416 | if (!props.isInvalid && props.description) { |
| 417 | return ( |
| 418 | <Text |
| 419 | slot="description" |
| 420 | ref={domDescriptionRef} |
| 421 | className={mergeStyles( |
| 422 | helpTextStyles({size: props.size || 'M', isDisabled: props.isDisabled}), |
| 423 | props.styles |
| 424 | )}> |
| 425 | {props.description} |
| 426 | </Text> |
| 427 | ); |
| 428 | } |
| 429 | |
| 430 | if (!props.isInvalid) { |
| 431 | return null; |
| 432 | } |
| 433 | |
| 434 | return ( |
| 435 | <FieldError |
| 436 | {...props} |
| 437 | ref={domErrorRef} |
| 438 | className={renderProps => |
| 439 | mergeStyles( |
| 440 | helpTextStyles({...renderProps, size: props.size || 'M', isDisabled: props.isDisabled}), |
| 441 | props.styles |
| 442 | ) |
| 443 | }> |
| 444 | {composeRenderProps(props.children, (children, {validationErrors}) => ( |
| 445 | <> |
| 446 | {props.showErrorIcon && ( |
| 447 | <CenterBaseline> |
| 448 | <AlertIcon |
| 449 | // @ts-ignore - ts doesn't know that AlertIcon is an icon and not a raw SVG |
| 450 | styles={style({ |
| 451 | size: { |
| 452 | size: { |
| 453 | XS: 14, |
| 454 | S: 16, |
| 455 | M: 20, |
| 456 | L: 22, |
| 457 | XL: 26 |
| 458 | } |
| 459 | } |
| 460 | })({size: props.size || 'M'})} |
| 461 | /> |
| 462 | </CenterBaseline> |
| 463 | )} |
| 464 | <span>{children || validationErrors.join(' ')}</span> |
nothing calls this directly
no test coverage detected