Skip to content

Commit 67105ac

Browse files
committed
Fix title for long function/event name (i.e getElementDistanceFromCentreOfMassToBaseOfModel)
1 parent b66d000 commit 67105ac

File tree

1 file changed

+67
-14
lines changed

1 file changed

+67
-14
lines changed

web/src/overrides/PageTitle.astro

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
---
2-
import { functionTypePrettyName } from '@src/utils/functions';
2+
import { functionTypePrettyName } from "@src/utils/functions";
33
---
4+
45
<div class="page-title-container">
5-
<h1>{Astro.locals.starlightRoute.entry.data.title}</h1>
6+
<h1 class="page-title">{Astro.locals.starlightRoute.entry.data.title}</h1>
67

7-
<div data-pagefind-ignore class="type-badge type-badge--client">{functionTypePrettyName['client']}</div>
8-
<div data-pagefind-ignore class="type-badge type-badge--server">{functionTypePrettyName['server']}</div>
9-
<div data-pagefind-ignore class="type-badge type-badge--shared">{functionTypePrettyName['shared']}</div>
8+
<div data-pagefind-ignore class="type-badge type-badge--client">
9+
{functionTypePrettyName["client"]}
10+
</div>
11+
<div data-pagefind-ignore class="type-badge type-badge--server">
12+
{functionTypePrettyName["server"]}
13+
</div>
14+
<div data-pagefind-ignore class="type-badge type-badge--shared">
15+
{functionTypePrettyName["shared"]}
16+
</div>
1017
</div>
1118

1219
<style is:global>
@@ -34,7 +41,7 @@ import { functionTypePrettyName } from '@src/utils/functions';
3441
<style>
3542
.type-badge {
3643
font-size: 12px;
37-
border-radius: .25rem;
44+
border-radius: 0.25rem;
3845
text-transform: uppercase;
3946
font-weight: bold;
4047
display: none;
@@ -50,13 +57,6 @@ import { functionTypePrettyName } from '@src/utils/functions';
5057
color: var(--color-type-shared);
5158
}
5259

53-
h1 {
54-
font-size: var(--sl-text-h1);
55-
line-height: var(--sl-line-height-headings);
56-
font-weight: 600;
57-
color: var(--sl-color-white);
58-
}
59-
6060
.page-title-container {
6161
display: flex;
6262
justify-content: flex-start;
@@ -68,10 +68,29 @@ import { functionTypePrettyName } from '@src/utils/functions';
6868
position: relative;
6969
}
7070

71+
.page-title {
72+
font-size: var(--sl-text-h1);
73+
line-height: var(--sl-line-height-headings);
74+
font-weight: 600;
75+
color: var(--sl-color-white);
76+
}
77+
78+
.page-title.size-h2 {
79+
font-size: var(--sl-text-h2);
80+
}
81+
82+
.page-title.size-h3 {
83+
font-size: var(--sl-text-h3);
84+
}
85+
86+
.page-title.size-h4 {
87+
font-size: var(--sl-text-h4);
88+
}
89+
7190
@media (width >= 48rem) {
7291
.type-badge {
7392
font-size: initial;
74-
padding: .15rem 1.5rem;
93+
padding: 0.15rem 1.5rem;
7594
}
7695

7796
.type-badge.type-badge--client {
@@ -95,3 +114,37 @@ import { functionTypePrettyName } from '@src/utils/functions';
95114
}
96115
}
97116
</style>
117+
118+
<script>
119+
document.addEventListener("DOMContentLoaded", () => {
120+
const title = document.querySelector(".page-title");
121+
const sizeClasses = ["size-h2", "size-h3", "size-h4"];
122+
123+
function adjustTitle() {
124+
if (!title) return;
125+
126+
title.classList.remove(...sizeClasses);
127+
128+
requestAnimationFrame(() => {
129+
const lineHeight = parseFloat(
130+
getComputedStyle(title).lineHeight,
131+
);
132+
133+
for (const sizeClass of sizeClasses) {
134+
title.classList.remove(...sizeClasses);
135+
if (sizeClass) title.classList.add(sizeClass);
136+
137+
const lines = Math.round(title.scrollHeight / lineHeight);
138+
console.log(lines);
139+
140+
if (lines <= 1) {
141+
break;
142+
}
143+
}
144+
});
145+
}
146+
147+
adjustTitle();
148+
window.addEventListener("resize", adjustTitle);
149+
});
150+
</script>

0 commit comments

Comments
 (0)