mirror of
https://github.com/immich-app/immich.git
synced 2025-12-19 09:13:14 +03:00
fix(web): consistent modal escape behavior (#7677)
* fix(web): consistent modal escape behavior * make onClose optional
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import FullScreenModal from './full-screen-modal.svelte';
|
||||
import Button from '../elements/buttons/button.svelte';
|
||||
import type { Color } from '$lib/components/elements/buttons/button.svelte';
|
||||
@@ -13,29 +12,18 @@
|
||||
export let hideCancelButton = false;
|
||||
export let disabled = false;
|
||||
export let width = 500;
|
||||
|
||||
const dispatch = createEventDispatcher<{ cancel: void; confirm: void; 'click-outside': void }>();
|
||||
export let onClose: () => void;
|
||||
export let onConfirm: () => void;
|
||||
|
||||
let isConfirmButtonDisabled = false;
|
||||
|
||||
const handleCancel = () => dispatch('cancel');
|
||||
const handleEscape = () => {
|
||||
if (!isConfirmButtonDisabled) {
|
||||
dispatch('cancel');
|
||||
}
|
||||
};
|
||||
|
||||
const handleConfirm = () => {
|
||||
isConfirmButtonDisabled = true;
|
||||
dispatch('confirm');
|
||||
};
|
||||
|
||||
const handleClickOutside = () => {
|
||||
dispatch('click-outside');
|
||||
onConfirm();
|
||||
};
|
||||
</script>
|
||||
|
||||
<FullScreenModal on:clickOutside={handleClickOutside} on:escape={() => handleEscape()}>
|
||||
<FullScreenModal {onClose}>
|
||||
<div
|
||||
class="max-w-[95vw] rounded-3xl border bg-immich-bg p-4 py-8 shadow-sm dark:border-immich-dark-gray dark:bg-immich-dark-gray dark:text-immich-dark-fg"
|
||||
style="width: {width}px"
|
||||
@@ -56,7 +44,7 @@
|
||||
|
||||
<div class="mt-4 flex w-full gap-4 px-4">
|
||||
{#if !hideCancelButton}
|
||||
<Button color={cancelColor} fullwidth on:click={handleCancel}>
|
||||
<Button color={cancelColor} fullwidth on:click={onClose}>
|
||||
{cancelText}
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user