Skip to content

Commit

Permalink
feat(core/breadcrumb): migrate to shadow dom (#679)
Browse files Browse the repository at this point in the history
Co-authored-by: Bergwein, Christopher (RC-AT DI PA SW) <christopher.bergwein@siemenes.com>
  • Loading branch information
christopher-bergwein-siemens and Bergwein, Christopher (RC-AT DI PA SW) committed Aug 7, 2023
1 parent a8c2187 commit f8dc56a
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 65 deletions.
4 changes: 2 additions & 2 deletions packages/core/component-doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
"usage": {},
"docs": "",
"docsTags": [],
"encapsulation": "scoped",
"encapsulation": "shadow",
"dependents": [],
"dependencies": [
"ix-icon",
Expand Down Expand Up @@ -576,7 +576,7 @@
"usage": {},
"docs": "",
"docsTags": [],
"encapsulation": "scoped",
"encapsulation": "shadow",
"dependents": [],
"dependencies": [],
"dependencyGraph": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* LICENSE file in the root directory of this source tree.
*/

@import 'mixins/shadow-dom/component';

:host {
@include ix-component;

display: block;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Component, h, Host, Prop } from '@stencil/core';
@Component({
tag: 'ix-breadcrumb-item',
styleUrl: 'breadcrumb-item.scss',
scoped: true,
shadow: true,
})
export class BreadcrumbItem {
/**
Expand Down
36 changes: 18 additions & 18 deletions packages/core/src/components/breadcrumb/breadcrumb.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
@import 'common-variables';
@import 'mixins/hover';
@import 'mixins/text-truncation';
@import 'mixins/shadow-dom/component';

@mixin crumb-hover($variant) {
@include hover {
background-color: var(--theme-breadcrumb-#{$variant}--background--hover);

.crumb-text,
.glyph {
ix-icon {
color: var(--theme-breadcrumb-#{$variant}--color--hover);
}

.crumb-text + .glyph-chevron-right-small {
.crumb-text + ix-icon {
color: var(--theme-breadcrumb-#{$variant}-arrow--color--hover);
}
}
Expand All @@ -29,11 +30,11 @@
background-color: var(--theme-breadcrumb-#{$variant}--background--active);

.crumb-text,
.glyph {
ix-icon {
color: var(--theme-breadcrumb-#{$variant}--color--active);
}

.crumb-text + .glyph-chevron-right-small {
.crumb-text + ix-icon {
color: var(--theme-breadcrumb-#{$variant}-arrow--color--active);
}
}
Expand All @@ -46,11 +47,11 @@
transition: $default-time;

.crumb-text,
.glyph {
ix-icon {
color: var(--theme-breadcrumb-#{$variant}--color);
}

.crumb-text + .glyph-chevron-right-small {
.crumb-text + ix-icon {
color: var(--theme-breadcrumb-#{$variant}-arrow--color);
}

Expand All @@ -65,11 +66,11 @@
);

.crumb-text,
.glyph {
ix-icon {
color: var(--theme-breadcrumb-#{$variant}--color--hover);
}

.crumb-text + .glyph-chevron-right-small {
.crumb-text + ix-icon {
color: var(--theme-breadcrumb-#{$variant}-arrow--color--hover);
}
}
Expand All @@ -80,11 +81,11 @@
);

.crumb-text,
.glyph {
ix-icon {
color: var(--theme-breadcrumb-#{$variant}--color--active);
}

.crumb-text + .glyph-chevron-right-small {
.crumb-text + ix-icon {
color: var(--theme-breadcrumb-#{$variant}-arrow--color--active);
}
}
Expand All @@ -93,6 +94,8 @@
}

:host {
@include ix-component;

display: flex;
height: $large-control-height;
justify-content: flex-start;
Expand Down Expand Up @@ -129,9 +132,8 @@
}
}

.crumb-text + .glyph-chevron-right-small {
.crumb-text + ix-icon {
margin-inline-start: $tiny-space;
margin-inline-end: 0; // Overwrite global selector: .btn .glyph
}

&.last {
Expand All @@ -154,10 +156,6 @@

.crumb-dropdown {
overflow: visible;

.glyph::after {
display: none;
}
}

.remove-anchor::after {
Expand All @@ -173,8 +171,10 @@
font-weight: $font-weight-bold;
}

.glyph {
line-height: unset;
ix-icon {
// line-height: unset; --> Note: 'line-height' can't be applied due to shadow DOM encapsulation at ix-icon
// using padding-top to achieve same position as before
padding-top: 2px;
}
}

Expand Down
21 changes: 10 additions & 11 deletions packages/core/src/components/breadcrumb/breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { createMutationObserver } from '../utils/mutation-observer';
@Component({
tag: 'ix-breadcrumb',
styleUrl: 'breadcrumb.scss',
scoped: true,
shadow: true,
})
export class Breadcrumb {
/**
Expand Down Expand Up @@ -62,7 +62,9 @@ export class Breadcrumb {
}

get crumbItems() {
return Array.from(this.hostElement.querySelectorAll('.crumb-items .crumb'));
return Array.from(
this.hostElement.shadowRoot.querySelectorAll('.crumb-items .crumb')
);
}

@State() items: { label: string; icon?: string }[] = [];
Expand All @@ -88,13 +90,10 @@ export class Breadcrumb {
}
});

this.mutationObserver.observe(
this.hostElement.querySelector('.crumb-items'),
{
subtree: true,
childList: true,
}
);
this.mutationObserver.observe(this.hostElement, {
subtree: true,
childList: true,
});
}

componentWillLoad() {
Expand Down Expand Up @@ -190,7 +189,7 @@ export class Breadcrumb {
</span>
</span>
{!isLastItem ? (
<span class="glyph glyph-18 glyph-chevron-right-small text-default-text"></span>
<ix-icon name="chevron-right-small" size="24"></ix-icon>
) : null}
</div>
);
Expand Down Expand Up @@ -223,7 +222,7 @@ export class Breadcrumb {
>
<span class="remove-anchor more-text">
<span class="more-text-ellipsis">...</span>
<span class="glyph glyph-16 glyph-chevron-right"></span>
<ix-icon name="chevron-right" size="16"></ix-icon>
</span>
</div>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,42 @@

exports[`ix-breadcrumb renders 1`] = `
<ix-breadcrumb>
<!---->
<ix-dropdown></ix-dropdown>
<div class="crumb-items">
<div class="btn clickable crumb" data-breadcrumb="0" data-testid="item">
<span class="crumb-text remove-anchor">
<span style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"></span>
</span>
<span class="glyph glyph-18 glyph-chevron-right-small text-default-text"></span>
<mock:shadow-root>
<ix-dropdown></ix-dropdown>
<div class="crumb-items">
<div class="btn clickable crumb" data-breadcrumb="0" data-testid="item">
<span class="crumb-text remove-anchor">
<span style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"></span>
</span>
<ix-icon name="chevron-right-small" size="24"></ix-icon>
</div>
<div class="btn clickable crumb" data-breadcrumb="1" data-testid="item">
<span class="crumb-text remove-anchor">
<span style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"></span>
</span>
<ix-icon name="chevron-right-small" size="24"></ix-icon>
</div>
<div class="btn clickable crumb" data-breadcrumb="2" data-testid="item">
<span class="crumb-text remove-anchor">
<span style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"></span>
</span>
<ix-icon name="chevron-right-small" size="24"></ix-icon>
</div>
<div class="btn clickable crumb last remove-hover" data-breadcrumb="3" data-testid="item">
<span class="crumb-text remove-anchor">
<span style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"></span>
</span>
</div>
<slot></slot>
</div>
<div class="btn clickable crumb" data-breadcrumb="1" data-testid="item">
<span class="crumb-text remove-anchor">
<span style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"></span>
</span>
<span class="glyph glyph-18 glyph-chevron-right-small text-default-text"></span>
</div>
<div class="btn clickable crumb" data-breadcrumb="2" data-testid="item">
<span class="crumb-text remove-anchor">
<span style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"></span>
</span>
<span class="glyph glyph-18 glyph-chevron-right-small text-default-text"></span>
</div>
<div class="btn clickable crumb last remove-hover" data-breadcrumb="3" data-testid="item">
<span class="crumb-text remove-anchor">
<span style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"></span>
</span>
</div>
<ix-breadcrumb-item label="Test 1">
<ix-breadcrumb-item label="Test 2">
<ix-breadcrumb-item label="Test 3">
<ix-breadcrumb-item label="Test 4"></ix-breadcrumb-item>
</ix-breadcrumb-item>
<ix-dropdown></ix-dropdown>
</mock:shadow-root>
<ix-breadcrumb-item label="Test 1">
<ix-breadcrumb-item label="Test 2">
<ix-breadcrumb-item label="Test 3">
<ix-breadcrumb-item label="Test 4"></ix-breadcrumb-item>
</ix-breadcrumb-item>
</ix-breadcrumb-item>
</div>
<ix-dropdown></ix-dropdown>
</ix-breadcrumb-item>
</ix-breadcrumb>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ describe('ix-breadcrumb', () => {
let callbackSpy = jest.fn();
page.win.addEventListener('itemClick', callbackSpy);

let item = page.doc.querySelector('[data-testid="item"]');
let item = page.doc
.querySelector('ix-breadcrumb')
.shadowRoot.querySelector('[data-testid="item"]');
fireEvent.click(item);
await page.waitForChanges();

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f8dc56a

Please sign in to comment.