Skip to content

Commit

Permalink
refactor(timeline): refactoring timeline components
Browse files Browse the repository at this point in the history
Closes: #345
  • Loading branch information
AntoninoBonanno committed Jul 7, 2024
1 parent 140f646 commit 1c96358
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 78 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ChangeDetectionStrategy, Component, Input, booleanAttribute } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ItAbstractComponent } from '../../../../abstracts/abstract.component';
import { ItIconComponent } from '../../../utils/icon/icon.component';
import { DatePipe, NgClass } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { TimelinePINType } from 'projects/design-angular-kit/src/lib/interfaces/core';
import { IconName } from 'projects/design-angular-kit/src/lib/interfaces/icon';
import { TimelinePINType } from '../../../../interfaces/core';
import { IconName } from '../../../../interfaces/icon';
import { inputToBoolean } from '../../../../utils/coercion';

/**
* Timeline Item
Expand All @@ -18,40 +19,65 @@ import { IconName } from 'projects/design-angular-kit/src/lib/interfaces/icon';
imports: [ItIconComponent, DatePipe, TranslateModule, NgClass],
})
export class ItTimelineItemComponent extends ItAbstractComponent {
/** Timeline element title */
/**
* Timeline element title
*/
@Input({ required: true }) title!: string;
/** Timeline element text */

/**
* Timeline element text
*/
@Input({ required: true }) text!: string;
/** Timeline element signature */
@Input() signature?: string | undefined;
/** Timeline element reference date */
@Input() eventDate?: Date | undefined;
/** Timeline element reference date format

/**
* Timeline element signature
*/
@Input() signature: string | undefined;

/**
* Timeline element reference date
*/
@Input() eventDate: Date | undefined;

/**
* Timeline element reference date format
* @default dd/MM/yyyy
*/
@Input() dateFormat?: string | undefined = 'dd/MM/yyyy';
@Input() dateFormat: string = 'dd/MM/yyyy';

/** Timeline element PIN text */
@Input({ required: true }) pinText!: string;
/** Timeline element PIN type
/**
* Timeline element PIN text
*/
@Input({ required: true }) pinText: string | undefined;

/**
* Timeline element PIN type
* @default none
*/
@Input() pinType?: TimelinePINType | undefined = 'default';
/** Timeline element PIN icon
@Input() pinType: TimelinePINType | undefined = 'default';

/**
* Timeline element PIN icon
* @default code-circle
*/
@Input() pinIcon?: IconName | undefined = 'code-circle';
@Input() pinIcon: IconName | undefined = 'code-circle';

/** Timeline element category title */
@Input() categoryTitle?: string | undefined;
/** Timeline element category link */
@Input() categoryLink?: string | undefined;
/**
* Timeline element category title
*/
@Input() categoryTitle: string | undefined;

/**
* Timeline element category link
*/
@Input() categoryLink: string | undefined;

/** Timeline element show detail link
* @default false
*/
@Input({ transform: booleanAttribute })
@Input({ transform: inputToBoolean })
showReadMore: boolean = false;

/** Timeline element detail link
* @default #
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[categoryTitle]="element.category?.title"
[categoryLink]="element.category?.link"
[showReadMore]="element.link?.length"

Check failure on line 16 in projects/design-angular-kit/src/lib/components/core/timeline/timeline.component.html

View workflow job for this annotation

GitHub Actions / run-build-and-tests

Type 'number | undefined' is not assignable to type 'BooleanInput'.

Check failure on line 16 in projects/design-angular-kit/src/lib/components/core/timeline/timeline.component.html

View workflow job for this annotation

GitHub Actions / run-build-and-tests

Type 'number | undefined' is not assignable to type 'BooleanInput'.
[readMoreLink]="element.link"></it-timeline-item>
[readMoreLink]="element.link" />
</div>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ItTimelineComponent } from './timeline.component';
import { tb_base } from '../../../../test';

describe('ItTimelineComponent', () => {
let component: ItTimelineComponent;
let fixture: ComponentFixture<ItTimelineComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule(tb_base).compileComponents();

fixture = TestBed.createComponent(ItTimelineComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ItTimelineItemComponent } from './timeline-item/timeline-item.component';
import { ItIconComponent } from '../../utils/icon/icon.component';
import { TranslateModule } from '@ngx-translate/core';
import { ItAbstractComponent } from '../../../abstracts/abstract.component';
import { TimelineElement } from '../../../interfaces/core';

/**
* Timeline
* @description Build timeline for chronological representation of events.
*/
@Component({
standalone: true,
selector: 'it-timeline',
templateUrl: './timeline.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [ItIconComponent, TranslateModule, ItTimelineItemComponent],
})
export class ItTimelineComponent extends ItAbstractComponent {
/**
* Timeline elements array
* @default []
*/
@Input() timelineElements: TimelineElement[] = [];

/**
* Default date format for timeline element reference date
* @default dd/MM/yyyy
*/
@Input() dateFormat: string = 'dd/MM/yyyy';
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NgModule } from '@angular/core';
import { ItTimelineContainerComponent } from './timeline-container/timeline-container.component';
import { ItTimelineComponent } from './timeline.component';
import { ItTimelineItemComponent } from './timeline-item/timeline-item.component';

const timelineComponents = [ItTimelineContainerComponent, ItTimelineItemComponent];
const timelineComponents = [ItTimelineComponent, ItTimelineItemComponent];

@NgModule({
imports: timelineComponents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { ItDateAgoPipe } from './pipes/date-ago.pipe';
import { ItDurationPipe } from './pipes/duration.pipe';
import { ItMarkMatchingTextPipe } from './pipes/mark-matching-text.pipe';
import { ItTimelineModule } from './components/core/timeline/timeline.module';
import { ItTimelineContainerComponent } from './components/core/timeline/timeline-container/timeline-container.component';
import { ItTimelineComponent } from './components/core/timeline/timeline.component';
import { ItTimelineItemComponent } from './components/core/timeline/timeline-item/timeline-item.component';

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ const core = [
ItTabModule,
ItTableModule,
ItTooltipDirective,
ItTimelineContainerComponent,
ItTimelineComponent,
ItTimelineItemComponent,
ItTimelineModule,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ <h3>Esempi</h3>

<div class="bd-example">
<div class="example-section">
<it-timeline-container [timelineElements]="timelineElements" [dateFormat]="defaultDateFormat"></it-timeline-container>
<it-timeline [timelineElements]="timelineElements" [dateFormat]="defaultDateFormat" />
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export class TimelineIndexComponent {
component: any;

constructor() {
this.component = (<any>Documentation).components.find(component => component.name === 'ItTimelineContainerComponent');
this.component = (<any>Documentation).components.find(component => component.name === 'ItTimelineComponent');
}
}

0 comments on commit 1c96358

Please sign in to comment.