import React, { useCallback } from 'react' import classNames from 'classnames' import { Card } from '../Card/Card' import { Popup } from '../Popup/Popup' import { Mana } from '../Mana/Mana' import { NFTImage } from '../NFTImage' import { getBadges, getSubtitle } from './utils' import { Badge as BadgeType, Props } from './NFTCard.types' import './NFTCard.css' const BadgeItem = ({ badge }: { badge: BadgeType }) => { if (badge.icon && badge.hideLabel) { return ( } /> ) } return ( {badge.icon && ( )} {badge.label} ) } export const NFTCard = (props: Props) => { const { nft, i18n, header, subtitle, badges, price, className, ...cardProps } = props const renderHeader = useCallback(() => { if (!header || typeof header === 'string') { return (
{header || nft.name} {price && ( {price} )}
) } return header }, [header]) const renderSubtitle = useCallback(() => { if (!subtitle || typeof subtitle === 'string') { return ( {subtitle || getSubtitle(nft, i18n)} ) } return subtitle }, [subtitle]) const renderBadges = useCallback(() => { if (badges) { return badges } const nftBadges = getBadges(nft, i18n) if (!nftBadges) { return null } return (
{nftBadges.map((badge) => ( ))}
) }, []) return ( {renderHeader()} {renderSubtitle()} {renderBadges()} ) } NFTCard.defaultProps = { i18n: { network: { ethereum: 'Ethereum', matic: 'Matic' }, bodyShape: { male: 'Male', female: 'Female', unisex: 'Unisex' }, playMode: { loop: 'Loop', once: 'Once' }, category: { body_shape: 'Body Shape', earring: 'Earring', eyebrows: 'Eyebrows', eyes: 'Eyes', eyewear: 'Eyewear', facial_hair: 'Facial Hair', feet: 'Feet', head: 'Head', hair: 'Hair', hat: 'Hat', helmet: 'Helmet', lower_body: 'Lower Body', mask: 'Mask', mouth: 'Mouth', tiara: 'Tiara', top_head: 'Top Head', upper_body: 'Upper Body', skin: 'Skin', hands_wear: 'Handwear' }, withSound: 'With sound', smart: 'Smart', social: 'Social' } }