Spaces:
Running
Running
Download algospaced-ui/src/components/store/StoreItemCard.tsx from iamfebin/algospaced-dsa: direct link, hf CLI and curl.
- Browser
- Download file 4.07 kB
-
https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/store/StoreItemCard.tsx
- Command line
-
hf download hf://spaces/iamfebin/algospaced-dsa/algospaced-ui/src/components/store/StoreItemCard.tsx
-
curl -L -o StoreItemCard.tsx https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/store/StoreItemCard.tsx
4.07 kB
| import React from 'react'; | |
| import { Coins, Eye } from 'lucide-react'; | |
| import type { StoreItem } from '../../types/storeTypes'; | |
| import { ItemIcon } from './ItemIcon'; | |
| interface StoreItemCardProps { | |
| item: StoreItem; | |
| playerGold: number; | |
| isPurchasing: boolean; | |
| onPurchase: (item: StoreItem) => void; | |
| onInspect: (item: StoreItem) => void; | |
| } | |
| export const StoreItemCard: React.FC<StoreItemCardProps> = ({ | |
| item, | |
| playerGold, | |
| isPurchasing, | |
| onPurchase, | |
| onInspect | |
| }) => { | |
| const isAffordable = playerGold >= item.price; | |
| const categoryColor = | |
| item.category === 'consumable' | |
| ? 'bg-emerald-100 text-emerald-800 border-emerald-700' | |
| : item.category === 'cosmetic' | |
| ? 'bg-purple-100 text-purple-800 border-purple-700' | |
| : 'bg-amber-100 text-amber-900 border-amber-700'; | |
| const categoryLabel = | |
| item.category === 'consumable' | |
| ? 'Consumable' | |
| : item.category === 'cosmetic' | |
| ? 'Cosmetic' | |
| : 'Companion Gift'; | |
| return ( | |
| <div className="bg-[#FFFDF0] border-[3px] border-ink-black rounded-lg p-4 shadow-[4px_4px_0px_0px_#1E293B] flex flex-col justify-between hover:translate-x-[-1px] hover:translate-y-[-1px] hover:shadow-[5px_5px_0px_0px_#1E293B] transition-all"> | |
| {/* Top Bar: Category & Inspect */} | |
| <div> | |
| <div className="flex items-center justify-between gap-2 mb-3"> | |
| <span | |
| className={`font-arcade text-[8px] px-2 py-0.5 border rounded uppercase font-bold tracking-wider ${categoryColor}`} | |
| > | |
| {categoryLabel} | |
| </span> | |
| <button | |
| type="button" | |
| onClick={() => onInspect(item)} | |
| className="p-1 hover:bg-amber-100 text-slate-600 hover:text-ink-black rounded transition-colors cursor-pointer" | |
| title="Inspect lore and mechanics" | |
| > | |
| <Eye className="w-3.5 h-3.5" /> | |
| </button> | |
| </div> | |
| {/* Item Icon & Title */} | |
| <div className="flex items-start gap-3 mb-3"> | |
| <div className="w-12 h-12 bg-white border-[2px] border-ink-black rounded flex items-center justify-center shrink-0 shadow-[2px_2px_0px_0px_#1E293B]"> | |
| <ItemIcon name={item.icon} className="w-6 h-6 text-amber-700" /> | |
| </div> | |
| <div className="min-w-0 flex-1"> | |
| <h4 | |
| onClick={() => onInspect(item)} | |
| className="font-headline-md font-bold text-sm text-ink-black leading-snug cursor-pointer hover:text-amber-800 truncate" | |
| title={item.name} | |
| > | |
| {item.name} | |
| </h4> | |
| <div className="flex items-center gap-1 mt-0.5 text-amber-800 font-arcade text-xs font-bold"> | |
| <Coins className="w-3.5 h-3.5 text-amber-500 fill-amber-500" /> | |
| <span>{item.price}g</span> | |
| </div> | |
| </div> | |
| </div> | |
| {/* Lore Snippet */} | |
| <p className="font-serif italic text-xs text-slate-600 line-clamp-2 mb-4 leading-relaxed"> | |
| “{item.lore}” | |
| </p> | |
| </div> | |
| {/* Action Footer */} | |
| <div className="pt-2 border-t border-ink-black/10 flex items-center justify-between gap-2"> | |
| <button | |
| type="button" | |
| disabled={!isAffordable || isPurchasing} | |
| onClick={() => onPurchase(item)} | |
| className={`w-full font-arcade text-[10px] py-2 px-3 border-[2px] border-ink-black rounded shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all uppercase tracking-wider font-bold ${ | |
| !isAffordable | |
| ? 'bg-slate-200 text-slate-400 border-slate-400 shadow-none cursor-not-allowed' | |
| : 'bg-amber-400 hover:bg-amber-300 text-ink-black cursor-pointer' | |
| }`} | |
| title={!isAffordable ? `Need ${item.price - playerGold} more gold to buy` : `Buy for ${item.price}g`} | |
| > | |
| {isPurchasing | |
| ? 'Purchasing...' | |
| : !isAffordable | |
| ? 'Insufficient Gold' | |
| : 'Purchase'} | |
| </button> | |
| </div> | |
| </div> | |
| ); | |
| }; | |