const PopupForm = ({
show,
setShow,
childComponent: ChildComponent,
size = 'lg', // 'sm' | 'lg' | 'xl' | undefined
effect = 'fadeModal',
title,
backdrop = 'static', // 'static' | true | false
fullscreen = false, // Thêm tùy chọn fullscreen
showCloseButton =true,
zIndex=1050,
...props
}) => {
const { Modal } = ReactBootstrap
const handleClose = () => {
setShow(false);
};
return (
{showCloseButton==true ?
(
<>
{title}
handleClose()}
style={{ fontSize:25, paddingLeft:10 , color:'gray', float:'right'}}
/>
>
):
(
<>
{title}
>
)
}
);
};
const ContainerExpanse =(props)=>{
const {
HeaderComponent,
BodyComponent,
showContentDefault =true,
style={margin:0}, key, actionExpand = null, effectHover = true,
styleHeader={background: showContentDefault ? 'rgb(241 170 240 / 24%)':"", padding:3},
styleBody={padding:'5px', display:(showContentDefault==false?'none':'')} ,
showExpand = true,
stylePaddingLeftExpanseButton=15,
styleExpanseIcon
}= props
const {Card} = ReactBootstrap
const [showContent, setShowContent] = useState(showContentDefault);
const handleToggle = () => {
setShowContent(!showContent);
if(showContent==false && actionExpand){
actionExpand();
}
};
return(
{ HeaderComponent &&
{ showExpand==true &&
}
{HeaderComponent}
}
{ BodyComponent && (
{BodyComponent}
)}
)
}
const CtlContainerExpanse =(props)=>{
const {
HeaderComponent,
BodyComponent,
showContent, setShowContent,effectHover = true,
style={margin:0}, key,
showExpand = false
}= props
const {Card} = ReactBootstrap
const handleToggle = () => {
if (setShowContent) setShowContent(!showContent);
};
return(
{ HeaderComponent &&
{ showExpand === true &&
}
{HeaderComponent}
}
{ BodyComponent && (
{BodyComponent}
)}
)
}
const ContentContainer = (props) => {
const { children, maxHeight = 300, flag = false } = props;
const [isExpanded, setIsExpanded] = useState(flag);
const [showExpandButton, setShowExpandButton] = useState(false);
const contentRef = useRef(null); // Ref for the visible content div
const measureRef = useRef(null); // Ref for measuring actual height
const toggleExpand = () => {
setIsExpanded(!isExpanded);
};
// Check if there's any content to display
const hasContent = React.Children.count(children) > 0 && children !== null && children !== undefined;
useEffect(() => {
if (measureRef.current && hasContent) {
// Measure the actual height of the content when it's fully rendered
const actualHeight = measureRef.current.scrollHeight;
setShowExpandButton(actualHeight > maxHeight);
} else {
setShowExpandButton(false); // No content or no overflow
}
}, [children, maxHeight, hasContent]);
// If no content, don't render the container at all
if (!hasContent) {
return null;
}
return (
{/* Content to be displayed and potentially truncated */}
{children}
{/* Hidden div to measure actual content height without affecting layout */}
{children}
{showExpandButton && !isExpanded && (
)}
{showExpandButton && isExpanded && (
)}
);
};