8000 Add option to hide navlinks on mobile by ThomasSingleton · Pull Request #204 · lorenzolewis/starlight-utils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add option to hide navlinks on mobile #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-items-wish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lorenzo_lewis/starlight-utils": minor
---

Adds navLinksMobileDisplay config option, allowing for user to optionally hide navlinks on mobile
12 changes: 7 additions & 5 deletions packages/starlight-utils/components/NavLinks.astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
// Styles adapted from https://github.com/withastro/starlight/blob/main/packages/starlight/components/SidebarSublist.astro
// and https://www.figma.com/design/GrDkcguAR7tSWPFuLVDixq/Theme---Starlight-Docs?node-id=454-34753&t=fgVYGvAg6ftBSpJY-0
const navLinksMobileDisplay = Astro.locals.starlightUtils.navLinksMobileDisplay || "flex";
---

{
Astro.locals.starlightUtils.navLinks && (
<ul>
<ul class="nav-links" style={`--nav-links-mobile-display: ${navLinksMobileDisplay};`}>
{Astro.locals.starlightUtils.navLinks.map((entry) => (
<li>
<a
Expand All @@ -22,12 +23,13 @@
}

<style>
ul {
.nav-links {
display: flex;
list-style: none;
padding: 0;
gap: var(--sl-nav-gap);
}

a {
text-decoration: none;
color: var(--sl-color-gray-1);
Expand All @@ -44,9 +46,9 @@
font-weight: 600;
}

@media (min-width: 50rem) {
a {
font-size: var(--sl-text-sm);
@media (max-width: 50rem) {
.nav-links {
display: var(--nav-links-mobile-display, none);
}
}
</style>
1 change: 1 addition & 0 deletions packages/starlight-utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const configSchema = z
.object({
multiSidebar: multiSidebarConfig,
navLinks: navLinksConfig,
navLinksMobileDisplay: z.enum(["none", "flex"]).optional(),
})
.optional();

Expand Down
8000
5 changes: 5 additions & 0 deletions packages/starlight-utils/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export const => {
context.locals.starlightRoute.sidebar = filteredSidebar;
}

// Logic for navLinksMobileDisplay
if (config?.navLinksMobileDisplay) {
context.locals.starlightUtils.navLinksMobileDisplay = config.navLinksMobileDisplay;
}

// Logic for multi-sidebar
if (config?.multiSidebar) {
// All entries must be group types
Expand Down
4 changes: 4 additions & 0 deletions packages/starlight-utils/virtual.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ declare module "virtual:starlight-utils/config" {
export default Config;
}

export interface StarlightUtilsConfig {
navLinksMobileDisplay?: "none" | "flex";
}

declare namespace App {
type StarlightLocals = import("@astrojs/starlight").StarlightLocals;
// Define the `locals.t` object in the context of a plugin.
Expand Down
0