import type { ApiMethodJSON, ApiMethodSignatureJSON } from '@discordjs/api-extractor-utils'; import { Menu, MenuButton, MenuItem, useMenuState } from 'ariakit'; import { useCallback, useMemo, useState } from 'react'; import { FiLink } from 'react-icons/fi'; import { VscChevronDown, VscVersions } from 'react-icons/vsc'; import { HyperlinkedText } from './HyperlinkedText'; import { InheritanceText } from './InheritanceText'; import { ParameterTable } from './ParameterTable'; import { TSDoc } from './tsdoc/TSDoc'; export function MethodItem({ data }: { data: ApiMethodJSON | ApiMethodSignatureJSON }) { const method = data as ApiMethodJSON; const [overloadIndex, setOverloadIndex] = useState(1); const overloadedData = method.mergedSiblings[overloadIndex - 1]!; const menu = useMenuState({ gutter: 8, sameWidth: true, fitViewport: true }); const key = useMemo( () => `${data.name}${data.overloadIndex && data.overloadIndex > 1 ? `:${data.overloadIndex}` : ''}`, [data.name, data.overloadIndex], ); const getShorthandName = useCallback( (data: ApiMethodJSON | ApiMethodSignatureJSON) => `${data.name}${data.optional ? '?' : ''}(${data.parameters.reduce((prev, cur, index) => { if (index === 0) { return `${prev}${cur.isOptional ? `${cur.name}?` : cur.name}`; } return `${prev}, ${cur.isOptional ? `${cur.name}?` : cur.name}`; }, '')})`, [], ); return (
{data.deprecated || (data.kind === 'Method' && method.protected) || (data.kind === 'Method' && method.static) ? (
{data.deprecated ? (
Deprecated
) : null} {data.kind === 'Method' && method.protected ? (
Protected
) : null} {data.kind === 'Method' && method.static ? (
Static
) : null}
) : null}

{getShorthandName(overloadedData)}

:

{data.mergedSiblings.length > 1 ? (
{`Overload ${overloadIndex}`} {` of ${data.mergedSiblings.length}`}
{data.mergedSiblings.map((_, idx) => ( setOverloadIndex(idx + 1)} >{`Overload ${idx + 1}`} ))}
) : null} {data.summary || data.parameters.length ? (
{overloadedData.deprecated ? : null} {overloadedData.summary ?? data.summary ? : null} {overloadedData.remarks ? : null} {overloadedData.comment ? : null} {overloadedData.parameters.length ? : null} {data.inheritanceData ? : null}
) : null}
); }