-
Notifications
You must be signed in to change notification settings - Fork 114
feat(modal)- Return closable instance #2159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
1307-Dev
wants to merge
14
commits into
siemens:main
Choose a base branch
from
1307-Dev:ix-modal-close
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
78c5257
Added code for angular
1307-Dev 133ee19
Added dismissmodal for react and vue
1307-Dev 6cbd467
Added close event to angular standalone
1307-Dev db59916
Renamed some functions
1307-Dev f643c2e
Added preview examples for modal close
1307-Dev 7c22e26
Sonarlint error fix
1307-Dev 16dab32
Added lint error fix
1307-Dev d44eaa9
Addressing review comments
1307-Dev 74bc48f
Create sharp-ladybugs-clap.md
nuke-ellington 351a134
Merge branch 'main' into ix-modal-close
1307-Dev 0c0be40
Added comment changes and corrected build fails
1307-Dev d5532be
Create-sbom fail
1307-Dev 5a5f0ae
added closemodal function imports as well
1307-Dev e1b3f1e
Merge branch 'main' into ix-modal-close
1307-Dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,7 @@ | ||
| --- | ||
| "@siemens/ix-angular": patch | ||
| "@siemens/ix-react": patch | ||
| "@siemens/ix-vue": patch | ||
| --- | ||
|
|
||
| Add dismissModal function to allow programmatic closing of **ix-modal**s. |
This file contains hidden or 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
35 changes: 35 additions & 0 deletions
35
packages/angular-standalone-test-app/src/preview-examples/modal-close.ts
This file contains hidden or 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,35 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 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 } from '@angular/core'; | ||
| import { IxButton } from '@siemens/ix-angular/standalone'; | ||
|
|
||
| import { ModalService } from '@siemens/ix-angular'; | ||
| import ModalByInstanceExample from './modal-by-instance-content'; | ||
|
|
||
| @Component({ | ||
| standalone: true, | ||
| selector: 'app-example', | ||
| imports: [IxButton], | ||
| template: | ||
| '<ix-button (click)="openModal()">Show modal (auto-dismiss)</ix-button>', | ||
| }) | ||
| export default class ModalClose { | ||
| constructor(private readonly modalService: ModalService) {} | ||
|
|
||
| async openModal() { | ||
| const modalInstance = await this.modalService.open({ | ||
| content: ModalByInstanceExample, | ||
| data: 'Some data', | ||
| }); | ||
| setTimeout(() => { | ||
| this.modalService.close(modalInstance, 'closed after 5 seconds'); | ||
| }, 5000); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
32 changes: 32 additions & 0 deletions
32
packages/angular-test-app/src/preview-examples/modal-close.ts
This file contains hidden or 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,32 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 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 } from '@angular/core'; | ||
| import { ModalService } from '@siemens/ix-angular'; | ||
| import ModalByInstanceExample from './modal-by-instance-content'; | ||
|
|
||
| @Component({ | ||
| standalone: false, | ||
| selector: 'app-example', | ||
| template: | ||
| '<ix-button (click)="openModal()">Show modal (auto-dismiss)</ix-button>', | ||
| }) | ||
| export default class ModalClose { | ||
| constructor(private readonly modalService: ModalService) {} | ||
|
|
||
| async openModal() { | ||
| const modalInstance = await this.modalService.open({ | ||
| content: ModalByInstanceExample, | ||
| data: 'Some data', | ||
| }); | ||
| setTimeout(() => { | ||
| this.modalService.close(modalInstance, 'closed after 5 seconds'); | ||
| }, 5000); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
96 changes: 96 additions & 0 deletions
96
packages/html-test-app/src/preview-examples/modal-close.html
This file contains hidden or 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,96 @@ | ||
| <!-- | ||
| SPDX-FileCopyrightText: 2025 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. | ||
| --> | ||
|
|
||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Modal example</title> | ||
| </head> | ||
| <body> | ||
| <ix-button>Show modal (auto-dismiss)</ix-button> | ||
| <template id="modal-example-template"> | ||
| <ix-modal-header>Message headline</ix-modal-header> | ||
| <ix-modal-content>Message text lorem ipsum</ix-modal-content> | ||
| <ix-modal-footer> | ||
| <ix-button outline data-cancel>Cancel</ix-button> | ||
| <ix-button data-okay>OK</ix-button> | ||
| </ix-modal-footer> | ||
| </template> | ||
|
|
||
| <script type="module"> | ||
| import { showModal, closeModal, dismissModal } from '@siemens/ix'; | ||
|
|
||
| function createExampleModal() { | ||
| const name = 'modal-example'; | ||
| window.customElements.define( | ||
| name, | ||
| class extends HTMLElement { | ||
| isInitalRender = false; | ||
|
|
||
| constructor() { | ||
| super(); | ||
| } | ||
|
|
||
| connectedCallback() { | ||
| if (this.isInitalRender) { | ||
| return; | ||
| } | ||
|
|
||
| this.isInitalRender = true; | ||
| this.firstRender(); | ||
| } | ||
|
|
||
| firstRender() { | ||
| const modalTemplate = document.getElementById( | ||
| 'modal-example-template' | ||
| ); | ||
| const template = modalTemplate.content.cloneNode(true); | ||
|
|
||
| const cancelButton = template.querySelector('[data-cancel]'); | ||
| const okayButton = template.querySelector('[data-okay]'); | ||
|
|
||
| cancelButton.addEventListener('click', () => { | ||
| dismissModal(this); | ||
| }); | ||
| okayButton.addEventListener('click', () => { | ||
| closeModal(this); | ||
| }); | ||
|
|
||
| this.append(template); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| return name; | ||
| } | ||
|
|
||
| (async function () { | ||
| const exampleModalName = createExampleModal(); | ||
|
|
||
| await window.customElements.whenDefined('ix-button'); | ||
| const button = document.querySelector('ix-button'); | ||
|
|
||
| button.addEventListener('click', async () => { | ||
| const customModal = document.createElement(exampleModalName); | ||
|
|
||
| const modal = await showModal({ | ||
| content: customModal, | ||
| }); | ||
|
|
||
| setTimeout(() => { | ||
| closeModal(customModal, 'closed after 5 seconds'); | ||
| }, 5000); | ||
| }); | ||
| })(); | ||
| </script> | ||
| <script type="module" src="./init.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or 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
63 changes: 63 additions & 0 deletions
63
packages/react-test-app/src/preview-examples/modal-close.tsx
This file contains hidden or 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,63 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 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 { | ||
| IxButton, | ||
| IxModalContent, | ||
| IxModalFooter, | ||
| IxModalHeader, | ||
| Modal, | ||
| ModalRef, | ||
| showModal, | ||
| dismissModal, | ||
| } from '@siemens/ix-react'; | ||
| import { useRef } from 'react'; | ||
|
|
||
| function CustomModal() { | ||
| const modalRef = useRef<ModalRef>(null); | ||
|
|
||
| const close = () => { | ||
| modalRef.current?.close('close payload!'); | ||
| }; | ||
| const dismiss = () => { | ||
| modalRef.current?.dismiss('dismiss payload'); | ||
| }; | ||
|
|
||
| return ( | ||
| <Modal ref={modalRef}> | ||
| <IxModalHeader onCloseClick={() => dismiss()}> | ||
| Message headline | ||
| </IxModalHeader> | ||
| <IxModalContent>Message text lorem ipsum</IxModalContent> | ||
| <IxModalFooter> | ||
| <IxButton outline onClick={() => dismiss()}> | ||
| Cancel | ||
| </IxButton> | ||
| <IxButton onClick={() => close()}>OK</IxButton> | ||
| </IxModalFooter> | ||
| </Modal> | ||
| ); | ||
| } | ||
|
|
||
| export default () => { | ||
| async function show() { | ||
| const modalInstance = await showModal({ | ||
| content: <CustomModal />, | ||
| }); | ||
| setTimeout(() => { | ||
| dismissModal(modalInstance); | ||
| }, 5000); | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <IxButton onClick={show}>Show modal (auto-dismiss)</IxButton> | ||
| </> | ||
| ); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed? Will be inherited from base ModalService, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have implemented it similar to the open service, should changes be made there too?