Animate admin user menu sheet

This commit is contained in:
Codex Agent
2026-02-02 16:26:11 +01:00
parent f161366119
commit 2f4ebfefd4
2 changed files with 103 additions and 14 deletions

View File

@@ -1,13 +1,8 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { ChevronRight, CreditCard, FileText, HelpCircle, User, X } from 'lucide-react';
import { XStack, YStack } from '@tamagui/stacks';
import { SizableText as Text } from '@tamagui/text';
import { XStack, YStack, SizableText as Text, ListItem, YGroup, Switch, Separator } from 'tamagui';
import { Pressable } from '@tamagui/react-native-web-lite';
import { ListItem } from '@tamagui/list-item';
import { YGroup } from '@tamagui/group';
import { Switch } from '@tamagui/switch';
import { Separator } from 'tamagui';
import { useAppearance } from '@/hooks/use-appearance';
import { ADMIN_BILLING_PATH, ADMIN_DATA_EXPORTS_PATH, ADMIN_FAQ_PATH, ADMIN_PROFILE_ACCOUNT_PATH, adminPath } from '../../constants';
@@ -23,6 +18,7 @@ type UserMenuSheetProps = {
};
const MENU_WIDTH = 320;
const MENU_CLOSED_OFFSET = MENU_WIDTH + 32;
export function UserMenuSheet({ open, onClose, user, isMember, navigate }: UserMenuSheetProps) {
const { t, i18n } = useTranslation('management');
@@ -84,18 +80,18 @@ export function UserMenuSheet({ open, onClose, user, isMember, navigate }: UserM
zIndex={100000}
pointerEvents={open ? 'auto' : 'none'}
>
<Pressable
<YStack
onPress={onClose}
opacity={open ? 1 : 0}
fullscreen
backgroundColor={theme.overlay}
style={{
position: 'absolute',
inset: 0,
backgroundColor: theme.overlay,
opacity: open ? 1 : 0,
transition: 'opacity 180ms ease',
transition: 'opacity 220ms ease',
}}
/>
<YStack
data-testid="user-menu-sheet-panel"
position="absolute"
top={0}
bottom={0}
@@ -107,9 +103,10 @@ export function UserMenuSheet({ open, onClose, user, isMember, navigate }: UserM
borderColor={theme.border}
padding="$4"
gap="$3"
opacity={open ? 1 : 0}
style={{
transform: open ? 'translateX(0)' : 'translateX(100%)',
transition: 'transform 220ms ease',
transform: `translateX(${open ? 0 : MENU_CLOSED_OFFSET}px)`,
transition: 'transform 260ms ease, opacity 260ms ease',
boxShadow: `-12px 0 24px ${theme.glassShadow ?? theme.shadow}`,
}}
>

View File

@@ -0,0 +1,92 @@
import React from 'react';
import { describe, expect, it, vi } from 'vitest';
import { render } from '@testing-library/react';
vi.mock('react-i18next', () => ({
useTranslation: () => ({ t: (key: string, fallback?: string) => fallback ?? key, i18n: { language: 'en-GB' } }),
}));
vi.mock('@tamagui/react-native-web-lite', () => ({
Pressable: ({ children, onPress, ...props }: { children: React.ReactNode; onPress?: () => void }) => (
<button type="button" onClick={onPress} {...props}>
{children}
</button>
),
}));
vi.mock('tamagui', () => {
const Stack = ({ children, ...props }: { children: React.ReactNode }) => <div {...props}>{children}</div>;
const Text = ({ children, ...props }: { children: React.ReactNode }) => <span {...props}>{children}</span>;
const Switch = ({ children }: { children?: React.ReactNode }) => <div>{children}</div>;
Switch.Thumb = () => <div />;
const ListItem = ({ title, iconAfter, ...props }: { title?: React.ReactNode; iconAfter?: React.ReactNode }) => (
<div {...props}>
{title}
{iconAfter}
</div>
);
const YGroup: any = ({ children }: { children: React.ReactNode }) => <div>{children}</div>;
YGroup.Item = ({ children }: { children: React.ReactNode }) => <div>{children}</div>;
return {
XStack: Stack,
YStack: Stack,
SizableText: Text,
ListItem,
YGroup,
Switch,
Separator: ({ children }: { children?: React.ReactNode }) => <div>{children}</div>,
};
});
vi.mock('../FormControls', () => ({
MobileSelect: ({ children }: { children: React.ReactNode }) => <select>{children}</select>,
}));
vi.mock('@/hooks/use-appearance', () => ({
useAppearance: () => ({
appearance: 'system',
resolved: 'light',
updateAppearance: vi.fn(),
}),
}));
vi.mock('../../theme', () => ({
useAdminTheme: () => ({
overlay: 'rgba(0,0,0,0.3)',
surface: '#ffffff',
border: '#e5e7eb',
textStrong: '#111827',
muted: '#6b7280',
surfaceMuted: '#f3f4f6',
accentSoft: '#fef2f2',
primary: '#FF5A5F',
glassShadow: 'rgba(15,23,42,0.14)',
shadow: 'rgba(0,0,0,0.12)',
}),
}));
import { UserMenuSheet } from '../UserMenuSheet';
const baseProps = {
onClose: vi.fn(),
user: { name: 'Ada Lovelace', email: 'ada@example.com' },
isMember: false,
navigate: vi.fn(),
};
describe('UserMenuSheet', () => {
it('slides in when open', () => {
const { getByTestId } = render(<UserMenuSheet {...baseProps} open={true} />);
expect(getByTestId('user-menu-sheet-panel').style.transform).toBe('translateX(0px)');
});
it('slides out when closed', () => {
const { getByTestId } = render(<UserMenuSheet {...baseProps} open={false} />);
expect(getByTestId('user-menu-sheet-panel').style.transform).toMatch(/translateX\(\d+px\)/);
});
});