init commit
This commit is contained in:
@@ -1,114 +1,79 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Bell, Calendar, Kanban, LayoutDashboard, Moon, Search, SquareCheck, Sun, Users } from 'lucide-react';
|
||||
import type { ComponentProps } from 'react';
|
||||
import { Slot } from 'radix-ui';
|
||||
import { cn } from '../../lib/cn';
|
||||
import { Avatar, type Person } from '../Avatar/Avatar';
|
||||
import { Logo } from '../Logo/Logo';
|
||||
import type { NavItemData } from '../Sidebar/Sidebar';
|
||||
|
||||
const tabIcon = { size: 22, strokeWidth: 1.75, 'aria-hidden': true } as const;
|
||||
|
||||
export const defaultMobileTabs: NavItemData[] = [
|
||||
{ id: 'dashboard', label: 'Dashboard', href: '#', icon: <LayoutDashboard {...tabIcon} /> },
|
||||
{ id: 'aufgaben', label: 'Aufgaben', href: '#', icon: <SquareCheck {...tabIcon} /> },
|
||||
{ id: 'kanban', label: 'Kanban', href: '#', icon: <Kanban {...tabIcon} /> },
|
||||
{ id: 'kalender', label: 'Kalender', href: '#', icon: <Calendar {...tabIcon} /> },
|
||||
{ id: 'gruppen', label: 'Gruppen', href: '#', icon: <Users {...tabIcon} /> },
|
||||
];
|
||||
|
||||
export interface MobileTabBarProps {
|
||||
items?: NavItemData[];
|
||||
activeId?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/** Sticky bottom navigation on phones. */
|
||||
export function MobileTabBar({ items = defaultMobileTabs, activeId = 'dashboard', className }: MobileTabBarProps) {
|
||||
/** 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,
|
||||
)}
|
||||
>
|
||||
{items.map((it) => {
|
||||
const active = it.id === activeId;
|
||||
return (
|
||||
<a
|
||||
key={it.id}
|
||||
href={it.href}
|
||||
aria-current={active ? 'page' : undefined}
|
||||
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',
|
||||
active ? 'text-accent-fg hover:text-accent-fg' : 'text-fg-subtle hover:text-fg',
|
||||
)}
|
||||
>
|
||||
{it.icon}
|
||||
{it.label}
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export interface MobileHeaderProps {
|
||||
user: Person;
|
||||
theme?: 'dark' | 'light';
|
||||
onToggleTheme?: () => void;
|
||||
onSearch?: () => void;
|
||||
unreadCount?: number;
|
||||
notificationsHref?: string;
|
||||
onProfile?: () => void;
|
||||
/** Replaces the logo, e.g. a back button and page title. */
|
||||
leading?: ReactNode;
|
||||
className?: string;
|
||||
export interface MobileTabProps extends ComponentProps<'a'> {
|
||||
active?: boolean;
|
||||
asChild?: boolean;
|
||||
}
|
||||
|
||||
/** Sticky glass header on phones: logo, theme, search, notifications, profile. */
|
||||
export function MobileHeader({
|
||||
user,
|
||||
theme = 'dark',
|
||||
onToggleTheme,
|
||||
onSearch,
|
||||
unreadCount = 0,
|
||||
notificationsHref = '#',
|
||||
onProfile,
|
||||
leading,
|
||||
className,
|
||||
}: MobileHeaderProps) {
|
||||
const btn = 'flex h-11 w-11 flex-none items-center justify-center rounded-[10px] text-fg-4 hover:bg-hover hover:text-fg';
|
||||
const themeLabel = theme === 'dark' ? 'Helles Design aktivieren' : 'Dunkles Design aktivieren';
|
||||
/** 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,
|
||||
)}
|
||||
>
|
||||
{leading ?? <Logo className="h-6" />}
|
||||
<div className="ml-auto flex items-center">
|
||||
<button type="button" onClick={onToggleTheme} aria-label={themeLabel} title={themeLabel} className={btn}>
|
||||
{theme === 'dark' ? <Sun size={18} strokeWidth={1.75} /> : <Moon size={18} strokeWidth={1.75} />}
|
||||
</button>
|
||||
<button type="button" onClick={onSearch} aria-label="Suchen" className={btn}>
|
||||
<Search size={20} strokeWidth={1.75} />
|
||||
</button>
|
||||
<a href={notificationsHref} aria-label={`Benachrichtigungen, ${unreadCount} ungelesen`} className={cn(btn, 'relative')}>
|
||||
<Bell size={20} strokeWidth={1.75} />
|
||||
{unreadCount > 0 && (
|
||||
<span className="absolute top-[11px] right-3 h-[7px] w-[7px] rounded-full bg-danger shadow-[0_0_0_2px_var(--cl-app)]" />
|
||||
)}
|
||||
</a>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onProfile}
|
||||
aria-label="Profil und Einstellungen"
|
||||
className="flex h-11 w-11 items-center justify-center p-0"
|
||||
>
|
||||
<Avatar person={user} size={30} aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
{...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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user