File

src/app/modules/filters/filters-popover/filters-popover.component.ts

Description

Popover box for filter settings

Metadata

Index

Properties
Methods
Inputs
Outputs
Accessors

Inputs

drawerExpanded
Type : boolean

Keeps track of whether or not the containing drawer is expanded Because the styles need to change accordingly

filters
Type : Record<string | | []>

Allows the filters to be set from outside the component, and still render / function normally

providerFilters
Type : string[]

List of providers in the data

spatialSearchFilters
Type : SpatialSearchFilterItem[]
Default value : []

List of spatial searches

technologyFilters
Type : string[]

List of technologies in the data

Outputs

filtersChange
Type : EventEmitter

Emits the current filters

spatialSearchRemoved
Type : EventEmitter

Emits when a spatial search is removed/deleted

spatialSearchSelected
Type : EventEmitter

Emits when a spatial search is selected/deselected

Methods

applyFilters
applyFilters(filters: Record)

Emits the current filters, and hides the popover box

Parameters :
Name Type Optional Description
filters Record<string | > No

The object containing all the currently set filters

Returns : void
removeBox
removeBox()
Decorators :
@Dispatch()

Hides the filters popover box

toggleFilterVisible
toggleFilterVisible()
Decorators :
@Dispatch()

Toggles filter visible

Properties

filtersVisible
Default value : false

Keeps track of whether or not the filters popover box is visible or not

Accessors

popupHeight
getpopupHeight()

Calculate the popup height based on length of spatial search list

Returns : string
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { Dispatch } from '@ngxs-labs/dispatch-decorator';

import { SpatialSearchFilterItem } from '../../../core/store/spatial-search-filter/spatial-search-filter.state';
import { SetExecuteSearchOnGenerate } from '../../../core/store/spatial-search-ui/spatial-search-ui.actions';

/**
 * Popover box for filter settings
 */
@Component({
  selector: 'ccf-filters-popover',
  templateUrl: './filters-popover.component.html',
  styleUrls: ['./filters-popover.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FiltersPopoverComponent {
  /**
   * Allows the filters to be set from outside the component, and still render / function normally
   */
  @Input() filters!: Record<string, unknown | unknown[]>;

  /**
   * Keeps track of whether or not the containing drawer is expanded
   * Because the styles need to change accordingly
   */
  @Input() drawerExpanded!: boolean;

  /**
   * List of technologies in the data
   */
  @Input() technologyFilters!: string[];

  /**
   * List of providers in the data
   */
  @Input() providerFilters!: string[];

  /**
   * List of spatial searches
   */
  @Input() spatialSearchFilters: SpatialSearchFilterItem[] = [];

  /**
   * Emits the current filters
   */
  @Output() readonly filtersChange = new EventEmitter<Record<string, unknown>>();

  /**
   * Emits when a spatial search is selected/deselected
   */
  @Output() readonly spatialSearchSelected = new EventEmitter<SpatialSearchFilterItem[]>();

  /**
   * Emits when a spatial search is removed/deleted
   */
  @Output() readonly spatialSearchRemoved = new EventEmitter<string>();

  /**
   * Keeps track of whether or not the filters popover box is visible or not
   */
  filtersVisible = false;

  /**
   * Calculate the popup height based on length of spatial search list
   */
  get popupHeight(): string {
    if (!this.filtersVisible) {
      return '0rem';
    } else {
      return `${this.spatialSearchFilters.length > 0 ? 43 + this.spatialSearchFilters.length * 3 : 40}rem`;
    }
  }

  /**
   * Toggles filter visible
   */
  @Dispatch()
  toggleFilterVisible(): SetExecuteSearchOnGenerate {
    this.filtersVisible = !this.filtersVisible;
    return new SetExecuteSearchOnGenerate(false);
  }

  /**
   * Hides the filters popover box
   */
  @Dispatch()
  removeBox(): SetExecuteSearchOnGenerate {
    this.filtersVisible = false;
    return new SetExecuteSearchOnGenerate(true);
  }

  /**
   * Emits the current filters, and hides the popover box
   *
   * @param filters The object containing all the currently set filters
   */
  applyFilters(filters: Record<string, unknown>): void {
    this.filters = filters;
    this.filtersChange.emit(filters);
    this.removeBox();
  }
}
<div class="filters-popover" [class.expanded]="drawerExpanded">
  <button (click)="toggleFilterVisible()" class="show-hide" [class.open]="filtersVisible">
    <div *ngIf="filtersVisible; else notShow">
      <mat-icon class="icon">close</mat-icon>
    </div>
    <ng-template #notShow>
      <mat-icon svgIcon="filter" class="icon funnel"></mat-icon>
    </ng-template>
  </button>
  <div
    class="popup-container"
    [class.visible]="filtersVisible"
    [class.hidden]="!filtersVisible"
    [style.height]="popupHeight"
  >
    <ccf-filters-content
      class="popup-body"
      [technologyFilters]="technologyFilters"
      [providerFilters]="providerFilters"
      [spatialSearchFilters]="spatialSearchFilters"
      [hidden]="!filtersVisible"
      [filters]="filters"
      (applyFilters)="applyFilters($event)"
      (spatialSearchSelected)="spatialSearchSelected.emit($event)"
      (spatialSearchRemoved)="spatialSearchRemoved.emit($event)"
    >
    </ccf-filters-content>
  </div>
</div>

./filters-popover.component.scss

.filters-popover {
  position: inherit;

  &.expanded {
    position: relative;

    .popup-container {
      right: inherit;
    }

    .popup-body {
      padding-left: 4em !important;
    }
  }
}

.popup-container {
  position: absolute;
  z-index: 5;
  top: 1.2rem;
  left: 1.48rem;
  box-shadow: 0.2rem 0.2rem 1rem 0rem #00000058;

  &.visible {
    border-width: 1px;
    padding: 2rem;
    width: 47.5rem;
    height: 40rem;
    transition: all 0.2s ease-in-out 0s;

    .popup-body {
      opacity: 1;
      transition: opacity 0.2s ease-in-out 0.3s;
    }
  }

  &.hidden {
    border-width: 0;
    padding: 0;
    width: 0;
    height: 0 !important;
    transition: all 0.2s ease-in-out 0.3s;

    .popup-body {
      opacity: 0;
      transition: opacity 0.2s ease-in-out 0s;
      pointer-events: none;
    }
  }
}

.show-hide {
  background: none;
  border: none;
  z-index: 10;
  position: relative;
  cursor: pointer;
  outline: none;
  padding: 0.5rem;
  border-radius: 0.25rem;
  transition: 0.6s;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""