Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@radix-ui/react-aspect-ratio
Advanced tools
@radix-ui/react-aspect-ratio is a React component library that provides a way to maintain a consistent aspect ratio for an element. This is particularly useful for responsive design, ensuring that elements like images, videos, and other media maintain their proportions across different screen sizes.
Basic Aspect Ratio
This feature allows you to wrap any element with the AspectRatio component to maintain a 16:9 aspect ratio. The child element will scale to fit the specified ratio.
import { AspectRatio } from '@radix-ui/react-aspect-ratio';
function App() {
return (
<AspectRatio ratio={16 / 9}>
<img src="https://via.placeholder.com/800x450" alt="Example" />
</AspectRatio>
);
}
Custom Aspect Ratio
This feature allows you to specify a custom aspect ratio, such as 4:3, for any element. The child element will adjust its size to maintain the specified ratio.
import { AspectRatio } from '@radix-ui/react-aspect-ratio';
function App() {
return (
<AspectRatio ratio={4 / 3}>
<div style={{ background: 'lightblue', width: '100%', height: '100%' }}>Custom Aspect Ratio</div>
</AspectRatio>
);
}
Responsive Aspect Ratio
This feature demonstrates how the AspectRatio component can be used within a responsive container. The aspect ratio is maintained even as the container resizes.
import { AspectRatio } from '@radix-ui/react-aspect-ratio';
function App() {
return (
<div style={{ width: '50%' }}>
<AspectRatio ratio={1}>
<div style={{ background: 'lightcoral', width: '100%', height: '100%' }}>Responsive Aspect Ratio</div>
</AspectRatio>
</div>
);
}
react-aspect-ratio is another package that allows you to maintain aspect ratios for elements. It is straightforward to use but may lack some of the advanced features and flexibility provided by @radix-ui/react-aspect-ratio.
react-container-query allows you to apply styles based on the size of a container, which can be used to maintain aspect ratios indirectly. It offers more general functionality for responsive design but requires more setup compared to @radix-ui/react-aspect-ratio.
react-aspect-ratio
$ yarn add @radix-ui/react-aspect-ratio
# or
$ npm install @radix-ui/react-aspect-ratio
View docs here.
FAQs
Unknown package
The npm package @radix-ui/react-aspect-ratio receives a total of 347,866 weekly downloads. As such, @radix-ui/react-aspect-ratio popularity was classified as popular.
We found that @radix-ui/react-aspect-ratio demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.