Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@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
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.