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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tots/filter-box

v15.0.20

Published

A flexible and customizable filter box component for Angular applications.

Readme

@tots/filter-box

A flexible and customizable filter box component for Angular applications.

Features

  • Dynamic filter management
  • Material Design integration
  • Customizable button styles and colors
  • Support for multiple filter types
  • Preset filter values
  • Clear and apply filter actions
  • Responsive design

Installation

npm install @tots/filter-box

Usage

Basic Implementation

import { TotsFilterBoxComponent, TotsFilterBoxConfig } from '@tots/filter-box';

@Component({
  selector: 'app-my-component',
  template: `
    <tots-filter-box
      [config]="filterConfig"
      (apply)="onApplyFilters($event)">
    </tots-filter-box>
  `
})
export class MyComponent {
  filterConfig: TotsFilterBoxConfig = {
    filters: [
      {
        title: 'Status',
        type: 'select',
        options: [
          { value: '1', title: 'Active' },
          { value: '2', title: 'Inactive' }
        ]
      },
      {
        title: 'Price Range',
        type: 'range',
        value: { min: 0, max: 1000 }
      }
    ]
  };

  onApplyFilters(filters: TotsItemSelectedFilter[]) {
    console.log('Applied filters:', filters);
  }
}

Advanced Implementation

Here's a more comprehensive example showing various filter types and configurations:

import { Component, ViewChild } from '@angular/core';
import { TotsFilterBoxComponent, TotsFilterBoxConfig } from '@tots/filter-box';
import { StringFilterComponent } from '@tots/filter-box';
import { MultiUsersFilterComponent } from '@tots/filter-box';
import { MultiSelectFilterComponent } from '@tots/filter-box';
import { TotsDateRangeFilterComponent } from '@tots/date-range-filter-box';
import { BetweenNumberFilterComponent } from '@tots/filter-box';
import { MultiSelectObsFilterComponent } from '@tots/filter-box';
import { Observable, of } from 'rxjs';
import * as moment from 'moment';

@Component({
  selector: 'app-root',
  template: `
    <tots-filter-box
      #filterBox
      [config]="config"
      (apply)="onApplyFilters($event)">
    </tots-filter-box>
    
    <button (click)="applyDefaultFilters()">Apply Default Filters</button>
  `
})
export class AppComponent {
  @ViewChild('filterBox') filterBox!: TotsFilterBoxComponent;
  
  config?: TotsFilterBoxConfig;
  
  // Example of saved filters
  readonly SAVED_FILTERS = [
    { 
      title: 'Title',
      value: 'Saved Title'
    },
    {
      title: 'Status',
      value: [
        { id: '2', label: 'In Progress' },
        { id: '3', label: 'Completed' }
      ]
    },
    {
      title: 'Price',
      value: {
        min: 500,
        max: 2000
      }
    },
    {
      title: 'Customer',
      value: [
        { id: '2', label: 'Customer 2' },
        { id: '3', label: 'Customer 3' }
      ]
    },
    {
      title: 'Updated At',
      value: {
        min: moment('2024-01-01').startOf('day'),
        max: moment('2024-03-20').startOf('day')
      }
    }
  ];

  ngOnInit(): void {
    this.loadConfig();
  }

  onApplyFilters(filters: any) {
    console.log('Applied filters:', filters);
  }

  // Method to apply predefined filters
  applyDefaultFilters() {
    this.filterBox.applyFilters(this.SAVED_FILTERS);
  }

  loadConfig() {
    this.config = new TotsFilterBoxConfig();
    this.config.isOnlyIconButton = false;

    this.config.filters = [
      { title: 'Title', component: StringFilterComponent },
      { 
        title: 'Created By', 
        component: MultiUsersFilterComponent, 
        extra: {
          service: this.userService,
          searchFields: ['firstname', 'lastname'],
          identifierField: 'id',
          firstnameField: 'firstname',
          lastnameField: 'lastname',
          photoField: 'photo',
          textButton: 'Select user',
          prependIcon: 'person',
        } 
      },
      { 
        title: 'Status', 
        component: MultiSelectFilterComponent, 
        extra: {
          allowMultiple: true,
          options: [
            { id: '1', label: 'Pending' },
            { id: '2', label: 'In Progress' },
            { id: '3', label: 'Completed' },
          ]
        } 
      },
      { title: 'Updated At', component: TotsDateRangeFilterComponent },
      { title: 'Price', component: BetweenNumberFilterComponent },
      { 
        title: 'Customer', 
        component: MultiSelectObsFilterComponent, 
        extra: {
          allowMultiple: true,
          obs: this.searchAutocompleteTest.bind(this)
        } 
      },
    ];
  }

  searchAutocompleteTest(query?: string): Observable<Array<any>> {
    let customers = [
      { id: '1', label: 'Customer 1' },
      { id: '2', label: 'Customer 2' },
      { id: '3', label: 'Customer 3' },
      { id: '4', label: 'Customer 4' },
      { id: '5', label: 'Customer 5' },
      { id: '6', label: 'Customer 6' },
    ];

    return of(customers.filter(c => c.label.toLowerCase().includes(query!.toLowerCase())));
  }
}

Preset Filter Values

You can set default values for filters that will be automatically applied when the component initializes:

filterConfig: TotsFilterBoxConfig = {
  filters: [
    {
      title: 'Status',
      type: 'select',
      options: [
        { value: '1', title: 'Active' },
        { value: '2', title: 'Inactive' }
      ],
      value: '1' // This filter will be pre-selected with "Active"
    },
    {
      title: 'Price Range',
      type: 'range',
      value: { min: 100, max: 500 } // This range will be pre-set
    },
    {
      title: 'Date',
      type: 'date',
      value: new Date() // Today's date will be pre-selected
    }
  ]
};

You can also apply filters programmatically using the applyFilters method:

// In your component
@ViewChild(TotsFilterBoxComponent) filterBox!: TotsFilterBoxComponent;

// Later in your code
this.filterBox.applyFilters([
  { title: 'Status', value: '2' },
  { title: 'Price Range', value: { min: 200, max: 800 } }
]);

Available Filter Components

The library provides several built-in filter components:

  • StringFilterComponent: For text input filters
  • MultiUsersFilterComponent: For selecting multiple users with search
  • MultiSelectFilterComponent: For selecting multiple options from a dropdown
  • TotsDateRangeFilterComponent: For selecting date ranges
  • BetweenNumberFilterComponent: For selecting number ranges
  • MultiSelectObsFilterComponent: For selecting multiple options with observable data source

Configuration Options

The component accepts a TotsFilterBoxConfig object with the following properties:

interface TotsFilterBoxConfig {
  filters: TotsItemFilter[];
  buttonIcon?: string;
  matButtonDirective?: string;
  matButtonColor?: ThemePalette;
  textAddButton?: string;
  textApplyFilters?: string;
  textClearButton?: string;
  textButton?: string;
  menuButtonsColor?: ThemePalette;
  isOnlyIconButton?: boolean;
}

Events

  • apply: Emitted when filters are applied, providing the selected filter values
  • clear: Emitted when filters are cleared

Styling

The component uses Angular Material's theming system and can be customized using CSS variables:

:host {
  --filter-box-primary-color: #your-color;
  --filter-box-background: #your-background;
}

Dependencies

  • Angular Material
  • Angular Core
  • Moment.js (for date handling)

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.