mirror of
https://github.com/hanzoai/shadcn.git
synced 2026-10-30 18:22:59 +00:00
Squash merge of shadcn-ui/ui main branch into hanzo/ui, bringing in: - [email protected] through [email protected] releases - New apps/v4 directory structure - Registry system improvements and MCP server - Framework support (Vue, Svelte, React Native) - New templates (vite-app, monorepo-next, laravel) - Zod 4 compatibility (scoped override for zod@>4) - Test fixture corrections for alias resolution All 867 merge conflicts resolved preserving Hanzo customizations. 1020/1020 shadcn tests pass.
67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
"use client"
|
|
|
|
import * as React from "react"
|
|
|
|
import { cn } from "@/registry/new-york-v4/lib/utils"
|
|
|
|
export function ComponentWrapper({
|
|
className,
|
|
name,
|
|
children,
|
|
...props
|
|
}: React.ComponentPropsWithoutRef<"div"> & { name: string }) {
|
|
return (
|
|
<ComponentErrorBoundary name={name}>
|
|
<div
|
|
id={name}
|
|
data-name={name.toLowerCase()}
|
|
className={cn(
|
|
"flex w-full scroll-mt-16 flex-col rounded-lg border",
|
|
className
|
|
)}
|
|
{...props}
|
|
>
|
|
<div className="border-b px-4 py-3">
|
|
<div className="text-sm font-medium">{getComponentName(name)}</div>
|
|
</div>
|
|
<div className="flex flex-1 items-center gap-2 p-4">{children}</div>
|
|
</div>
|
|
</ComponentErrorBoundary>
|
|
)
|
|
}
|
|
|
|
class ComponentErrorBoundary extends React.Component<
|
|
{ children: React.ReactNode; name: string },
|
|
{ hasError: boolean }
|
|
> {
|
|
constructor(props: { children: React.ReactNode; name: string }) {
|
|
super(props)
|
|
this.state = { hasError: false }
|
|
}
|
|
|
|
static getDerivedStateFromError() {
|
|
return { hasError: true }
|
|
}
|
|
|
|
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
console.error(`Error in component ${this.props.name}:`, error, errorInfo)
|
|
}
|
|
|
|
render() {
|
|
if (this.state.hasError) {
|
|
return (
|
|
<div className="p-4 text-red-500">
|
|
Something went wrong in component: {this.props.name}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return this.props.children
|
|
}
|
|
}
|
|
|
|
function getComponentName(name: string) {
|
|
// convert kebab-case to title case
|
|
return name.replace(/-/g, " ").replace(/\b\w/g, (char) => char.toUpperCase())
|
|
}
|