Przeglądaj źródła

Custom selector component

master
kj1352 5 lat temu
rodzic
commit
b3b4d4216f
8 zmienionych plików z 140 dodań i 1 usunięć
  1. +3
    -1
      src/app/app.module.ts
  2. +15
    -0
      src/app/custom-selector/custom-selector.component.html
  3. +54
    -0
      src/app/custom-selector/custom-selector.component.scss
  4. +25
    -0
      src/app/custom-selector/custom-selector.component.spec.ts
  5. +28
    -0
      src/app/custom-selector/custom-selector.component.ts
  6. +2
    -0
      src/app/dashboard/dashboard.component.html
  7. +11
    -0
      src/app/dashboard/dashboard.component.ts
  8. +2
    -0
      src/styles.scss

+ 3
- 1
src/app/app.module.ts Wyświetl plik

@@ -10,6 +10,7 @@ import { OrdersComponent } from './orders/orders.component';
import { MenuItemsComponent } from './menu-items/menu-items.component';
import { OffersComponent } from './offers/offers.component';
import { SchedulesComponent } from './schedules/schedules.component';
import { CustomSelectorComponent } from './custom-selector/custom-selector.component';

@NgModule({
declarations: [
@@ -20,7 +21,8 @@ import { SchedulesComponent } from './schedules/schedules.component';
OrdersComponent,
MenuItemsComponent,
OffersComponent,
SchedulesComponent
SchedulesComponent,
CustomSelectorComponent
],
imports: [
BrowserModule,


+ 15
- 0
src/app/custom-selector/custom-selector.component.html Wyświetl plik

@@ -0,0 +1,15 @@
<div class="selector" [ngStyle]="{'width.px' : 200 }">
<div class="container">
<div class="selected-value">
{{ header }}: <span *ngIf="selectedOption"> {{ selectedOption.name }} </span>
</div>
<button (click)="showDropdown = !showDropdown">
<i class="icon" [ngClass]="{'ion-md-arrow-dropdown': !showDropdown, 'ion-md-arrow-dropup': showDropdown}"></i>
</button>
</div>
<ul *ngIf="showDropdown">
<li *ngFor="let option of options" (click)="selectedOption = option; showDropdown = false">
{{ option.name }}
</li>
</ul>
</div>

+ 54
- 0
src/app/custom-selector/custom-selector.component.scss Wyświetl plik

@@ -0,0 +1,54 @@
.selector {
.container {
display: flex;
width: 100%;
border-radius: 20px;
background-color: white;
color: var(--brand-blue);
align-items: center;
justify-content: space-between;

.selected-value {
font-weight: 500;
margin-left: 20px;
font-size: 14px;

span {
margin-left: 5px;
}
}

button {
border-radius: 50%;
width: 30px;
height: 30px;
color: var(--brand-blue);
font-size: 20px;
border: 1px solid var(--brand-blue);
background-color: white;
}
}

ul {
list-style: none;
background-color: white;
width: 80%;
margin: 0 auto;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
overflow: hidden;
}

li {
padding: 10px;
font-size: 14px;
color: var(--brand-blue);
cursor: pointer;
transition: background-color 0.3s, color 0.3s;

&:hover {
background-color: var(--brand-blue);
color: white;
}
}
}

+ 25
- 0
src/app/custom-selector/custom-selector.component.spec.ts Wyświetl plik

@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { CustomSelectorComponent } from './custom-selector.component';

describe('CustomSelectorComponent', () => {
let component: CustomSelectorComponent;
let fixture: ComponentFixture<CustomSelectorComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CustomSelectorComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CustomSelectorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});

+ 28
- 0
src/app/custom-selector/custom-selector.component.ts Wyświetl plik

@@ -0,0 +1,28 @@
import { Component, OnInit, Input } from '@angular/core';

@Component({
selector: 'app-custom-selector',
templateUrl: './custom-selector.component.html',
styleUrls: ['./custom-selector.component.scss']
})
export class CustomSelectorComponent implements OnInit {
@Input() width: number;
@Input() options: Array<{
name: string,
id: string
}>;
@Input() header: string;
@Input() defaultOptionId: string;
selectedOption: {
name: string,
id: string
};
showDropdown: boolean = false;

constructor() { }

ngOnInit() {
this.selectedOption = this.options.find(option => option.id === this.defaultOptionId);
}

}

+ 2
- 0
src/app/dashboard/dashboard.component.html Wyświetl plik

@@ -2,6 +2,8 @@
<section class="order-stats">
<div class="widget-heading-holder">
<header> Dashboard </header>
<app-custom-selector header="Date" [options]="filterOptions" width="200"
[defaultOptionId]="filterOptions[1].id"></app-custom-selector>
</div>

<ul>


+ 11
- 0
src/app/dashboard/dashboard.component.ts Wyświetl plik

@@ -6,10 +6,21 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
filterOptions: Array<{
name: string,
id: string
}>

constructor() { }

ngOnInit() {
this.filterOptions = [{
name: 'Yesterday',
id: 'yesterday'
}, {
name: 'Today',
id: 'today'
}]
}

}

+ 2
- 0
src/styles.scss Wyświetl plik

@@ -42,6 +42,8 @@ button {
.widget-heading-holder {
width: 90%;
margin: 30px auto 0;
display: flex;
justify-content: space-between;

header {
font-size: 20px;


Ładowanie…
Anuluj
Zapisz