|
6 | 6 | * LICENSE file in the root directory of this source tree. |
7 | 7 | */ |
8 | 8 |
|
| 9 | +import { ComponentRegistry } from '@object-ui/core'; |
| 10 | +import compact from 'lodash/compact'; |
9 | 11 | import { ComponentRegistry } from '@object-ui/core'; |
10 | 12 | import type { ListSchema } from '@object-ui/types'; |
| 13 | +import { useDataScope } from '@object-ui/react'; |
11 | 14 | import { renderChildren } from '../../lib/utils'; |
12 | 15 | import { cn } from '../../lib/utils'; |
13 | | -import { ChevronRight, Hexagon, Terminal } from 'lucide-react'; |
14 | 16 |
|
15 | 17 | ComponentRegistry.register('list', |
16 | 18 | ({ schema, className, ...props }: { schema: ListSchema; className?: string; [key: string]: any }) => { |
17 | | - // We use 'ul' for both to control semantics manually with visuals |
18 | | - const ListTag = 'ul'; |
| 19 | + // Support data binding |
| 20 | + const boundData = useDataScope(schema.bind); |
| 21 | + const items = boundData || schema.items || []; |
19 | 22 |
|
20 | | - return ( |
21 | | - <div className={cn("relative p-4 rounded-lg bg-slate-950/30 border border-slate-800/50 backdrop-blur-sm", schema.wrapperClass)}> |
22 | | - {/* Decorative corner accents for container */} |
23 | | - <div className="absolute top-0 left-0 w-2 h-2 border-l-2 border-t-2 border-cyan-500/50 rounded-tl-sm" /> |
24 | | - <div className="absolute top-0 right-0 w-2 h-2 border-r-2 border-t-2 border-cyan-500/50 rounded-tr-sm" /> |
25 | | - <div className="absolute bottom-0 left-0 w-2 h-2 border-l-2 border-b-2 border-cyan-500/50 rounded-bl-sm" /> |
26 | | - <div className="absolute bottom-0 right-0 w-2 h-2 border-r-2 border-b-2 border-cyan-500/50 rounded-br-sm" /> |
| 23 | + // We use 'ol' or 'ul' based on ordered prop |
| 24 | + const ListTag = schema.ordered ? 'ol' : 'ul'; |
| 25 | + |
| 26 | + // Default styles for ordered/unordered |
| 27 | + const listStyle = schema.ordered ? "list-decimal" : "list-disc"; |
27 | 28 |
|
| 29 | + return ( |
| 30 | + <div className={cn("space-y-2", schema.wrapperClass)}> |
28 | 31 | {schema.title && ( |
29 | | - <div className="flex items-center gap-2 mb-4 pb-2 border-b border-cyan-900/30"> |
30 | | - <Terminal className="w-4 h-4 text-cyan-500" /> |
31 | | - <h3 className="text-sm font-bold uppercase tracking-widest text-cyan-400 drop-shadow-[0_0_5px_rgba(6,182,212,0.5)]"> |
32 | | - {schema.title} |
33 | | - </h3> |
34 | | - </div> |
| 32 | + <h3 className="text-lg font-semibold tracking-tight"> |
| 33 | + {schema.title} |
| 34 | + </h3> |
35 | 35 | )} |
36 | 36 |
|
37 | 37 | <ListTag |
38 | 38 | className={cn( |
39 | | - "space-y-1", |
| 39 | + "ml-6 [&>li]:mt-2", |
| 40 | + listStyle, |
40 | 41 | className |
41 | 42 | )} |
42 | 43 | {...props} |
43 | 44 | > |
44 | | - {schema.items?.map((item: any, index: number) => ( |
45 | | - <li |
46 | | - key={index} |
47 | | - className={cn( |
48 | | - "group flex items-start gap-3 p-2 rounded-sm transition-all duration-300", |
49 | | - "hover:bg-cyan-950/20 hover:pl-3", |
50 | | - typeof item === 'object' && item.className |
51 | | - )} |
52 | | - > |
53 | | - {/* Marker Area */} |
54 | | - <div className="flex-shrink-0 mt-0.5"> |
55 | | - {schema.ordered ? ( |
56 | | - <span className="flex items-center justify-center w-5 h-5 text-[10px] font-mono font-bold text-slate-950 bg-cyan-600 rounded-sm shadow-[0_0_8px_cyan] group-hover:bg-cyan-400 group-hover:scale-110 transition-all"> |
57 | | - {String(index + 1).padStart(2, '0')} |
58 | | - </span> |
59 | | - ) : ( |
60 | | - <div className="relative flex items-center justify-center w-5 h-5"> |
61 | | - <Hexagon className="w-3 h-3 text-cyan-600 group-hover:text-cyan-400 group-hover:rotate-90 transition-transform duration-500" /> |
62 | | - <div className="absolute inset-0 bg-cyan-500/20 blur-[2px] rounded-full opacity-0 group-hover:opacity-100 transition-opacity" /> |
63 | | - </div> |
64 | | - )} |
65 | | - </div> |
66 | | - |
67 | | - {/* Content Area */} |
68 | | - <div className="flex-1 text-sm text-slate-400 group-hover:text-cyan-100 font-medium font-sans leading-tight transition-colors"> |
69 | | - {typeof item === 'string' ? item : item.content || renderChildren(item.body)} |
70 | | - </div> |
71 | | - |
72 | | - {/* Hover Indicator */} |
73 | | - <ChevronRight className="w-4 h-4 text-cyan-500/0 -translate-x-2 group-hover:text-cyan-500 group-hover:translate-x-0 transition-all duration-300 opacity-0 group-hover:opacity-100" /> |
| 45 | + {items.map((item: any, index: number) => ( |
| 46 | + <li key={index} className={cn(typeof item === 'object' && item.className)}> |
| 47 | + {typeof item === 'string' ? item : item.content || renderChildren(item.body)} |
74 | 48 | </li> |
75 | 49 | ))} |
76 | 50 | </ListTag> |
|
0 commit comments