161 lines
6.1 KiB
TypeScript
161 lines
6.1 KiB
TypeScript
import React from 'react';
|
|
import { CopyButton } from './CopyButton';
|
|
|
|
// 1. Callouts (Info, Warning, Error, Success)
|
|
export function Callout({
|
|
children,
|
|
type = 'info'
|
|
}: {
|
|
children: React.ReactNode;
|
|
type?: 'info' | 'warning' | 'error' | 'success'
|
|
}) {
|
|
const variants = {
|
|
info: "bg-blue-500/10 border-blue-500 text-blue-200",
|
|
warning: "bg-amber-500/10 border-amber-500 text-amber-200",
|
|
error: "bg-red-500/10 border-red-500 text-red-200",
|
|
success: "bg-emerald-500/10 border-emerald-500 text-emerald-200",
|
|
};
|
|
|
|
return (
|
|
<div className={`p-4 my-6 rounded-xl border-l-4 ${variants[type]}`}>
|
|
<div className="flex gap-3 items-start">
|
|
<div className="mt-0.5 shrink-0">
|
|
{type === 'info' && <svg className="w-5 h-5 text-blue-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>}
|
|
{type === 'warning' && <svg className="w-5 h-5 text-amber-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg>}
|
|
{type === 'error' && <svg className="w-5 h-5 text-red-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>}
|
|
{type === 'success' && <svg className="w-5 h-5 text-emerald-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" /></svg>}
|
|
</div>
|
|
<div className="text-sm leading-relaxed [&>p]:m-0">{children}</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// 2. Grid & Cards
|
|
export function Grid({ children }: { children: React.ReactNode }) {
|
|
return <div className="grid grid-cols-1 md:grid-cols-2 gap-4 my-8">{children}</div>;
|
|
}
|
|
|
|
export function Card({ title, href, children }: { title: string; href: string; children: React.ReactNode }) {
|
|
return (
|
|
<a href={href} className="block p-6 bg-zinc-900 border border-zinc-800 rounded-xl hover:border-blue-500 transition-colors group no-underline">
|
|
<h3 className="text-lg font-bold text-white group-hover:text-blue-400 m-0 mb-2">{title}</h3>
|
|
<div className="text-zinc-400 text-sm m-0 leading-relaxed [&>p]:m-0">
|
|
{children}
|
|
</div>
|
|
</a>
|
|
);
|
|
}
|
|
|
|
// 3. Steps
|
|
export function Steps({ children }: { children: React.ReactNode }) {
|
|
// Wir gehen durch alle Kinder und fügen automatisch die 'stepNumber' als Prop hinzu
|
|
const steps = React.Children.map(children, (child, index) => {
|
|
if (React.isValidElement(child)) {
|
|
return React.cloneElement(child as React.ReactElement<any>, {
|
|
stepNumber: index + 1,
|
|
});
|
|
}
|
|
return child;
|
|
});
|
|
|
|
return (
|
|
<div className="ml-4 border-l border-zinc-800 pl-8 my-8 space-y-8">
|
|
{steps}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function Step({
|
|
title,
|
|
children,
|
|
stepNumber
|
|
}: {
|
|
title: string;
|
|
children: React.ReactNode;
|
|
stepNumber?: number;
|
|
}) {
|
|
return (
|
|
<div className="relative">
|
|
{/* Die Nummer wird direkt als Text aus React gerendert */}
|
|
<div className="absolute -left-[41px] flex h-5 w-5 items-center justify-center rounded-full bg-zinc-900 border border-zinc-800 text-[10px] font-bold text-white">
|
|
{stepNumber}
|
|
</div>
|
|
|
|
<h3 className="text-white font-bold mb-2 mt-0 text-base">{title}</h3>
|
|
<div className="text-zinc-400 text-sm [&>p]:m-0">{children}</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Custom Inline Code (verhindert das Erben auf große Codeblöcke)
|
|
export function InlineCode({ children, className, ...props }: React.HTMLAttributes<HTMLElement>) {
|
|
// Wenn 'data-theme' oder 'data-language' existiert, kommt das Element aus rehype-pretty-code (Code-Block)
|
|
const isCodeBlock = props && ('data-theme' in props || 'data-language' in props);
|
|
|
|
// Falls es Teil eines großen Codeblocks ist -> normales <code> ohne Inline-Styling rendern
|
|
if (isCodeBlock || className?.includes('language-')) {
|
|
return <code className={className} {...props}>{children}</code>;
|
|
}
|
|
|
|
// Ansonsten: Unser schickes Inline-Code-Design anwenden
|
|
return (
|
|
<code
|
|
className="px-1.5 py-0.5 rounded-md bg-zinc-800 text-pink-400 font-mono text-sm border border-zinc-700/50 before:content-none after:content-none"
|
|
{...props}
|
|
>
|
|
{children}
|
|
</code>
|
|
);
|
|
}
|
|
|
|
export function CodeBlockContainer({ children, ...props }: React.HTMLAttributes<HTMLPreElement>) {
|
|
return (
|
|
<div className="relative group">
|
|
<CopyButton />
|
|
<pre {...props}>{children}</pre>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function API({
|
|
method = 'GET',
|
|
route,
|
|
children
|
|
}: {
|
|
method?: string;
|
|
route: string;
|
|
children?: React.ReactNode;
|
|
}) {
|
|
const methodUpper = method.toUpperCase();
|
|
|
|
// Farben für die verschiedenen HTTP-Methoden
|
|
const methodStyles: Record<string, string> = {
|
|
GET: 'bg-emerald-500/10 text-emerald-400 border-emerald-500/30',
|
|
POST: 'bg-blue-500/10 text-blue-400 border-blue-500/30',
|
|
PUT: 'bg-amber-500/10 text-amber-400 border-amber-500/30',
|
|
PATCH: 'bg-orange-500/10 text-orange-400 border-orange-500/30',
|
|
DELETE: 'bg-rose-500/10 text-rose-400 border-rose-500/30',
|
|
};
|
|
|
|
const badgeStyle = methodStyles[methodUpper] || 'bg-zinc-800 text-zinc-300 border-zinc-700';
|
|
|
|
return (
|
|
<div className="my-6 rounded-xl border border-zinc-800 bg-zinc-900/50 overflow-hidden">
|
|
{/* Route & Methoden-Header */}
|
|
<div className="flex items-center gap-3 p-4 bg-zinc-900 border-b border-zinc-800 font-mono text-sm">
|
|
<span className={`px-2.5 py-1 rounded-md text-xs font-bold border ${badgeStyle}`}>
|
|
{methodUpper}
|
|
</span>
|
|
<span className="text-zinc-200 font-semibold">/api/{route}</span>
|
|
</div>
|
|
|
|
{/* Beschreibung / Inhalt */}
|
|
{children && (
|
|
<div className="p-4 text-sm text-zinc-400 leading-relaxed [&>p]:m-0">
|
|
{children}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
} |