mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-12 07:58:49 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d980d7a9ea | |||
| eab3b7aea4 | |||
| 3af177be19 |
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix dropdown menu not staying fixed
|
||||||
@@ -10,18 +10,22 @@ export type DropdownButtonProps<E extends HTMLElement = HTMLElement> = Omit<
|
|||||||
'ref'
|
'ref'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/**
|
export type DropdownProps<E extends HTMLElement = HTMLElement> = {
|
||||||
* Button with a dropdown.
|
|
||||||
*/
|
|
||||||
export function Dropdown<E extends HTMLElement>(props: {
|
|
||||||
/** Content of the button */
|
/** Content of the button */
|
||||||
button: (buttonProps: DropdownButtonProps<E>) => React.ReactNode;
|
button: (buttonProps: DropdownButtonProps<E>) => React.ReactNode;
|
||||||
/** Content of the dropdown */
|
/** Content of the dropdown */
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
/** Custom styles */
|
/** Custom styles */
|
||||||
className?: ClassValue;
|
className?: ClassValue;
|
||||||
}) {
|
/** Whether to use fixed positioning (for fixed navbars) */
|
||||||
const { button, children, className } = props;
|
useFixedPosition?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Button with a dropdown.
|
||||||
|
*/
|
||||||
|
export function Dropdown<E extends HTMLElement = HTMLElement>(props: DropdownProps<E>) {
|
||||||
|
const { button, children, className, useFixedPosition = false } = props;
|
||||||
const dropdownId = useId();
|
const dropdownId = useId();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -53,7 +57,7 @@ export function Dropdown<E extends HTMLElement>(props: {
|
|||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="fixed z-50 w-52">
|
<div className={tcls(useFixedPosition ? 'fixed' : 'absolute', 'z-50 w-52')}>
|
||||||
<div
|
<div
|
||||||
className={tcls(
|
className={tcls(
|
||||||
'mt-2',
|
'mt-2',
|
||||||
@@ -92,6 +96,7 @@ export function DropdownChevron() {
|
|||||||
'ms-1',
|
'ms-1',
|
||||||
'transition-all',
|
'transition-all',
|
||||||
'group-hover/dropdown:opacity-11',
|
'group-hover/dropdown:opacity-11',
|
||||||
|
'group-hover/dropdown:rotate-180',
|
||||||
'group-focus-within/dropdown:rotate-180'
|
'group-focus-within/dropdown:rotate-180'
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ export function Header(props: { context: GitBookSiteContext; withTopHeader?: boo
|
|||||||
siteSpace={siteSpace}
|
siteSpace={siteSpace}
|
||||||
siteSpaces={siteSpaces}
|
siteSpaces={siteSpaces}
|
||||||
className="w-full grow py-1"
|
className="w-full grow py-1"
|
||||||
|
useFixedPosition={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -3,15 +3,17 @@ import type { SiteSpace } from '@gitbook/api';
|
|||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
import type { GitBookSiteContext } from '@v2/lib/context';
|
import type { GitBookSiteContext } from '@v2/lib/context';
|
||||||
import { Dropdown, DropdownChevron, DropdownMenu } from './Dropdown';
|
import { Dropdown, DropdownChevron, DropdownMenu, type DropdownProps } from './Dropdown';
|
||||||
import { SpacesDropdownMenuItem } from './SpacesDropdownMenuItem';
|
import { SpacesDropdownMenuItem } from './SpacesDropdownMenuItem';
|
||||||
|
|
||||||
export function SpacesDropdown(props: {
|
export function SpacesDropdown(
|
||||||
context: GitBookSiteContext;
|
props: {
|
||||||
siteSpace: SiteSpace;
|
context: GitBookSiteContext;
|
||||||
siteSpaces: SiteSpace[];
|
siteSpace: SiteSpace;
|
||||||
className?: string;
|
siteSpaces: SiteSpace[];
|
||||||
}) {
|
className?: string;
|
||||||
|
} & Partial<DropdownProps>
|
||||||
|
) {
|
||||||
const { context, siteSpace, siteSpaces, className } = props;
|
const { context, siteSpace, siteSpaces, className } = props;
|
||||||
const { linker } = context;
|
const { linker } = context;
|
||||||
|
|
||||||
@@ -67,6 +69,7 @@ export function SpacesDropdown(props: {
|
|||||||
<DropdownChevron />
|
<DropdownChevron />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{...props}
|
||||||
>
|
>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
{siteSpaces.map((otherSiteSpace, index) => (
|
{siteSpaces.map((otherSiteSpace, index) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user