fix: fixes an issue preventing to use badges with generated sidebar groups

This commit is contained in:
HiDeoo
2024-05-11 18:16:30 +02:00
parent f5dbcf84d8
commit c6a495dd83
4 changed files with 18 additions and 3 deletions

View File

@@ -30,7 +30,7 @@ export default defineConfig({
sidebar: [
{
label: 'Bar Content',
items: [barTypeDocSidebarGroup],
items: [{ ...barTypeDocSidebarGroup, badge: 'generated' }],
},
{
label: 'Foo Content',

View File

@@ -43,7 +43,7 @@ export function getSidebarFromReflections(
function replaceSidebarGroupPlaceholder(group: SidebarManualGroup): SidebarGroup {
if (group.label === sidebarGroupPlaceholder.label) {
return sidebarGroup
return group.badge ? { ...sidebarGroup, badge: group.badge } : sidebarGroup
}
if (isSidebarManualGroup(group)) {
@@ -252,6 +252,13 @@ interface SidebarManualGroup {
collapsed?: boolean
items: (LinkItem | SidebarGroup)[]
label: string
badge?:
| string
| {
text: string
variant: 'note' | 'danger' | 'success' | 'caution' | 'tip' | 'default'
}
| undefined
}
interface LinkItem {

View File

@@ -75,7 +75,7 @@ export class DocPage {
for (const category of await list.locator('> li > details').all()) {
items.push({
collapsed: !(await category.getAttribute('open')),
label: await category.locator(`> summary > div > span`).textContent(),
label: await category.locator(`> summary > div > span:not(.sl-badge)`).textContent(),
items: await this.#getTypeDocSidebarChildrenItems(category.locator('> ul')),
})
}

View File

@@ -42,3 +42,11 @@ test('should generate the proper items for for multiple plugins with different c
},
])
})
test('should support having a badge', async ({ docPage }) => {
docPage.useMultiplePlugins()
await docPage.goto('api-multiple-plugins-bar/classes/bar')
await expect(docPage.page.locator('.sl-badge:has-text("generated")')).toBeVisible()
})