Skip to content

Commit

Permalink
feat(core/toast): enable shadow dom (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-bergwein-siemens committed Jun 15, 2023
1 parent 898ae23 commit 8ac2a47
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 76 deletions.
5 changes: 5 additions & 0 deletions packages/angular-test-app/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import Tile from 'src/preview-examples/tile';
import Timepicker from 'src/preview-examples/timepicker';
import Toast from 'src/preview-examples/toast';
import ToastCustom from 'src/preview-examples/toast-custom';
import ToastPosition from 'src/preview-examples/toast-position';
import Toggle from 'src/preview-examples/toggle';
import ToggleCustomLabel from 'src/preview-examples/toggle-custom-label';
import ToggleCustomDisabled from 'src/preview-examples/toggle-disabled';
Expand Down Expand Up @@ -161,6 +162,10 @@ const routes: Routes = [
path: 'toast-custom',
component: ToastCustom,
},
{
path: 'toast-position',
component: ToastPosition,
},
{
path: 'tree',
component: Tree,
Expand Down
2 changes: 2 additions & 0 deletions packages/angular-test-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import Tile from 'src/preview-examples/tile';
import Timepicker from 'src/preview-examples/timepicker';
import Toast from 'src/preview-examples/toast';
import ToastCustom from 'src/preview-examples/toast-custom';
import ToastPosition from 'src/preview-examples/toast-position';
import Toggle from 'src/preview-examples/toggle';
import ToggleCustomLabel from 'src/preview-examples/toggle-custom-label';
import ToggleCustomDisabled from 'src/preview-examples/toggle-disabled';
Expand All @@ -123,6 +124,7 @@ import { NavigationTestComponent } from './components/navigation-test.component'
Modal,
Toast,
ToastCustom,
ToastPosition,
Tree,
TreeCustom,
AboutAndLegal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* LICENSE file in the root directory of this source tree.
*/

import { Component, TemplateRef, ViewChild } from '@angular/core';
import { Component } from '@angular/core';
import { ToastService } from '@siemens/ix-angular';

@Component({
Expand All @@ -23,10 +23,7 @@ import { ToastService } from '@siemens/ix-angular';
<ix-button (click)="showToastMessage()">Show Toast</ix-button>
`,
})
export default class Toast {
@ViewChild('customToast', { read: TemplateRef })
customModalRef!: TemplateRef<any>;

export default class ToastPosition {
constructor(private readonly toastService: ToastService) {}

async showToastMessage() {
Expand Down
5 changes: 1 addition & 4 deletions packages/angular-test-app/src/preview-examples/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* LICENSE file in the root directory of this source tree.
*/

import { Component, TemplateRef, ViewChild } from '@angular/core';
import { Component } from '@angular/core';
import { ToastService } from '@siemens/ix-angular';

@Component({
Expand All @@ -24,9 +24,6 @@ import { ToastService } from '@siemens/ix-angular';
`,
})
export default class Toast {
@ViewChild('customToast', { read: TemplateRef })
customModalRef!: TemplateRef<any>;

constructor(private readonly toastService: ToastService) {}

async showToastMessage() {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/component-doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9455,7 +9455,7 @@
"usage": {},
"docs": "",
"docsTags": [],
"encapsulation": "scoped",
"encapsulation": "shadow",
"dependents": [
"ix-toast-container"
],
Expand Down Expand Up @@ -9617,7 +9617,7 @@
"usage": {},
"docs": "",
"docsTags": [],
"encapsulation": "scoped",
"encapsulation": "shadow",
"dependents": [],
"dependencies": [
"ix-toast"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
*/

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

:host {
@include ix-component;
}

#toast-container {
> :not(:last-child) {
Expand Down
45 changes: 0 additions & 45 deletions packages/core/src/components/toast/test/cw-toast.spec.tsx

This file was deleted.

48 changes: 48 additions & 0 deletions packages/core/src/components/toast/test/toast.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* SPDX-FileCopyrightText: 2023 Siemens AG
*
* SPDX-License-Identifier: MIT
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import { newSpecPage } from '@stencil/core/testing';
import '@testing-library/jest-dom';
import { Toast } from '../toast';

describe('toast', () => {
it('renders', async () => {
const page = await newSpecPage({
components: [Toast],
html: '<ix-toast toast-title="Test title">Test message</ix-toast>',
});

await page.waitForChanges();

expect(page.root).toEqualHtml(`
<ix-toast class=\"animate__animated animate__fadeIn\" toast-title=\"Test title\">
<mock:shadow-root>
<div class=\"toast-body\">
<div class="toast-icon">
<ix-icon color="color-std-text" name="info" size="24"></ix-icon>
</div>
<div class=\"toast-content\">
<div class=\"toast-title\">
Test title
</div>
<div class=\"toast-message\">
<slot></slot>
</div>
</div>
<div class=\"toast-close\">
<ix-icon-button icon=\"close\" ghost=\"\" size=\"24\"></ix-icon-button>
</div>
</div>
<div class=\"toast-progress-bar toast-progress-bar--animated\" style=\"animation-duration: 5000ms; animation-play-state: running;\"></div>
</mock:shadow-root>
Test message
</ix-toast>
`);
});
});
14 changes: 2 additions & 12 deletions packages/core/src/components/toast/toast-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,15 @@
* LICENSE file in the root directory of this source tree.
*/

import {
Component,
Element,
h,
Host,
Method,
Prop,
Watch,
} from '@stencil/core';
import { Component, h, Host, Method, Prop, Watch } from '@stencil/core';
import { TypedEvent } from '../utils/typed-event';
import { ToastConfig } from './toast-utils';

@Component({
tag: 'ix-toast-container',
scoped: true,
shadow: true,
})
export class ToastContainer {
@Element() host!: HTMLIxToastContainerElement;

/**
*/
@Prop() containerId = 'toast-container';
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/components/toast/toast.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
@import 'common-variables';
@import 'mixins/hover';
@import 'mixins/text-truncation';
@import 'mixins/shadow-dom/component';
@import 'mixins/fonts';

:host {
@include ix-component;

display: flex;
flex-direction: column;
position: relative;
Expand Down Expand Up @@ -52,8 +56,13 @@
);
margin-bottom: $medium-space;

.toast-title {
@include text-default-title-single;
}
.toast-message {
min-width: 0;

@include text-default;
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions packages/core/src/components/toast/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ToastType } from './toast-utils';
@Component({
tag: 'ix-toast',
styleUrl: 'toast.scss',
scoped: true,
shadow: true,
})
export class Toast {
/**
Expand Down Expand Up @@ -63,7 +63,7 @@ export class Toast {
@State() progress = 0;
@State() touched = false;

@Element() host!: HTMLIxToastElement;
@Element() hostElement!: HTMLIxToastElement;

private getIcon() {
if (this.icon) {
Expand All @@ -89,8 +89,8 @@ export class Toast {
}

private close() {
if (this.host) {
this.host.classList.add('animate__fadeOut');
if (this.hostElement) {
this.hostElement.classList.add('animate__fadeOut');
}
setTimeout(() => {
this.closeToast.emit();
Expand Down Expand Up @@ -125,11 +125,9 @@ export class Toast {
) : null}
<div class="toast-content">
{this.toastTitle ? (
<div class="toast-title text-default-title-single">
{this.toastTitle}
</div>
<div class="toast-title">{this.toastTitle}</div>
) : null}
<div class="toast-message text-default">
<div class="toast-message">
<slot></slot>
</div>
</div>
Expand Down

0 comments on commit 8ac2a47

Please sign in to comment.