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

@glasp/multi-search

v0.0.9

Published

This library allows to show connected suggestions on multiple Angular Material Input Fields (levaraging from Angular's autocomplete library).

Downloads

1

Readme

MultiSearch

This library allows to show connected suggestions on multiple Angular Material Input Fields (levaraging from Angular's autocomplete library).

multi-search

Installation & Module Configuration

Run npm i @glasp/multi-search to install the library. Please add the SearchModule as import in your app's module file.

import {NgModule} from "@angular/core";
import {SearchModule} from "./search.module";

@NgModule({
  imports: [
    SearchModule
  ]
})

Search Entity for input fields

Define an entity with the properties which connect the input fields, e.g. actors and which characters they have played.

export class Role {
  character!: string;
  actor!: string;

  constructor(character: string, actor: string) {
    this.character = character;
    this.actor = actor;
  }
}

IController Interface

In the Search Module, the SearchController is coordinating the suggestions of the input fields and processing the ingoing & outgoing module commmunication. Please implement a custom controller to communicate with the SearchController.

@Injectable()
export class RoleController implements IController<Role> {
  roles = [
    new Role("Hermione Granger", "Emma Watson"),
    ...
  ]

  provideSearchResults(params?: Role): Observable<Role[]> {
    return of(this._filter(params));
  }

  setCurrentValidation(status: boolean): void {
    console.log(status);
  }

  suggestionTrigger(input: Role): boolean {
    return input.character.length > 0 || input.actor.length > 0;
  }

  private _filter(value?: Role): Role[] {
    ...
  }
}

Three methods can be implemented:

  1. provideSearchResults(params?: Role): Observable<Role[]> is providing the values the user has inserted into the input fields and should return an array of suggestions (here of Search Entity type Role)
  2. setCurrentValidation(status: boolean): void provides a boolean value after each user input which indicates whether all user input fields are valid (meaning equalling one suggestion)
  3. suggestionTrigger(input: Role): boolean defines when the suggestions should be shown and when provideSearchResults(params?: Role): Observable<Role[]> is calles

Providing the IController Implementation

The IController Implementation needs to be provided with the InjectionToken DATA_PROVIDER in your app's module file.

@NgModule({
  ...,
  providers: [{
    provide: DATA_PROVIDER,
    useClass: RoleController
  }]
})

Displaying the Form Suggestions

Each MultiSearch component requires at least two Material form fields. And as below, each form field needs to have an input field and a search element below which holds the suggestions.

<mat-form-field>
  <mat-label>Character</mat-label>
  <input aria-label="character"
         formControlName="characterInput"
         [search]="character">
  <search #character="search">
    <ng-template let-role>{{role.character}}</ng-template>
  </search>
</mat-form-field>

The following attributes for the input element are necessary for the MultiSearch component to work:

  1. The aria-label is necessary for the mapping between the suggestions and the input field. The value should be the same wording as the corresponding property in the SearchEntity.
  2. The input element needs to be a FormControl.
  3. The [search] attribute requires the value of the template reference variable of the search element, here that's "character".

The value of the template reference variable of the search element always is "search". For the individual suggestions, the property of the Search Entity can be referenced through an ng-template.

Further information

That's it! For more information you can find the sample application at https://github.com/glasp-api/angular-components.