sandbox
kibo-ui-registry/sandboxFreeComponent
The sandbox component allows you to preview and test components in a sandboxed environment.
Live preview
live · rendered by the registry
Rendered by Kibo UI Registry on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.kibo-ui.com/r/sandbox.jsonSource
1"use client";23import type {4 CodeEditorProps,5 PreviewProps,6 SandpackLayoutProps,7 SandpackProviderProps,8} from "@codesandbox/sandpack-react";9import {10 SandpackCodeEditor,11 SandpackConsole,12 SandpackFileExplorer,13 SandpackLayout,14 SandpackPreview,15 SandpackProvider,16} from "@codesandbox/sandpack-react";17import type {18 ButtonHTMLAttributes,19 ComponentProps,20 HTMLAttributes,21 ReactNode,22} from "react";23import {24 createContext,25 useCallback,26 useContext,27 useEffect,28 useState,29} from "react";30import { cn } from "@/lib/utils";3132export type SandboxProviderProps = SandpackProviderProps;3334export const SandboxProvider = ({35 className,36 ...props37}: SandpackProviderProps): ReactNode => (38 <div className={cn("size-full", className)}>39 <SandpackProvider className="!size-full !max-h-none" {...props} />40 </div>41);4243export type SandboxLayoutProps = SandpackLayoutProps;4445export const SandboxLayout = ({46 className,47 ...props48}: SandpackLayoutProps): ReactNode => (49 <SandpackLayout50 className={cn(51 "!rounded-none !border-none !bg-transparent !h-full",52 className53 )}54 {...props}55 />56);5758export type SandboxTabsContextValue = {59 selectedTab: string | undefined;60 setSelectedTab: (value: string) => void;61};6263const SandboxTabsContext = createContext<SandboxTabsContextValue | undefined>(64 undefined65);6667const useSandboxTabsContext = () => {68 const context = useContext(SandboxTabsContext);6970 if (!context) {71 throw new Error(72 "SandboxTabs components must be used within a SandboxTabsProvider"73 );74 }7576 return context;77};7879export type SandboxTabsProps = HTMLAttributes<HTMLDivElement> & {80 defaultValue?: string;81 value?: string;82 onValueChange?: (value: string) => void;83};8485export const SandboxTabs = ({86 className,87 defaultValue,88 value,89 onValueChange,90 ...props91}: SandboxTabsProps): ReactNode => {92 const [selectedTab, setSelectedTabState] = useState(value || defaultValue);9394 useEffect(() => {95 if (value !== undefined) {96 setSelectedTabState(value);97 }98 }, [value]);99100 const setSelectedTab = useCallback(101 (newValue: string) => {102 if (value === undefined) {103 setSelectedTabState(newValue);104 }105 onValueChange?.(newValue);106 },107 [value, onValueChange]108 );109110 return (111 <SandboxTabsContext.Provider value={{ selectedTab, setSelectedTab }}>112 <div113 className={cn(114 "group relative flex size-full flex-col overflow-hidden rounded-lg border text-sm",115// … truncated
What it pulls in
npm packages
Files it writes
More from Kibo UI Registry
All 41 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| announcementannouncement | Kibo UI Registry | Components | Free | no deps | |
| avatar-stackavatar-stack | Kibo UI Registry | Components | Free | no deps | |
| bannerbanner | Kibo UI Registry | Components | Free | 2 deps | |
| calendarcalendar | Kibo UI Registry | Components | Free | 3 deps | |
| choiceboxchoicebox | Kibo UI Registry | Components | Free | 2 deps | |
| code-blockcode-block | Kibo UI Registry | Components | Free | 5 deps · 2 files | |
| color-pickercolor-picker | Kibo UI Registry | Components | Free | 3 deps | |
| comboboxcombobox | Kibo UI Registry | Components | Free | 2 deps |
