Skip to content

Commit 6a679bc

Browse files
committed
feat(lib): added mat algolia toggle component
1 parent 9c944d0 commit 6a679bc

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<mat-slide-toggle (change)="onChange($event)"
2+
*ngIf="state?.value"
3+
[checked]="state?.value?.isRefined">
4+
{{ label || state?.value?.name}}
5+
<span *ngIf="!state?.value?.isRefined">({{state?.value?.count}})</span>
6+
</mat-slide-toggle>

projects/angular-material-extensions/algolia/src/lib/components/mat-algolia-toggle/mat-algolia-toggle.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { MatAlgoliaToggleComponent } from './mat-algolia-toggle.component';
4+
5+
describe('MatAlgoliaToggleComponent', () => {
6+
let component: MatAlgoliaToggleComponent;
7+
let fixture: ComponentFixture<MatAlgoliaToggleComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [MatAlgoliaToggleComponent]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(MatAlgoliaToggleComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Component, forwardRef, Inject, Input, OnInit } from '@angular/core';
2+
import { BaseWidget, NgAisInstantSearch } from 'angular-instantsearch';
3+
import { connectToggleRefinement } from 'instantsearch.js/es/connectors';
4+
import { ThemePalette } from '@angular/material/core';
5+
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
6+
7+
@Component({
8+
selector: 'mat-algolia-toggle',
9+
templateUrl: './mat-algolia-toggle.component.html',
10+
styleUrls: ['./mat-algolia-toggle.component.scss']
11+
})
12+
export class MatAlgoliaToggleComponent extends BaseWidget implements OnInit {
13+
14+
@Input()
15+
attribute: string;
16+
17+
@Input()
18+
label: string;
19+
20+
@Input()
21+
color: ThemePalette;
22+
23+
public state: {
24+
value: object;
25+
refine: Function;
26+
createURL: Function;
27+
widgetParams: object;
28+
};
29+
30+
constructor(
31+
@Inject(forwardRef(() => NgAisInstantSearch))
32+
public instantSearchParent: NgAisInstantSearch
33+
) {
34+
super('MatAlgoliaToggleComponent');
35+
}
36+
37+
ngOnInit() {
38+
this.createWidget(connectToggleRefinement, {
39+
// instance options
40+
attribute: this.attribute
41+
});
42+
super.ngOnInit();
43+
}
44+
45+
onChange($event: MatSlideToggleChange) {
46+
console.log('onChange', $event);
47+
this.state.refine(this.state.value);
48+
// this.state.refine($event.checked);
49+
}
50+
}

0 commit comments

Comments
 (0)