mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
- pair-scan: type BARCODE_SCANNER_SETTINGS as BarcodeSettings - explorer-sidebar: add missing desktopSidebarStyle useMemo - sidebar-workspace-list: coerce null dotColor to transparent - menu-header, e2e.test: formatting
126 lines
3.6 KiB
TypeScript
126 lines
3.6 KiB
TypeScript
import { useCallback, useMemo, type ReactNode } from "react";
|
|
import { View, type StyleProp, type ViewStyle } from "react-native";
|
|
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
|
import { PanelLeft } from "lucide-react-native";
|
|
import { ScreenHeader } from "./screen-header";
|
|
import { ScreenTitle } from "./screen-title";
|
|
import { HeaderToggleButton } from "./header-toggle-button";
|
|
import { selectIsAgentListOpen, usePanelStore } from "@/stores/panel-store";
|
|
import { useIsCompactFormFactor } from "@/constants/layout";
|
|
import { getShortcutOs } from "@/utils/shortcut-platform";
|
|
|
|
interface MenuHeaderProps {
|
|
title?: string;
|
|
rightContent?: ReactNode;
|
|
borderless?: boolean;
|
|
}
|
|
|
|
interface SidebarMenuToggleProps {
|
|
style?: StyleProp<ViewStyle>;
|
|
tooltipSide?: "left" | "right" | "top" | "bottom";
|
|
testID?: string;
|
|
nativeID?: string;
|
|
}
|
|
|
|
const MOBILE_MENU_LINE_WIDTH = 16;
|
|
const MOBILE_MENU_LINE_SHORT_WIDTH = 8;
|
|
const MOBILE_MENU_LINE_HEIGHT = 2;
|
|
|
|
function MobileMenuIcon({ color }: { color: string }) {
|
|
const lineStyle = useMemo(() => [styles.mobileMenuLine, { backgroundColor: color }], [color]);
|
|
const shortLineStyle = useMemo(
|
|
() => [styles.mobileMenuLine, styles.mobileMenuLineShort, { backgroundColor: color }],
|
|
[color],
|
|
);
|
|
return (
|
|
<View style={styles.mobileMenuIcon} pointerEvents="none">
|
|
<View style={lineStyle} />
|
|
<View style={lineStyle} />
|
|
<View style={shortLineStyle} />
|
|
</View>
|
|
);
|
|
}
|
|
|
|
export function SidebarMenuToggle({
|
|
style,
|
|
tooltipSide = "right",
|
|
testID = "menu-button",
|
|
nativeID = "menu-button",
|
|
}: SidebarMenuToggleProps = {}) {
|
|
const { theme } = useUnistyles();
|
|
const isMobile = useIsCompactFormFactor();
|
|
const isOpen = usePanelStore((state) => selectIsAgentListOpen(state, { isCompact: isMobile }));
|
|
const toggleAgentListForLayout = usePanelStore((state) => state.toggleAgentListForLayout);
|
|
const toggleShortcutKeys = useMemo(
|
|
() => (getShortcutOs() === "mac" ? ["mod", "B"] : ["mod", "."]),
|
|
[],
|
|
);
|
|
|
|
const menuIconColor =
|
|
!isMobile && isOpen ? theme.colors.foreground : theme.colors.foregroundMuted;
|
|
|
|
const handlePress = useCallback(() => {
|
|
toggleAgentListForLayout({ isCompact: isMobile });
|
|
}, [toggleAgentListForLayout, isMobile]);
|
|
|
|
const accessibilityState = useMemo(() => ({ expanded: isOpen }), [isOpen]);
|
|
|
|
return (
|
|
<HeaderToggleButton
|
|
onPress={handlePress}
|
|
tooltipLabel="Toggle sidebar"
|
|
tooltipKeys={toggleShortcutKeys}
|
|
tooltipSide={tooltipSide}
|
|
testID={testID}
|
|
nativeID={nativeID}
|
|
style={style}
|
|
accessible
|
|
accessibilityRole="button"
|
|
accessibilityLabel={isOpen ? "Close menu" : "Open menu"}
|
|
accessibilityState={accessibilityState}
|
|
>
|
|
{isMobile ? (
|
|
<MobileMenuIcon color={menuIconColor} />
|
|
) : (
|
|
<PanelLeft size={theme.iconSize.md} color={menuIconColor} />
|
|
)}
|
|
</HeaderToggleButton>
|
|
);
|
|
}
|
|
|
|
export function MenuHeader({ title, rightContent, borderless }: MenuHeaderProps) {
|
|
return (
|
|
<ScreenHeader
|
|
left={
|
|
<>
|
|
<SidebarMenuToggle />
|
|
{title && <ScreenTitle>{title}</ScreenTitle>}
|
|
</>
|
|
}
|
|
right={rightContent}
|
|
leftStyle={styles.left}
|
|
borderless={borderless}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create((theme) => ({
|
|
left: {
|
|
gap: theme.spacing[2],
|
|
},
|
|
mobileMenuIcon: {
|
|
width: MOBILE_MENU_LINE_WIDTH,
|
|
height: 12,
|
|
justifyContent: "space-between",
|
|
alignItems: "flex-start",
|
|
},
|
|
mobileMenuLine: {
|
|
width: MOBILE_MENU_LINE_WIDTH,
|
|
height: MOBILE_MENU_LINE_HEIGHT,
|
|
borderRadius: theme.borderRadius.full,
|
|
},
|
|
mobileMenuLineShort: {
|
|
width: MOBILE_MENU_LINE_SHORT_WIDTH,
|
|
},
|
|
}));
|