4.0.1 • Published 6 months ago

@lazycuh/angular-anchored-floating-box v4.0.1

Weekly downloads
-
License
-
Repository
github
Last release
6 months ago

angular-anchored-floating-box npm.io

An easy, declarative way to render a floating box with arbitrary content anchored to an element.

Table of contents

Angular compatibility

This libraryAngular
4.x.x20.x.x
3.x.x19.x.x
2.x.x19.x.x
1.x.x16 - 18

Installation

  • npm
    npm i -S @lazycuh/angular-anchored-floating-box
  • pnpm
    pnpm i -S @lazycuh/angular-anchored-floating-box
  • yarn
    yarn add @lazycuh/angular-anchored-floating-box

Available APIs

These are the symbols that are available from this package

TriggerFloatingBoxForDirective

Inputs

NameTypeDescription
lcTriggerFloatingBoxForAnchoredFloatingBoxRequired input that accepts a template reference variable to a AnchoredFloatingBox component that specifies the content of the floating box, the floating box is anchored to the HTMLElement to which this input is applied.

AnchoredFloatingBox

Inputs

NameTypeDescription
classstringOptional CSS class attribute to add.
themelight | darkOptional theme. Default is light.

Outputs

NameTypeDescription
closed() => voidCalled after the floating box is closed.
beforeOpened() => voidCalled before the floating box is opened.
opened() => voidCalled after the floating box is opened.

Methods

  • AnchoredFloatingBox.setDefaultTheme(theme): Set the default theme that will be used for all future floating boxes. Use this method if you want to set the theme once instead of each time you render the floating box.

Example:

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: 'lc-test',
  // Import the directive and the component to use it
  imports: [TriggerFloatingBoxForDirective, AnchoredFloatingBox],
  template: `
    <button
      id="click-me"
      [lcTriggerFloatingBoxFor]="floatingBoxTemplateRefVar"
      type="button">
      Click me
    </button>

    <lc-anchored-floating-box
      #floatingBoxTemplateRefVar
      class="test-example"
      theme="dark">
      Hello Angular!!!</span>
    </ng-template>
  `
})
class MyComponent {}

Result

  • Light theme Example 1, light theme

  • Dark theme Example 2, dark theme

It will also reposition itself if it overflows the top or bottom edge of the viewport like so. Example 3, auto-repositioning when overflowing the bottom Example 4, auto-repositioning when overflowing the top

Real world example

Below is a screenshot of a personal app of mine at https://memecomposer.com that uses this component. Clicking on the brush icon button popped open an anchored floating box, then clicking "Text appearance" button inside of it opened another anchored floating box that is independent of the previous one and any others.

Example 5, real world usage example

3.0.3

6 months ago

3.0.2

8 months ago

3.0.1

8 months ago

3.0.0

8 months ago

2.3.0

8 months ago

2.2.0

8 months ago

4.0.1

6 months ago

4.0.0

6 months ago

2.1.0

8 months ago

2.0.1

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

2.0.0

2 years ago

1.0.0

2 years ago