Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion nx2/blocks/shared/breadcrumb/breadcrumb.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
gap: 0;
min-width: 0;
font-family: var(--s2-font-family);
font-size: var(--s2-component-m-regular-font-size);
font-size: var(--nx-breadcrumb-font-size, var(--s2-component-m-regular-font-size));
line-height: var(--s2-component-m-regular-line-height);
font-weight: var(--s2-component-m-regular-font-weight);
color: var(--s2-gray-700);
Expand Down Expand Up @@ -61,3 +61,18 @@
color: var(--s2-gray-800);
font-weight: var(--s2-component-m-bold-font-weight);
}

::slotted([slot="leaf"]) {
display: inline-flex;
align-items: center;
flex-shrink: 0;
}

.crumb-suffix {
display: flex;
align-items: center;
}

.crumb-suffix.hide {
display: none;
}
18 changes: 15 additions & 3 deletions nx2/blocks/shared/breadcrumb/breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ export default class NxBreadcrumb extends LitElement {
static properties = {
pathSegments: { type: Array, attribute: false },
baseUrl: { type: String, attribute: false },
_hasSuffix: { state: true },
};

connectedCallback() {
super.connectedCallback();
this.shadowRoot.adoptedStyleSheets = [style];
}

firstUpdated() {
const slot = this.shadowRoot.querySelector('slot[name="suffix"]');
slot.addEventListener('slotchange', () => {
this._hasSuffix = slot.assignedElements().length > 0;
});
}

render() {
const crumbs = pathSegmentsToCrumbs(this.pathSegments, { baseUrl: this.baseUrl });
if (!crumbs.length) return nothing;
Expand All @@ -24,11 +32,15 @@ export default class NxBreadcrumb extends LitElement {
<ol>
${crumbs.map((c, i) => html`
<li class="crumb">
${i === crumbs.length - 1
? html`<span class="current" aria-current="page">${c.label}</span>`
: html`<a href="${c.href}">${c.label}</a>`}
${i === crumbs.length - 1
? html`<span class="current" aria-current="page">${c.label}</span>
<slot name="leaf"></slot>`
: html`<a href="${c.href}">${c.label}</a>`}
</li>
`)}
<li class="crumb crumb-suffix ${this._hasSuffix ? '' : 'hide'}">
<slot name="suffix"></slot>
</li>
</ol>
</nav>
`;
Expand Down
Loading