Skip to content

Commit

Permalink
feat(panel-select): add style, dropdown prop
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxin committed Sep 19, 2018
1 parent 72e93e4 commit b1149c3
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 42 deletions.
49 changes: 30 additions & 19 deletions mat-panel-select/mat-panel-select.component.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
<div
class="ngx-mat-panel-select__container"
[class.ngx-mat-panel-select__grid-container]="type === 'grid'"
[class.ngx-mat-panel-select__list-container]="type === 'list'"
>
<ng-container *ngIf="!dropdown">
<ng-container *ngTemplateOutlet="tpl"></ng-container>
</ng-container>

<mat-menu class="ngx-mat-panel-select__menu" #panelSelect>
<ng-container *ngTemplateOutlet="tpl"></ng-container>
</mat-menu>

<ng-template #tpl>
<div
class="ngx-mat-panel-select__list"
*ngFor="let list of data"
class="ngx-mat-panel-select__container {{containerClass}}"
[class.ngx-mat-panel-select__grid-container]="type === 'grid'"
[class.ngx-mat-panel-select__list-container]="type === 'list'"
[class.ngx-mat-panel-select__dropdown-container]="dropdown === false"
>
<div class="ngx-mat-panel-select__list-title">
{{list.title}}
</div>
<div
class="ngx-mat-panel-select__list"
*ngFor="let list of data"
>
<div class="ngx-mat-panel-select__list-title">
{{list.title}}
</div>

<div class="ngx-mat-panel-select__item-container">
<div
class="ngx-mat-panel-select__item"
*ngFor="let item of list.children"
>
<button mat-button (click)="itemClick.emit(item)">
<div class="ngx-mat-panel-select__item-text">{{item.text}}</div>
</button>
<div class="ngx-mat-panel-select__item-container">
<div
class="ngx-mat-panel-select__item"
*ngFor="let item of list.children"
>
<button mat-button (click)="itemClick.emit(item)">
<div class="ngx-mat-panel-select__item-text">{{item.text}}</div>
</button>
</div>
</div>
</div>
</div>
</div>
</ng-template>

42 changes: 26 additions & 16 deletions mat-panel-select/mat-panel-select.component.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@mixin ngx-mat-panel-select-theme() {
.ngx-mat-panel-select {
&__menu[class] {
max-width: none;
}

&__container {
overflow: hidden;
width: 500px;
Expand All @@ -15,6 +19,10 @@
@include ngx-mat-panel-select-grid-theme();
}

&__dropdown-container {
width: auto;
}

&__list {
margin-top: 24px;

Expand All @@ -35,22 +43,6 @@
}
}

@mixin ngx-mat-panel-select-list-theme() {
.ngx-mat-panel-select {
&__item {
&-container {
display: flex;
flex-wrap: wrap;
align-items: center;
}

.mat-button {
min-width: auto;
}
}
}
}

@mixin ngx-mat-panel-select-grid-theme() {
.ngx-mat-panel-select {
&__item {
Expand All @@ -70,5 +62,23 @@
}
}

@mixin ngx-mat-panel-select-list-theme() {
.ngx-mat-panel-select {
&__item {
margin: 4px;

&-container {
display: flex;
flex-wrap: wrap;
align-items: center;
}

.mat-button {
min-width: auto;
}
}
}
}

@include ngx-mat-panel-select-theme();

24 changes: 18 additions & 6 deletions mat-panel-select/mat-panel-select.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import {
Component,
OnInit,
Input,
Output,
EventEmitter,
ViewChild,
ViewEncapsulation,
} from '@angular/core';
import {
MatMenu,
} from '@angular/material';
import {
IMatPanelSelectData,
IMatPanelSelectType,
Expand All @@ -13,21 +17,29 @@ import {
@Component({
selector: 'ngx-mat-panel-select',
templateUrl: './mat-panel-select.component.html',
styleUrls: ['./mat-panel-select.component.scss']
styleUrls: ['./mat-panel-select.component.scss'],
// set encapsulation to None
encapsulation: ViewEncapsulation.None,
})
export class MatPanelSelectComponent implements OnInit {
export class MatPanelSelectComponent {
@Input()
data: IMatPanelSelectData[] = [];
@Input()
type: IMatPanelSelectType = 'list';
@Input()
dropdown = true;
@Input('class')
containerClass = '';

@Output()
itemClick: EventEmitter<any> = new EventEmitter<any>();

@ViewChild(MatMenu)
private _menu: MatMenu;

constructor() { }

ngOnInit() {
console.log(this.data);
get menu() {
return this._menu;
}

}
4 changes: 3 additions & 1 deletion mat-panel-select/mat-panel-select.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatButtonModule } from '@angular/material';

import { MatButtonModule, MatMenuModule } from '@angular/material';

import { MatPanelSelectComponent } from './mat-panel-select.component';

@NgModule({
imports: [
CommonModule,
MatButtonModule,
MatMenuModule,
],
declarations: [
MatPanelSelectComponent,
Expand Down

0 comments on commit b1149c3

Please sign in to comment.