Socket
Socket
Sign inDemoInstall

@ncstate/sat-popover

Package Overview
Dependencies
7
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ncstate/sat-popover

Popover component for Angular


Version published
Maintainers
1
Install size
402 kB
Created

Changelog

Source

1.0.0-beta.1 flopover-facsimile

Breaking Changes

The npm package name has changed from @sat/popover to @ncstate/sat-popover. All class names and directive selectors are the same.

npm uninstall @sat/popover
npm install --save @ncstate/sat-popover
import { SatPopoverModule } from '@ncstate/sat-popover';

Features

  • By default, the opening and closing animations of a popover are quick with a simple easing curve. You can now modify these animation curves using openTransition and closeTransition.
  • By default, when a popover is open and the user scrolls the container, the popover will reposition itself to stay attached to its anchor. You can now adjust this behavior with scrollStrategy.
  • RTL support. The popover will now position and animate itself in accordance with the document's body direction.

Fixes

  • Pressing <kbd>esc</kbd> while focused inside a popover will now properly close the popover. This was a regression introduced in the last release.
  • Changing the position properties of a popover will now apply even if the popover has been opened before.
  • Recreation of the popover waits until it is closed so that the popover isn't disposed while open.

Other

  • An error will be thrown if you try to call the open/close/toggle methods on a popover with no corresponding anchor.
  • An error will be thrown if you try to pass an invalid xPosition or yPosition
  • Refactor of the demo-app to better encapsulate each demo.
  • Updated import statement in README (thanks to @julianobrasil)
  • Added note to README about cdkScrollable

Readme

Source

Popover Component for Angular

StackBlitz Demo

Installation

sat-popover has a peer dependency on the Angular CDK to leverage its overlay API.

npm install --save @ncstate/sat-popover @angular/cdk

If you want the popover animations to work, you must include BrowserAnimationsModule in your app.

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
  ...
  imports: [ BrowserAnimationsModule ],
  ...
})
export class AppModule { }

If you prefer to not have animations, you can include NoopAnimationsModule.

import { NoopAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
  ...
  imports: [ NoopAnimationsModule ],
  ...
})
export class AppModule { }

Finally, import the SatPopoverModule to provide the necessary components and directives.

import { SatPopoverModule } from '@ncstate/sat-popover';

@NgModule({
  ...
  imports: [ SatPopoverModule ],
  ...
})
export class AppModule { }

Usage

Getting started

Wrap any component you want to display in a popover with an <sat-popover> component.

<sat-popover>
  <app-contact-overview [contact]="myContact"></app-contact-overview>
</sat-popover>

Next, hook the popover to an anchor element.

<button [satPopoverAnchorFor]="contactPopover" (click)="contactPopover.toggle()">
  See Contact Details
</button>

<sat-popover #contactPopover hasBackdrop>
  <app-contact-overview [contact]="myContact"></app-contact-overview>
</sat-popover>

Note: hasBackdrop is explained below

Positioning

By default, the popover will appear centered over the button. If you instead want the popover to appear below the anchor:

<sat-popover #contactPopover yPosition="below" [overlapAnchor]="false">
  <!-- ... -->
</sat-popover>

You can use the following to position the popover around the anchor:

InputTypeDefault
xPosition'before' | 'center' | 'after''center'
yPosition'above' | 'center' | 'below''center'
overlapAnchorbooleantrue

Note: When xPosition and yPosition are both 'center', overlapAnchor will have no effect.

Opening and closing

You are in full control of when the popover opens and closes. You can hook into any event or trigger that fits your application's needs.

SatPopover has the following methods,

  • open
  • close
  • toggle

SatPopoverAnchor has similar methods,

  • openPopover
  • closePopover
  • togglePopover

Backdrop

You can add a fullscreen backdrop that appears behind the popover when it is open. It prevents interaction with the rest of the application and will automatically close the popover when clicked. To add it to your popover, use hasBackdrop.

<sat-popover #myBlockingPopover hasBackdrop>
  <!-- ... -->
</sat-popover>

If used, the default backdrop will be transparent. You can add any custom backdrop class with backdropClass.

<sat-popover #myBlockingPopover hasBackdrop backdropClass="app-fancy-backdrop">
  <!-- ... -->
</sat-popover>

Note: if you plan on using mouseenter and mouseleave events to open and close your popover, keep in mind that a backdrop will block pointer events once it is open, immediately triggering a mouseleave event.

Scrolling

By default, when a popover is open and the user scrolls the container, the popover will reposition itself to stay attached to its anchor. You can adjust this behavior with scrollStrategy.

<sat-popover #importantPopover scrollStrategy="block">
  <!-- so important that the user must interact with it -->
</sat-popover>
StrategyDescription
'noop'Don't update position.
'block'Block page scrolling while open.
'reposition'Reposition the popover on scroll (default).

Note: if your popover fails to stay anchored with the reposition strategy, you may need to add the cdkScrollable directive to your scrolling container. This will ensure scroll events are dispatched to the popover's positioning service.

Animations

By default, the opening and closing animations of a popover are quick with a simple easing curve. You can modify these animation curves using openTransition and closeTransition.

<!-- open slowly but close quickly -->
<sat-popover #mySlowPopover
    openTransition="1000ms ease-out"
    closeTransition="100ms ease-in">
  <!-- ... -->
</sat-popover>

Styles

The <sat-popover> component only provides styles to affect its own transform origin. It is the responsibility of the elements you project inside the popover to styles themselves. This includes background color, box shadows, margin offsets, etc.

Keywords

FAQs

Last updated on 26 Oct 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc