Download components/builder/ConfigurationPanel.tsx from phungtuan/fluxify: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/spaces/phungtuan/fluxify/resolve/main/components/builder/ConfigurationPanel.tsx
- Command line
-
hf download hf://spaces/phungtuan/fluxify/components/builder/ConfigurationPanel.tsx
-
curl -L -o ConfigurationPanel.tsx https://huggingface.co/spaces/phungtuan/fluxify/resolve/main/components/builder/ConfigurationPanel.tsx
2.59 kB
| "use client"; | |
| import { Suspense, useCallback } from "react"; | |
| import { ComponentType } from "@prisma/client"; | |
| import { Spinner } from "@heroui/spinner"; | |
| import { ComponentConfig } from "@/types/shop"; | |
| import { COMPONENT_REGISTRY } from "@/lib/registry/component-registry"; | |
| interface ConfigurationPanelProps { | |
| componentType: ComponentType | null; | |
| config: ComponentConfig | null; | |
| onUpdateConfig: (newConfig: ComponentConfig) => void; | |
| } | |
| /** | |
| * Configuration panel for editing shop component properties | |
| * Uses the component registry for dynamic config panel loading | |
| */ | |
| export default function ConfigurationPanel({ | |
| componentType, | |
| config, | |
| onUpdateConfig, | |
| }: ConfigurationPanelProps) { | |
| const updateField = useCallback( | |
| ( | |
| field: string | number | symbol | Partial<ComponentConfig>, | |
| value?: unknown, | |
| ) => { | |
| let newConfig: ComponentConfig; | |
| if (typeof field === "object" && field !== null) { | |
| // Handle partial update | |
| newConfig = { ...config, ...field } as ComponentConfig; | |
| } else { | |
| // Handle single field update | |
| newConfig = { ...config, [field as string]: value } as ComponentConfig; | |
| } | |
| onUpdateConfig(newConfig); | |
| }, | |
| [config, onUpdateConfig], | |
| ); | |
| if (!componentType || !config) { | |
| return ( | |
| <div className="w-80 bg-content1 border-l border-divider p-4"> | |
| <h3 className="text-lg font-bold mb-4">cấu hình</h3> | |
| <p className="text-sm text-default-500"> | |
| chọn một thành phần để cấu hình | |
| </p> | |
| </div> | |
| ); | |
| } | |
| // @ts-ignore - Validated by runtime check or we accept undefined for excluded types | |
| const meta = | |
| COMPONENT_REGISTRY[componentType as keyof typeof COMPONENT_REGISTRY]; | |
| if (!meta) { | |
| return ( | |
| <div className="w-80 bg-content1 border-l border-divider p-4"> | |
| <h3 className="text-lg font-bold mb-4">cấu hình</h3> | |
| <p className="text-sm text-default-500"> | |
| Loại thành phần không xác định: {componentType} | |
| </p> | |
| </div> | |
| ); | |
| } | |
| const { ConfigPanel } = meta; | |
| return ( | |
| <div className="w-80 bg-content1 border-l border-divider p-4 overflow-y-auto"> | |
| <h3 className="text-lg font-bold mb-4">cấu hình</h3> | |
| <div className="space-y-4"> | |
| <Suspense | |
| fallback={ | |
| <div className="flex items-center justify-center py-8"> | |
| <Spinner size="sm" /> | |
| </div> | |
| } | |
| > | |
| <ConfigPanel config={config} onUpdate={updateField} /> | |
| </Suspense> | |
| </div> | |
| </div> | |
| ); | |
| } | |