Skip to content

Commit 591675a

Browse files
committed
1 parent 14367cd commit 591675a

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default defineConfig({
1111
title: 'PokéAPI',
1212
components: {
1313
Footer: './src/components/PokeFooter.astro',
14+
Header: './src/components/PokeHeader.astro',
1415
},
1516
customCss: [
1617
'./src/styles/global.css',

src/components/PokeHeader.astro

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

src/components/PokeNav.astro

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<nav>
2+
<ul
3+
class="
4+
flex gap-6
5+
text-(--sl-color-white) pr-4
6+
[&_li]:hover:text-(--sl-color-accent-high)
7+
[&_li]:hover:font-bold
8+
[&_li]:hover:underline
9+
"
10+
>
11+
<li>
12+
<a href="/">Home</a>
13+
</li>
14+
<li>
15+
<a href="/about">About</a>
16+
</li>
17+
<li>
18+
<a href="/v2">API v2</a>
19+
</li>
20+
<li>
21+
<a href="/graphql">GraphQL v1Beta</a>
22+
</li>
23+
</ul>
24+
</nav>

0 commit comments

Comments
 (0)