Files
collabry-components/src/components/MobileNav/MobileNav.tsx
T
2026-11-14 08:49:19 +01:00

80 lines
2.7 KiB
TypeScript

import type { ComponentProps } from 'react';
import { Slot } from 'radix-ui';
import { cn } from '../../lib/cn';
/** Sticky bottom navigation on phones. Children are `MobileTab`s. */
export function MobileTabBar({ className, ...props }: ComponentProps<'nav'>) {
return (
<nav
aria-label="Hauptnavigation"
data-slot="mobile-tab-bar"
className={cn(
'sticky bottom-0 z-[5] box-border flex border-t border-line-shell bg-glass-2 px-1.5 pt-1.5 pb-[calc(8px+env(safe-area-inset-bottom))] backdrop-blur-md',
className,
)}
{...props}
/>
);
}
export interface MobileTabProps extends ComponentProps<'a'> {
active?: boolean;
asChild?: boolean;
}
/** Icon over a label. */
export function MobileTab({ active, asChild, className, ...props }: MobileTabProps) {
const Comp = asChild ? Slot.Root : 'a';
return (
<Comp
aria-current={active ? 'page' : undefined}
data-slot="mobile-tab"
className={cn(
'flex h-[52px] min-w-0 flex-1 basis-0 flex-col items-center justify-center gap-1 rounded-[10px] text-2xs font-bold text-fg-subtle hover:text-fg',
'aria-[current=page]:text-accent-fg aria-[current=page]:hover:text-accent-fg',
className,
)}
{...props}
/>
);
}
/** Sticky glass header on phones: logo (or a back button and title), then `MobileHeaderActions`. */
export function MobileHeader({ className, ...props }: ComponentProps<'header'>) {
return (
<header
data-slot="mobile-header"
className={cn(
'sticky top-0 z-[5] box-border flex h-14 items-center gap-2.5 border-b border-line-shell bg-glass pr-2 pl-4 backdrop-blur-md',
className,
)}
{...props}
/>
);
}
export function MobileHeaderActions({ className, ...props }: ComponentProps<'div'>) {
return <div data-slot="mobile-header-actions" className={cn('ml-auto flex items-center', className)} {...props} />;
}
export interface MobileHeaderButtonProps extends ComponentProps<'button'> {
asChild?: boolean;
}
/** 44px touch target for icons or the profile avatar. Holds an `IndicatorDot`. Give it an `aria-label`. */
export function MobileHeaderButton({ asChild, className, ...props }: MobileHeaderButtonProps) {
const Comp = asChild ? Slot.Root : 'button';
return (
<Comp
type={asChild ? undefined : 'button'}
data-slot="mobile-header-button"
className={cn(
'relative flex h-11 w-11 flex-none items-center justify-center rounded-[10px] text-fg-4 hover:bg-hover hover:text-fg',
'[--indicator-ring:var(--cl-app)] *:data-[slot=indicator-dot]:top-[11px] *:data-[slot=indicator-dot]:right-3',
className,
)}
{...props}
/>
);
}