Spaces:
Running
Running
Download components/Card.tsx from codebybrody/codebydante: direct link, hf CLI and curl.
- Browser
- Download file 6.34 kB
-
https://huggingface.co/spaces/codebybrody/codebydante/resolve/269ea4c5aa9c8ed277c8c5953a3a48b04d280430/components/Card.tsx
- Command line
-
hf download hf://spaces/codebybrody/codebydante@269ea4c5aa9c8ed277c8c5953a3a48b04d280430/components/Card.tsx
-
curl -L -o Card.tsx https://huggingface.co/spaces/codebybrody/codebydante/resolve/269ea4c5aa9c8ed277c8c5953a3a48b04d280430/components/Card.tsx
6.34 kB
| import React from 'react'; | |
| import { DataItem } from '../types'; | |
| import { Download, ExternalLink, Check, Folder } from 'lucide-react'; | |
| import { getIconComponent } from './IconPicker'; | |
| interface CardProps { | |
| item: DataItem; | |
| onClick: (item: DataItem) => void; | |
| isSelectable?: boolean; | |
| isSelected?: boolean; | |
| onMouseDown?: (e: React.MouseEvent, item: DataItem) => void; | |
| onMouseEnter?: (e: React.MouseEvent, item: DataItem) => void; | |
| onDoubleClick?: (item: DataItem) => void; | |
| } | |
| export const Card: React.FC<CardProps> = ({ item, onClick, isSelectable, isSelected, onMouseDown, onMouseEnter, onDoubleClick }) => { | |
| const Icon = getIconComponent(item.icon); | |
| if (item.isFolder) { | |
| return ( | |
| <div | |
| onClick={() => onClick(item)} | |
| onDoubleClick={() => onDoubleClick?.(item)} | |
| onMouseDown={(e) => onMouseDown?.(e, item)} | |
| onMouseEnter={(e) => onMouseEnter?.(e, item)} | |
| style={{ userSelect: isSelectable ? 'none' : 'auto' }} | |
| className={`relative group bg-surface border ${isSelected ? 'border-primary ring-2 ring-primary bg-primary/10 shadow-[0_0_20px_rgba(187,134,252,0.15)]' : 'border-white/5 hover:border-primary/30 hover:bg-white/[0.02]'} rounded-xl p-6 cursor-pointer transition-all duration-300 ${isSelected ? 'scale-[0.98]' : 'hover:-translate-y-1 hover:shadow-xl'} flex flex-col items-center justify-center h-[200px] text-center overflow-hidden`} | |
| > | |
| {isSelected && ( | |
| <div className="absolute top-3 right-3 z-20 w-6 h-6 bg-primary rounded-full flex items-center justify-center shadow-lg transition-transform animate-in zoom-in duration-200 pointer-events-none"> | |
| <Check size={14} className="text-[#121212]" strokeWidth={3} /> | |
| </div> | |
| )} | |
| <div className="p-4 bg-white/5 rounded-2xl mb-4 group-hover:bg-primary/10 transition-colors"> | |
| <Folder size={48} className="text-primary opacity-80 group-hover:opacity-100 transition-opacity" strokeWidth={1} /> | |
| </div> | |
| <h3 className="text-lg font-bold text-white group-hover:text-primary transition-colors line-clamp-2 w-full px-2"> | |
| {item.title} | |
| </h3> | |
| {item.summary && item.summary !== 'Carpeta' && ( | |
| <p className="text-xs text-gray-500 mt-2 line-clamp-1 break-words">{item.summary}</p> | |
| )} | |
| </div> | |
| ); | |
| } | |
| return ( | |
| <div | |
| onClick={(e) => { | |
| onClick(item); | |
| }} | |
| onDoubleClick={() => onDoubleClick?.(item)} | |
| onMouseDown={(e) => onMouseDown?.(e, item)} | |
| onMouseEnter={(e) => onMouseEnter?.(e, item)} | |
| style={{ userSelect: isSelectable ? 'none' : 'auto' }} | |
| className={`relative group bg-surface border ${isSelected ? 'border-primary ring-2 ring-primary bg-primary/10 shadow-[0_0_20px_rgba(187,134,252,0.15)]' : 'border-white/5 hover:border-primary/30'} rounded-xl p-3 sm:p-4 cursor-pointer transition-all duration-300 ${isSelected ? 'scale-[0.98]' : 'hover:-translate-y-1 hover:shadow-xl'} flex flex-col h-full min-h-[200px] overflow-hidden`} | |
| > | |
| {isSelected && ( | |
| <div className="absolute top-3 right-3 z-20 w-6 h-6 bg-primary rounded-full flex items-center justify-center shadow-lg transition-transform animate-in zoom-in duration-200 pointer-events-none"> | |
| <Check size={14} className="text-[#121212]" strokeWidth={3} /> | |
| </div> | |
| )} | |
| <div className="mb-2 flex-grow flex flex-col"> | |
| <div className="flex items-start gap-2"> | |
| {Icon && ( | |
| <div className="text-primary shrink-0 mt-0.5"> | |
| <Icon size={18} className="sm:w-5 sm:h-5" /> | |
| </div> | |
| )} | |
| <h3 | |
| className="text-base sm:text-lg font-bold text-white mb-2 group-hover:text-primary transition-colors break-words" | |
| title={(item.title || '').replace(/<[^>]*>?/gm, '')} | |
| > | |
| {(() => { | |
| const text = (item.title || '').replace(/<[^>]*>?/gm, '').replace(/ /g, ' '); | |
| return text.length > 30 ? text.slice(0, 30).trim() + '...' : text; | |
| })()} | |
| </h3> | |
| </div> | |
| <div | |
| className="text-zinc-400 text-[11px] sm:text-xs leading-normal [&>p]:m-0 [&_img]:w-full [&_img]:h-full [&_img]:object-cover [&_img]:p-0 [&_img]:m-0 [&_img]:rounded-none [&_figure]:p-0 [&_figure]:m-0 [&_figure]:bg-transparent overflow-hidden" | |
| dangerouslySetInnerHTML={{ __html: item.summary }} | |
| style={{ | |
| display: '-webkit-box', | |
| WebkitLineClamp: (item.visitUrl || item.downloadUrl) ? 4 : 7, | |
| WebkitBoxOrient: 'vertical', | |
| overflow: 'hidden' | |
| }} | |
| /> | |
| </div> | |
| {/* Buttons Section */} | |
| {/* Buttons Section */} | |
| {(item.visitUrl || item.downloadUrl) && ( | |
| <div className="mt-auto flex flex-col sm:flex-row gap-2 pt-3"> | |
| {item.visitUrl && ( | |
| <a | |
| href={item.visitUrl} | |
| target="_blank" | |
| rel="noopener noreferrer" | |
| onClick={(e) => e.stopPropagation()} | |
| className={`flex-1 w-full bg-transparent border border-[#bb86fc] text-[#bb86fc] font-medium py-2 px-3 sm:py-2.5 sm:px-4 rounded-lg flex items-center justify-center gap-2 hover:bg-[#bb86fc] hover:text-[#121212] transition-all text-xs sm:text-sm shadow-[0_0_5px_rgba(187,134,252,0.2)]`} | |
| > | |
| <ExternalLink size={14} className="sm:w-4 sm:h-4" strokeWidth={2.5} /> | |
| Visitar | |
| </a> | |
| )} | |
| {item.downloadUrl && ( | |
| <a | |
| href={item.downloadUrl} | |
| target="_blank" | |
| rel="noopener noreferrer" | |
| onClick={(e) => e.stopPropagation()} | |
| className={`flex-1 w-full bg-transparent border border-[#bb86fc] text-[#bb86fc] font-medium py-2 px-3 sm:py-2.5 sm:px-4 rounded-lg flex items-center justify-center gap-2 hover:bg-[#bb86fc] hover:text-[#121212] transition-all text-xs sm:text-sm shadow-[0_0_5px_rgba(187,134,252,0.2)]`} | |
| > | |
| <Download size={14} className="sm:w-4 sm:h-4" strokeWidth={2.5} /> | |
| Descargar | |
| </a> | |
| )} | |
| </div> | |
| )} | |
| </div> | |
| ); | |
| }; |