Skip to content
Merged
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/long-wombats-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gitbook": patch
---

Add icon support in tab items
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"catalog": {
"@tsconfig/strictest": "^2.0.6",
"@tsconfig/node20": "^20.1.6",
"@gitbook/api": "0.181.0",
"@gitbook/api": "0.182.0",
"@scalar/api-client-react": "^1.3.46",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useLanguage } from '@/intl/client';
import { tString } from '@/intl/translate';
import { getLocalStorageItem, setLocalStorageItem } from '@/lib/browser';
import { tcls } from '@/lib/tailwind';
import { Icon } from '@gitbook/icons';
import { Icon, type IconName } from '@gitbook/icons';
import { useRouter } from 'next/navigation';

interface TabsState {
Expand Down Expand Up @@ -56,6 +56,7 @@ const TITLES_MAX = 5;
export interface TabsItem {
id: string;
title: string;
icon?: IconName;
body: React.ReactNode;
}

Expand Down Expand Up @@ -319,6 +320,7 @@ function TabsDropdownMenu(props: {
key={tab.id}
onClick={() => onSelect(tab.id)}
active={tab.id === activeTabId}
leadingIcon={tab.icon}
>
{tab.title}
</DropdownMenuItem>
Expand Down Expand Up @@ -347,7 +349,8 @@ const TabItem = memo(function TabItem(props: {
id={getTabButtonId(tab.id)}
onClick={() => onSelect(tab.id)}
>
{tab.title}
{tab.icon && <Icon icon={tab.icon} className="size-4 shrink-0" />}
<span className="min-w-0 truncate">{tab.title}</span>
</TabButton>
);
});
Expand Down Expand Up @@ -411,7 +414,7 @@ function TabButton(
{...rest}
type="button"
className={tcls(
'relative inline-block max-w-full truncate px-3.5 py-2 font-medium text-sm transition-[color]',
'relative inline-flex max-w-full items-center gap-1.5 px-3.5 py-2 font-medium text-sm transition-[color]',
props.className
)}
/>
Expand Down
6 changes: 6 additions & 0 deletions packages/gitbook/src/components/DocumentView/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { DocumentBlockTabs } from '@gitbook/api';
import type { IconName } from '@gitbook/icons';
import { validateIconName } from '@gitbook/icons/icons';

import { tcls } from '@/lib/tailwind';

Expand All @@ -20,9 +22,13 @@ export function Tabs(props: BlockProps<DocumentBlockTabs>) {
throw new Error('Tab block is missing a key');
}

const icon: IconName | undefined =
tab.data.icon && validateIconName(tab.data.icon) ? tab.data.icon : undefined;

return {
id: tab.meta?.id ?? tab.key,
title: tab.data.title ?? '',
icon,
body: (
<Blocks
key={tab.key}
Expand Down
1 change: 0 additions & 1 deletion packages/gitbook/src/components/PageBody/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export async function PageHeader(props: {

const hasAncestors = ancestors.length > 0;

// @ts-expect-error available in next API update
const pageActionsEnabled = page.layout.actions !== false;

// Show page actions if *any* of the actions are enabled
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/lib/icons/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ function collectDocumentIconSourceRequests(

const record = node as Record<string, unknown>;

if (record.type === 'icon' || record.type === 'button') {
if (record.type === 'icon' || record.type === 'button' || record.type === 'tabs-item') {
const data = record.data;
if (data && typeof data === 'object') {
addIconSourceRequest(requests, (data as Record<string, unknown>).icon, iconStyle);
Expand Down
5 changes: 5 additions & 0 deletions packages/gitbook/src/lib/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('resolveFirstDocument', () => {
width: RevisionPageLayoutOptionsWidth.Default,
metadata: true,
tags: true,
actions: true,
},
},
],
Expand Down Expand Up @@ -137,6 +138,7 @@ describe('resolveFirstDocument', () => {
width: RevisionPageLayoutOptionsWidth.Default,
metadata: true,
tags: true,
actions: true,
},
},
];
Expand Down Expand Up @@ -182,6 +184,7 @@ describe('resolvePagePath', () => {
width: RevisionPageLayoutOptionsWidth.Default,
metadata: true,
tags: true,
actions: true,
},
},
];
Expand Down Expand Up @@ -257,6 +260,7 @@ describe('resolvePagePath', () => {
width: RevisionPageLayoutOptionsWidth.Default,
metadata: true,
tags: true,
actions: true,
},
},
],
Expand Down Expand Up @@ -374,6 +378,7 @@ function createDocumentPage(id: string, path: string, hidden = false): RevisionP
width: RevisionPageLayoutOptionsWidth.Default,
metadata: true,
tags: true,
actions: true,
},
};
}
Loading