import React, { JSXElementConstructor, ReactElement, useEffect } from "react"; import { ButtonGroup, Separator } from "../.."; import Group from "../Group/Group"; import { getClassName } from "../utils"; import './ActionSheet.css' export interface IActionSheet extends React.HTMLAttributes { children: React.ReactNode | ReactElement>, component?: React.ReactNode, className?: string | undefined, }; const ActionSheet = ({ children, component, className, ...props }: IActionSheet) => { const [open, setOpen] = React.useState(false); const [__x, setX] = React.useState(1); const [__width, setWidth] = React.useState(`100%`); const __ref = React.useRef(null); const __refComponent = React.useRef(null); const [openPosition, setOpenPosition] = React.useState(`top`) const testOpenClick = () => setOpen(!open); useEffect(() => { if (__ref.current && __refComponent.current) { setX(__refComponent.current.getBoundingClientRect().height) if (__ref.current.getBoundingClientRect().bottom < window.innerHeight / 2) setOpenPosition(`bottom`) setWidth(__refComponent.current.offsetWidth); } }, [open]) return
{component &&
{Array.isArray(component) ? component.map((child: any, index: number) => { var separator = index + 1 < component.length const is_top_separator = index + 1 == component.length const last_is_separator = index + 2 == component.length && Array.isArray(component[index + 1]); if (Array.isArray(child)) return
{is_top_separator && } {child} {!is_top_separator && separator && }
return
{child} {!last_is_separator && separator && }
}) : children}
} {open &&
{children}
}
{children}
} export default ActionSheet;