1.0.1 • Published 25 days ago

@ngx-popovers/core v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
25 days ago

core

This library was generated with Nx and floating-ui for Angular applications.

To see a demo, click on the link provided.

FloatingService

Before use, ensure this service is added to the providers list.

You can import the FloatingService from '@ngx-popovers/core'.

Example usage:

import { FloatingService } from '@ngx-popovers/core';

@Component({
  standalone: true,
  providers: [FloatingService],
  template: '',
  styles: ''
})
export class AppComponent {
}
MethodDescriptionType
computePositionThe computePosition method is a proxy for computePositionfrom floating-uiComputePositionReturn
autoUpdateThe autoUpdate method is a proxy for autoUpdate from floating-uicleanup function
floatingService = inject(FloatingService);

this.floatingService.computePosition(trigger, floating);

You can also import all types and methods from floating-ui from this package:

import {
  Derivable,
  FlipOptions,
  OffsetOptions,
  Placement,
  ShiftOptions
} from '@ngx-popovers/core';

portal

To see a demo, click on the link provided.

Usage

The <ngx-portal/> component displays content on the body.

You can also display portal content within an element of your choice:

<div #portalWillBeInsideMe>
  <p>Portal content will be rendered after this tag</p>
  <!-- Here -->
</div>

<ngx-portal [bindTo]="portalWillBeInsideMe">
    <p>It will be displayed as the last child of the div</p>
</ngx-portal>

This component is essential for displaying tooltips correctly without overlapping with other elements on the page.

ClickOutside directive

The click outside directive manages clicks inside and outside HTMLElements. This directive is used by the ngx-floating component.

To see a demo, click on the link provided.

Usage

import { ClickOutsideDirective } from '@ngx-popovers/core';

@Component({
  selector: 'ngx-click-outside-example',
  standalone: true,
  imports: [ClickOutsideDirective],
  template: `
    <div
      ngxClickOutside
      (inside)="onInsideClicked($event)"
      (outside)="onOutsideClicked($event)"
    ></div>
  `
})
export class ClickOutsideExample {
  onInsideClicked(el: EventTarget) {
    console.log('Inside click!', el);
  }

  onOutsideClicked(el: EventTarget) {
    console.log('Outside click!', el);
  }
}

floating

The Floating component implements the floating-ui library for Angular

To see a demo, click on the link provided.

Usage

For more information about the properties, refer to the official documentation for floating-ui.

<div #trigger>
    <p>Trigger content</p>
</div>

<ngx-floating
  [trigger]="trigger"
  [placement]="'bottom'"
  [middleware]="middleware"
>
  <div class="floating">
    <p>Floating content</p>
  </div>
</ngx-floating>

API

Inputs

MethodDescriptionTypeDefault
placementcontrols the position of the floating relative to the triggerPlacementbottom
middlewarelist of middleware from floating-uiMiddlewareListoffset(4), flip()
autoUpdateupdates floating element automaticallybooleantrue
bindTourenders floating element as last child of bindTostring | HTMLElement.body

Outputs

MethodDescriptionType
clickedOutsideemits when user clicks outside the floating elementElement
clickedInsideemits when user clicks inside the floating elementElement
computePositionReturnemits every time when the floating component calls computePositionComputePositionReturn

Configuration

There is a configuration token NGX_FLOATING_CONFIG. Please use the NgxFloatingConfig class to change the default floating properties.

export const FloatingConfigProvider: Provider = {
  provide: NGX_FLOATING_CONFIG,
  useValue: new NgxFloatingConfig({
    placement: 'top-end',
    arrow: true
  })
};

Arrow

The arrow component adds an arrow to the floating component.

<div #trigger>Trigger</div>

<ngx-floating
  [trigger]="trigger"
>
  <p>Floating content</p>
  
  <ngx-arrow padding="10" />
</ngx-floating>

To see a demo, click on the link provided.

You can provide your own component for arrow visualization:

@Component({
  standalone: true,
  template: `
    <div
      style="
        width: 5px;
        height: 5px;
        transform: rotate(45deg);
        background: indianred;
      "
    ></div>
  `
})
export class CustomArrow extends FloatingArrowBase {
}

export const ArrowProvider: Provider = {
  provide: NGX_ARROW_COMPONENT,
  useValue: CustomArrow
};

Any module:

@Component({
  standalone: true,
  selector: 'app',
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss',
  providers: [ArrowProvider]
})

Sources

This package is a major dependency for other npm packages:

1.0.1

25 days ago

1.0.0

1 month ago

0.1.5

3 months ago

0.1.4

3 months ago

0.1.3

3 months ago

0.1.2

3 months ago

0.1.1

3 months ago

0.1.0

3 months ago

0.0.23

4 months ago

0.0.22

4 months ago

0.0.21

4 months ago

0.0.20

4 months ago

0.0.19

4 months ago

0.0.18

4 months ago

0.0.17

4 months ago

0.0.15

4 months ago

0.0.16

4 months ago

0.0.14

4 months ago

0.0.13

4 months ago

0.0.10

4 months ago

0.0.11

4 months ago

0.0.12

4 months ago

0.0.9

4 months ago

0.0.8

5 months ago

0.0.7

5 months ago

0.0.6

5 months ago

0.0.5

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago