Skip to content

Commit b8cc6db

Browse files
committed
Fixed anchor links not aligning properly working
Fixed link on methods/events/constructors not appearing to copy the anchor link
1 parent ea4b907 commit b8cc6db

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

src/components/ClassBuilder.jsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,18 @@ export const FunctionParametersDeclaration = ({ parameters, include_default = tr
302302
);
303303

304304
// Function Block Declaration
305-
export const FunctionDeclaration = ({ function_data, is_static, class_name, show_lean_declaration = false }) => (
306-
<>
305+
export const FunctionDeclaration = ({ function_data, is_static, class_name, show_lean_declaration = false }) => {
306+
const id = `${is_static ? "static-function" : "function"}-${function_data.name.toLowerCase()}`;
307+
const hash_link = `Direct Link to ${function_data.name}`;
308+
return <>
307309
{ !show_lean_declaration ? <hr /> : null }
308-
<h3 id={ `${is_static ? "static-function" : "function"}-${function_data.name.toLowerCase()}` }>
310+
<h3 id={ id } className="custom-anchor">
309311
{ GetAuthorityType(function_data.authority) }
310312
{ GetNative(function_data.is_native) }
311313
<code>
312314
{ function_data.name }
313315
</code>
316+
<a className="hash-link" href={ `#${id}` } aria-label={ hash_link } title={ hash_link } translate="no"></a>
314317
</h3>
315318
<blockquote>
316319
<span dangerouslySetInnerHTML={{ __html: !show_lean_declaration && function_data.description_long ? function_data.description_long : function_data.description }}></span>
@@ -344,18 +347,21 @@ export const FunctionDeclaration = ({ function_data, is_static, class_name, show
344347
</p>
345348
: <></>}
346349
</>
347-
);
350+
};
348351

349352
// Event Block Declaration
350-
export const EventDeclaration = ({ event_data, class_name, show_lean_declaration = false }) => (
351-
<>
353+
export const EventDeclaration = ({ event_data, class_name, show_lean_declaration = false }) => {
354+
const id = `event-${event_data.name.toLowerCase()}`;
355+
const hash_link = `Direct Link to ${event_data.name}`;
356+
return <>
352357
{ !show_lean_declaration ? <hr /> : null }
353-
<h3 id={ `event-${event_data.name.toLowerCase()}` }>
358+
<h3 id={ id } className="custom-anchor">
354359
{ GetAuthorityType(event_data.authority) }
355360
{ GetNative(event_data.is_native) }
356361
<code>
357362
{ event_data.name }
358363
</code>
364+
<a className="hash-link" href={ `#${id}` } aria-label={ hash_link } title={ hash_link } translate="no"></a>
359365
</h3>
360366
<blockquote dangerouslySetInnerHTML={{ __html: `${ !show_lean_declaration && event_data.description_long ? event_data.description_long : (event_data.description ? event_data.description : "<span class='subtle-description'>No description provided</span>") }${ event_data.return ? "<br/><br/>" + event_data.return[0].description : ""}` }}></blockquote>
361367
<CodeBlock className="language-lua">
@@ -398,7 +404,7 @@ export const EventDeclaration = ({ event_data, class_name, show_lean_declaration
398404
</p>
399405
: <></>}
400406
</>
401-
);
407+
};
402408

403409
export const StaticFunctionNameDeclaration = ({ class_name, function_data, base_class }) => (
404410
<Tippy interactive={true} maxWidth={1200} animation={"scale-subtle"} content={<StaticFunctionToolTip class_name={class_name} function_data={function_data} />}>
@@ -547,9 +553,14 @@ export const HeaderDeclaration = ({ type, name, image, is_static, open_source_ur
547553
// Block of Constructor
548554
export const ConstructorDeclaration = ({ type, name }) => {
549555
const class_data = GetClassData(type, name);
550-
return class_data.constructors.map((constructor, index) =>
551-
<>
552-
<h3 id={ `constructor-${ constructor.name.toLowerCase().replace(' ', '-') }` }>{ constructor.name }</h3>
556+
return class_data.constructors.map((constructor, index) => {
557+
const id = `constructor-${constructor.name.toLowerCase().replace(' ', '-')}`;
558+
const hash_link = `Direct Link to ${constructor.name}`;
559+
return <>
560+
<h3 id={ id } className="custom-anchor">
561+
{ constructor.name }
562+
<a className="hash-link" href={ `#${id}` } aria-label={ hash_link } title={ hash_link } translate="no"></a>
563+
</h3>
553564
<p class="subtle-description" style={{ marginTop: "-20px" }}>{ constructor.description || "No description provided" }</p>
554565
<CodeBlock className="language-lua">
555566
{ GetConstructorExample(class_data, index) }
@@ -582,7 +593,7 @@ export const ConstructorDeclaration = ({ type, name }) => {
582593
</>
583594
}
584595
</>
585-
);
596+
});
586597
};
587598

588599
// Base Class Functions

src/css/custom.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ code {
177177
color: var(--ifm-color-emphasis-900);
178178
}
179179

180+
h3 code {
181+
vertical-align: initial;
182+
}
183+
184+
/* Custom Anchor tag to fix offset */
185+
.custom-anchor {
186+
scroll-margin-top: calc(var(--ifm-navbar-height) + 2rem);
187+
}
188+
180189
html[data-theme='dark'] .prism-code,
181190
html[data-theme='dark'] div[class^='codeBlockTitle'],
182191
html[data-theme='dark'] span[class^='codeLineNumber'] {

0 commit comments

Comments
 (0)