starlight-sidebar-topics-dropdown 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +15 -15
- package/components/Topics.astro +253 -253
- package/index.ts +92 -82
- package/lib/config.ts +82 -74
- package/lib/content.ts +15 -11
- package/lib/i18n.ts +27 -22
- package/lib/pathname.ts +20 -17
- package/lib/plugin.ts +32 -32
- package/lib/sidebar.ts +210 -173
- package/lib/vite.ts +36 -34
- package/overrides/Pagination.astro +18 -18
- package/overrides/Sidebar.astro +40 -28
- package/package.json +46 -46
- package/schema.ts +10 -10
- package/starlight.d.ts +5 -5
- package/virtual.d.ts +5 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# starlight-sidebar-topics-dropdown
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#16](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/16) [`9edb5dc`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/9edb5dca0215df684c4471ed7e1fe878617be91a) Thanks [@trueberryless](https://github.com/trueberryless)! - Adds support for Astro v5, drops support for Astro v4.
|
|
8
|
+
|
|
9
|
+
⚠️ **BREAKING CHANGE:** The minimum supported version of Starlight is now `0.30.0`.
|
|
10
|
+
|
|
11
|
+
Please follow the [upgrade guide](https://github.com/withastro/starlight/releases/tag/%40astrojs/starlight%400.30.0) to update your project.
|
|
12
|
+
|
|
13
|
+
Note that the [`legacy.collections` flag](https://docs.astro.build/en/reference/legacy-flags/#collections) is not supported by this plugin and you should update your collections to use Astro's new Content Layer API.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#18](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/18) [`2039e9a`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/2039e9a60659b5628c7406952bde0d453e38aeda) Thanks [@trueberryless](https://github.com/trueberryless)! - Add Unnested Sidebar configuration
|
|
18
|
+
|
|
19
|
+
## 0.2.2
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#11](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/11) [`88b99c5`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/88b99c5efda810aa7a614752af18dd01af7fc1e0) Thanks [@trueberryless](https://github.com/trueberryless)! - Improves missing topic error messages by including the slug of the relevant page
|
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# `starlight-sidebar-topics-dropdown`
|
|
2
|
-
|
|
3
|
-
Starlight plugin to split your docs page into multiple subpages and switch between them with a dropdown menu in the sidebar.
|
|
4
|
-
|
|
5
|
-
## Documentation
|
|
6
|
-
|
|
7
|
-
Want to get started immediately?
|
|
8
|
-
|
|
9
|
-
Check out the `starlight-sidebar-topics-dropdown` getting started guide.
|
|
10
|
-
|
|
11
|
-
## License
|
|
12
|
-
|
|
13
|
-
Licensed under the MIT
|
|
14
|
-
|
|
15
|
-
See [LICENSE](
|
|
1
|
+
# `starlight-sidebar-topics-dropdown`
|
|
2
|
+
|
|
3
|
+
Starlight plugin to split your docs page into multiple subpages and switch between them with a dropdown menu in the sidebar.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
Want to get started immediately?
|
|
8
|
+
|
|
9
|
+
Check out the `starlight-sidebar-topics-dropdown` getting started guide.
|
|
10
|
+
|
|
11
|
+
## License
|
|
12
|
+
|
|
13
|
+
Licensed under the MIT license, Copyright © trueberryless.
|
|
14
|
+
|
|
15
|
+
See [LICENSE](/LICENSE) for more information.
|
package/components/Topics.astro
CHANGED
|
@@ -1,253 +1,253 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { Badge, Icon } from '@astrojs/starlight/components'
|
|
3
|
-
import { AstroError } from 'astro/errors'
|
|
4
|
-
import type { ComponentProps } from 'astro/types'
|
|
5
|
-
import { getRelativeLocaleUrl } from 'astro:i18n'
|
|
6
|
-
import starlightConfig from 'virtual:starlight/user-config'
|
|
7
|
-
import config from 'virtual:starlight-sidebar-topics-dropdown/config'
|
|
8
|
-
|
|
9
|
-
import type { StarlightSidebarTopicsDropdownSharedConfig } from '../lib/config'
|
|
10
|
-
|
|
11
|
-
interface Props {
|
|
12
|
-
current: StarlightSidebarTopicsDropdownSharedConfig[number]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const { current } = Astro.props
|
|
16
|
-
|
|
17
|
-
const defaultLang = starlightConfig.defaultLocale?.lang || starlightConfig.defaultLocale?.locale || 'en'
|
|
18
|
-
|
|
19
|
-
function getTranslation(translations: Record<string, string>, link: string, description: string) {
|
|
20
|
-
const defaultTranslation = translations[defaultLang]
|
|
21
|
-
|
|
22
|
-
if (!defaultTranslation) {
|
|
23
|
-
throw new AstroError(
|
|
24
|
-
`The ${description} for "${link}" must have a key for the default language "${defaultLang}".`,
|
|
25
|
-
'Update the Starlight config to include a topic label for the default language.',
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let translation = defaultTranslation
|
|
30
|
-
|
|
31
|
-
if (Astro.currentLocale) {
|
|
32
|
-
translation = translations[Astro.currentLocale] ?? defaultTranslation
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return translation
|
|
36
|
-
}
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
<div class="starlight-sidebar-topics-dropdown-dropdown">
|
|
40
|
-
<button id="starlight-sidebar-topics-dropdown-button" class="starlight-sidebar-topics-dropdown-button">
|
|
41
|
-
{current.icon && (
|
|
42
|
-
<div class="starlight-sidebar-topics-dropdown-button-icon">
|
|
43
|
-
<Icon name={current.icon as ComponentProps<typeof Icon>['name']} />
|
|
44
|
-
</div>
|
|
45
|
-
)}
|
|
46
|
-
<span class="starlight-sidebar-topics-dropdown-button-label">{typeof current.label === 'string' ? current.label : getTranslation(current.label, current.link, 'topic label')}</span>
|
|
47
|
-
{current.badge && (
|
|
48
|
-
<Badge
|
|
49
|
-
class="starlight-sidebar-topics-dropdown-badge"
|
|
50
|
-
text={
|
|
51
|
-
typeof current.badge.text === 'string'
|
|
52
|
-
? current.badge.text
|
|
53
|
-
: getTranslation(current.badge.text, current.link, 'current badge text')
|
|
54
|
-
}
|
|
55
|
-
variant={current.badge.variant}
|
|
56
|
-
/>
|
|
57
|
-
)}
|
|
58
|
-
<svg width="16" height="16" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 opacity-50" aria-hidden="true"><path d="M4.93179 5.43179C4.75605 5.60753 4.75605 5.89245 4.93179 6.06819C5.10753 6.24392 5.39245 6.24392 5.56819 6.06819L7.49999 4.13638L9.43179 6.06819C9.60753 6.24392 9.89245 6.24392 10.0682 6.06819C10.2439 5.89245 10.2439 5.60753 10.0682 5.43179L7.81819 3.18179C7.73379 3.0974 7.61933 3.04999 7.49999 3.04999C7.38064 3.04999 7.26618 3.0974 7.18179 3.18179L4.93179 5.43179ZM10.0682 9.56819C10.2439 9.39245 10.2439 9.10753 10.0682 8.93179C9.89245 8.75606 9.60753 8.75606 9.43179 8.93179L7.49999 10.8636L5.56819 8.93179C5.39245 8.75606 5.10753 8.75606 4.93179 8.93179C4.75605 9.10753 4.75605 9.39245 4.93179 9.56819L7.18179 11.8182C7.35753 11.9939 7.64245 11.9939 7.81819 11.8182L10.0682 9.56819Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg>
|
|
59
|
-
</button>
|
|
60
|
-
|
|
61
|
-
<div id="starlight-sidebar-topics-dropdown-menu" class="starlight-sidebar-topics-dropdown-menu" hidden>
|
|
62
|
-
{
|
|
63
|
-
config.map((topic) => {
|
|
64
|
-
const isLinkTopic = topic.type === 'link'
|
|
65
|
-
const isCurrent = isLinkTopic ? false : topic.label === current.label && topic.link === current.link
|
|
66
|
-
const link =
|
|
67
|
-
!isLinkTopic && Astro.currentLocale ? getRelativeLocaleUrl(Astro.currentLocale, topic.link) : topic.link
|
|
68
|
-
const label =
|
|
69
|
-
typeof topic.label === 'string' ? topic.label : getTranslation(topic.label, topic.link, 'topic label')
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<a href={link} class:list={{ 'starlight-sidebar-topics-dropdown-item': true, 'starlight-sidebar-topics-dropdown-current-item': isCurrent }}>
|
|
73
|
-
{topic.icon && (
|
|
74
|
-
<div class="starlight-sidebar-topics-dropdown-icon">
|
|
75
|
-
<Icon name={topic.icon as ComponentProps<typeof Icon>['name']} />
|
|
76
|
-
</div>
|
|
77
|
-
)}
|
|
78
|
-
<span class="starlight-sidebar-topics-dropdown-label">{label}</span>
|
|
79
|
-
{topic.badge && (
|
|
80
|
-
<Badge
|
|
81
|
-
class="starlight-sidebar-topics-dropdown-badge"
|
|
82
|
-
text={
|
|
83
|
-
typeof topic.badge.text === 'string'
|
|
84
|
-
? topic.badge.text
|
|
85
|
-
: getTranslation(topic.badge.text, topic.link, 'topic badge text')
|
|
86
|
-
}
|
|
87
|
-
variant={topic.badge.variant}
|
|
88
|
-
/>
|
|
89
|
-
)}
|
|
90
|
-
</a>
|
|
91
|
-
)
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
</div>
|
|
95
|
-
</div>
|
|
96
|
-
|
|
97
|
-
<style>
|
|
98
|
-
.starlight-sidebar-topics-dropdown-dropdown {
|
|
99
|
-
position: relative;
|
|
100
|
-
display: block;
|
|
101
|
-
width: calc(100% - 8px - 2 * 2px);
|
|
102
|
-
margin-left: calc(8px + 2px);
|
|
103
|
-
margin-right: calc(2px);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
.starlight-sidebar-topics-dropdown-button {
|
|
107
|
-
display: flex;
|
|
108
|
-
align-items: center;
|
|
109
|
-
background-color: var(--sl-color-gray-6);
|
|
110
|
-
border: none;
|
|
111
|
-
border-radius: 0.25rem;
|
|
112
|
-
color: var(--sl-color-white);
|
|
113
|
-
padding: 0.3rem 0.5rem;
|
|
114
|
-
cursor: pointer;
|
|
115
|
-
width: 100%;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
.starlight-sidebar-topics-dropdown-button::before {
|
|
119
|
-
content: '';
|
|
120
|
-
background-color: var(--sl-color-gray-5);
|
|
121
|
-
border-radius: 0.25rem;
|
|
122
|
-
inset: -2px;
|
|
123
|
-
position: absolute;
|
|
124
|
-
z-index: -1;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
.starlight-sidebar-topics-dropdown-button:has(.starlight-sidebar-topics-dropdown-button-icon)::before {
|
|
129
|
-
content: '';
|
|
130
|
-
background-image: linear-gradient(to right, var(--sl-color-text-accent) calc(1.4rem + 16px + 2px), var(--sl-color-gray-5) 0);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
.starlight-sidebar-topics-dropdown-button:has(.starlight-sidebar-topics-dropdown-button-icon) {
|
|
134
|
-
background: linear-gradient(to right, var(--sl-color-text-accent) calc(1.4rem + 16px), var(--sl-color-gray-6) 0);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
.starlight-sidebar-topics-dropdown-button-icon {
|
|
138
|
-
align-items: center;
|
|
139
|
-
border-radius: 0.25rem;
|
|
140
|
-
display: flex;
|
|
141
|
-
justify-content: center;
|
|
142
|
-
padding: 0.2rem;
|
|
143
|
-
background-color: var(--sl-color-text-accent);
|
|
144
|
-
color: var(--sl-color-text-invert);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
.starlight-sidebar-topics-dropdown-button-label {
|
|
148
|
-
font-weight: 600;
|
|
149
|
-
margin-right: 0.5rem;
|
|
150
|
-
overflow: hidden;
|
|
151
|
-
text-overflow: ellipsis;
|
|
152
|
-
white-space: nowrap;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
.starlight-sidebar-topics-dropdown-button:has(.starlight-sidebar-topics-dropdown-button-icon) .starlight-sidebar-topics-dropdown-button-label {
|
|
156
|
-
font-weight: 600;
|
|
157
|
-
margin-left: 1rem;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
.starlight-sidebar-topics-dropdown-label {
|
|
161
|
-
font-weight: 600;
|
|
162
|
-
margin-right: 0.5rem;
|
|
163
|
-
overflow: hidden;
|
|
164
|
-
text-overflow: ellipsis;
|
|
165
|
-
white-space: nowrap;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
.starlight-sidebar-topics-dropdown-item:has(.starlight-sidebar-topics-dropdown-icon) .starlight-sidebar-topics-dropdown-label {
|
|
169
|
-
margin-left: 0.5rem;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
.starlight-sidebar-topics-dropdown-button>svg {
|
|
173
|
-
margin-left: auto;
|
|
174
|
-
font-size: 1rem;
|
|
175
|
-
color: var(--sl-color-white);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
.starlight-sidebar-topics-dropdown-menu {
|
|
179
|
-
display: block;
|
|
180
|
-
position: absolute;
|
|
181
|
-
margin-top: 0.5rem;
|
|
182
|
-
width: 100%;
|
|
183
|
-
background-color: var(--sl-color-gray-6);
|
|
184
|
-
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
|
|
185
|
-
min-width: 200px;
|
|
186
|
-
padding: 0.5rem;
|
|
187
|
-
border-radius: 0.25rem;
|
|
188
|
-
z-index: 1000000;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
.starlight-sidebar-topics-dropdown-menu[hidden] {
|
|
192
|
-
display: none;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
.starlight-sidebar-topics-dropdown-item {
|
|
196
|
-
display: flex;
|
|
197
|
-
align-items: center;
|
|
198
|
-
padding: 0.3em;
|
|
199
|
-
color: var(--sl-color-white);
|
|
200
|
-
text-decoration: none;
|
|
201
|
-
font-weight: 600;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
.starlight-sidebar-topics-dropdown-icon {
|
|
205
|
-
align-items: center;
|
|
206
|
-
border-radius: 0.25rem;
|
|
207
|
-
border: 1px solid var(--sl-color-gray-4);
|
|
208
|
-
display: flex;
|
|
209
|
-
justify-content: center;
|
|
210
|
-
padding: 0.25rem;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
.starlight-sidebar-topics-dropdown-button:is(.starlight-sidebar-topics-dropdown-current, :hover, :focus-visible) .starlight-sidebar-topics-dropdown-icon {
|
|
214
|
-
background-color: var(--sl-color-text-accent);
|
|
215
|
-
border-color: var(--sl-color-text-accent);
|
|
216
|
-
color: var(--sl-color-text-invert);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
.starlight-sidebar-topics-dropdown-item:is(:hover, .starlight-sidebar-topics-dropdown-current-item) .starlight-sidebar-topics-dropdown-icon {
|
|
220
|
-
background-color: var(--sl-color-text-accent);
|
|
221
|
-
border-color: var(--sl-color-text-accent);
|
|
222
|
-
color: var(--sl-color-text-invert);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
.starlight-sidebar-topics-dropdown-badge {
|
|
226
|
-
margin-left: 0.25rem;
|
|
227
|
-
overflow: hidden;
|
|
228
|
-
text-overflow: ellipsis;
|
|
229
|
-
white-space: nowrap;
|
|
230
|
-
}
|
|
231
|
-
</style>
|
|
232
|
-
|
|
233
|
-
<script is:inline>
|
|
234
|
-
const dropdownButton = document.getElementById('starlight-sidebar-topics-dropdown-button');
|
|
235
|
-
const dropdownMenu = document.getElementById('starlight-sidebar-topics-dropdown-menu');
|
|
236
|
-
|
|
237
|
-
if (!dropdownButton || !dropdownMenu) {
|
|
238
|
-
throw new Error('Dropdown elements not found');
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
dropdownButton.addEventListener('click', () => {
|
|
242
|
-
const isOpen = !dropdownMenu.hidden;
|
|
243
|
-
dropdownMenu.hidden = isOpen;
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
function closeDropdown(event) {
|
|
247
|
-
if (dropdownMenu && !dropdownMenu.contains(event.target) && dropdownButton && !dropdownButton.contains(event.target)) {
|
|
248
|
-
dropdownMenu.hidden = true;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
document.addEventListener('click', closeDropdown);
|
|
253
|
-
</script>
|
|
1
|
+
---
|
|
2
|
+
import { Badge, Icon } from '@astrojs/starlight/components'
|
|
3
|
+
import { AstroError } from 'astro/errors'
|
|
4
|
+
import type { ComponentProps } from 'astro/types'
|
|
5
|
+
import { getRelativeLocaleUrl } from 'astro:i18n'
|
|
6
|
+
import starlightConfig from 'virtual:starlight/user-config'
|
|
7
|
+
import config from 'virtual:starlight-sidebar-topics-dropdown/config'
|
|
8
|
+
|
|
9
|
+
import type { StarlightSidebarTopicsDropdownSharedConfig } from '../lib/config'
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
current: StarlightSidebarTopicsDropdownSharedConfig[number]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { current } = Astro.props
|
|
16
|
+
|
|
17
|
+
const defaultLang = starlightConfig.defaultLocale?.lang || starlightConfig.defaultLocale?.locale || 'en'
|
|
18
|
+
|
|
19
|
+
function getTranslation(translations: Record<string, string>, link: string, description: string) {
|
|
20
|
+
const defaultTranslation = translations[defaultLang]
|
|
21
|
+
|
|
22
|
+
if (!defaultTranslation) {
|
|
23
|
+
throw new AstroError(
|
|
24
|
+
`The ${description} for "${link}" must have a key for the default language "${defaultLang}".`,
|
|
25
|
+
'Update the Starlight config to include a topic label for the default language.',
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let translation = defaultTranslation
|
|
30
|
+
|
|
31
|
+
if (Astro.currentLocale) {
|
|
32
|
+
translation = translations[Astro.currentLocale] ?? defaultTranslation
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return translation
|
|
36
|
+
}
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
<div class="starlight-sidebar-topics-dropdown-dropdown">
|
|
40
|
+
<button id="starlight-sidebar-topics-dropdown-button" class="starlight-sidebar-topics-dropdown-button">
|
|
41
|
+
{current.icon && (
|
|
42
|
+
<div class="starlight-sidebar-topics-dropdown-button-icon">
|
|
43
|
+
<Icon name={current.icon as ComponentProps<typeof Icon>['name']} />
|
|
44
|
+
</div>
|
|
45
|
+
)}
|
|
46
|
+
<span class="starlight-sidebar-topics-dropdown-button-label">{typeof current.label === 'string' ? current.label : getTranslation(current.label, current.link, 'topic label')}</span>
|
|
47
|
+
{current.badge && (
|
|
48
|
+
<Badge
|
|
49
|
+
class="starlight-sidebar-topics-dropdown-badge"
|
|
50
|
+
text={
|
|
51
|
+
typeof current.badge.text === 'string'
|
|
52
|
+
? current.badge.text
|
|
53
|
+
: getTranslation(current.badge.text, current.link, 'current badge text')
|
|
54
|
+
}
|
|
55
|
+
variant={current.badge.variant}
|
|
56
|
+
/>
|
|
57
|
+
)}
|
|
58
|
+
<svg width="16" height="16" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 opacity-50" aria-hidden="true"><path d="M4.93179 5.43179C4.75605 5.60753 4.75605 5.89245 4.93179 6.06819C5.10753 6.24392 5.39245 6.24392 5.56819 6.06819L7.49999 4.13638L9.43179 6.06819C9.60753 6.24392 9.89245 6.24392 10.0682 6.06819C10.2439 5.89245 10.2439 5.60753 10.0682 5.43179L7.81819 3.18179C7.73379 3.0974 7.61933 3.04999 7.49999 3.04999C7.38064 3.04999 7.26618 3.0974 7.18179 3.18179L4.93179 5.43179ZM10.0682 9.56819C10.2439 9.39245 10.2439 9.10753 10.0682 8.93179C9.89245 8.75606 9.60753 8.75606 9.43179 8.93179L7.49999 10.8636L5.56819 8.93179C5.39245 8.75606 5.10753 8.75606 4.93179 8.93179C4.75605 9.10753 4.75605 9.39245 4.93179 9.56819L7.18179 11.8182C7.35753 11.9939 7.64245 11.9939 7.81819 11.8182L10.0682 9.56819Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg>
|
|
59
|
+
</button>
|
|
60
|
+
|
|
61
|
+
<div id="starlight-sidebar-topics-dropdown-menu" class="starlight-sidebar-topics-dropdown-menu" hidden>
|
|
62
|
+
{
|
|
63
|
+
config.map((topic) => {
|
|
64
|
+
const isLinkTopic = topic.type === 'link'
|
|
65
|
+
const isCurrent = isLinkTopic ? false : topic.label === current.label && topic.link === current.link
|
|
66
|
+
const link =
|
|
67
|
+
!isLinkTopic && Astro.currentLocale ? getRelativeLocaleUrl(Astro.currentLocale, topic.link) : topic.link
|
|
68
|
+
const label =
|
|
69
|
+
typeof topic.label === 'string' ? topic.label : getTranslation(topic.label, topic.link, 'topic label')
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<a href={link} class:list={{ 'starlight-sidebar-topics-dropdown-item': true, 'starlight-sidebar-topics-dropdown-current-item': isCurrent }}>
|
|
73
|
+
{topic.icon && (
|
|
74
|
+
<div class="starlight-sidebar-topics-dropdown-icon">
|
|
75
|
+
<Icon name={topic.icon as ComponentProps<typeof Icon>['name']} />
|
|
76
|
+
</div>
|
|
77
|
+
)}
|
|
78
|
+
<span class="starlight-sidebar-topics-dropdown-label">{label}</span>
|
|
79
|
+
{topic.badge && (
|
|
80
|
+
<Badge
|
|
81
|
+
class="starlight-sidebar-topics-dropdown-badge"
|
|
82
|
+
text={
|
|
83
|
+
typeof topic.badge.text === 'string'
|
|
84
|
+
? topic.badge.text
|
|
85
|
+
: getTranslation(topic.badge.text, topic.link, 'topic badge text')
|
|
86
|
+
}
|
|
87
|
+
variant={topic.badge.variant}
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
</a>
|
|
91
|
+
)
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<style>
|
|
98
|
+
.starlight-sidebar-topics-dropdown-dropdown {
|
|
99
|
+
position: relative;
|
|
100
|
+
display: block;
|
|
101
|
+
width: calc(100% - 8px - 2 * 2px);
|
|
102
|
+
margin-left: calc(8px + 2px);
|
|
103
|
+
margin-right: calc(2px);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.starlight-sidebar-topics-dropdown-button {
|
|
107
|
+
display: flex;
|
|
108
|
+
align-items: center;
|
|
109
|
+
background-color: var(--sl-color-gray-6);
|
|
110
|
+
border: none;
|
|
111
|
+
border-radius: 0.25rem;
|
|
112
|
+
color: var(--sl-color-white);
|
|
113
|
+
padding: 0.3rem 0.5rem;
|
|
114
|
+
cursor: pointer;
|
|
115
|
+
width: 100%;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.starlight-sidebar-topics-dropdown-button::before {
|
|
119
|
+
content: '';
|
|
120
|
+
background-color: var(--sl-color-gray-5);
|
|
121
|
+
border-radius: 0.25rem;
|
|
122
|
+
inset: -2px;
|
|
123
|
+
position: absolute;
|
|
124
|
+
z-index: -1;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
.starlight-sidebar-topics-dropdown-button:has(.starlight-sidebar-topics-dropdown-button-icon)::before {
|
|
129
|
+
content: '';
|
|
130
|
+
background-image: linear-gradient(to right, var(--sl-color-text-accent) calc(1.4rem + 16px + 2px), var(--sl-color-gray-5) 0);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.starlight-sidebar-topics-dropdown-button:has(.starlight-sidebar-topics-dropdown-button-icon) {
|
|
134
|
+
background: linear-gradient(to right, var(--sl-color-text-accent) calc(1.4rem + 16px), var(--sl-color-gray-6) 0);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.starlight-sidebar-topics-dropdown-button-icon {
|
|
138
|
+
align-items: center;
|
|
139
|
+
border-radius: 0.25rem;
|
|
140
|
+
display: flex;
|
|
141
|
+
justify-content: center;
|
|
142
|
+
padding: 0.2rem;
|
|
143
|
+
background-color: var(--sl-color-text-accent);
|
|
144
|
+
color: var(--sl-color-text-invert);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.starlight-sidebar-topics-dropdown-button-label {
|
|
148
|
+
font-weight: 600;
|
|
149
|
+
margin-right: 0.5rem;
|
|
150
|
+
overflow: hidden;
|
|
151
|
+
text-overflow: ellipsis;
|
|
152
|
+
white-space: nowrap;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.starlight-sidebar-topics-dropdown-button:has(.starlight-sidebar-topics-dropdown-button-icon) .starlight-sidebar-topics-dropdown-button-label {
|
|
156
|
+
font-weight: 600;
|
|
157
|
+
margin-left: 1rem;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.starlight-sidebar-topics-dropdown-label {
|
|
161
|
+
font-weight: 600;
|
|
162
|
+
margin-right: 0.5rem;
|
|
163
|
+
overflow: hidden;
|
|
164
|
+
text-overflow: ellipsis;
|
|
165
|
+
white-space: nowrap;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.starlight-sidebar-topics-dropdown-item:has(.starlight-sidebar-topics-dropdown-icon) .starlight-sidebar-topics-dropdown-label {
|
|
169
|
+
margin-left: 0.5rem;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.starlight-sidebar-topics-dropdown-button>svg {
|
|
173
|
+
margin-left: auto;
|
|
174
|
+
font-size: 1rem;
|
|
175
|
+
color: var(--sl-color-white);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.starlight-sidebar-topics-dropdown-menu {
|
|
179
|
+
display: block;
|
|
180
|
+
position: absolute;
|
|
181
|
+
margin-top: 0.5rem;
|
|
182
|
+
width: 100%;
|
|
183
|
+
background-color: var(--sl-color-gray-6);
|
|
184
|
+
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
|
|
185
|
+
min-width: 200px;
|
|
186
|
+
padding: 0.5rem;
|
|
187
|
+
border-radius: 0.25rem;
|
|
188
|
+
z-index: 1000000;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.starlight-sidebar-topics-dropdown-menu[hidden] {
|
|
192
|
+
display: none;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.starlight-sidebar-topics-dropdown-item {
|
|
196
|
+
display: flex;
|
|
197
|
+
align-items: center;
|
|
198
|
+
padding: 0.3em;
|
|
199
|
+
color: var(--sl-color-white);
|
|
200
|
+
text-decoration: none;
|
|
201
|
+
font-weight: 600;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.starlight-sidebar-topics-dropdown-icon {
|
|
205
|
+
align-items: center;
|
|
206
|
+
border-radius: 0.25rem;
|
|
207
|
+
border: 1px solid var(--sl-color-gray-4);
|
|
208
|
+
display: flex;
|
|
209
|
+
justify-content: center;
|
|
210
|
+
padding: 0.25rem;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.starlight-sidebar-topics-dropdown-button:is(.starlight-sidebar-topics-dropdown-current, :hover, :focus-visible) .starlight-sidebar-topics-dropdown-icon {
|
|
214
|
+
background-color: var(--sl-color-text-accent);
|
|
215
|
+
border-color: var(--sl-color-text-accent);
|
|
216
|
+
color: var(--sl-color-text-invert);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.starlight-sidebar-topics-dropdown-item:is(:hover, .starlight-sidebar-topics-dropdown-current-item) .starlight-sidebar-topics-dropdown-icon {
|
|
220
|
+
background-color: var(--sl-color-text-accent);
|
|
221
|
+
border-color: var(--sl-color-text-accent);
|
|
222
|
+
color: var(--sl-color-text-invert);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.starlight-sidebar-topics-dropdown-badge {
|
|
226
|
+
margin-left: 0.25rem;
|
|
227
|
+
overflow: hidden;
|
|
228
|
+
text-overflow: ellipsis;
|
|
229
|
+
white-space: nowrap;
|
|
230
|
+
}
|
|
231
|
+
</style>
|
|
232
|
+
|
|
233
|
+
<script is:inline>
|
|
234
|
+
const dropdownButton = document.getElementById('starlight-sidebar-topics-dropdown-button');
|
|
235
|
+
const dropdownMenu = document.getElementById('starlight-sidebar-topics-dropdown-menu');
|
|
236
|
+
|
|
237
|
+
if (!dropdownButton || !dropdownMenu) {
|
|
238
|
+
throw new Error('Dropdown elements not found');
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
dropdownButton.addEventListener('click', () => {
|
|
242
|
+
const isOpen = !dropdownMenu.hidden;
|
|
243
|
+
dropdownMenu.hidden = isOpen;
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
function closeDropdown(event) {
|
|
247
|
+
if (dropdownMenu && !dropdownMenu.contains(event.target) && dropdownButton && !dropdownButton.contains(event.target)) {
|
|
248
|
+
dropdownMenu.hidden = true;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
document.addEventListener('click', closeDropdown);
|
|
253
|
+
</script>
|