-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core/toast): add position top-right (#432)
Co-authored-by: Daniel Leroux <daniel.leroux@siemens.com>
- Loading branch information
1 parent
da7d4a6
commit ed88175
Showing
17 changed files
with
289 additions
and
10 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
packages/angular-test-app/src/preview-examples/toast-position.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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 { Component, TemplateRef, ViewChild } from '@angular/core'; | ||
import { ToastService } from '@siemens/ix-angular'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
template: ` | ||
<div> | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy | ||
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam | ||
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet | ||
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit | ||
amet. | ||
</div> | ||
<ix-button (click)="showToastMessage()">Show Toast</ix-button> | ||
`, | ||
}) | ||
export default class Toast { | ||
@ViewChild('customToast', { read: TemplateRef }) | ||
customModalRef!: TemplateRef<any>; | ||
|
||
constructor(private readonly toastService: ToastService) {} | ||
|
||
async showToastMessage() { | ||
this.toastService.setPosition('top-right'); | ||
this.toastService.show({ | ||
message: 'Hello World!', | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: 2023 Siemens AG | ||
SPDX-License-Identifier: MIT | ||
--> | ||
|
||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" | ||
/> | ||
<title>Stencil Component Starter</title> | ||
</head> | ||
<body> | ||
<ix-toast-container></ix-toast-container> | ||
<script> | ||
(async () => { | ||
await window.customElements.whenDefined('ix-toast-container'); | ||
const toastContainer = document.querySelector('ix-toast-container'); | ||
|
||
toastContainer.position = 'top-right'; | ||
|
||
toast = {}; | ||
toast.info = (config) => { | ||
toastContainer.showToast({ | ||
...config, | ||
autoClose: false, | ||
type: 'info', | ||
}); | ||
}; | ||
|
||
toast.error = (config) => { | ||
toastContainer.showToast({ | ||
...config, | ||
autoClose: false, | ||
type: 'error', | ||
}); | ||
}; | ||
|
||
toast.success = (config) => { | ||
toastContainer.showToast({ | ||
...config, | ||
autoClose: false, | ||
type: 'success', | ||
}); | ||
}; | ||
|
||
toast.warning = (config) => { | ||
toastContainer.showToast({ | ||
...config, | ||
autoClose: false, | ||
type: 'warning', | ||
}); | ||
}; | ||
|
||
toast.info({ | ||
message: 'Info', | ||
}); | ||
toast.error({ | ||
message: 'Error', | ||
}); | ||
toast.success({ | ||
message: 'Success', | ||
}); | ||
toast.warning({ | ||
message: 'Warning', | ||
}); | ||
toast.info({ | ||
icon: 'bulb', | ||
message: 'Custom icon', | ||
}); | ||
})(); | ||
</script> | ||
<script src="http://127.0.0.1:8080/scripts/e2e/load-e2e-runtime.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+24 KB
...toast.e2e.ts-snapshots/toast-position-1-chromium---theme-classic-dark-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.9 KB
...oast.e2e.ts-snapshots/toast-position-1-chromium---theme-classic-light-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/html-test-app/src/preview-examples/toast-position.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: 2023 Siemens AG | ||
SPDX-License-Identifier: MIT | ||
--> | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Test example</title> | ||
</head> | ||
<body class="theme-brand-dark"> | ||
<!-- Preview code --> | ||
<ix-toast-container></ix-toast-container> | ||
|
||
<ix-button id="toastButton">Trigger toast</ix-button> | ||
<script type="module"> | ||
import { toast, setToastPosition } from '@siemens/ix'; | ||
|
||
(async function () { | ||
await window.customElements.whenDefined('ix-toast-container'); | ||
setToastPosition('top-right'); | ||
document.getElementById('toastButton').addEventListener('click', () => { | ||
toast({ | ||
message: 'My toast message!', | ||
}); | ||
}); | ||
})(); | ||
</script> | ||
<!-- Preview code --> | ||
<script type="module" src="./init.js"></script> | ||
</body> | ||
</html> |
36 changes: 36 additions & 0 deletions
36
packages/react-test-app/src/preview-examples/toast-position.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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 { setToastPosition, ToastPosition } from '@siemens/ix'; | ||
import { IxButton, showToast } from '@siemens/ix-react'; | ||
import React, { useEffect } from 'react'; | ||
|
||
function useToastPosition(position: ToastPosition) { | ||
useEffect(() => { | ||
setToastPosition(position); | ||
}, []); | ||
} | ||
|
||
export default () => { | ||
useToastPosition('top-right'); | ||
|
||
return ( | ||
<> | ||
<IxButton | ||
onClick={() => { | ||
showToast({ | ||
message: 'My toast message!', | ||
}); | ||
}} | ||
> | ||
Trigger toast | ||
</IxButton> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.