Code Comparison Demo
magicui/code-comparison-demoFreeExample
Example showing a component which compares two code snippets.
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/code-comparison-demo.jsonSource
1import { CodeComparison } from "@/registry/magicui/code-comparison"23const beforeCode = `import { NextRequest } from 'next/server';45export const middleware = async (req: NextRequest) => {6 let user = undefined;7 let team = undefined;8 const token = req.headers.get('token');910 if(req.nextUrl.pathname.startsWith('/auth')) {11 user = await getUserByToken(token);1213 if(!user) {14 return NextResponse.redirect('/login');15 }16 }1718 if(req.nextUrl.pathname.startsWith('/team')) {19 user = await getUserByToken(token);2021 if(!user) {22 return NextResponse.redirect('/login');23 }2425 const slug = req.nextUrl.query.slug;26 team = await getTeamBySlug(slug); // [!code highlight]2728 if(!team) { // [!code highlight]29 return NextResponse.redirect('/'); // [!code highlight]30 } // [!code highlight]31 } // [!code highlight]3233 return NextResponse.next(); // [!code highlight]34}3536export const config = {37 matcher: ['/((?!_next/|_static|_vercel|[\\w-]+\\.\\w+).*)'], // [!code highlight]38};`3940const afterCode = `import { createMiddleware, type MiddlewareFunctionProps } from '@app/(auth)/auth/_middleware';41import { auth } from '@/app/(auth)/auth/_middleware'; // [!code --]42import { auth } from '@/app/(auth)/auth/_middleware'; // [!code ++]43import { team } from '@/app/(team)/team/_middleware';4445const middlewares = {46 '/auth{/:path?}': auth,47 '/team{/:slug?}': [ auth, team ],48};4950export const middleware = createMiddleware(middlewares); // [!code focus]5152export const config = {53 matcher: ['/((?!_next/|_static|_vercel|[\\w-]+\\.\\w+).*)'],54};`5556export default function CodeComparisonDemo() {57 return (58 <CodeComparison59 beforeCode={beforeCode}60 afterCode={afterCode}61 language="typescript"62 filename="middleware.ts"63 lightTheme="github-light"64 darkTheme="github-dark"65 highlightColor="rgba(101, 117, 133, 0.16)"66 />67 )68}
What it pulls in
Other registry items
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Android Demoandroid-demo | magicui | Examples | Free | no deps | |
| Android Demo 2android-demo-2 | magicui | Examples | Free | no deps | |
| Android Demo 3android-demo-3 | magicui | Examples | Free | no deps | |
| Animated Beam Bidirectionalanimated-beam-bidirectional | magicui | Examples | Free | no deps | |
| Animated Beam Demoanimated-beam-demo | magicui | Examples | Free | 1 dep | |
| Animated Beam Multiple Inputsanimated-beam-multiple-inputs | magicui | Examples | Free | no deps | |
| Animated Beam Multiple Outputsanimated-beam-multiple-outputs | magicui | Examples | Free | no deps | |
| Animated Beam Unidirectionalanimated-beam-unidirectional | magicui | Examples | Free | no deps |
