-
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(theme): add new Select component (#698)
Closes #671
- Loading branch information
1 parent
b29418f
commit d6a211f
Showing
45 changed files
with
1,906 additions
and
1 deletion.
There are no files selected for viewing
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
105 changes: 105 additions & 0 deletions
105
src/framework/theme/components/select/_select.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,105 @@ | ||
/* | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
@mixin nb-select-status($status) { | ||
border: nb-theme(select-border-width) solid nb-theme(color-#{$status}); | ||
|
||
nb-option { | ||
&:hover, &.selected { | ||
background-color: nb-theme(color-#{$status}); | ||
color: nb-theme(color-white); | ||
} | ||
} | ||
} | ||
|
||
@mixin nb-select-theme() { | ||
nb-select > button[nbButton] { | ||
transition: all 0.1s; | ||
|
||
&::after { | ||
@include nb-rtl(left, 0.75rem); | ||
@include nb-rtl(right, auto); | ||
} | ||
|
||
&.opened { | ||
&.top { | ||
border-top-left-radius: 0; | ||
border-top-right-radius: 0; | ||
} | ||
|
||
&.bottom { | ||
border-bottom-left-radius: 0; | ||
border-bottom-right-radius: 0; | ||
} | ||
} | ||
} | ||
|
||
nb-card.select { | ||
background-color: nb-theme(select-bg); | ||
max-height: nb-theme(select-max-height); | ||
margin-bottom: 0; | ||
box-shadow: none; | ||
|
||
nb-card-body { | ||
padding: 0; | ||
} | ||
|
||
nb-option { | ||
padding: nb-theme(select-option-padding); | ||
} | ||
|
||
&.primary { | ||
@include nb-select-status(primary); | ||
} | ||
|
||
&.danger { | ||
@include nb-select-status(danger); | ||
} | ||
|
||
&.warning { | ||
@include nb-select-status(warning); | ||
} | ||
|
||
&.info { | ||
@include nb-select-status(info); | ||
} | ||
|
||
&.success { | ||
@include nb-select-status(success); | ||
} | ||
|
||
&.bottom { | ||
border-top-left-radius: 0; | ||
border-top-right-radius: 0; | ||
} | ||
|
||
&.top { | ||
border-bottom-left-radius: 0; | ||
border-bottom-right-radius: 0; | ||
} | ||
|
||
nb-checkbox { | ||
.customised-control-description { | ||
color: inherit; | ||
} | ||
|
||
.customised-control-input:checked ~ .customised-control-indicator { | ||
border-color: nb-theme(select-checkbox-color); | ||
|
||
&::before { | ||
border-color: nb-theme(select-checkmark-color); | ||
} | ||
} | ||
} | ||
|
||
nb-option, nb-option-group { | ||
&.disabled { | ||
background-color: nb-theme(select-option-disabled-bg); | ||
opacity: nb-theme(select-option-disabled-opacity); | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/framework/theme/components/select/option-group.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,22 @@ | ||
/* | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
:host { | ||
display: block; | ||
|
||
span { | ||
padding: 1.125rem 0.5rem; | ||
display: block; | ||
} | ||
|
||
&.disabled { | ||
pointer-events: none; | ||
} | ||
|
||
/deep/ nb-option { | ||
padding: 0.75rem 0.75rem 0.75rem 2.5rem; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/framework/theme/components/select/option-group.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,36 @@ | ||
/* | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { ChangeDetectionStrategy, Component, HostBinding, Input } from '@angular/core'; | ||
import { convertToBoolProperty } from '../helpers'; | ||
|
||
|
||
@Component({ | ||
selector: 'nb-option-group', | ||
styleUrls: ['./option-group.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: ` | ||
<span>{{ title }}</span> | ||
<ng-content select="nb-option, ng-container"></ng-content> | ||
`, | ||
}) | ||
export class NbOptionGroupComponent { | ||
@Input() title: string; | ||
|
||
@Input('disabled') | ||
set setDisabled(disabled: boolean) { | ||
this.disabled = convertToBoolProperty(disabled); | ||
} | ||
|
||
disabled: boolean = false; | ||
|
||
@HostBinding('class.disabled') | ||
get disabledClass(): boolean { | ||
return this.disabled; | ||
} | ||
} | ||
|
||
|
22 changes: 22 additions & 0 deletions
22
src/framework/theme/components/select/option.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,22 @@ | ||
/*! | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
:host { | ||
display: block; | ||
|
||
&.disabled { | ||
pointer-events: none; | ||
} | ||
|
||
&:hover { | ||
cursor: pointer; | ||
} | ||
|
||
nb-checkbox { | ||
pointer-events: none; | ||
} | ||
} | ||
|
108 changes: 108 additions & 0 deletions
108
src/framework/theme/components/select/option.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,108 @@ | ||
/* | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { | ||
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
ElementRef, | ||
EventEmitter, | ||
forwardRef, | ||
HostBinding, | ||
HostListener, | ||
Inject, | ||
Input, | ||
Output, | ||
} from '@angular/core'; | ||
import { convertToBoolProperty } from '../helpers'; | ||
import { NbSelectComponent } from './select.component'; | ||
|
||
|
||
@Component({ | ||
selector: 'nb-option', | ||
styleUrls: ['./option.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: ` | ||
<nb-checkbox *ngIf="withCheckbox" [(ngModel)]="selected"> | ||
<ng-container *ngTemplateOutlet="content"></ng-container> | ||
</nb-checkbox> | ||
<ng-container *ngIf="!withCheckbox"> | ||
<ng-container *ngTemplateOutlet="content"></ng-container> | ||
</ng-container> | ||
<ng-template #content> | ||
<ng-content></ng-content> | ||
</ng-template> | ||
`, | ||
}) | ||
export class NbOptionComponent<T> { | ||
/** | ||
* Option value that will be fired on selection. | ||
* */ | ||
@Input() value: T; | ||
|
||
@Input('disabled') | ||
set setDisabled(disabled: boolean) { | ||
this.disabled = convertToBoolProperty(disabled); | ||
} | ||
|
||
/** | ||
* Fires value on click. | ||
* */ | ||
@Output() selectionChange: EventEmitter<NbOptionComponent<T>> = new EventEmitter(); | ||
|
||
selected: boolean = false; | ||
disabled: boolean = false; | ||
|
||
constructor(@Inject(forwardRef(() => NbSelectComponent)) protected parent, | ||
protected elementRef: ElementRef, | ||
protected cd: ChangeDetectorRef) { | ||
} | ||
|
||
/** | ||
* Determines should we render checkbox. | ||
* */ | ||
get withCheckbox(): boolean { | ||
return this.multiple && !!this.value; | ||
} | ||
|
||
get content() { | ||
return this.elementRef.nativeElement.textContent; | ||
} | ||
|
||
get multiple() { | ||
return this.parent.multiple; | ||
} | ||
|
||
@HostBinding('class.selected') | ||
get selectedClass(): boolean { | ||
return this.selected; | ||
} | ||
|
||
@HostBinding('class.disabled') | ||
get disabledClass(): boolean { | ||
return this.disabled; | ||
} | ||
|
||
@HostListener('click') | ||
onClick() { | ||
this.selectionChange.emit(this); | ||
} | ||
|
||
select() { | ||
this.selected = true; | ||
this.cd.markForCheck(); | ||
this.cd.detectChanges(); | ||
} | ||
|
||
deselect() { | ||
this.selected = false; | ||
this.cd.markForCheck(); | ||
this.cd.detectChanges(); | ||
} | ||
} | ||
|
Oops, something went wrong.