shadcn-registry-item-code-block
domain-ui/shadcn-registry-item-code-blockFreeComponent
domain-ui publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/teurons/domain-ui/main/apps/web/public/r/shadcn-registry-item-code-block.jsonSource
1"use client";23import { useEffect, useState, createContext, useContext } from "react";4import type { RegistryItem } from "shadcn/registry";5// DynamicCodeBlock is not available, use CodeBlock instead6import { Button } from "@/components/ui/button";7import {8 TreeExpander,9 TreeIcon,10 TreeLabel,11 TreeNode,12 TreeNodeContent,13 TreeNodeTrigger,14 TreeProvider,15 TreeView,16} from "@/components/domain-ui/tree";17import { PanelLeftClose, PanelLeft, FileText, File } from "lucide-react";18import { CodeBlock, Pre } from "fumadocs-ui/components/codeblock";19import { type ComponentProps, useMemo } from "react";20import { cn } from "@/lib/utils";21import { DynamicCodeBlock } from "fumadocs-ui/components/dynamic-codeblock";2223interface FileData {24 path: string;25 content?: string;26}2728interface FileTreeNode {29 path: string;30 type: "file" | "directory";31 children?: FileTreeNode[];32 content?: string;33}3435interface FileSelectionContextValue {36 selectedFilePath: string;37 setSelectedFilePath: (path: string) => void;38}3940const FileSelectionContext = createContext<FileSelectionContextValue | null>(41 null42);4344function useFileSelection() {45 const context = useContext(FileSelectionContext);46 if (!context) {47 throw new Error(48 "useFileSelection must be used within FileSelectionProvider"49 );50 }51 return context;52}5354// FilePath component - displays file path55interface FilePathProps {56 filePath?: string;57}5859function FilePath({ filePath }: FilePathProps) {60 if (!filePath) {61 return null;62 }6364 return (65 <div className="bg-muted/10">66 <div className="flex h-12 items-center gap-2 border-b px-3">67 <FileText className="h-3 w-3" />68 <span className="text-muted-foreground text-sm">{filePath}</span>69 </div>70 </div>71 );72}7374// FileContent component - displays file content75interface FileContentProps {76 files: FileData[];77}7879function pre(props: ComponentProps<"pre">) {80 return (81 <CodeBlock {...props} className={cn("my-0 rounded-none", props.className)}>82 <Pre>{props.children}</Pre>83 </CodeBlock>84 );85}8687function FileContent({ files }: FileContentProps) {88 const { selectedFilePath } = useFileSelection();8990 const options = useMemo(91 () => ({92 components: {93 pre,94 },95 themes: {96 light: "github-light",97 dark: "github-dark",98 },99 }),100 []101 );102103 const selectedFile = files.find((file) => file.path === selectedFilePath);104105 if (!selectedFile) {106 return (107// … truncated
What it pulls in
Other registry items
Files it writes
More from domain-ui
All 16 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| pan-inputpan-input | domain-ui | Components | Free | no deps | |
| pan-input-incrementalpan-input-incremental | domain-ui | Components | Free | no deps | |
| passport-inputpassport-input | domain-ui | Components | Free | no deps | |
| passport-input-incrementalpassport-input-incremental | domain-ui | Components | Free | no deps | |
| phone-inputphone-input | domain-ui | Components | Free | 2 deps | |
| portfolio-chartportfolio-chart | domain-ui | Components | Free | no deps | |
| regex-inputregex-input | domain-ui | Components | Free | no deps · 2 files | |
| regex-input-incrementalregex-input-incremental | domain-ui | Components | Free | no deps · 5 files |
