npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@teedeez/tdz-anchored-floating-box

v2.1.3

Published

An Angular service that renders a template ref or a component anchored to some element.

Downloads

6

Readme

Installation

npm i -S @teedeez/tdz-anchored-floating-box

Available APIs

These are the symbols that are available from this package

/**
 * The module class for this package
 */
class AnchoredFloatingBoxModule {
}
class AnchoredFloatingBoxService {

    /**
     * Open a new floating box with a configuration object specified by `configuration`. This service
     * supports rendering `TemplateRef` as well as any `@Component()` class.
     *
     * @param configuration The configuration object for the anchored floating box
     * @returns A ref object to the created anchored floating box {@see AnchoredFloatingBoxRef}
     */
    open(configuration: AnchoredFloatingBoxConfiguration): AnchoredFloatingBoxRef;

    /**
     * Set the default theme that will be used for all floating boxes created in the future
     *
     * @param theme The new theme to be used as the default {@see Theme}
     */
    setDefaultTheme(theme: Theme): void;
}
/**
 * The configuration object for the current anchored floating box.
 * The type parameter `C` describes the type of the optional context
 * object passed to `TemplateRef<C>`.
 */
interface AnchoredFloatingBoxConfiguration<C = Record<string, unknown>> {

    /**
     * The content to show, it accepts `TemplateRef` as well as any `@Component()` class
     */
    content: TemplateRef<C> | Type<any>;

    /**
     * The element that the floating box will be anchored to
     */
    anchor: Element;

    /**
     * Optional class name to add to the anchored floating box's container
     */
    className?: string;

    /**
     * Optional context object that is referenced by the template ref
     */
    context?: C;

    /**
     * Optional theme for the floating box. Default is 'dark' {@see Theme}
     */
    theme?: Theme;

}
const enum Theme {
    LIGHT = "light",
    DARK = "dark"
}
/**
 * A wrapper class around the AnchoredFloatingBoxComponent
 */
class AnchoredFloatingBoxRef {

    /**
     * Close this anchored floating box only
     */
    close(): void;

    /**
     * @returns An RxJS observable that emits after this anchored floating box is closed
     */
    afterClosed(): Observable<void>;

    /**
     * @returns An RxJS observable that emits after this anchored floating is opened
     */
    afterOpened(): Observable<void>;

}

Example Usage

Code example

// Import the service into your class to start using it
import { AnchoredFloatingBoxService } from '@teedeez/tdz-anchored-floating-box'

@Component({
    selector: 'test-component',
    template: `
        <button
                #button
                type='button'
                (click)='onOpen(template, button)'>
                Click me!!!
        </button>
        <ng-template
                #template
                let-name <-- The context['$implicit'] from below
                let-greeting='greeting'> <-- The context.greeting from below
            {{greeting}} {{name}}
        </ng-template>
    `
})
export class TestComponent {

    constructor(private readonly _anchoredFloatingBoxService: AnchoredFloatingBoxService) {

    }

    onOpen(templateRef: TemplateRef<any>, anchor: HTMLButtonElement) {
        this._anchoredFloatingBoxService.open({
            content: templateRef,
            anchor,
            className: 'optional-class-name',
            context: {
                greeting: 'Hello',
                '$implicit': 'Angular!!!'
            }
        });
    }

}

Result

Example 1

It will also reposition itself if it overflows the top or bottom edge of the viewport like so Example 2

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 3