Skip to content

Commit

Permalink
feat(progressbar): added moduleless support
Browse files Browse the repository at this point in the history
  • Loading branch information
lexasq committed Jul 18, 2024
1 parent 76a1b15 commit 6b58679
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 61 deletions.
2 changes: 1 addition & 1 deletion libs/doc-pages/progressbar/src/lib/docs/usage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProgressbarModule } from 'ngx-bootstrap/progressbar';

@NgModule({
imports: [ProgressbarModule.forRoot(),...]
imports: [ProgressbarModule,...]
})
export class AppModule(){}
2 changes: 1 addition & 1 deletion libs/doc-pages/progressbar/src/lib/progressbar.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export { ProgressbarSectionComponent } from './progressbar-section.component';
CommonModule,
FormsModule,
DocsModule,
ProgressbarModule.forRoot(),
ProgressbarModule,
RouterModule.forChild(routes)
],
exports: [ProgressbarSectionComponent]
Expand Down
33 changes: 17 additions & 16 deletions src/progressbar/bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ import {
import { ProgressbarType } from './progressbar-type.interface';

@Component({
selector: 'bar',
templateUrl: './bar.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: {
role: 'progressbar',
'aria-valuemin': '0',
'[class.progress-bar]': 'true',
'[class.progress-bar-animated]': 'animate',
'[class.progress-bar-striped]': 'striped',
'[attr.aria-valuenow]': 'value',
'[attr.aria-valuetext]': 'percent ? percent.toFixed(0) + "%" : ""',
'[attr.aria-valuemax]': 'max',
'[style.height.%]': '"100"',
'[style.width.%]': 'percent'
}
selector: 'bar',
templateUrl: './bar.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: {
role: 'progressbar',
'aria-valuemin': '0',
'[class.progress-bar]': 'true',
'[class.progress-bar-animated]': 'animate',
'[class.progress-bar-striped]': 'striped',
'[attr.aria-valuenow]': 'value',
'[attr.aria-valuetext]': 'percent ? percent.toFixed(0) + "%" : ""',
'[attr.aria-valuemax]': 'max',
'[style.height.%]': '"100"',
'[style.width.%]': 'percent'
},
standalone: true
})
export class BarComponent implements OnChanges {
/** maximum total value of progress element */
Expand Down
24 changes: 14 additions & 10 deletions src/progressbar/progressbar.component.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { BarValue, ProgressbarType } from './progressbar-type.interface';
import { ProgressbarConfig } from './progressbar.config';
import { BarComponent } from './bar.component';
import { NgIf, NgFor } from '@angular/common';

@Component({
selector: 'progressbar',
templateUrl: './progressbar.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: {
'[class.progress]': 'true',
'[attr.max]': 'max'
},
styles: [`
selector: 'progressbar',
templateUrl: './progressbar.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: {
'[class.progress]': 'true',
'[attr.max]': 'max'
},
styles: [`
:host {
width: 100%;
display: flex;
} `]
} `],
standalone: true,
imports: [NgIf, BarComponent, NgFor]
})
export class ProgressbarComponent {
/** maximum total value of progress element */
Expand Down
14 changes: 4 additions & 10 deletions src/progressbar/progressbar.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { CommonModule } from '@angular/common';
import { NgModule, ModuleWithProviders } from '@angular/core';
import { NgModule } from '@angular/core';

import { BarComponent } from './bar.component';
import { ProgressbarComponent } from './progressbar.component';

@NgModule({
imports: [CommonModule],
declarations: [BarComponent, ProgressbarComponent],
exports: [BarComponent, ProgressbarComponent]
imports: [BarComponent, ProgressbarComponent],
exports: [BarComponent, ProgressbarComponent]
})
export class ProgressbarModule {
static forRoot(): ModuleWithProviders<ProgressbarModule> {
return { ngModule: ProgressbarModule, providers: [] };
}
}
export class ProgressbarModule {}
40 changes: 17 additions & 23 deletions src/progressbar/testing/progressbar.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { ProgressbarComponent, ProgressbarModule } from '../index';

@Component({
selector: 'progressbar-test',
template: ''
selector: 'progressbar-test',
template: '',
standalone: true
})
class TestProgressbarComponent extends ProgressbarComponent {}

Expand All @@ -19,9 +20,8 @@ describe('Component: Progress Bar', () => {

it('check animate setter when _animate is equal to setter\'s argument', () => {
TestBed.configureTestingModule({
declarations: [TestProgressbarComponent],
imports: [ProgressbarModule.forRoot()]
});
imports: [ProgressbarModule, TestProgressbarComponent]
});
fixture = TestBed.createComponent(TestProgressbarComponent);
component = fixture.componentInstance;
component.animate = false;
Expand All @@ -32,9 +32,8 @@ describe('Component: Progress Bar', () => {

it('check striped setter when _striped is equal to setter\'s argument', () => {
TestBed.configureTestingModule({
declarations: [TestProgressbarComponent],
imports: [ProgressbarModule.forRoot()]
});
imports: [ProgressbarModule, TestProgressbarComponent]
});
fixture = TestBed.createComponent(TestProgressbarComponent);
component = fixture.componentInstance;
component.striped = false;
Expand All @@ -46,9 +45,8 @@ describe('Component: Progress Bar', () => {
it('should work correctly with default values', () => {
const tpl = `<progressbar></progressbar>`;
TestBed.configureTestingModule({
declarations: [TestProgressbarComponent],
imports: [ProgressbarModule.forRoot()]
});
imports: [ProgressbarModule, TestProgressbarComponent]
});
TestBed.overrideComponent(TestProgressbarComponent, {
set: { template: tpl }
});
Expand All @@ -64,9 +62,8 @@ describe('Component: Progress Bar', () => {
it('checking appropriate styles after setting up of type', () => {
const tpl = `<progressbar [type]="typeValue"></progressbar>`;
TestBed.configureTestingModule({
declarations: [TestProgressbarComponent],
imports: [ProgressbarModule.forRoot()]
});
imports: [ProgressbarModule, TestProgressbarComponent]
});
TestBed.overrideComponent(TestProgressbarComponent, {
set: { template: tpl }
});
Expand All @@ -84,9 +81,8 @@ describe('Component: Progress Bar', () => {
it('checking of correct calculation of percent value(bar length)', () => {
const tpl = `<progressbar [max]="100" [value]="60"></progressbar>`;
TestBed.configureTestingModule({
declarations: [TestProgressbarComponent],
imports: [ProgressbarModule.forRoot()]
});
imports: [ProgressbarModule, TestProgressbarComponent]
});
TestBed.overrideComponent(TestProgressbarComponent, {
set: { template: tpl }
});
Expand All @@ -112,9 +108,8 @@ describe('Component: Progress Bar', () => {
};
const tpl = `<progressbar [type]="typeValue" [value]="valueValue" [animate]="true" [max]="maxValue"></progressbar>`;
TestBed.configureTestingModule({
declarations: [TestProgressbarComponent],
imports: [ProgressbarModule.forRoot()]
});
imports: [ProgressbarModule, TestProgressbarComponent]
});
TestBed.overrideComponent(TestProgressbarComponent, {
set: { template: tpl }
});
Expand Down Expand Up @@ -146,9 +141,8 @@ describe('progress bar', () => {

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestProgressbarComponent],
imports: [ProgressbarModule.forRoot()]
});
imports: [ProgressbarModule, TestProgressbarComponent]
});
fixture = TestBed.overrideComponent(TestProgressbarComponent, {
set: { template: tpl }
})
Expand Down

0 comments on commit 6b58679

Please sign in to comment.