import React, { FC, HTMLAttributes, Children, useState, useEffect, useRef, createContext, useMemo, startTransition, ReactNode } from "react"; import { Padding } from "../../index"; import { getCN, randomId } from '../utils' import './ModalCard.css' interface IModalCard extends HTMLAttributes { id: string, autoPadding?: boolean header?: ReactNode | string; background?: boolean; onClose?: React.ReactNode; }; const ModalCard: FC = ({ id, children, header, onClose, background = true, ...restProps }) => { const ref = React.useRef(null); const [size, setSize] = React.useState(); const resizeHandler = () => { if (ref.current) { const { offsetHeight, clientWidth } = ref.current; setSize(offsetHeight); } }; useEffect(() => { resizeHandler(); }, [ ref.current && ref.current.offsetHeight, children, ref ]); useEffect(() => { bindImagesOnload(ref.current, function () { resizeHandler() }); }, [children]) return
{!onClose && header &&
{header}
} {onClose &&
{onClose}
}
{children}
} const bindImagesOnload = (node: any, fn: () => void) => { var imgs = node.getElementsByTagName("img"), length = imgs.length; var onload = () => fn(); for (var i = 0; i < length; i++) imgs[i].onload = onload; } export default ModalCard;