-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(toggle): add toggle component (#1304)
- Loading branch information
Showing
23 changed files
with
1,070 additions
and
2 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { browser, by, element } from 'protractor'; | ||
|
||
describe('nb-toggle', () => { | ||
beforeEach((done) => { | ||
browser.get('#/toggle/toggle-test.component').then(() => done()); | ||
}); | ||
|
||
it('should turn on on click', () => { | ||
const input = element(by.css('#first input')); | ||
const indicator = element(by.css('#first .toggle')); | ||
|
||
expect(input.getAttribute('checked')).toBeFalsy(); | ||
indicator.click(); | ||
expect(input.getAttribute('checked')).toBeTruthy(); | ||
indicator.click(); | ||
expect(input.getAttribute('checked')).toBeFalsy(); | ||
}); | ||
}); |
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
130 changes: 130 additions & 0 deletions
130
src/framework/theme/components/toggle/_toggle.component.theme.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,130 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
@mixin nb-toggle-theme() { | ||
nb-toggle { | ||
.toggle { | ||
height: nb-theme(toggle-height); | ||
width: nb-theme(toggle-width); | ||
background-color: nb-theme(toggle-background-color); | ||
border: nb-theme(toggle-border-width) solid nb-theme(toggle-border-color); | ||
border-radius: nb-theme(toggle-border-radius); | ||
cursor: nb-theme(toggle-cursor); | ||
} | ||
|
||
.toggle.checked { | ||
background-color: nb-theme(toggle-primary-checked-background-color); | ||
border-color: nb-theme(toggle-primary-checked-border-color); | ||
} | ||
|
||
.native-input { | ||
&:focus + .toggle { | ||
border-color: nb-theme(toggle-primary-focus-border-color); | ||
box-shadow: 0 0 0 nb-theme(toggle-outline-width) nb-theme(toggle-outline-color); | ||
} | ||
|
||
&:active + .toggle { | ||
background-color: nb-theme(toggle-primary-active-background-color); | ||
border-color: nb-theme(toggle-primary-active-border-color); | ||
} | ||
} | ||
|
||
.toggle:hover { | ||
background-color: nb-theme(toggle-primary-hover-background-color); | ||
border-color: nb-theme(toggle-primary-hover-border-color); | ||
} | ||
|
||
.native-input:disabled { | ||
& + .toggle { | ||
background-color: nb-theme(toggle-disabled-background-color); | ||
border-color: nb-theme(toggle-disabled-border-color); | ||
cursor: nb-theme(toggle-disabled-cursor); | ||
|
||
nb-icon { | ||
color: nb-theme(toggle-disabled-switcher-checkmark-color); | ||
} | ||
} | ||
|
||
& ~ .text { | ||
color: nb-theme(toggle-disabled-text-color); | ||
} | ||
} | ||
|
||
.toggle-switcher { | ||
width: nb-theme(toggle-switcher-size); | ||
height: nb-theme(toggle-switcher-size); | ||
background-color: nb-theme(toggle-switcher-background-color); | ||
|
||
nb-icon { | ||
color: nb-theme(toggle-switcher-checkmark-color); | ||
} | ||
} | ||
|
||
.text { | ||
color: nb-theme(toggle-text-color); | ||
font-family: nb-theme(toggle-text-font-family); | ||
font-size: nb-theme(toggle-text-font-size); | ||
font-weight: nb-theme(toggle-text-font-weight); | ||
line-height: nb-theme(toggle-text-line-height); | ||
} | ||
} | ||
|
||
@each $status in nb-get-statuses() { | ||
@include nb-toggle-status($status); | ||
} | ||
} | ||
|
||
@mixin nb-toggle-status($status: '') { | ||
nb-toggle.status-#{$status} { | ||
|
||
.toggle { | ||
background-color: nb-theme(toggle-#{$status}-background-color); | ||
border-color: nb-theme(toggle-#{$status}-border-color); | ||
} | ||
|
||
.toggle.checked { | ||
background-color: nb-theme(toggle-#{$status}-checked-background-color); | ||
border-color: nb-theme(toggle-#{$status}-checked-border-color); | ||
} | ||
|
||
.native-input { | ||
&:focus + .toggle { | ||
border-color: nb-theme(toggle-#{$status}-focus-border-color); | ||
} | ||
|
||
&:active + .toggle { | ||
background-color: nb-theme(toggle-#{$status}-active-background-color); | ||
border-color: nb-theme(toggle-#{$status}-active-border-color); | ||
} | ||
} | ||
|
||
.toggle:hover { | ||
background-color: nb-theme(toggle-#{$status}-hover-background-color); | ||
border-color: nb-theme(toggle-#{$status}-hover-border-color); | ||
} | ||
|
||
.toggle-switcher { | ||
nb-icon { | ||
color: nb-theme(toggle-#{$status}-checked-switcher-checkmark-color); | ||
} | ||
} | ||
|
||
.native-input:disabled { | ||
& + .toggle { | ||
background-color: nb-theme(toggle-disabled-background-color); | ||
border-color: nb-theme(toggle-disabled-border-color); | ||
|
||
nb-icon { | ||
color: nb-theme(toggle-disabled-switcher-checkmark-color); | ||
} | ||
} | ||
|
||
& ~ .text { | ||
color: nb-theme(toggle-disabled-text-color); | ||
} | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/framework/theme/components/toggle/toggle.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,59 @@ | ||
@import '../../styles/core/mixins'; | ||
|
||
:host { | ||
display: inline-flex; | ||
outline: none; | ||
} | ||
|
||
:host(.toggle-label-left) .text { | ||
padding-right: 0.6875rem; | ||
@include nb-ltr(order, -1); | ||
@include nb-rtl(order, 1); | ||
} | ||
|
||
:host(.toggle-label-right) .text { | ||
padding-left: 0.6875rem; | ||
@include nb-ltr(order, 1); | ||
@include nb-rtl(order, -1); | ||
} | ||
|
||
:host(.toggle-label-start) .toggle-label { | ||
flex-direction: row-reverse; | ||
|
||
.text { | ||
@include nb-ltr(padding-right, 0.6875rem); | ||
@include nb-rtl(padding-left, 0.6875rem); | ||
} | ||
} | ||
|
||
:host(.toggle-label-end) .text { | ||
@include nb-ltr(padding-left, 0.6875rem); | ||
@include nb-rtl(padding-right, 0.6875rem); | ||
} | ||
|
||
.toggle-label { | ||
position: relative; | ||
display: inline-flex; | ||
align-items: center; | ||
} | ||
|
||
.toggle { | ||
position: relative; | ||
display: inline-flex; | ||
box-sizing: content-box; | ||
@include nb-component-animation(background-color, border, box-shadow); | ||
} | ||
|
||
.toggle-switcher { | ||
position: absolute; | ||
border-radius: 50%; | ||
margin: 1px; | ||
|
||
nb-icon { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
width: 40%; | ||
} | ||
} |
Oops, something went wrong.