-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/US-CBP/ngx-cbp-theme into…
… upstream_master # Conflicts: # package-lock.json
- Loading branch information
Showing
12 changed files
with
216 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { CBPToggleSwitchComponent } from './cbp-toggle-switch/cbp-toggle-switch.component'; | ||
import {FormsModule} from '@angular/forms'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, FormsModule | ||
], | ||
exports: [CBPToggleSwitchComponent], | ||
declarations: [CBPToggleSwitchComponent] | ||
}) | ||
export class CBPButtonsModule { } |
4 changes: 4 additions & 0 deletions
4
src/app/buttons/cbp-toggle-switch/cbp-toggle-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,4 @@ | ||
<span class="switch"> | ||
<input type="checkbox" [(ngModel)]="isOn" (ngModelChange)="valueChange($event)" [attr.required]="required" [attr.id]="toggleSwitchId" [attr.disabled]="disabled"> | ||
<label [attr.for]="toggleSwitchId" [attr.data-on]="onLabel" [attr.data-off]="offLabel">{{ label }}</label> | ||
</span> |
94 changes: 94 additions & 0 deletions
94
src/app/buttons/cbp-toggle-switch/cbp-toggle-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,94 @@ | ||
@import '../../variables'; | ||
|
||
// copied from https://raw.githubusercontent.com/US-CBP/cbp-theme/master/app/styles/custom/_forms.scss | ||
.switch { | ||
padding-left: 64px; | ||
overflow: hidden; | ||
position: relative; | ||
|
||
> input { | ||
appearance: none; | ||
position: absolute; | ||
width: inherit; | ||
height: inherit; | ||
opacity: 0; | ||
left: 0; | ||
top: 0; | ||
} | ||
|
||
> label { | ||
display: inline-block; | ||
position: relative; | ||
cursor: pointer; | ||
font-weight: 400; | ||
margin-bottom: 0; | ||
} | ||
|
||
> label:before { | ||
cursor: pointer; | ||
display: inline-block; | ||
border-radius: 25px; | ||
height: 25px; | ||
width: 58px; | ||
color: #fff; | ||
font-size: 10px; | ||
font-weight: 600; | ||
line-height: 25px; | ||
text-align: center; | ||
background: #aaa; | ||
transition: 0.2s background-color ease-out; | ||
margin-left: -64px; | ||
margin-right: 6px; | ||
} | ||
|
||
> input:checked + label:before { | ||
background: $brand-info; | ||
} | ||
|
||
> input:disabled + label:before { | ||
cursor: not-allowed; | ||
background: mix(#aaa, #fff, 30%); | ||
} | ||
> input:checked:disabled + label:before { | ||
background: mix($brand-primary, #fff, 30%); | ||
} | ||
|
||
> label:before { | ||
content: attr(data-off); | ||
padding-left: 20px; | ||
padding-right: 0; | ||
} | ||
|
||
> input:checked + label:before { | ||
content: attr(data-on); | ||
padding-right: 20px; | ||
padding-left: 0; | ||
} | ||
|
||
> label:after { | ||
cursor: pointer; | ||
content: ""; | ||
margin: 1px; | ||
border-radius: 19px; | ||
width: 19px; | ||
height: 19px; | ||
display: block; | ||
background: #fff; | ||
position: absolute; | ||
top: 2px; | ||
left: -62px; | ||
z-index: 2; | ||
transition: 0.2s left ease-out; | ||
} | ||
|
||
> input:checked + label:after { | ||
left: -29px; | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
*, :after, :before { | ||
box-sizing: border-box; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/app/buttons/cbp-toggle-switch/cbp-toggle-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,26 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { CBPToggleSwitchComponent } from './cbp-toggle-switch.component'; | ||
import {CBPButtonsModule} from '../buttons.module'; | ||
|
||
describe('CBPToggleSwitchComponent', () => { | ||
let component: CBPToggleSwitchComponent; | ||
let fixture: ComponentFixture<CBPToggleSwitchComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [CBPButtonsModule] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CBPToggleSwitchComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
src/app/buttons/cbp-toggle-switch/cbp-toggle-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,37 @@ | ||
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; | ||
|
||
let toggleSwitchCounter = 1; | ||
|
||
|
||
@Component({ | ||
selector: 'cbp-toggle-switch', | ||
templateUrl: './cbp-toggle-switch.component.html', | ||
styleUrls: ['./cbp-toggle-switch.component.scss'] | ||
}) | ||
export class CBPToggleSwitchComponent implements OnInit { | ||
|
||
@Input() onLabel = 'ON'; | ||
@Input() offLabel = 'OFF'; | ||
@Input() onValue = true; | ||
@Input() offValue = false; | ||
@Input() label: string = null; | ||
@Input() initialValue: any; | ||
@Input() required: boolean; | ||
@Input() disabled: boolean; | ||
@Output() changed = new EventEmitter<boolean>(); | ||
|
||
isOn: Boolean; | ||
|
||
toggleSwitchId = `cbp-toggle-sw-${toggleSwitchCounter}`; | ||
|
||
constructor() { | ||
toggleSwitchCounter++; | ||
} | ||
ngOnInit() { | ||
this.isOn = this.initialValue === this.onValue; | ||
} | ||
|
||
valueChange($event: any) { | ||
this.changed.emit($event ? this.onValue : this.offValue); | ||
} | ||
} |
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,2 @@ | ||
export * from './cbp-toggle-switch/cbp-toggle-switch.component'; | ||
export * from './buttons.module'; |
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