/** @jsxImportSource @emotion/react */ import { css } from '@emotion/react'; import { Fragment, useState } from 'react'; import { RcIconVertDots } from '../icons'; import { floatBoxCss, floatBoxItemCss } from './floatBoxCss'; import { OutsideClick } from '../helpers'; export interface RcGameCardMenuEntry { message: string; onClick: () => void; } export interface RcGameCardProps { width?: string; height?: string; iconSize?: string; iconPadding?: string; borderRadius?: string; bgColor?: string; menuEntries?: RcGameCardMenuEntry[]; menuWidthBox?: string; // width of entries box menuHeightBox?: string; // height of entries box menuZIndexBox?: number; // zIndex of box menuEntryHeight?: string; headerColor?: string; headerBgColor?: string; headerHeight?: string; title?: string; titleBgColor?: string; titleBorderColor?: string; paddingHoriz?: string; paddingVert?: string; heroHeight?: string; heroBg?: string; hero?: any; buttonsHeight?: string; buttonsBg?: string; buttons?: any; noZoom?: boolean; cssTitle?: string; cssMenuText?: string; } export const RcGameCard: React.FC = ({ width = '280px', height = '435px', iconSize = '20px', iconPadding = '25px', borderRadius = '8px', bgColor = '#ffffff', menuEntries, menuWidthBox, menuHeightBox, menuZIndexBox = 1, menuEntryHeight = '50px', headerColor = '#484848', headerBgColor = '#ffffff', headerHeight = '52px', title, paddingHoriz = '20px', paddingVert = '10px', heroHeight = '100px', heroBg = `background-image: linear-gradient(to top, #dfe9f3 0%, white 100%);`, hero, buttonsHeight = '60px', buttonsBg = '#ffffff', buttons, noZoom = true, cssMenuText, cssTitle = `font-weight: bold;`, children, }) => { const [showMenu, setShowMenu] = useState(false); const zoomCss = noZoom ? '' : ` /* grow */ -webkit-transition: all 0.5s ease; -moz-transition: all 0.5s ease; -o-transition: all 0.5s ease; -ms-transition: all 0.5s ease; transition: all 0.5s ease; :hover { /* highlight */ -webkit-box-shadow: 1px 1px 7px rgba(0, 0, 0, 0.4); box-shadow: 1px 1px 7px rgba(0, 0, 0, 0.4); /* grow */ -webkit-box-shadow: 1px 1px 7px rgba(0, 0, 0, 0.9); box-shadow: 1px 1px 7px rgba(0, 0, 0, 0.9); -webkit-transform: scale(1.05, 1.05); -moz-transform: scale(1.05, 1.05); -o-transform: scale(1.05, 1.05); -ms-transform: scale(1.05, 1.05); transform: scale(1.05, 1.05); } `; const dhHero = hero ? `- ${heroHeight}` : ''; const dtHero = hero ? `+ ${heroHeight}` : ''; const dhButtons = buttons ? `- ${buttonsHeight}` : ''; const contentWidth = `calc(${width} - 2 * ${paddingHoriz})`; let contentHeight = `calc(${height} - ${headerHeight} - 2 * ${paddingVert} ${dhHero} ${dhButtons})`; let contentTop = `calc(${headerHeight} + ${paddingVert} ${dtHero})`; const floatCss = menuEntries ? floatBoxCss(showMenu, menuHeightBox, menuWidthBox, true, menuZIndexBox) : undefined; const menuEntryCss = menuEntries ? floatBoxItemCss(paddingHoriz, menuEntryHeight) : undefined; return (
{title && (
{cssTitle ? {title} : {title}}
)} {hero && (
{hero}
)}
{children}
{buttons && (
{buttons}
)} {menuEntries && (
setShowMenu(true)} >
setShowMenu(false)}>
{menuEntries.map((e) => (
{ if (e.onClick) { e.onClick(); } }} > {cssMenuText ? ( {e.message} ) : ( {e.message} )}
))}
)}
); };