New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-stay-in-view

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-stay-in-view

A react hook and component to create popper (popover) that never leave the screen.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

react-stay-in-view

Version Badge NPM license PRs Welcome GZipped size Downloads NPM total downloads

A react hook and component to create popper (popover) that never leave the screen. Created elements will not disappear from the screen when scrolling and resizing.

Features

  • 🚀 Fast - Built with hooks and functional components only.
  • 🛠 Written in TypeScript - It'll fit right into your existing TypeScript project.
  • 👫 Cross-browser - Works out-of-the-box for most browsers, regardless of version.
  • 📲 Mobile-friendly - Supports mobile devices and touch screens.
  • 🌳 Tree-shakeable - Only include the parts you use.
  • 🗜 Lightweight - Around ~1.1kB.
  • 💨 No dependencies

Try it live:
Try it live

Preview

Install

  # with npm
  npm install --save react-stay-in-view
  # with yarn
  yarn add react-stay-in-view

Usage

useStayInView hook

import { useStayInView } from 'react-stay-in-view';

const StayInView = ({ className, children, anchorEl, placement }) => {
  const { ref } = useStayInView({ anchorEl, placement });

  return (
    <div ref={ref} className={className}>
      {children}
    </div>
  );
};

Props

Output: ref - paste this ref in your component

NameDescriptionTypeRequiredDefault Value
anchorElAn element relative to which the new position will be fixedHTMLElementnull
placementElement position relative to anchorElstringright-start
avoidAnchorOverlapPrevents anchorEl from overlapping when scrolling to screen borderbooleantrue

StayInView component

import { StayInView } from 'react-stay-in-view';

const App = () => {
  const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
  const [isVisible, setIsVisible] = useState<boolean>(false);

  const onClick = (e: React.MouseEvent<HTMLButtonElement>) => {
    setAnchorEl(e.currentTarget);
    setIsVisible((prev) => !prev);
  };

  return (
    <div>
      {isVisible && (
        <StayInView anchorEl={anchorEl}>
          <div>I stay on the screen</div>
        </StayInView>
      )}
      <button onClick={onClick}>Click me!</button>
    </div>
  );
};

Props

NameDescriptionTypeRequiredDefault Value
childrenA children elementReactNode
classNameContainer class name.stringnull
anchorElAn element relative to which the new position will be fixedHTMLElementnull
placementElement position relative to anchorElstringright-start
avoidAnchorOverlapPrevents anchorEl from overlapping when scrolling to screen borderbooleantrue

Contributions

Learn how to contribute

License

MIT © vdmrgv

Keywords

FAQs

Package last updated on 15 Feb 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc