Skip to content

Commit

Permalink
feat(core/button): enable shadowDOM (#534)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Maurer <lukas.maurer@siemens.com>
  • Loading branch information
danielleroux and nuke-ellington committed May 15, 2023
1 parent 2f94f3b commit 7f47305
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/core/component-doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@
"usage": {},
"docs": "",
"docsTags": [],
"encapsulation": "scoped",
"encapsulation": "shadow",
"dependents": [
"ix-date-picker",
"ix-datetime-picker",
Expand Down Expand Up @@ -4076,7 +4076,7 @@
"usage": {},
"docs": "",
"docsTags": [],
"encapsulation": "scoped",
"encapsulation": "shadow",
"dependents": [
"ix-category-filter",
"ix-date-picker",
Expand Down
9 changes: 3 additions & 6 deletions packages/core/scss/components/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@

.glyph {
margin-right: $tiny-space;
}

.glyph {
font-weight: $font-weight-normal;
}

Expand All @@ -42,9 +39,7 @@ $button-categories: (primary, secondary);

@mixin btn($name, $enable-border: true) {
.btn-#{$name} {
& {
border-radius: var(--theme-btn--border-radius);
}
border-radius: var(--theme-btn--border-radius);

@if $enable-border == false {
--bs-btn-border-width: 0px;
Expand All @@ -61,6 +56,8 @@ $button-categories: (primary, secondary);
border-width: var(--theme-btn--border-thickness);
border-color: var(--theme-btn-#{$name}--border-color);
border-style: solid;
} @else {
border-color: transparent;
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/components/button/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
* LICENSE file in the root directory of this source tree.
*/

@import 'common-variables';
@import './components/buttons';

:host {
display: inline-block;
width: auto;
height: 2rem;
vertical-align: middle;

&.disabled {
pointer-events: none;
Expand All @@ -20,4 +24,8 @@
width: 100%;
height: 100%;
}

button:not(:disabled) {
cursor: pointer;
}
}
2 changes: 1 addition & 1 deletion packages/core/src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type ButtonVariant = 'Primary' | 'Secondary';

@Component({
tag: 'ix-button',
scoped: true,
shadow: true,
styleUrl: './button.scss',
})
export class Button {
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/components/icon-button/icon-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

@import 'common-variables';
@import './components/buttons';

:host {
display: inline-block;
vertical-align: middle;

&.disabled {
pointer-events: none;
}
Expand All @@ -15,4 +22,8 @@
padding: 0;
overflow: hidden;
}

button:not(:disabled) {
cursor: pointer;
}
}
16 changes: 11 additions & 5 deletions packages/core/src/components/icon-button/icon-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type IconButtonVariant = ButtonVariant;
@Component({
tag: 'ix-icon-button',
styleUrl: 'icon-button.scss',
scoped: true,
shadow: true,
})
export class IconButton implements Button {
/**
Expand Down Expand Up @@ -76,6 +76,14 @@ export class IconButton implements Button {
*/
@Prop() type: 'button' | 'submit' = 'button';

private getIconSizeClass() {
return {
'btn-icon-12': this.size === '12',
'btn-icon-16': this.size === '16',
'btn-icon-32': this.size === '32' || this.size === '24' || !this.size,
};
}

private getIconButtonClasses() {
return {
...getButtonClasses(
Expand All @@ -88,15 +96,13 @@ export class IconButton implements Button {
this.disabled
),
'icon-button': true,
'btn-icon-12': this.size === '12',
'btn-icon-16': this.size === '16',
'btn-icon-32': this.size === '32' || this.size === '24' || !this.size,
...this.getIconSizeClass(),
};
}

render() {
return (
<Host class={{ disabled: this.disabled }}>
<Host class={{ ...this.getIconSizeClass(), disabled: this.disabled }}>
<button class={this.getIconButtonClasses()} type={this.type}>
<ix-icon size={this.size} name={this.icon} color={this.color} />
<div style={{ display: 'none' }}>
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.
14 changes: 12 additions & 2 deletions packages/core/src/tests/button/button.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ regressionTest.describe('button: basic', () => {
const bodyElement = await page.waitForSelector('body');

await page.evaluate((body) => {
body.querySelectorAll('button').forEach((b) => b.classList.add('hover'));
body
.querySelectorAll('ix-button')
.forEach((b) =>
b.shadowRoot.querySelector('button').classList.add('hover')
);
}, bodyElement);

await page.waitForSelector('ix-button > button.hover');
Expand All @@ -38,9 +42,15 @@ regressionTest.describe('button: basic', () => {
const bodyElement = await page.waitForSelector('body');

await page.evaluate((body) => {
body.querySelectorAll('button').forEach((b) => b.classList.add('active'));
body
.querySelectorAll('ix-button')
.forEach((b) =>
b.shadowRoot.querySelector('button').classList.add('active')
);
}, bodyElement);

await page.waitForSelector('ix-button > button.active');

expect(await page.screenshot({ fullPage: true })).toMatchSnapshot();
});
});
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 7f47305

Please sign in to comment.