Skip to content

Commit ace9622

Browse files
committed
fix: Customizing header
1 parent 6c2c423 commit ace9622

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

docs-starlight/astro.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ export default defineConfig({
7979
starlight({
8080
title: "Terragrunt",
8181
customCss: ["./src/styles/global.css"],
82+
components: {
83+
Header: './src/components/Header.astro',
84+
},
8285
logo: {
8386
dark: "/src/assets/logo-light.svg",
8487
light: "/src/assets/logo-dark.svg",
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
import config from 'virtual:starlight/user-config';
3+
import type { Props } from '@astrojs/starlight/props';
4+
5+
import LanguageSelect from 'virtual:starlight/components/LanguageSelect';
6+
import Search from 'virtual:starlight/components/Search';
7+
import SiteTitle from 'virtual:starlight/components/SiteTitle';
8+
import SocialIcons from 'virtual:starlight/components/SocialIcons';
9+
import ThemeSelect from 'virtual:starlight/components/ThemeSelect';
10+
11+
/**
12+
* Render the `Search` component if Pagefind is enabled or the default search component has been overridden.
13+
*/
14+
const shouldRenderSearch =
15+
config.pagefind || config.components.Search !== '@astrojs/starlight/components/Search.astro';
16+
---
17+
18+
<div class="header sl-flex">
19+
<div class="title-wrapper sl-flex">
20+
<SiteTitle {...Astro.props} />
21+
</div>
22+
<div class="sl-flex print:hidden">
23+
{shouldRenderSearch && <Search {...Astro.props} />}
24+
</div>
25+
<div class="sl-hidden md:sl-flex print:hidden right-group">
26+
<div class="sl-flex social-icons">
27+
<SocialIcons {...Astro.props} />
28+
</div>
29+
<ThemeSelect {...Astro.props} />
30+
<LanguageSelect {...Astro.props} />
31+
</div>
32+
</div>
33+
34+
<style>
35+
.header {
36+
gap: var(--sl-nav-gap);
37+
justify-content: space-between;
38+
align-items: center;
39+
height: 100%;
40+
}
41+
42+
.title-wrapper {
43+
/* Prevent long titles overflowing and covering the search and menu buttons on narrow viewports. */
44+
overflow: clip;
45+
/* Avoid clipping focus ring around link inside title wrapper. */
46+
padding: 0.25rem;
47+
margin: -0.25rem;
48+
min-width: 0;
49+
}
50+
51+
.right-group,
52+
.social-icons {
53+
gap: 1rem;
54+
align-items: center;
55+
}
56+
.social-icons::after {
57+
content: '';
58+
height: 2rem;
59+
border-inline-end: 1px solid var(--sl-color-gray-5);
60+
}
61+
62+
@media (min-width: 50rem) {
63+
:global(:root[data-has-sidebar]) {
64+
--__sidebar-pad: calc(2 * var(--sl-nav-pad-x));
65+
}
66+
:global(:root:not([data-has-toc])) {
67+
--__toc-width: 0rem;
68+
}
69+
.header {
70+
--__sidebar-width: max(0rem, var(--sl-content-inline-start, 0rem) - var(--sl-nav-pad-x));
71+
--__main-column-fr: calc(
72+
(
73+
100% + var(--__sidebar-pad, 0rem) - var(--__toc-width, var(--sl-sidebar-width)) -
74+
(2 * var(--__toc-width, var(--sl-nav-pad-x))) - var(--sl-content-inline-start, 0rem) -
75+
var(--sl-content-width)
76+
) / 2
77+
);
78+
display: grid;
79+
grid-template-columns:
80+
/* 1 (site title): runs up until the main content column’s left edge or the width of the title, whichever is the largest */
81+
minmax(
82+
calc(var(--__sidebar-width) + max(0rem, var(--__main-column-fr) - var(--sl-nav-gap))),
83+
auto
84+
)
85+
/* 2 (search box): all free space that is available. */
86+
1fr
87+
/* 3 (right items): use the space that these need. */
88+
auto;
89+
align-content: center;
90+
}
91+
}
92+
</style>

0 commit comments

Comments
 (0)