Feat/wiki #37
No files matched your search
+8
-19
@@ -33,18 +33,6 @@ h1 {
|
|||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.steps-container {
|
|
||||||
counter-reset: step;
|
|
||||||
}
|
|
||||||
|
|
||||||
.steps-container .relative {
|
|
||||||
counter-increment: step;
|
|
||||||
}
|
|
||||||
|
|
||||||
.steps-container .relative div:first-child::before {
|
|
||||||
content: counter(step);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Shiki Code-Blöcke stylen */
|
/* Shiki Code-Blöcke stylen */
|
||||||
pre {
|
pre {
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
@@ -94,6 +82,7 @@ figure[data-rehype-pretty-code-figure] code {
|
|||||||
font-family: var(--font-mono, monospace);
|
font-family: var(--font-mono, monospace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Container für den Code-Block */
|
||||||
/* Container für den Code-Block */
|
/* Container für den Code-Block */
|
||||||
figure[data-rehype-pretty-code-figure] {
|
figure[data-rehype-pretty-code-figure] {
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -101,22 +90,22 @@ figure[data-rehype-pretty-code-figure] {
|
|||||||
margin-bottom: 1.5rem;
|
margin-bottom: 1.5rem;
|
||||||
border-radius: 0.75rem;
|
border-radius: 0.75rem;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
border: 1px solid #27272a; /* Tailwind zinc-800 */
|
border: 1px solid #27272a;
|
||||||
background-color: #0d1117;
|
background-color: #0d1117;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Eventuelle leere Pseudo-Elemente der Figure deaktivieren */
|
/* Leeres Pseudo-Element der Figure deaktivieren */
|
||||||
figure[data-rehype-pretty-code-figure]::before {
|
figure[data-rehype-pretty-code-figure]::before {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Das Sprach-Badge ganz nach links rücken */
|
/* Sprach-Badge links oben */
|
||||||
figure[data-rehype-pretty-code-figure] pre[data-language]::before {
|
figure[data-rehype-pretty-code-figure] pre[data-language]::before {
|
||||||
content: attr(data-language);
|
content: attr(data-language);
|
||||||
display: block !important;
|
display: block !important;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0.6rem;
|
top: 0.6rem;
|
||||||
left: 0.6rem; /* <-- Auf 0.5rem (oder 0.4rem) verringert für noch weiter links */
|
left: 0.5rem;
|
||||||
font-family: var(--font-mono, ui-monospace, monospace);
|
font-family: var(--font-mono, ui-monospace, monospace);
|
||||||
font-size: 0.68rem;
|
font-size: 0.68rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
@@ -128,14 +117,14 @@ figure[data-rehype-pretty-code-figure] pre[data-language]::before {
|
|||||||
padding: 0.15rem 0.5rem;
|
padding: 0.15rem 0.5rem;
|
||||||
border-radius: 0.375rem;
|
border-radius: 0.375rem;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
z-index: 20;
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Platz oben für das Badge schaffen */
|
/* Platz oben im Code-Block */
|
||||||
figure[data-rehype-pretty-code-figure] pre {
|
figure[data-rehype-pretty-code-figure] pre {
|
||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
padding: 1rem !important;
|
padding: 1rem !important;
|
||||||
padding-top: 2.4rem !important; /* Genügend Abstand nach oben */
|
padding-top: 2.6rem !important; /* Platz für Badge & Button */
|
||||||
background-color: transparent !important;
|
background-color: transparent !important;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { getWikiPageBySlug } from '@/lib/wiki';
|
|||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
import { MDXRemote } from 'next-mdx-remote/rsc';
|
import { MDXRemote } from 'next-mdx-remote/rsc';
|
||||||
import rehypePrettyCode from 'rehype-pretty-code';
|
import rehypePrettyCode from 'rehype-pretty-code';
|
||||||
import { Callout, Grid, Card, Steps, Step, InlineCode } from '@/components/mdx-components';
|
import { Callout, Grid, Card, Steps, Step, InlineCode, CodeBlockContainer } from '@/components/mdx-components';
|
||||||
|
|
||||||
const mdxOptions = {
|
const mdxOptions = {
|
||||||
mdxOptions: {
|
mdxOptions: {
|
||||||
@@ -25,9 +25,9 @@ const mdxComponents = {
|
|||||||
Card,
|
Card,
|
||||||
Steps,
|
Steps,
|
||||||
Step,
|
Step,
|
||||||
|
|
||||||
// Custom Typography Überschreibungen
|
// Custom Typography Überschreibungen
|
||||||
code: InlineCode,
|
code: InlineCode,
|
||||||
|
pre: CodeBlockContainer,
|
||||||
h1: (props: any) => <h1 className="text-3xl font-bold text-white mt-8 mb-4 border-b border-zinc-800 pb-3" {...props} />,
|
h1: (props: any) => <h1 className="text-3xl font-bold text-white mt-8 mb-4 border-b border-zinc-800 pb-3" {...props} />,
|
||||||
h2: (props: any) => <h2 className="text-2xl font-bold text-white mt-10 mb-4" {...props} />,
|
h2: (props: any) => <h2 className="text-2xl font-bold text-white mt-10 mb-4" {...props} />,
|
||||||
h3: (props: any) => <h3 className="text-xl font-semibold text-white mt-6 mb-3" {...props} />,
|
h3: (props: any) => <h3 className="text-xl font-semibold text-white mt-6 mb-3" {...props} />,
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
export function CopyButton({ code }: { code?: string }) {
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
|
||||||
|
const handleCopy = async (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// Falls kein expliziter Code übergeben wird, suchen wir den Text im Elternelement (Codeblock)
|
||||||
|
let textToCopy = code;
|
||||||
|
if (!textToCopy) {
|
||||||
|
const parent = e.currentTarget.closest('figure');
|
||||||
|
const codeElement = parent?.querySelector('code');
|
||||||
|
textToCopy = codeElement?.textContent || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textToCopy) {
|
||||||
|
await navigator.clipboard.writeText(textToCopy);
|
||||||
|
setCopied(true);
|
||||||
|
setTimeout(() => setCopied(false), 2000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
onClick={handleCopy}
|
||||||
|
className="absolute top-2.5 right-3 p-1.5 rounded-md bg-zinc-900 border border-zinc-800 text-zinc-400 hover:text-white hover:bg-zinc-800 transition-colors z-20"
|
||||||
|
aria-label="Code kopieren"
|
||||||
|
>
|
||||||
|
{copied ? (
|
||||||
|
// Check Icon (Erfolg)
|
||||||
|
<svg className="w-4 h-4 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>
|
||||||
|
) : (
|
||||||
|
// Clipboard Icon
|
||||||
|
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
|
||||||
|
</svg>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { CopyButton } from './CopyButton';
|
||||||
|
|
||||||
// 1. Callouts (Info, Warning, Error, Success)
|
// 1. Callouts (Info, Warning, Error, Success)
|
||||||
export function Callout({
|
export function Callout({
|
||||||
@@ -48,17 +49,39 @@ export function Card({ title, href, children }: { title: string; href: string; c
|
|||||||
|
|
||||||
// 3. Steps
|
// 3. Steps
|
||||||
export function Steps({ children }: { children: React.ReactNode }) {
|
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 (
|
return (
|
||||||
<div className="steps-container ml-4 border-l border-zinc-800 pl-8 my-8 space-y-8">
|
<div className="ml-4 border-l border-zinc-800 pl-8 my-8 space-y-8">
|
||||||
{children}
|
{steps}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Step({ title, children }: { title: string; children: React.ReactNode }) {
|
export function Step({
|
||||||
|
title,
|
||||||
|
children,
|
||||||
|
stepNumber
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
stepNumber?: number;
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<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" />
|
{/* 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>
|
<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 className="text-zinc-400 text-sm [&>p]:m-0">{children}</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -84,4 +107,13 @@ export function InlineCode({ children, className, ...props }: React.HTMLAttribut
|
|||||||
{children}
|
{children}
|
||||||
</code>
|
</code>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CodeBlockContainer({ children, ...props }: React.HTMLAttributes<HTMLPreElement>) {
|
||||||
|
return (
|
||||||
|
<div className="relative group">
|
||||||
|
<CopyButton />
|
||||||
|
<pre {...props}>{children}</pre>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user