-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(breadcrumb): add breadcrumb component #460
feat(breadcrumb): add breadcrumb component #460
Conversation
Close #459 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breadcrumb component/directive looks good. Left a few suggestions
apps/app/src/app/pages/(components)/components/(breadcrumb)/breadcrumb.page.ts
Show resolved
Hide resolved
libs/ui/breadcrumb/helm/src/lib/breadcrumb-separator.component.ts
Outdated
Show resolved
Hide resolved
libs/ui/breadcrumb/helm/src/lib/breadcrumb-separator.component.ts
Outdated
Show resolved
Hide resolved
apps/app/src/app/pages/(components)/components/(breadcrumb)/breadcrumb--collapsed.example.ts
Outdated
Show resolved
Hide resolved
libs/ui/breadcrumb/helm/src/lib/breadcrumb-separator.component.ts
Outdated
Show resolved
Hide resolved
I noticed one more difference between Maybe the <nav hlmBreadcrumb>
<ol hlmBreadcrumbList>
<li hlmBreadcrumbItem>
<a hlmBreadcrumbLink href="/home">Home</a>
</li>
- <li hlmBreadcrumbItem>
- <hlm-breadcrumb-separator />
- </li>
+ <hlm-breadcrumb-separator />
<li hlmBreadcrumbItem>
<hlm-breadcrumb-ellipsis />
</li>
</ol>
</nav> Alternative would be to follow the |
@marcjulian your suggestion is my first solution for separator component, because I want to keep it same as Shadcn. But I decided to wrap |
I think you are correct, its best to always have a Apply the attributes with import { Directive, computed, contentChild, input } from '@angular/core';
import { hlm } from '@spartan-ng/ui-core';
import { ClassValue } from 'clsx';
import { HlmBreadcrumbSeparatorComponent } from './breadcrumb-separator.component';
@Directive({
selector: '[hlmBreadcrumbItem]',
standalone: true,
host: {
'[class]': '_computedClass()',
// only applied if a HlmBreadcrumbSeparatorComponent is present
'[role]': 'seperatorAttributes().role',
'[attr.aria-hidden]': 'seperatorAttributes().ariaHidden',
},
})
export class HlmBreadcrumbItemDirective {
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() => hlm('inline-flex items-center gap-1.5', this.userClass()));
// if a HlmBreadcrumbSeparatorComponent is present, we need to add additional attributes to the li item
protected readonly seperator = contentChild(HlmBreadcrumbSeparatorComponent);
protected readonly seperatorAttributes = computed(() => {
const separator = this.seperator();
return {
role: separator ? 'presentation' : undefined,
ariaHidden: separator ? 'true' : undefined,
};
});
} |
@marcjulian It look nice. I think this is the only way to keep the template markup style and result after render same as Shadcn. |
@marcjulian an idea popped into my head as i updated my code. I will change the selector of import { Component, computed, input } from '@angular/core';
import { lucideChevronRight } from '@ng-icons/lucide';
import { hlm } from '@spartan-ng/ui-core';
import { HlmIconComponent, provideIcons } from '@spartan-ng/ui-icon-helm';
import { ClassValue } from 'clsx';
@Component({
// Change the selector
selector: '[hlmBreadcrumbSeparator]',
standalone: true,
imports: [HlmIconComponent],
providers: [provideIcons({ lucideChevronRight })],
host: {
role: 'presentation',
'[class]': '_computedClass()',
'[attr.aria-hidden]': 'true',
},
template: `
<ng-content>
<hlm-icon name="lucideChevronRight" class="h-3.5 w-3.5" />
</ng-content>
`,
})
export class HlmBreadcrumbSeparatorComponent {
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() => hlm('h-3.5', this.userClass()));
} And the template markup will be like: <li hlmBreadcrumbSeparator></li> For case custom separator: <li hlmBreadcrumbSeparator>
<hlm-icon name="lucideSlash" class="h-4 w-4" />
</li> With this approach, we can keep the How do you think about this approach? |
Thats an even better solution. Just a question is Perhaps |
@marcjulian But now I found a solution to fix it, I will set the import { Component, computed, input } from '@angular/core';
import { lucideChevronRight } from '@ng-icons/lucide';
import { hlm } from '@spartan-ng/ui-core';
import { HlmIconComponent, provideIcons } from '@spartan-ng/ui-icon-helm';
import { ClassValue } from 'clsx';
@Component({
selector: '[hlmBreadcrumbSeparator]',
standalone: true,
imports: [HlmIconComponent],
providers: [provideIcons({ lucideChevronRight })],
host: {
role: 'presentation',
'[class]': '_computedClass()',
'[attr.aria-hidden]': 'true',
},
template: `
<ng-content>
<hlm-icon name="lucideChevronRight" />
</ng-content>
`,
})
export class HlmBreadcrumbSeparatorComponent {
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() =>
hlm('[&>hlm-icon]:w-3.5 [&>hlm-icon]:h-3.5 [&>hlm-icon]:flex', this.userClass()),
);
} |
That looks good too me! |
The breadcrumb component looks clean! @goetzrobin this looks good and uses a similar approach as the pagination component. This contains a breaking change because of the updated ng-icon package, as stated in the PR description. |
@marcjulian @goetzrobin I saw @ng-icon was updated to v 29.10.0 in latest main, so this PR will not contain any breaking change. |
@dongphuong0905 there's a couple issues with linting that need to be addressed and for the commit message it just needs to start with lowercase. Let me know if you need help with this! |
@goetzrobin I fixed the lint error, but for the commitlint, I have a uppercase on the first message. Do you have any idea to fix this commit message? |
I can take care of it while merging! |
@goetzrobin Thanks a lot 😄 |
Hey @dongphuong0905 I checked the code, I have one recommendation. For the seperator you are always providing the chevronIconRight. Maybe it make sense to create a brain directive which is handling that dynamicly like
After that angular don't have to provide every time the icon and the hlm-icon in case that someone want to have custom seperator |
Hi @MerlinMoos, IMHO, I think code will be more simple and maintainable with this approach. This is the screenshot of DOM when I use custom separator, It only have slash icon 😄 |
Hi @goetzrobin, |
PR #499 was merged. So I will close this PR |
PR Checklist
Please check if your PR fulfills the following requirements:
guidelines: https://github.com/goetzrobin/spartan/blob/main/CONTRIBUTING.md#-commit-message-guidelines
PR Type
What kind of change does this PR introduce?
Which package are you modifying?
What is the current behavior?
Closes #
What is the new behavior?
Does this PR introduce a breaking change?
Other information