mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +01:00
refactor(website): extract shared code heading styling into component (#9414)
* refactor(website): extract shared code heading styling into component * chore: remove redundant variable
This commit is contained in:
28
apps/website/src/components/CodeHeading.tsx
Normal file
28
apps/website/src/components/CodeHeading.tsx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import type { ReactNode } from 'react';
|
||||||
|
import { Anchor } from './Anchor';
|
||||||
|
|
||||||
|
export interface CodeListingProps {
|
||||||
|
/**
|
||||||
|
* The value of this heading.
|
||||||
|
*/
|
||||||
|
children: ReactNode;
|
||||||
|
/**
|
||||||
|
* Additional class names to apply to the root element.
|
||||||
|
*/
|
||||||
|
className?: string | undefined;
|
||||||
|
/**
|
||||||
|
* The href of this heading.
|
||||||
|
*/
|
||||||
|
href?: string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CodeHeading({ href, className, children }: CodeListingProps) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`flex flex-row flex-wrap place-items-center gap-1 break-all font-mono text-lg font-bold ${className}`}
|
||||||
|
>
|
||||||
|
{href ? <Anchor href={href} /> : null}
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export function NameText({ name }: { name: string }) {
|
|
||||||
return <h4 className="break-all font-mono text-lg font-bold">{name}</h4>;
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@ import type {
|
|||||||
ApiPropertySignature,
|
ApiPropertySignature,
|
||||||
} from '@microsoft/api-extractor-model';
|
} from '@microsoft/api-extractor-model';
|
||||||
import type { PropsWithChildren } from 'react';
|
import type { PropsWithChildren } from 'react';
|
||||||
import { Anchor } from './Anchor';
|
import { CodeHeading } from './CodeHeading';
|
||||||
import { ExcerptText } from './ExcerptText';
|
import { ExcerptText } from './ExcerptText';
|
||||||
import { InheritanceText } from './InheritanceText';
|
import { InheritanceText } from './InheritanceText';
|
||||||
import { TSDoc } from './documentation/tsdoc/TSDoc';
|
import { TSDoc } from './documentation/tsdoc/TSDoc';
|
||||||
@@ -55,21 +55,13 @@ export function Property({
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
<div className="flex flex-row flex-wrap place-items-center gap-1">
|
<CodeHeading href={`#${item.displayName}`}>
|
||||||
<Anchor href={`#${item.displayName}`} />
|
{`${item.displayName}${item.isOptional ? '?' : ''}`}
|
||||||
<h4 className="break-all font-mono text-lg font-bold">
|
<span>{separator}</span>
|
||||||
{item.displayName}
|
|
||||||
{item.isOptional ? '?' : ''}
|
|
||||||
</h4>
|
|
||||||
{item.propertyTypeExcerpt.text ? (
|
{item.propertyTypeExcerpt.text ? (
|
||||||
<>
|
<ExcerptText excerpt={item.propertyTypeExcerpt} model={item.getAssociatedModel()!} />
|
||||||
<h4 className="font-mono text-lg font-bold">{separator}</h4>
|
|
||||||
<h4 className="break-all font-mono text-lg font-bold">
|
|
||||||
<ExcerptText excerpt={item.propertyTypeExcerpt} model={item.getAssociatedModel()!} />
|
|
||||||
</h4>
|
|
||||||
</>
|
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</CodeHeading>
|
||||||
</div>
|
</div>
|
||||||
{hasSummary || inheritedFrom ? (
|
{hasSummary || inheritedFrom ? (
|
||||||
<div className="mb-4 flex flex-col gap-4">
|
<div className="mb-4 flex flex-col gap-4">
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
import type { ApiEnumMember } from '@microsoft/api-extractor-model';
|
import type { ApiEnumMember } from '@microsoft/api-extractor-model';
|
||||||
import { Anchor } from '../../Anchor';
|
|
||||||
import { NameText } from '../../NameText';
|
|
||||||
import { SignatureText } from '../../SignatureText';
|
import { SignatureText } from '../../SignatureText';
|
||||||
import { TSDoc } from '../../documentation/tsdoc/TSDoc';
|
import { TSDoc } from '../../documentation/tsdoc/TSDoc';
|
||||||
|
import { CodeHeading } from '~/components/CodeHeading';
|
||||||
|
|
||||||
export function EnumMember({ member }: { member: ApiEnumMember }) {
|
export function EnumMember({ member }: { member: ApiEnumMember }) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col scroll-mt-30" id={member.displayName}>
|
<div className="flex flex-col scroll-mt-30" id={member.displayName}>
|
||||||
<div className="flex flex-col gap-2 md:flex-row md:place-items-center md:-ml-8.5">
|
<CodeHeading className="md:-ml-8.5" href={`#${member.displayName}`}>
|
||||||
<Anchor href={`#${member.displayName}`} />
|
{member.name}
|
||||||
<NameText name={member.name} />
|
<span>=</span>
|
||||||
<h4 className="font-bold">=</h4>
|
|
||||||
{member.initializerExcerpt ? (
|
{member.initializerExcerpt ? (
|
||||||
<SignatureText excerpt={member.initializerExcerpt} model={member.getAssociatedModel()!} />
|
<SignatureText excerpt={member.initializerExcerpt} model={member.getAssociatedModel()!} />
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</CodeHeading>
|
||||||
{member.tsdocComment ? <TSDoc item={member} tsdoc={member.tsdocComment.summarySection} /> : null}
|
{member.tsdocComment ? <TSDoc item={member} tsdoc={member.tsdocComment.summarySection} /> : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { ApiMethod, ApiMethodSignature } from '@microsoft/api-extractor-model';
|
import type { ApiMethod, ApiMethodSignature } from '@microsoft/api-extractor-model';
|
||||||
import { ApiItemKind } from '@microsoft/api-extractor-model';
|
import { ApiItemKind } from '@microsoft/api-extractor-model';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { Anchor } from '~/components/Anchor';
|
import { CodeHeading } from '~/components/CodeHeading';
|
||||||
import { ExcerptText } from '~/components/ExcerptText';
|
import { ExcerptText } from '~/components/ExcerptText';
|
||||||
import { resolveParameters } from '~/util/model';
|
import { resolveParameters } from '~/util/model';
|
||||||
|
|
||||||
@@ -49,14 +49,11 @@ export function MethodHeader({ method }: { method: ApiMethod | ApiMethodSignatur
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
<div className="flex flex-row flex-wrap place-items-center gap-1">
|
<CodeHeading href={`#${key}`}>
|
||||||
<Anchor href={`#${key}`} />
|
{getShorthandName(method)}
|
||||||
<h4 className="break-all font-mono text-lg font-bold">{getShorthandName(method)}</h4>
|
<span>:</span>
|
||||||
<h4 className="font-mono text-lg font-bold">:</h4>
|
<ExcerptText excerpt={method.returnTypeExcerpt} model={method.getAssociatedModel()!} />
|
||||||
<h4 className="break-all font-mono text-lg font-bold">
|
</CodeHeading>
|
||||||
<ExcerptText excerpt={method.returnTypeExcerpt} model={method.getAssociatedModel()!} />
|
|
||||||
</h4>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user