mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-17 07:50:12 +01:00
feat(inputs\multi-checkbox): add multi-checkbox directive
This commit is contained in:
parent
73cec2fceb
commit
fa854ad6cc
12 changed files with 191 additions and 111 deletions
|
|
@ -1,12 +1,32 @@
|
||||||
import {Component} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {BaCheckbox} from '../../../../../../theme/components';
|
import {BaMultiCheckbox} from '../../../../../../theme/components';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'checkbox-inputs',
|
selector: 'checkbox-inputs',
|
||||||
template: require('./checkboxInputs.html'),
|
template: require('./checkboxInputs.html'),
|
||||||
directives: [BaCheckbox]
|
directives: [BaMultiCheckbox]
|
||||||
})
|
})
|
||||||
export class CheckboxInputs {
|
export class CheckboxInputs {
|
||||||
|
public checkboxModel = [{
|
||||||
|
name: 'Check 1',
|
||||||
|
checked: false,
|
||||||
|
class: 'col-md-4'
|
||||||
|
}, {
|
||||||
|
name: 'Check 2',
|
||||||
|
checked: true,
|
||||||
|
class: 'col-md-4'
|
||||||
|
}, {
|
||||||
|
name: 'Check 3',
|
||||||
|
checked: false,
|
||||||
|
class: 'col-md-4'
|
||||||
|
}];
|
||||||
|
|
||||||
|
public checkboxPropertiesMapping = {
|
||||||
|
model: 'checked',
|
||||||
|
value: 'name',
|
||||||
|
label: 'name',
|
||||||
|
baCheckboxClass: 'class'
|
||||||
|
};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
<div class="checkbox-demo-row">
|
<div class="checkbox-demo-row">
|
||||||
<div class="input-demo checkbox-demo row">
|
<div class="input-demo checkbox-demo row">
|
||||||
<ba-checkbox [(ngModel)]="value1" [baCheckboxClass]="'col-md-4'" [label]="'Check 1'" [disabled]="false" [value]="option1" id="inlineCheckbox01"></ba-checkbox>
|
<ba-multi-checkbox [(ngModel)]="checkboxModel" [propertiesMapping]="checkboxPropertiesMapping"></ba-multi-checkbox>
|
||||||
<ba-checkbox [(ngModel)]="value2" [baCheckboxClass]="'col-md-4'" [label]="'Check 2'" [disabled]="false" [value]="option2" id="inlineCheckbox02"></ba-checkbox>
|
|
||||||
<ba-checkbox [(ngModel)]="value3" [baCheckboxClass]="'col-md-4'" [label]="'Check 3'" [disabled]="false" [value]="option3" id="inlineCheckbox03"></ba-checkbox>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="input-demo radio-demo row">
|
<div class="input-demo radio-demo row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
|
|
@ -27,10 +25,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="checkbox disabled">
|
<div class="checkbox disabled">
|
||||||
<label class="custom-checkbox nowrap">
|
<ba-checkbox [label]="'Disabled checkbox'" [disabled]="true"></ba-checkbox>
|
||||||
<input type="checkbox" value="" disabled>
|
|
||||||
<span>Checkbox is disabled</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="radio disabled">
|
<div class="radio disabled">
|
||||||
<label class="custom-radio nowrap">
|
<label class="custom-radio nowrap">
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,32 @@
|
||||||
import {Component} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
|
import {BaMultiCheckbox} from '../../../../../../theme/components';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'validation-inputs',
|
selector: 'validation-inputs',
|
||||||
|
directives: [BaMultiCheckbox],
|
||||||
template: require('./validationInputs.html'),
|
template: require('./validationInputs.html'),
|
||||||
})
|
})
|
||||||
export class ValidationInputs {
|
export class ValidationInputs {
|
||||||
|
public checkboxModel = [{
|
||||||
|
name: 'Checkbox with success',
|
||||||
|
state: false,
|
||||||
|
class: 'has-success checkbox'
|
||||||
|
}, {
|
||||||
|
name: 'Checkbox with warning',
|
||||||
|
state: false,
|
||||||
|
class: 'has-warning checkbox',
|
||||||
|
}, {
|
||||||
|
name: 'Checkbox with error',
|
||||||
|
state: false,
|
||||||
|
class: 'has-error checkbox'
|
||||||
|
}];
|
||||||
|
|
||||||
|
public checkboxPropertiesMapping = {
|
||||||
|
model: 'state',
|
||||||
|
value: 'name',
|
||||||
|
label: 'name',
|
||||||
|
baCheckboxClass: 'class'
|
||||||
|
};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,31 +10,7 @@
|
||||||
<label class="control-label" for="inputError1">Input with error</label>
|
<label class="control-label" for="inputError1">Input with error</label>
|
||||||
<input type="text" class="form-control" id="inputError1">
|
<input type="text" class="form-control" id="inputError1">
|
||||||
</div>
|
</div>
|
||||||
<div class="has-success">
|
<ba-multi-checkbox [(ngModel)]="checkboxModel" [propertiesMapping]="checkboxPropertiesMapping"></ba-multi-checkbox>
|
||||||
<div class="checkbox">
|
|
||||||
<label class="custom-checkbox">
|
|
||||||
<input type="checkbox" id="checkboxSuccess" value="option1">
|
|
||||||
<span>Checkbox with success</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="has-warning">
|
|
||||||
<div class="checkbox">
|
|
||||||
<label class="custom-checkbox">
|
|
||||||
<input type="checkbox" id="checkboxWarning" value="option1">
|
|
||||||
<span>Checkbox with warning</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="has-error">
|
|
||||||
<div class="checkbox">
|
|
||||||
<label class="custom-checkbox">
|
|
||||||
<input type="checkbox" id="checkboxError" value="option1">
|
|
||||||
<span>Checkbox with error</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group has-success has-feedback">
|
<div class="form-group has-success has-feedback">
|
||||||
<label class="control-label" for="inputSuccess2">Input with success</label>
|
<label class="control-label" for="inputSuccess2">Input with success</label>
|
||||||
<input type="text" class="form-control" id="inputSuccess2" aria-describedby="inputSuccess2Status">
|
<input type="text" class="form-control" id="inputSuccess2" aria-describedby="inputSuccess2Status">
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ export class BaCheckbox implements ControlValueAccessor {
|
||||||
@Input() disabled:boolean;
|
@Input() disabled:boolean;
|
||||||
@Input() label:string;
|
@Input() label:string;
|
||||||
@Input() value:string;
|
@Input() value:string;
|
||||||
@Input() name:string;
|
|
||||||
@Input() baCheckboxClass:string;
|
@Input() baCheckboxClass:string;
|
||||||
|
|
||||||
public state: boolean;
|
public state: boolean;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="{{baCheckboxClass}}">
|
<div class="{{baCheckboxClass}}">
|
||||||
<label class="checkbox-inline custom-checkbox nowrap">
|
<label class="checkbox-inline custom-checkbox nowrap">
|
||||||
<input type="checkbox" [name]="name" [checked]=state
|
<input type="checkbox" [checked]=state
|
||||||
(change)="onChange($event.target.checked)"
|
(change)="onChange($event.target.checked)"
|
||||||
[disabled]="disabled" [value]="value">
|
[disabled]="disabled" [value]="value">
|
||||||
<span>{{label}}</span>
|
<span>{{label}}</span>
|
||||||
|
|
|
||||||
78
src/app/theme/components/baCheckbox/baCheckbox.scss
Normal file
78
src/app/theme/components/baCheckbox/baCheckbox.scss
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
label.custom-checkbox > span {
|
||||||
|
display: block;
|
||||||
|
margin-top: -13px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
label.custom-checkbox {
|
||||||
|
padding-right: 0;
|
||||||
|
padding-left: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
|
& > input {
|
||||||
|
height: 0;
|
||||||
|
z-index: -100 !important;
|
||||||
|
opacity: 0;
|
||||||
|
position: absolute;
|
||||||
|
&:checked {
|
||||||
|
& + span {
|
||||||
|
&:before {
|
||||||
|
content: "\f00c";
|
||||||
|
font-weight: $font-light;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&:disabled {
|
||||||
|
& + span {
|
||||||
|
color: $disabled;
|
||||||
|
cursor: not-allowed;
|
||||||
|
&:before {
|
||||||
|
border-color: $disabled !important;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
& > span {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
margin: 0;
|
||||||
|
line-height: 16px;
|
||||||
|
font-weight: $font-light;
|
||||||
|
cursor: pointer;
|
||||||
|
padding-left: 22px;
|
||||||
|
width: 100%;
|
||||||
|
&:before {
|
||||||
|
cursor: pointer;
|
||||||
|
font-family: fontAwesome;
|
||||||
|
font-weight: $font-light;
|
||||||
|
font-size: 12px;
|
||||||
|
color: $content-text;
|
||||||
|
content: "\a0";
|
||||||
|
background-color: transparent;
|
||||||
|
border: 1px solid $border;
|
||||||
|
border-radius: 0;
|
||||||
|
display: inline-block;
|
||||||
|
text-align: center;
|
||||||
|
height: 16px;
|
||||||
|
line-height: 14px;
|
||||||
|
min-width: 16px;
|
||||||
|
margin-right: 6px;
|
||||||
|
position: relative;
|
||||||
|
top: 0;
|
||||||
|
margin-left: -22px;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
&:before {
|
||||||
|
border-color: $primary-bg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-horizontal {
|
||||||
|
.checkbox, .checkbox-inline{
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
import {Component, Provider, forwardRef, Input} from "@angular/core";
|
||||||
|
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from "@angular/common";
|
||||||
|
import {BaCheckbox} from '../baCheckbox';
|
||||||
|
|
||||||
|
const BA_MULTI_CHECKBOX_CONTROL_VALUE_ACCESSOR = new Provider(
|
||||||
|
NG_VALUE_ACCESSOR, {
|
||||||
|
useExisting: forwardRef(() => BaMultiCheckbox),
|
||||||
|
multi: true
|
||||||
|
});
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'ba-multi-checkbox',
|
||||||
|
template: require('./baMultiCheckbox.html'),
|
||||||
|
directives: [BaCheckbox],
|
||||||
|
providers: [BA_MULTI_CHECKBOX_CONTROL_VALUE_ACCESSOR]
|
||||||
|
})
|
||||||
|
export class BaMultiCheckbox implements ControlValueAccessor {
|
||||||
|
@Input() baMultiCheckboxClass:string;
|
||||||
|
@Input() propertiesMapping:any;
|
||||||
|
private _model;
|
||||||
|
|
||||||
|
getProp(item: any, propName: string): string {
|
||||||
|
const prop = this.propertiesMapping[propName];
|
||||||
|
|
||||||
|
if (!prop) {
|
||||||
|
return item[propName];
|
||||||
|
} else if (typeof prop === 'function') {
|
||||||
|
return prop(item);
|
||||||
|
}
|
||||||
|
return item[prop];
|
||||||
|
}
|
||||||
|
onChange(value: any): void {}
|
||||||
|
onTouch(value: any): void {}
|
||||||
|
writeValue(value: any): void {
|
||||||
|
this._model = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
registerOnChange(fn: any): void { this.onChange = fn; }
|
||||||
|
registerOnTouched(fn: any): void { this.onTouch = fn; }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
<div class="{{baMultiCheckboxClass}}">
|
||||||
|
<ba-checkbox *ngFor="let item of _model"
|
||||||
|
[(ngModel)]="item[propertiesMapping.model]"
|
||||||
|
[baCheckboxClass]="getProp(item, 'baCheckboxClass')"
|
||||||
|
[label]="getProp(item, 'label')"
|
||||||
|
[disabled]="getProp(item, 'disabled')"
|
||||||
|
[value]="getProp(item, 'value')"
|
||||||
|
id="{{getProp(item, 'id')}}">
|
||||||
|
</ba-checkbox>
|
||||||
|
</div>
|
||||||
1
src/app/theme/components/baMultiCheckbox/index.ts
Normal file
1
src/app/theme/components/baMultiCheckbox/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './baMultiCheckbox.component'
|
||||||
|
|
@ -8,3 +8,4 @@ export * from './baChartistChart';
|
||||||
export * from './baBackTop';
|
export * from './baBackTop';
|
||||||
export * from './baFullCalendar';
|
export * from './baFullCalendar';
|
||||||
export * from './baCheckbox';
|
export * from './baCheckbox';
|
||||||
|
export * from './baMultiCheckbox';
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
@import "../components/baCheckbox/baCheckbox";
|
||||||
|
|
||||||
.label {
|
.label {
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
@ -75,12 +77,6 @@ textarea.form-control {
|
||||||
button[type="submit"] {
|
button[type="submit"] {
|
||||||
margin-left: 12px;
|
margin-left: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
label.custom-checkbox > span {
|
|
||||||
display: block;
|
|
||||||
margin-top: -13px;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@mixin setSwitchBorder($color) {
|
@mixin setSwitchBorder($color) {
|
||||||
|
|
@ -182,71 +178,6 @@ textarea.form-control {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
label.custom-checkbox {
|
|
||||||
padding-right: 0;
|
|
||||||
padding-left: 0;
|
|
||||||
margin-bottom: 0;
|
|
||||||
& > input {
|
|
||||||
height: 0;
|
|
||||||
z-index: -100 !important;
|
|
||||||
opacity: 0;
|
|
||||||
position: absolute;
|
|
||||||
&:checked {
|
|
||||||
& + span {
|
|
||||||
&:before {
|
|
||||||
content: "\f00c";
|
|
||||||
font-weight: $font-light;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&:disabled {
|
|
||||||
& + span {
|
|
||||||
color: $disabled;
|
|
||||||
cursor: not-allowed;
|
|
||||||
&:before {
|
|
||||||
border-color: $disabled !important;
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
& > span {
|
|
||||||
position: relative;
|
|
||||||
display: inline-block;
|
|
||||||
margin: 0;
|
|
||||||
line-height: 16px;
|
|
||||||
font-weight: $font-light;
|
|
||||||
cursor: pointer;
|
|
||||||
padding-left: 22px;
|
|
||||||
width: 100%;
|
|
||||||
&:before {
|
|
||||||
cursor: pointer;
|
|
||||||
font-family: fontAwesome;
|
|
||||||
font-weight: $font-light;
|
|
||||||
font-size: 12px;
|
|
||||||
color: $content-text;
|
|
||||||
content: "\a0";
|
|
||||||
background-color: transparent;
|
|
||||||
border: 1px solid $border;
|
|
||||||
border-radius: 0;
|
|
||||||
display: inline-block;
|
|
||||||
text-align: center;
|
|
||||||
height: 16px;
|
|
||||||
line-height: 14px;
|
|
||||||
min-width: 16px;
|
|
||||||
margin-right: 6px;
|
|
||||||
position: relative;
|
|
||||||
top: 0;
|
|
||||||
margin-left: -22px;
|
|
||||||
float: left;
|
|
||||||
}
|
|
||||||
&:hover {
|
|
||||||
&:before {
|
|
||||||
border-color: $primary-bg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.nowrap {
|
.nowrap {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
@ -307,7 +238,7 @@ label.custom-input-danger {
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-horizontal {
|
.form-horizontal {
|
||||||
.radio, .checkbox, .radio-inline, .checkbox-inline {
|
.radio, .radio-inline {
|
||||||
padding-top: 0;
|
padding-top: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -327,7 +258,6 @@ label.custom-input-danger {
|
||||||
border-color: $focusColor;
|
border-color: $focusColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
label.custom-checkbox {
|
label.custom-checkbox {
|
||||||
color: $color;
|
color: $color;
|
||||||
& > span {
|
& > span {
|
||||||
|
|
@ -582,3 +512,11 @@ label.custom-input-danger {
|
||||||
.sub-little-text {
|
.sub-little-text {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.rating {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
rating-inputs span {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue