MCPcopy Create free account
hub / github.com/adobe/react-spectrum / HelpText

Function HelpText

packages/@react-spectrum/s2/src/Field.tsx:407–469  ·  view source on GitHub ↗
(
  props: HelpTextProps & {
    descriptionRef?: DOMRef<HTMLDivElement>;
    errorRef?: DOMRef<HTMLDivElement>;
  }
)

Source from the content-addressed store, hash-verified

405});
406
407export 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>

Callers

nothing calls this directly

Calls 3

useDOMRefFunction · 0.90
mergeStylesFunction · 0.90
composeRenderPropsFunction · 0.85

Tested by

no test coverage detected