Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@automattic/viewport
Advanced tools
This package contains functions to identify and track changes to the viewport. This can be used for displaying different components depending on a desktop or mobile view.
For React helpers, please check the @automattic/viewport-react
package.
Simple usage:
import { isDesktop, isMobile } from '@automattic/viewport';
if ( isDesktop() ) {
// Render a component optimized for desktop view
} else if ( isMobile() ) {
// Render a component optimized for mobile view
}
Using one of the other breakpoints:
import { isWithinBreakpoint } from '@automattic/viewport';
if ( isWithinBreakpoint( '>1400px' ) ) {
// Render a component optimized for a very large screen
} else {
// Render alternative component
}
Registering to listen to changes, using vanilla methods:
import { subscribeIsDesktop } from '@automattic/viewport';
class MyComponent extends React.Component {
sizeChanged = ( matches ) => {
console.log( `Screen changed to ${ matches ? 'desktop' : 'non-desktop' } size` );
this.forceUpdate();
};
componentDidMount() {
this.unsubscribe = subscribeIsDesktop( this.sizeChanged );
}
componentWillUnmount() {
this.unsubscribe();
}
}
Note: the above usage is more easily accomplished using the hooks and higher-order components in @automattic/viewport-react
.
isWithinBreakpoint( breakpoint )
: Whether the current screen size matches the breakpoint.isMobile()
: Whether the current screen size matches a mobile breakpoint (equivalent to "<480px"). See note at end of document.isDesktop()
: Whether the current screen size matches a desktop breakpoint (equivalent to ">960px"). See note at end of document.subscribeIsWithinBreakpoint( breakpoint, listener )
: Register a listener for size changes that affect the breakpoint. Returns the unsubscribe function.subscribeIsMobile( listener )
: Register a listener for size changes that affect the mobile breakpoint (equivalent to "<480px"). Returns the unsubscribe function. See note at end of document.subscribeIsDesktop( listener )
: Register a listener for size changes that affect the desktop breakpoint (equivalent to ">960px"). Returns the unsubscribe function. See note at end of document.getWindowInnerWidth()
: Get the inner width for the browser window. Warning: This method triggers a layout recalc, potentially resulting in performance issues. Please use a breakpoint instead wherever possible.Note: As implemented in Calypso media query mixins, minimums are exclusive, while maximums are inclusive. i.e.:
@media (min-width: 481px)
@media (max-width: 960px)
@media (max-width: 960px) and (min-width: 481px)
FAQs
Vanilla helpers for tracking viewport changes.
The npm package @automattic/viewport receives a total of 1,951 weekly downloads. As such, @automattic/viewport popularity was classified as popular.
We found that @automattic/viewport demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 37 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.