Files
FitOS/admin/src/components/ui/content.tsx

222 lines
5.8 KiB
TypeScript

import type { ReactNode } from 'react';
import { Link } from 'react-router-dom';
import { ArrowLeft, X } from 'lucide-react';
import { buttonVariants } from './button';
import { H2, H3, Muted } from './typography';
import { cn } from '../../lib/utils';
/* Page header: title + optional badge, actions on the right (stacks on mobile) */
export function PageHeader({
title,
leading,
badge,
actions,
}: {
title: string;
/** Element przed tytułem (np. awatar). */
leading?: ReactNode;
badge?: ReactNode;
actions?: ReactNode;
}) {
return (
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 mb-5">
<div className="flex items-center gap-3 flex-wrap">
{leading}
{/* `<h1>` należy do topbaru (tytuł strony) — nagłówek treści to `<h2>` */}
<H2 className="mb-0">{title}</H2>
{badge}
</div>
{actions}
</div>
);
}
/* Back button — ghost, small; `to` renders a Link, `onClick` a plain button */
export function BackButton({
to,
onClick,
children = 'Wstecz',
className = '',
}: {
to?: string;
onClick?: () => void;
children?: ReactNode;
className?: string;
}) {
// na telefonie „Wstecz” siedzi w topmenu („<”) — tu tylko md+
const cls = cn(buttonVariants({ variant: 'ghost', size: 'sm' }), 'max-md:hidden', className);
if (to) {
return (
<Link to={to} className={cls}>
<ArrowLeft className="w-4 h-4" />
{children}
</Link>
);
}
return (
<button type="button" onClick={onClick} className={cls}>
<ArrowLeft className="w-4 h-4" />
{children}
</button>
);
}
/* Section header: H2 + muted description + optional actions (right) */
export function SectionHeader({
title,
description,
actions,
className = '',
}: {
title: ReactNode;
description?: ReactNode;
actions?: ReactNode;
className?: string;
}) {
return (
<div className={`flex flex-wrap items-start justify-between gap-3 mb-3 ${className}`.trim()}>
<div className="min-w-0">
<H2 className="mb-0.5">{title}</H2>
{description && <Muted className="text-[0.875rem]">{description}</Muted>}
</div>
{actions && <div className="flex items-center gap-2 shrink-0">{actions}</div>}
</div>
);
}
/* Meta item: small icon + muted text */
export function MetaItem({
icon: Icon,
children,
className = '',
}: {
icon: React.ComponentType<{ className?: string }>;
children: ReactNode;
className?: string;
}) {
return (
<span
className={`inline-flex items-center gap-1.5 text-dim text-[0.875rem] ${className}`.trim()}
>
<Icon className="w-4 h-4 shrink-0" />
<span className="min-w-0 truncate">{children}</span>
</span>
);
}
/* List row: płaski wiersz (tytuł + meta lewo, akcje prawo); w listach w karcie
rodzic używa `divide-y divide-line` (dłuższe) albo `space-y-1` (krótkie). */
export function ListRow({
title,
meta,
actions,
children,
className = '',
}: {
title: ReactNode;
meta?: ReactNode;
actions?: ReactNode;
children?: ReactNode;
className?: string;
}) {
return (
<div
data-slot="list-row"
className={`flex flex-wrap items-center justify-between gap-3 px-2 py-3 rounded-[10px] transition-colors hover:bg-line/20 ${className}`.trim()}
>
<div className="min-w-0 flex-1">
<div className="text-[0.95rem] font-semibold min-w-0 truncate">{title}</div>
{meta && <Muted className="text-[0.875rem]">{meta}</Muted>}
</div>
{actions && <div className="flex items-center gap-2 shrink-0">{actions}</div>}
{children}
</div>
);
}
/* Chip: small pill (+ optional remove button) */
export function Chip({
children,
onRemove,
removeLabel = 'Usuń',
className = '',
}: {
children: ReactNode;
onRemove?: () => void;
removeLabel?: string;
className?: string;
}) {
return (
<span
data-slot="chip"
className={`inline-flex items-center gap-1.5 bg-card border border-line rounded-full px-3 py-1 text-[0.8125rem] font-semibold text-dim ${className}`.trim()}
>
{children}
{onRemove && (
<button
type="button"
onClick={onRemove}
aria-label={removeLabel}
className="text-dim hover:text-danger cursor-pointer"
>
<X className="w-3.5 h-3.5" />
</button>
)}
</span>
);
}
/* Empty state */
export function EmptyState({
icon: Icon,
title,
description,
action,
}: {
icon: React.ComponentType<{ className?: string }>;
title: string;
description?: string;
action?: ReactNode;
}) {
return (
<div className="flex flex-col items-center justify-center text-center py-10 px-4">
<div className="w-14 h-14 rounded-full bg-accent/10 border border-accent/25 text-accent-text flex items-center justify-center mb-4">
<Icon className="w-7 h-7" />
</div>
<H3 className="mb-1">{title}</H3>
{description && <p className="text-dim text-[0.9rem] max-w-sm">{description}</p>}
{action && <div className="mt-4">{action}</div>}
</div>
);
}
/* Tabs */
export function Tabs({
tabs,
active,
onChange,
}: {
tabs: { id: string; label: string }[];
active: string;
onChange: (id: string) => void;
}) {
return (
<div className="flex gap-1 p-1 bg-input rounded-[10px] border border-line overflow-x-auto">
{tabs.map((t) => (
<button
key={t.id}
type="button"
onClick={() => onChange(t.id)}
className={`px-3.5 py-2 rounded-[10px] text-[0.9rem] font-semibold whitespace-nowrap cursor-pointer transition-all duration-150 ${
active === t.id
? 'bg-card text-ink border border-line shadow-card'
: 'border border-transparent text-dim hover:text-ink'
}`}
>
{t.label}
</button>
))}
</div>
);
}