-
Notifications
You must be signed in to change notification settings - Fork 13.1k
style: improve sidebar item layout, focus style, and spacing #29078
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6c46b5d
style: improve sidebar item layout, focus style, and spacing
MohamedH1998 b62b957
fix: change icon path
MohamedH1998 989c0b8
fix: revert icon path
MohamedH1998 a16a450
Merge remote-tracking branch 'origin' into style/sidebar-improvements
MohamedH1998 706d94c
fix: fix build error
MohamedH1998 de9af20
style: PR comment fixes
MohamedH1998 44b7522
style: refine sidebar
MohamedH1998 a53c274
Merge branch 'production' into style/sidebar-improvements
MohamedH1998 0530278
style: show active state in parents of nested items
MohamedH1998 87dbaff
fix: ci failure
MohamedH1998 3e674c3
style: improve theming
MohamedH1998 ddd81c0
fix: improve animation
MohamedH1998 2369e1e
Update src/components/overrides/SidebarSublist.astro
MohamedH1998 3a4d0dd
style: header design improvements (#29123)
MohamedH1998 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| --- | ||
| import { Icon, Badge } from "@astrojs/starlight/components"; | ||
|
|
||
| interface Props { | ||
| sublist: any[]; | ||
MohamedH1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| nested?: boolean; | ||
| } | ||
|
|
||
| const { sublist, nested } = Astro.props; | ||
|
|
||
| /** Flatten a sidebar tree into a flat list of link entries. */ | ||
| function flattenSidebar(entries: any[]): any[] { | ||
MohamedH1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return entries.flatMap((entry: any) => | ||
| entry.type === "group" ? flattenSidebar(entry.entries) : entry, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * SidebarRestorePoint counter — inlined from Starlight's internal component. | ||
| * Each <details> needs a unique, incrementing index for the sidebar persister. | ||
| */ | ||
| const currentGroupIndexSymbol = Symbol.for("starlight-sidebar-group-index"); | ||
| const locals = Astro.locals as typeof Astro.locals & { | ||
| [currentGroupIndexSymbol]: number; | ||
| }; | ||
|
|
||
| function nextRestoreIndex(): number { | ||
| const index = locals[currentGroupIndexSymbol] || 0; | ||
| locals[currentGroupIndexSymbol] = index + 1; | ||
| return index; | ||
| } | ||
|
|
||
| // Pre-compute restore indices for each group entry in this sublist | ||
| const restoreIndices = sublist.map((entry) => | ||
| entry.type === "group" ? nextRestoreIndex() : -1, | ||
| ); | ||
| --- | ||
|
|
||
| <ul | ||
| class:list={[ | ||
| !nested | ||
| ? "top-level list-none p-0" | ||
| : "mt-0.5 ml-3 list-none border-l border-[var(--sidebar-border)] p-0 pl-2", | ||
| ]} | ||
| > | ||
| { | ||
| sublist.map((entry, idx) => ( | ||
| <li class="break-words"> | ||
| {entry.type === "link" ? ( | ||
| <a | ||
| href={entry.href} | ||
| aria-current={entry.isCurrent ? "page" : undefined} | ||
| class:list={[ | ||
| "flex min-h-[2.125rem] items-start rounded-lg px-3 py-1.5 text-sm font-medium no-underline transition-colors duration-150", | ||
| "outline-2 outline-offset-0 outline-transparent focus-visible:outline-blue-500 dark:focus-visible:outline-blue-400", | ||
| "text-[var(--sidebar-text)] hover:bg-[var(--sidebar-hover-bg)] hover:text-[var(--sidebar-text-strong)]", | ||
| entry.isCurrent && | ||
| "!bg-[var(--sidebar-active-bg)] !font-semibold !text-[var(--sidebar-text-strong)]", | ||
| !nested && "large", | ||
| entry.attrs.class, | ||
| ]} | ||
| {...entry.attrs} | ||
| > | ||
| <span class=""> | ||
MohamedH1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {entry.label} | ||
| </span> | ||
| {entry.badge && ( | ||
| <Badge | ||
| variant={entry.badge.variant} | ||
| class={`ml-[0.5em] ${entry.badge.class ?? ""}`} | ||
| text={entry.badge.text} | ||
| /> | ||
| )} | ||
| </a> | ||
| ) : ( | ||
| <details | ||
| open={ | ||
| flattenSidebar(entry.entries).some((i: any) => i.isCurrent) || | ||
| !entry.collapsed | ||
| } | ||
| > | ||
| <summary class="flex min-h-[2.125rem] cursor-pointer items-start justify-between rounded-lg px-3 py-1.5 text-sm font-medium text-[var(--sidebar-text)] no-underline outline-2 outline-offset-0 outline-transparent transition-colors duration-150 select-none hover:bg-[var(--sidebar-hover-bg)] hover:text-[var(--sidebar-text-strong)] focus-visible:outline-blue-500 dark:focus-visible:outline-blue-400 [&::-webkit-details-marker]:hidden [&::marker]:hidden"> | ||
| <span class="group-label"> | ||
| <span class:list={["", !nested && "large"]}>{entry.label}</span> | ||
MohamedH1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {entry.badge && ( | ||
| <Badge | ||
| variant={entry.badge.variant} | ||
| class={`ml-[0.5em] ${entry.badge.class ?? ""}`} | ||
| text={entry.badge.text} | ||
| /> | ||
| )} | ||
| </span> | ||
| <Icon | ||
| name="right-caret" | ||
| class="caret shrink-0 text-base text-[var(--sidebar-text)] opacity-60 transition-transform duration-200" | ||
| size="1.25rem" | ||
| /> | ||
| </summary> | ||
| <sl-sidebar-restore data-index={restoreIndices[idx]} /> | ||
| <Astro.self sublist={entry.entries} nested /> | ||
| </details> | ||
| )} | ||
| </li> | ||
| )) | ||
| } | ||
| </ul> | ||
|
|
||
| <style is:global> | ||
| /* Caret rotation — must be global because .caret is on an SVG from a child component */ | ||
| .sidebar-content [open] > summary .caret { | ||
| transform: rotate(90deg); | ||
| } | ||
| .sidebar-content [dir="rtl"] .caret { | ||
| transform: rotateZ(180deg); | ||
| } | ||
| </style> | ||
|
|
||
| <style> | ||
| /* Spacing between top-level items */ | ||
| .top-level > li + li { | ||
| margin-top: 1px; | ||
| } | ||
| </style> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.