Aller au contenu principal

Popper Component

Description

The Popper component provides a floating UI container that appears next to an anchor element. It supports various placements and can be configured as a modal.

Props

PropTypeDefaultDescription
openbooleanfalseControls the visibility of the popper.
anchorElHTMLElement | null | undefinedundefinedThe element that the popper is anchored to.
placement"top" | "bottom" | "left" | "right" | "bottom-start" | "bottom-end""bottom-start"The position of the popper relative to the anchor.
disablePortalbooleanfalseIf true, the popper will not be rendered inside a portal.
modalbooleanfalseIf true, a backdrop is shown behind the popper, making it act like a modal.
onClose() => voidundefinedCallback triggered when the popper is closed.

Example Usage

import { useState } from "react";
import { Popper, Button } from "@nomana-it/liberty-core"

export const PopperExample = () => {
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
const [open, setOpen] = useState(false);

const handleOpen = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
setOpen(true);
};

const handleClose = () => {
setOpen(false);
};

return (
<div>
<Button onClick={handleOpen}>Open Popper</Button>

<Popper open={open} anchorEl={anchorEl} onClose={handleClose} placement="bottom-start">
<div style={{ padding: "10px", background: "#fff", boxShadow: "0px 4px 10px rgba(0, 0, 0, 0.1)", borderRadius: "8px" }}>
This is a popper content.
<Button onClick={handleClose}>Close</Button>
</div>
</Popper>
</div>
);
};

🔗 GitHub Repository (Core): Liberty Core
🔗 GitHub Repository (Test Project): Liberty Test
📖 Live Documentation: Liberty Core Docs
💖 Sponsor & Support: Sponsor Liberty Core