-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 81-feature-frontend-for-engine-configuration…
…-group5
- Loading branch information
Showing
9 changed files
with
84 additions
and
125 deletions.
There are no files selected for viewing
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,3 @@ | ||
|
||
|
||
|
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 |
---|---|---|
@@ -1,62 +1,66 @@ | ||
<script lang="ts"> | ||
let dialogContainer: HTMLDialogElement; | ||
export let ModalCloseOnBackdrop: boolean = false; | ||
let dialog: HTMLDialogElement | undefined; | ||
/** | ||
* Function for showing the current modal | ||
* Allows the user to close the modal by clicking outside it. | ||
*/ | ||
export function showModal() { | ||
dialogContainer.showModal(); | ||
} | ||
export let closeOnBackdrop: boolean = false; | ||
/** | ||
* Function for closing the current modal | ||
* Whether or not the modal is open or closed. | ||
*/ | ||
export function closeModal() { | ||
dialogContainer.close(); | ||
export let show: boolean = false; | ||
/** | ||
* Ensures that the real DOM element is opened or closed when the svelte value changes. | ||
*/ | ||
$: if (dialog && show) { | ||
dialog.showModal(); | ||
} else { | ||
dialog?.close(); | ||
} | ||
/** | ||
* Function for closing the current modal when the backdrop is clicked if | ||
* ModalCloseOnBackdrop is true | ||
* Closes the modal if the user clicks outside it | ||
* Only works if closeOnBackdrop is true | ||
*/ | ||
function closeModalOnBackdropClick() { | ||
if (ModalCloseOnBackdrop) { | ||
dialogContainer.close(); | ||
function closeOnBackdropClick(event: MouseEvent) { | ||
if (!closeOnBackdrop) return; | ||
if (!dialog) { | ||
throw new TypeError("Dialog should always be defined on mount"); | ||
} | ||
/** | ||
* TODO: Is there really no better way to check if the user clicked outside? | ||
*/ | ||
const rect = dialog.getBoundingClientRect(); | ||
const clickIsOnDialog = | ||
rect.top <= event.clientY && | ||
event.clientY <= rect.top + rect.height && | ||
rect.left <= event.clientX && | ||
event.clientX <= rect.left + rect.width; | ||
if (!clickIsOnDialog) { | ||
show = false; | ||
} | ||
} | ||
</script> | ||
|
||
<!--TODO: Remove this when supported by Svelte--> | ||
<!-- svelte-ignore a11y-click-events-have-key-events a11y-no-noninteractive-element-interactions --> | ||
<dialog | ||
bind:this={dialogContainer} | ||
on:click|self={() => { | ||
closeModalOnBackdropClick(); | ||
bind:this={dialog} | ||
on:click|self={(event) => { | ||
closeOnBackdropClick(event); | ||
}} | ||
> | ||
<div class="box"> | ||
<slot /> | ||
</div> | ||
<slot /> | ||
</dialog> | ||
|
||
<style> | ||
.box { | ||
max-width: 100vw; | ||
display: block; | ||
position: fixed; | ||
background-color: var(--modal-background-color); | ||
z-index: 100; | ||
transform: translate(-50%, -50%); | ||
top: 50%; | ||
left: 50%; | ||
} | ||
dialog { | ||
max-width: 100vw; | ||
width: 100vw; | ||
max-height: 100vh; | ||
height: 100vh; | ||
background-color: rgba(0, 0, 0, 0.2); | ||
color: var(--text-color); | ||
background-color: var(--background-color); | ||
} | ||
dialog::backdrop { | ||
background-color: var(--modal-background-color); | ||
} | ||
</style> |
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,3 @@ | ||
import { writable } from "svelte/store"; | ||
|
||
export const showSettings = writable(false); |
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