Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@react-aria/overlays
Advanced tools
@react-aria/overlays is a library that provides accessible overlay components for React applications. It includes components for modals, popovers, and tooltips, ensuring they are accessible and follow best practices.
Modal
This code demonstrates how to create a modal using @react-aria/overlays. It includes state management for opening and closing the modal, and ensures accessibility features like preventing background scroll and proper focus management.
import { useOverlayTriggerState } from '@react-stately/overlays';
import { OverlayContainer, OverlayProvider, useModal, useOverlay, usePreventScroll } from '@react-aria/overlays';
function ModalExample() {
let state = useOverlayTriggerState({});
return (
<OverlayProvider>
<button onClick={() => state.open()}>Open Modal</button>
{state.isOpen && (
<OverlayContainer>
<ModalDialog onClose={state.close} />
</OverlayContainer>
)}
</OverlayProvider>
);
}
function ModalDialog(props) {
let ref = React.useRef();
let { modalProps } = useModal();
let { overlayProps } = useOverlay(props, ref);
usePreventScroll();
return (
<div {...overlayProps} {...modalProps} ref={ref}>
<h3>Modal Title</h3>
<p>Modal Content</p>
<button onClick={props.onClose}>Close</button>
</div>
);
}
Popover
This code demonstrates how to create a popover using @react-aria/overlays. It includes state management for opening and closing the popover, and ensures accessibility features like preventing background scroll and proper focus management.
import { useOverlayTriggerState } from '@react-stately/overlays';
import { OverlayContainer, OverlayProvider, useOverlay, usePreventScroll, usePopover } from '@react-aria/overlays';
function PopoverExample() {
let state = useOverlayTriggerState({});
return (
<OverlayProvider>
<button onClick={() => state.open()}>Open Popover</button>
{state.isOpen && (
<OverlayContainer>
<PopoverDialog onClose={state.close} />
</OverlayContainer>
)}
</OverlayProvider>
);
}
function PopoverDialog(props) {
let ref = React.useRef();
let { popoverProps } = usePopover(props, ref);
let { overlayProps } = useOverlay(props, ref);
usePreventScroll();
return (
<div {...overlayProps} {...popoverProps} ref={ref}>
<h3>Popover Title</h3>
<p>Popover Content</p>
<button onClick={props.onClose}>Close</button>
</div>
);
}
Tooltip
This code demonstrates how to create a tooltip using @react-aria/overlays. It includes state management for showing and hiding the tooltip, and ensures accessibility features like proper focus management and delay handling.
import { useTooltipTriggerState } from '@react-stately/tooltip';
import { useTooltip, TooltipTrigger, Tooltip } from '@react-aria/tooltip';
function TooltipExample() {
let state = useTooltipTriggerState({});
return (
<TooltipTrigger state={state} delay={300} placement="top">
<button>Hover or focus me</button>
<Tooltip>Tooltip Content</Tooltip>
</TooltipTrigger>
);
}
react-modal is a widely-used library for creating accessible modal dialogs in React. It provides a simple API for creating modals and ensures accessibility features like focus management and ARIA attributes. Compared to @react-aria/overlays, react-modal is more focused on modals and may not provide as comprehensive a set of overlay components.
react-popper is a library for creating poppers (floating elements) in React. It provides a powerful positioning engine and is often used for tooltips, popovers, and dropdowns. While it offers great flexibility and control over positioning, it may require more manual setup for accessibility compared to @react-aria/overlays.
react-tooltip is a library specifically for creating tooltips in React. It offers a simple API and various customization options for styling and behavior. While it is easy to use and highly customizable, it may not provide the same level of accessibility features as @react-aria/overlays.
This package is part of react-spectrum. See the repo for more details.
FAQs
Spectrum UI components in React
The npm package @react-aria/overlays receives a total of 848,666 weekly downloads. As such, @react-aria/overlays popularity was classified as popular.
We found that @react-aria/overlays demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.