Skip to content

Commit 6fc344b

Browse files
committed
TD-31 Add Starlight Header and MobileMenuFooter components
1 parent 1d112a9 commit 6fc344b

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

src/components/overrides/Header.astro

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

0 commit comments

Comments
 (0)