Skip to content

⬅️ Back to Table of Contents

πŸ“„ ast/PropertyName

πŸ“Š Analysis Summary

Metric Count
πŸ”§ Functions 1
πŸ“¦ Imports 5
πŸ’  JSX Elements 1
πŸ“ Interfaces 1

πŸ“š Table of Contents

πŸ› οΈ File Location:

πŸ“‚ packages/website/src/components/ast/PropertyName.tsx

πŸ“¦ Imports

Name Source
KeyboardEvent react
MouseEvent react
Link @docusaurus/Link
useCallback react
React react

JSX Elements

Component Type Props Children
Link component className={className}, href={#${value}}, onClick={onClick}, onKeyDown={onKe... {value}

Functions

PropertyName({ className, onClick: onClickPr…: PropertyNameProps): React.JSX.Element

Parameters:

  • { className, onClick: onClickProp, onHover: onHoverProp, value, } PropertyNameProps

Returns: React.JSX.Element

Calls:

  • useCallback (from react)
  • e.preventDefault
  • onClickProp
  • onHoverProp
Code
export default function PropertyName({
  className,
  onClick: onClickProp,
  onHover: onHoverProp,
  value,
}: PropertyNameProps): React.JSX.Element {
  const onClick = useCallback(
    (e: MouseEvent<HTMLElement>) => {
      e.preventDefault();
      onClickProp?.();
    },
    [onClickProp],
  );

  const onMouseEnter = useCallback(() => {
    onHoverProp?.(true);
  }, [onHoverProp]);

  const onMouseLeave = useCallback(() => {
    onHoverProp?.(false);
  }, [onHoverProp]);

  const onKeyDown = useCallback(
    (e: KeyboardEvent<HTMLElement>) => {
      if (e.code === 'Space') {
        e.preventDefault();
        onClickProp?.();
      }
    },
    [onClickProp],
  );

  return (
    <Link
      className={className}
      href={`#${value}`}
      onClick={onClick}
      onKeyDown={onKeyDown}
      onMouseEnter={onMouseEnter}
      onMouseLeave={onMouseLeave}
      role="button"
      tabIndex={onClickProp && 0}
    >
      {value}
    </Link>
  );
}

Interfaces

PropertyNameProps

Interface Code
export interface PropertyNameProps {
  readonly className?: string;
  readonly onClick?: () => void;
  readonly onHover?: (e: boolean) => void;
  readonly value?: string;
}

Properties

Name Type Optional Description
className string βœ“ not shown
onClick () => void βœ“ not shown
onHover (e: boolean) => void βœ“ not shown
value string βœ“ not shown

Generated by Syntax Scribe