add breadcrumbs

This commit is contained in:
Roland Schneider
2025-11-21 15:24:35 +01:00
parent dfc3afd4a9
commit b047ecc589
19 changed files with 294 additions and 73 deletions

View File

@@ -0,0 +1,26 @@
@if (breadcrumbs()?.length) {
<div class="breadcrumbs text-sm">
<ul>
@for (breadcrumb of breadcrumbs(); track breadcrumb; ) {
<li>
@if (breadcrumb.url) {
<a [routerLink]="breadcrumb.url">
@if (breadcrumb.showIcon !== false) {
<span [outerHTML]="(breadcrumb.svgIcon || defaultLinkIcon) | safeHtml"></span>
}
{{ breadcrumb.text }}
</a>
} @else {
<span class="inline-flex items-center gap-2">
@if (breadcrumb.showIcon !== false) {
<span [outerHTML]="(breadcrumb.svgIcon || defaultIcon) | safeHtml"></span>
}
{{ breadcrumb.text }}
</span>
}
</li>
}
</ul>
</div>
}

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Breadcrumbs } from './breadcrumbs';
describe('Breadcrumbs', () => {
let component: Breadcrumbs;
let fixture: ComponentFixture<Breadcrumbs>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Breadcrumbs]
})
.compileComponents();
fixture = TestBed.createComponent(Breadcrumbs);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,46 @@
import { Component, input } from '@angular/core';
import { Breadcrumb } from '../../daisy.types';
import { RouterLink } from '@angular/router';
import { SafeHtmlPipe } from '../../pipes/safe-html-pipe';
@Component({
selector: 'rs-daisy-breadcrumbs',
imports: [
RouterLink,
SafeHtmlPipe,
],
templateUrl: './breadcrumbs.html',
styleUrl: './breadcrumbs.css',
})
export class Breadcrumbs {
breadcrumbs = input<Breadcrumb[]>([]);
defaultLinkIcon: string = `<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
class="h-4 w-4 stroke-current">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"></path>
</svg>
`;
defaultIcon: string = `
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
class="h-4 w-4 stroke-current">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M9 13h6m-3-3v6m5 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
</svg>
`;
}

View File

@@ -11,3 +11,10 @@ export interface FooterNav{
export interface FooterConfig{
navs: FooterNav[]
}
export interface Breadcrumb{
text: string;
url?: string;
showIcon?: boolean;
svgIcon?: string;
}

View File

@@ -0,0 +1,16 @@
import { inject, Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
@Pipe({
name: 'safeHtml'
})
export class SafeHtmlPipe implements PipeTransform {
private sanitized = inject(DomSanitizer);
transform(value: string | undefined): SafeHtml {
if (!value) return '';
return this.sanitized.bypassSecurityTrustHtml(value);
}
}

View File

@@ -5,5 +5,6 @@
export * from './lib/ng-daisyui';
export * from './lib/components/button/button';
export * from './lib/components/footer/footer';
export * from './lib/components/breadcrumbs/breadcrumbs';
export * from './lib/daisy.types';
export * from './lib/layout/';