Components / Transitions and utilities
ClickAwayListener
Wraps one element and calls onClickAway when someone clicks outside it.
import { ClickAwayListener } from "@stylhero/ui";
Example
Code
import { useState } from "react";
import { Button, ClickAwayListener } from "@stylhero/ui";
function ClickAwayListenerExample() {
const [open, setOpen] = useState(false);
return (
<ClickAwayListener onClickAway={() => setOpen(false)}>
<div style={{ display: "inline-block" }}>
<Button variant="secondary" onClick={() => setOpen(true)}>{open ? "Click outside to close" : "Open"}</Button>
</div>
</ClickAwayListener>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children required |
ReactElement |
- | |
onClickAway required |
(e: PointerEvent) => void |
- |
Generated from src/utils.tsx. Something wrong or missing? Open an issue.