-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement switch component and use it for the active status of …
…recurring orders
- Loading branch information
1 parent
5d21abd
commit d4125b1
Showing
11 changed files
with
138 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/app/shared/components/common/switch/switch.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<span class="custom-control custom-switch d-inline"> | ||
<input | ||
[formControl]="activeSwitch" | ||
type="checkbox" | ||
role="switch" | ||
class="custom-control-input" | ||
id="{{ id }}" | ||
[ngModel]="active" | ||
(ngModelChange)="switchActive(id, $event)" | ||
/> | ||
<label class="custom-control-label" for="{{ id }}">{{ label }}</label> | ||
</span> |
15 changes: 15 additions & 0 deletions
15
src/app/shared/components/common/switch/switch.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import 'variables'; | ||
|
||
.custom-control-input ~ .custom-control-label::before { | ||
background-color: #999; | ||
border-color: #999; | ||
} | ||
|
||
.custom-control-input:checked ~ .custom-control-label::before { | ||
background-color: $color-corporate; | ||
border-color: $color-corporate; | ||
} | ||
|
||
.custom-switch .custom-control-label::after { | ||
background-color: #fff; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/app/shared/components/common/switch/switch.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { SwitchComponent } from './switch.component'; | ||
|
||
describe('Switch Component', () => { | ||
let component: SwitchComponent; | ||
let fixture: ComponentFixture<SwitchComponent>; | ||
let element: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [SwitchComponent], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SwitchComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/app/shared/components/common/switch/switch.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { FormControl } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'ish-switch', | ||
templateUrl: './switch.component.html', | ||
styleUrls: ['./switch.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class SwitchComponent { | ||
@Input({ required: true }) id: string; | ||
@Input() active = false; | ||
@Input() label = ''; | ||
|
||
@Output() switchActiveStatus = new EventEmitter<{ id: string; active: boolean }>(); | ||
|
||
activeSwitch: FormControl = new FormControl(); | ||
|
||
switchActive(id: string, active: boolean) { | ||
this.switchActiveStatus.emit({ id, active }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters