From b3b4d4216f3ac1d890ec8fae9d297ad4b281f878 Mon Sep 17 00:00:00 2001 From: kj1352 Date: Fri, 22 Nov 2019 19:17:48 +0530 Subject: [PATCH] Custom selector component --- src/app/app.module.ts | 4 +- .../custom-selector.component.html | 15 ++++++ .../custom-selector.component.scss | 54 +++++++++++++++++++ .../custom-selector.component.spec.ts | 25 +++++++++ .../custom-selector.component.ts | 28 ++++++++++ src/app/dashboard/dashboard.component.html | 2 + src/app/dashboard/dashboard.component.ts | 11 ++++ src/styles.scss | 2 + 8 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 src/app/custom-selector/custom-selector.component.html create mode 100644 src/app/custom-selector/custom-selector.component.scss create mode 100644 src/app/custom-selector/custom-selector.component.spec.ts create mode 100644 src/app/custom-selector/custom-selector.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index dab925f..668c692 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -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, diff --git a/src/app/custom-selector/custom-selector.component.html b/src/app/custom-selector/custom-selector.component.html new file mode 100644 index 0000000..379fd54 --- /dev/null +++ b/src/app/custom-selector/custom-selector.component.html @@ -0,0 +1,15 @@ +
+
+
+ {{ header }}: {{ selectedOption.name }} +
+ +
+ +
diff --git a/src/app/custom-selector/custom-selector.component.scss b/src/app/custom-selector/custom-selector.component.scss new file mode 100644 index 0000000..803a7d5 --- /dev/null +++ b/src/app/custom-selector/custom-selector.component.scss @@ -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; + } + } +} diff --git a/src/app/custom-selector/custom-selector.component.spec.ts b/src/app/custom-selector/custom-selector.component.spec.ts new file mode 100644 index 0000000..c2af372 --- /dev/null +++ b/src/app/custom-selector/custom-selector.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CustomSelectorComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CustomSelectorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/custom-selector/custom-selector.component.ts b/src/app/custom-selector/custom-selector.component.ts new file mode 100644 index 0000000..91548dc --- /dev/null +++ b/src/app/custom-selector/custom-selector.component.ts @@ -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); + } + +} diff --git a/src/app/dashboard/dashboard.component.html b/src/app/dashboard/dashboard.component.html index 528cb31..fa07226 100644 --- a/src/app/dashboard/dashboard.component.html +++ b/src/app/dashboard/dashboard.component.html @@ -2,6 +2,8 @@
Dashboard
+
    diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts index f104d63..75a1a91 100644 --- a/src/app/dashboard/dashboard.component.ts +++ b/src/app/dashboard/dashboard.component.ts @@ -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' + }] } } diff --git a/src/styles.scss b/src/styles.scss index 47a57cb..8f80343 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -42,6 +42,8 @@ button { .widget-heading-holder { width: 90%; margin: 30px auto 0; + display: flex; + justify-content: space-between; header { font-size: 20px;