import React, {FC, PropsWithChildren} from "react"; import {colors} from "./Colors"; import {useHover} from "./hooks"; import {ColorOption, ColorOptionWithCustomTint, ColorWithCustomTint, CurrentColor, request} from "./Color"; import classNames from "classnames"; import {motion} from "motion/react"; export type CardProps = ColorOptionWithCustomTint & { id?: string, highlight?: boolean, blur?: boolean, onHoverStart?: () => void, onHoverEnd?: () => void, bottomButton?: { icon: React.ReactNode, text: string, onClick: () => void }, afterContent?: React.ReactNode | ((isHovered: boolean) => React.ReactNode), beforeCardInsideContent?: React.ReactNode, beforeCardInsideContentHorizontal?: boolean, // default is false outsideContent?: React.ReactNode | ((isHovered: boolean) => React.ReactNode), innerRing?: boolean, outerRing?: boolean, outerRingWidth?: string, outerRingColor?: { default: ColorWithCustomTint, highlight?: ColorWithCustomTint, }, roundness?: string, outerRingRoundness?: string, enableSelfHovering?: boolean, explicitWidth?: boolean, fullWidth?: boolean, scaleOnHover?: boolean, animateLayout?: boolean, } export const Card: FC = ({ id, highlight, children, blur, onHoverStart, onHoverEnd, bottomButton, afterContent, outsideContent, beforeCardInsideContent, beforeCardInsideContentHorizontal, color, innerRing = true, outerRing, outerRingWidth, outerRingColor, roundness, outerRingRoundness, enableSelfHovering = false, explicitWidth = false, fullWidth = false, scaleOnHover = true, animateLayout = true, }) => { const resizeTransition = React.useMemo(() => ({ type: "spring" as const, stiffness: 500, damping: 38, mass: 0.42, }), []) const hoverRef = useHover({ onMouseEnter: () => { if (enableSelfHovering) { setIsHovered(true) } onHoverStart?.() }, onMouseLeave: () => { if (enableSelfHovering) { setIsHovered(false) } onHoverEnd?.() } }) const [isHovered, setIsHovered] = React.useState(false) return
{beforeCardInsideContent}
{children} {bottomButton && } {typeof afterContent === 'function' ? afterContent(isHovered) : afterContent}
{typeof outsideContent === 'function' ? outsideContent(isHovered) : outsideContent}
}