Skip to content

Commit 054a163

Browse files
authored
Improve AI Actions dropdown (#3499)
1 parent 6ff63f2 commit 054a163

File tree

4 files changed

+54
-27
lines changed

4 files changed

+54
-27
lines changed

packages/gitbook/src/components/AIActions/AIActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function AIActionWrapper(props: {
232232
size="xsmall"
233233
variant="secondary"
234234
label={shortLabel || label}
235-
className="hover:!scale-100 !shadow-none !rounded-r-none hover:!translate-y-0 border-r-0 bg-tint-base text-sm"
235+
className="bg-tint-base text-sm"
236236
onClick={onClick}
237237
href={href}
238238
target={href ? '_blank' : undefined}

packages/gitbook/src/components/AIActions/AIActionsDropdown.tsx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
OpenInLLM,
77
ViewAsMarkdown,
88
} from '@/components/AIActions/AIActions';
9-
import { Button } from '@/components/primitives/Button';
10-
import { DropdownMenu } from '@/components/primitives/DropdownMenu';
9+
import { Button, ButtonGroup } from '@/components/primitives/Button';
10+
import { DropdownMenu, DropdownMenuSeparator } from '@/components/primitives/DropdownMenu';
1111
import type { SiteCustomizationSettings } from '@gitbook/api';
1212

1313
import { Icon } from '@gitbook/icons';
@@ -27,29 +27,31 @@ export function AIActionsDropdown(props: AIActionsDropdownProps) {
2727
const ref = useRef<HTMLDivElement>(null);
2828

2929
return (
30-
<div ref={ref} className="flex h-fit items-stretch justify-start">
30+
<ButtonGroup ref={ref}>
3131
<DefaultAction {...props} />
32-
<DropdownMenu
33-
align="end"
34-
className="!min-w-60 max-w-max"
35-
button={
36-
<Button
37-
icon={
38-
<Icon
39-
icon="chevron-down"
40-
className="size-3 transition-transform group-data-[state=open]/button:rotate-180"
41-
/>
42-
}
43-
iconOnly
44-
size="xsmall"
45-
variant="secondary"
46-
className="hover:!scale-100 hover:!translate-y-0 !shadow-none !rounded-l-none bg-tint-base text-sm"
47-
/>
48-
}
49-
>
50-
<AIActionsDropdownMenuContent {...props} />
51-
</DropdownMenu>
52-
</div>
32+
{props.actions.markdown || props.actions.externalAI ? (
33+
<DropdownMenu
34+
align="end"
35+
className="!min-w-60 max-w-max"
36+
button={
37+
<Button
38+
icon={
39+
<Icon
40+
icon="chevron-down"
41+
className="size-3 transition-transform group-data-[state=open]/button:rotate-180"
42+
/>
43+
}
44+
iconOnly
45+
size="xsmall"
46+
variant="secondary"
47+
className="bg-tint-base text-sm"
48+
/>
49+
}
50+
>
51+
<AIActionsDropdownMenuContent {...props} />
52+
</DropdownMenu>
53+
) : null}
54+
</ButtonGroup>
5355
);
5456
}
5557

@@ -67,6 +69,7 @@ function AIActionsDropdownMenuContent(props: AIActionsDropdownProps) {
6769

6870
{actions.markdown ? (
6971
<>
72+
<DropdownMenuSeparator className="first:hidden" />
7073
<CopyMarkdown
7174
isDefaultAction={!withAIChat}
7275
markdownPageUrl={markdownPageUrl}
@@ -78,6 +81,7 @@ function AIActionsDropdownMenuContent(props: AIActionsDropdownProps) {
7881

7982
{actions.externalAI ? (
8083
<>
84+
<DropdownMenuSeparator className="first:hidden" />
8185
<OpenInLLM provider="chatgpt" url={markdownPageUrl} type="dropdown-menu-item" />
8286
<OpenInLLM provider="claude" url={markdownPageUrl} type="dropdown-menu-item" />
8387
</>

packages/gitbook/src/components/primitives/Button.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,17 @@ export const Button = React.forwardRef<
185185
);
186186
}
187187
);
188+
189+
export const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonProps>(({ children }, ref) => {
190+
return (
191+
<div
192+
ref={ref}
193+
className={tcls(
194+
'*:!transform-none *:!shadow-none flex h-fit items-stretch justify-start',
195+
'[&>*:not(:first-child)]:border-l-0 [&>*:not(:first-child,:last-child)]:rounded-none [&>*:not(:only-child):first-child]:rounded-r-none [&>*:not(:only-child):last-child]:rounded-l-none'
196+
)}
197+
>
198+
{children}
199+
</div>
200+
);
201+
});

packages/gitbook/src/components/primitives/DropdownMenu.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function DropdownMenu(props: {
8686
>
8787
<div
8888
className={tcls(
89-
'flex max-h-80 min-w-40 max-w-[40vw] flex-col gap-1 overflow-auto circular-corners:rounded-xl rounded-md straight-corners:rounded-none border border-tint bg-tint-base p-2 shadow-lg sm:min-w-52 sm:max-w-80',
89+
'flex max-h-96 min-w-40 max-w-[40vw] flex-col gap-1 overflow-auto circular-corners:rounded-xl rounded-md straight-corners:rounded-none border border-tint bg-tint-base p-2 shadow-lg sm:min-w-52 sm:max-w-80',
9090
className
9191
)}
9292
>
@@ -194,7 +194,7 @@ export function DropdownSubMenu(props: { children: React.ReactNode; label: React
194194
collisionPadding={8}
195195
className="z-40 animate-present"
196196
>
197-
<div className="flex max-h-80 min-w-40 max-w-[40vw] flex-col gap-1 overflow-auto rounded-lg straight-corners:rounded-sm bg-tint-base p-2 shadow-lg ring-1 ring-tint-subtle sm:min-w-52 sm:max-w-80">
197+
<div className="flex max-h-96 min-w-40 max-w-[40vw] flex-col gap-1 overflow-auto rounded-lg straight-corners:rounded-sm bg-tint-base p-2 shadow-lg ring-1 ring-tint-subtle sm:min-w-52 sm:max-w-80">
198198
{children}
199199
</div>
200200
</RadixDropdownMenu.SubContent>
@@ -203,6 +203,15 @@ export function DropdownSubMenu(props: { children: React.ReactNode; label: React
203203
);
204204
}
205205

206+
export function DropdownMenuSeparator(props: { className?: ClassValue }) {
207+
const { className } = props;
208+
return (
209+
<RadixDropdownMenu.Separator
210+
className={tcls('my-1 h-px w-full border-tint-subtle border-t', className)}
211+
/>
212+
);
213+
}
214+
206215
/**
207216
* Hook to close the dropdown menu.
208217
*/

0 commit comments

Comments
 (0)