Skip to content

Commit 2479091

Browse files
authored
feat(bootstrap): add addons to select (#1381)
fix #1380
1 parent 34eccf5 commit 2479091

15 files changed

+90
-81
lines changed

src/bootstrap/addons/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './src/public_api';

src/bootstrap/addons/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ngPackage": {}
3+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div class="input-group">
2+
<div class="input-group-prepend" *ngIf="to.addonLeft" [ngStyle]="{cursor: to.addonLeft.onClick ? 'pointer' : 'inherit'}"
3+
(click)="addonLeftClick($event)">
4+
<i class="input-group-text" [ngClass]="to.addonLeft.class" *ngIf="to.addonLeft.class"></i>
5+
<span *ngIf="to.addonLeft.text" class="input-group-text">{{ to.addonLeft.text }}</span>
6+
</div>
7+
<div class="input-addons">
8+
<ng-container #fieldComponent></ng-container>
9+
</div>
10+
<div class="input-group-append" *ngIf="to.addonRight" [ngStyle]="{cursor: to.addonRight.onClick ? 'pointer' : 'inherit'}"
11+
(click)="addonRightClick($event)">
12+
<i class="input-group-text" [ngClass]="to.addonRight.class" *ngIf="to.addonRight.class"></i>
13+
<span *ngIf="to.addonRight.text" class="input-group-text">{{ to.addonRight.text }}</span>
14+
</div>
15+
</div>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
:host ::ng-deep .input-group> {
2+
:not(:first-child) .form-control {
3+
border-top-left-radius: 0;
4+
border-bottom-left-radius: 0;
5+
}
6+
:not(:last-child) .form-control {
7+
border-top-right-radius: 0;
8+
border-bottom-right-radius: 0;
9+
}
10+
.input-addons {
11+
position: relative;
12+
flex: 1 1 auto;
13+
width: 1%;
14+
margin-bottom: 0;
15+
}
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Component, ViewChild, ViewContainerRef } from '@angular/core';
2+
import { FieldWrapper } from '@ngx-formly/core';
3+
4+
@Component({
5+
selector: 'formly-wrapper-addons',
6+
templateUrl: './addons.component.html',
7+
styleUrls: ['./addons.component.scss'],
8+
})
9+
export class FormlyWrapperAddons extends FieldWrapper {
10+
@ViewChild('fieldComponent', {read: ViewContainerRef}) fieldComponent!: ViewContainerRef;
11+
12+
addonRightClick($event: any) {
13+
if (this.to.addonRight.onClick) {
14+
this.to.addonRight.onClick(this.to, this, $event);
15+
}
16+
}
17+
18+
addonLeftClick($event: any) {
19+
if (this.to.addonLeft.onClick) {
20+
this.to.addonLeft.onClick(this.to, this, $event);
21+
}
22+
}
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { FormlyModule } from '@ngx-formly/core';
4+
import { ReactiveFormsModule } from '@angular/forms';
5+
6+
import { FormlyWrapperAddons } from './addons.component';
7+
import { addonsExtension } from './addon.extension';
8+
9+
@NgModule({
10+
declarations: [FormlyWrapperAddons],
11+
imports: [
12+
CommonModule,
13+
ReactiveFormsModule,
14+
15+
FormlyModule.forChild({
16+
wrappers: [
17+
{ name: 'addons', component: FormlyWrapperAddons },
18+
],
19+
extensions: [
20+
{ name: 'addons', extension: { postPopulate: addonsExtension } },
21+
],
22+
}),
23+
],
24+
})
25+
export class FormlyBootstrapAddonsModule { }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { FormlyBootstrapAddonsModule } from './addons.module';

src/bootstrap/ng-package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"deleteDestPath": false,
55
"lib": {
66
"entryFile": "src/public_api.ts",
7+
"addons": [{ "path": "addons" }],
78
"externals": {
89
"@ngx-formly/core": "@ngx-formly/core"
910
}

src/bootstrap/src/lib/bootstrap.config.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import {
77
FormlyFieldTextArea,
88
FormlyFieldMultiCheckbox,
99
} from './types/types';
10-
import {
11-
FormlyWrapperAddons,
12-
FormlyWrapperFormField,
13-
} from './wrappers/wrappers';
14-
import { addonsExtension } from './extension/addon';
10+
import { FormlyWrapperFormField } from './wrappers/wrappers';
1511

1612
export const FIELD_TYPE_COMPONENTS = [
1713
// types
@@ -23,7 +19,6 @@ export const FIELD_TYPE_COMPONENTS = [
2319
FormlyFieldMultiCheckbox,
2420

2521
// wrappers
26-
FormlyWrapperAddons,
2722
FormlyWrapperFormField,
2823
];
2924

@@ -61,10 +56,6 @@ export const BOOTSTRAP_FORMLY_CONFIG: ConfigOption = {
6156
},
6257
],
6358
wrappers: [
64-
{name: 'addons', component: FormlyWrapperAddons},
65-
{name: 'form-field', component: FormlyWrapperFormField},
66-
],
67-
extensions: [
68-
{ name: 'addons', extension: { onPopulate: addonsExtension } },
59+
{name: 'form-field', component: FormlyWrapperFormField },
6960
],
7061
};

0 commit comments

Comments
 (0)