@@ -5,53 +5,87 @@ import {
55 input ,
66 OnInit ,
77} from '@angular/core' ;
8+ import { TranslocoDirective } from '@jsverse/transloco' ;
89import { CarouselModule , OwlOptions } from 'ngx-owl-carousel-o' ;
910
1011import { RelatedArticleListStore } from '@angular-love/blog/articles/data-access' ;
1112import { UiArticleCardComponent } from '@angular-love/blog/articles/ui-article-card' ;
13+ import { ButtonComponent } from '@angular-love/blog/shared/ui-button' ;
1214
1315@Component ( {
1416 selector : 'al-related-articles' ,
1517 template : `
1618 @if (store.isFetchRelatedArticleListLoaded()) {
17- <strong class="text-3xl">Related Articles</strong>
18- <owl-carousel-o [options]="customOptions">
19- @for (article of store.relatedArticles(); track $index) {
20- <ng-template carouselSlide>
21- <al-article-card [article]="article" cardType="compact" />
22- </ng-template>
23- <ng-template carouselSlide>
24- <al-article-card [article]="article" cardType="compact" />
25- </ng-template>
26- }
27- </owl-carousel-o>
19+ <ng-container *transloco="let t; read: 'relatedArticles'">
20+ <h2 class="mb-4 text-3xl font-bold">{{ t('title') }}</h2>
21+ <div class="relative lg:px-14">
22+ <owl-carousel-o #carousel role="list" [options]="customOptions">
23+ @for (article of store.relatedArticles(); track $index) {
24+ <ng-template carouselSlide>
25+ <!-- Prevents focus rings from being cut off -->
26+ <li class="list-none py-1">
27+ <al-article-card [article]="article" cardType="compact" />
28+ </li>
29+ </ng-template>
30+ }
31+ </owl-carousel-o>
32+ <div
33+ class="absolute left-0 top-1/2 hidden w-full -translate-y-1/2 justify-between lg:flex"
34+ >
35+ <button
36+ al-button
37+ type="button"
38+ class="bg-al-pink text-white"
39+ [attr.aria-label]="t('previousSlide')"
40+ (click)="carousel.prev()"
41+ size="small"
42+ >
43+ <span class="text-2xl">‹</span>
44+ </button>
45+ <button
46+ al-button
47+ type="button"
48+ class="bg-al-pink text-white"
49+ [attr.aria-label]="t('nextSlide')"
50+ (click)="carousel.next()"
51+ size="small"
52+ >
53+ <span class="text-2xl">›</span>
54+ </button>
55+ </div>
56+ </div>
57+ </ng-container>
2858 }
2959 ` ,
3060 changeDetection : ChangeDetectionStrategy . OnPush ,
3161 providers : [ RelatedArticleListStore ] ,
32- imports : [ UiArticleCardComponent , CarouselModule ] ,
62+ imports : [
63+ UiArticleCardComponent ,
64+ CarouselModule ,
65+ ButtonComponent ,
66+ TranslocoDirective ,
67+ ] ,
3368} )
3469export class RelatedArticlesComponent implements OnInit {
3570 readonly id = input . required < number > ( ) ;
3671 customOptions : OwlOptions = {
3772 loop : true ,
3873 mouseDrag : false ,
3974 touchDrag : true ,
40- pullDrag : false ,
75+ pullDrag : true ,
4176 dots : true ,
42- margin : 24 , // Add spacing between items
77+ margin : 24 ,
4378 navSpeed : 700 ,
4479 navText : [ '' , '' ] ,
4580 responsive : {
4681 // Keep in mind these breakpoints refer to container width, not the viewport width
4782 0 : {
4883 items : 1 ,
4984 } ,
50- 640 : {
85+ 540 : {
5186 items : 2 ,
5287 } ,
5388 } ,
54- nav : true ,
5589 } ;
5690
5791 readonly store = inject ( RelatedArticleListStore ) ;
0 commit comments