Skip to content

Commit f1fdd5b

Browse files
refactor(website): extract shared code heading styling into component (#9414)
* refactor(website): extract shared code heading styling into component * chore: remove redundant variable
1 parent 5d1a4c2 commit f1fdd5b

File tree

5 files changed

+45
-33
lines changed

5 files changed

+45
-33
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { ReactNode } from 'react';
2+
import { Anchor } from './Anchor';
3+
4+
export interface CodeListingProps {
5+
/**
6+
* The value of this heading.
7+
*/
8+
children: ReactNode;
9+
/**
10+
* Additional class names to apply to the root element.
11+
*/
12+
className?: string | undefined;
13+
/**
14+
* The href of this heading.
15+
*/
16+
href?: string | undefined;
17+
}
18+
19+
export function CodeHeading({ href, className, children }: CodeListingProps) {
20+
return (
21+
<div
22+
className={`flex flex-row flex-wrap place-items-center gap-1 break-all font-mono text-lg font-bold ${className}`}
23+
>
24+
{href ? <Anchor href={href} /> : null}
25+
{children}
26+
</div>
27+
);
28+
}

apps/website/src/components/NameText.tsx

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/website/src/components/Property.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
ApiPropertySignature,
66
} from '@microsoft/api-extractor-model';
77
import type { PropsWithChildren } from 'react';
8-
import { Anchor } from './Anchor';
8+
import { CodeHeading } from './CodeHeading';
99
import { ExcerptText } from './ExcerptText';
1010
import { InheritanceText } from './InheritanceText';
1111
import { TSDoc } from './documentation/tsdoc/TSDoc';
@@ -55,21 +55,13 @@ export function Property({
5555
) : null}
5656
</div>
5757
) : null}
58-
<div className="flex flex-row flex-wrap place-items-center gap-1">
59-
<Anchor href={`#${item.displayName}`} />
60-
<h4 className="break-all font-mono text-lg font-bold">
61-
{item.displayName}
62-
{item.isOptional ? '?' : ''}
63-
</h4>
58+
<CodeHeading href={`#${item.displayName}`}>
59+
{`${item.displayName}${item.isOptional ? '?' : ''}`}
60+
<span>{separator}</span>
6461
{item.propertyTypeExcerpt.text ? (
65-
<>
66-
<h4 className="font-mono text-lg font-bold">{separator}</h4>
67-
<h4 className="break-all font-mono text-lg font-bold">
68-
<ExcerptText excerpt={item.propertyTypeExcerpt} model={item.getAssociatedModel()!} />
69-
</h4>
70-
</>
62+
<ExcerptText excerpt={item.propertyTypeExcerpt} model={item.getAssociatedModel()!} />
7163
) : null}
72-
</div>
64+
</CodeHeading>
7365
</div>
7466
{hasSummary || inheritedFrom ? (
7567
<div className="mb-4 flex flex-col gap-4">

apps/website/src/components/model/enum/EnumMember.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import type { ApiEnumMember } from '@microsoft/api-extractor-model';
2-
import { Anchor } from '../../Anchor';
3-
import { NameText } from '../../NameText';
42
import { SignatureText } from '../../SignatureText';
53
import { TSDoc } from '../../documentation/tsdoc/TSDoc';
4+
import { CodeHeading } from '~/components/CodeHeading';
65

76
export function EnumMember({ member }: { member: ApiEnumMember }) {
87
return (
98
<div className="flex flex-col scroll-mt-30" id={member.displayName}>
10-
<div className="flex flex-col gap-2 md:flex-row md:place-items-center md:-ml-8.5">
11-
<Anchor href={`#${member.displayName}`} />
12-
<NameText name={member.name} />
13-
<h4 className="font-bold">=</h4>
9+
<CodeHeading className="md:-ml-8.5" href={`#${member.displayName}`}>
10+
{member.name}
11+
<span>=</span>
1412
{member.initializerExcerpt ? (
1513
<SignatureText excerpt={member.initializerExcerpt} model={member.getAssociatedModel()!} />
1614
) : null}
17-
</div>
15+
</CodeHeading>
1816
{member.tsdocComment ? <TSDoc item={member} tsdoc={member.tsdocComment.summarySection} /> : null}
1917
</div>
2018
);

apps/website/src/components/model/method/MethodHeader.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ApiMethod, ApiMethodSignature } from '@microsoft/api-extractor-model';
22
import { ApiItemKind } from '@microsoft/api-extractor-model';
33
import { useMemo } from 'react';
4-
import { Anchor } from '~/components/Anchor';
4+
import { CodeHeading } from '~/components/CodeHeading';
55
import { ExcerptText } from '~/components/ExcerptText';
66
import { resolveParameters } from '~/util/model';
77

@@ -49,14 +49,11 @@ export function MethodHeader({ method }: { method: ApiMethod | ApiMethodSignatur
4949
) : null}
5050
</div>
5151
) : null}
52-
<div className="flex flex-row flex-wrap place-items-center gap-1">
53-
<Anchor href={`#${key}`} />
54-
<h4 className="break-all font-mono text-lg font-bold">{getShorthandName(method)}</h4>
55-
<h4 className="font-mono text-lg font-bold">:</h4>
56-
<h4 className="break-all font-mono text-lg font-bold">
57-
<ExcerptText excerpt={method.returnTypeExcerpt} model={method.getAssociatedModel()!} />
58-
</h4>
59-
</div>
52+
<CodeHeading href={`#${key}`}>
53+
{getShorthandName(method)}
54+
<span>:</span>
55+
<ExcerptText excerpt={method.returnTypeExcerpt} model={method.getAssociatedModel()!} />
56+
</CodeHeading>
6057
</div>
6158
</div>
6259
);

0 commit comments

Comments
 (0)