From 823e351e1c1fc68ca3c20ab35c9a7d9b13760a70 Mon Sep 17 00:00:00 2001 From: 李瑞丰 Date: Fri, 19 May 2023 05:54:29 +0800 Subject: Add a collapse function to the sidebar (#63) Co-authored-by: Chris Swithinbank --- .changeset/loud-books-wash.md | 5 ++++ packages/starlight/components/SidebarSublist.astro | 34 +++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 .changeset/loud-books-wash.md diff --git a/.changeset/loud-books-wash.md b/.changeset/loud-books-wash.md new file mode 100644 index 00000000..f3ba894f --- /dev/null +++ b/.changeset/loud-books-wash.md @@ -0,0 +1,5 @@ +--- +"@astrojs/starlight": patch +--- + +Make sidebar groups to collapsible diff --git a/packages/starlight/components/SidebarSublist.astro b/packages/starlight/components/SidebarSublist.astro index 344df808..762ee446 100644 --- a/packages/starlight/components/SidebarSublist.astro +++ b/packages/starlight/components/SidebarSublist.astro @@ -1,5 +1,6 @@ --- import type { SidebarEntry } from '../utils/navigation'; +import Icon from './Icon.astro'; interface Props { sublist: SidebarEntry[]; @@ -15,10 +16,13 @@ interface Props { {entry.label} ) : ( - <> -

{entry.label}

+
+ +

{entry.label}

+ +
- +
)} )) @@ -36,13 +40,35 @@ interface Props { font-size: var(--sl-text-lg); font-weight: 600; color: var(--sl-color-white); - padding-inline: var(--sl-sidebar-item-padding-inline); } .sidebar-group + .sidebar-group { margin-top: 0.75rem; } + summary { + display: flex; + align-items: center; + justify-content: space-between; + padding-inline: var(--sl-sidebar-item-padding-inline); + cursor: pointer; + user-select: none; + } + summary::marker, + summary::-webkit-details-marker { + display: none; + } + + .caret { + transition: transform 0.2s ease-in-out; + } + :global([dir='rtl']) .caret { + transform: rotateZ(180deg); + } + [open] .caret { + transform: rotateZ(90deg); + } + a { display: block; border-radius: 0.25rem; -- cgit