dialog: expose frozen, disabled, loading as bindable props
This commit is contained in:
@@ -83,6 +83,9 @@
|
||||
controls?: Snippet | DialogControlOpts;
|
||||
onopen?: (dialog: DialogAPI) => void;
|
||||
onclose?: (dialog: DialogAPI) => void;
|
||||
loading?: boolean;
|
||||
frozen?: boolean;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -94,14 +97,14 @@
|
||||
children,
|
||||
controls,
|
||||
onopen,
|
||||
onclose
|
||||
onclose,
|
||||
loading = $bindable(false),
|
||||
frozen = $bindable(false),
|
||||
disabled = $bindable(false)
|
||||
}: Props = $props();
|
||||
|
||||
let dialogContainer = $state<HTMLDivElement | null>(null);
|
||||
let error = $state<ErrorMessage | null>(null);
|
||||
let loading = $state(false);
|
||||
let frozen = $state(false);
|
||||
let disabled = $state(false);
|
||||
|
||||
// disable window scroll when dialog is open
|
||||
$effect(() => {
|
||||
@@ -148,10 +151,11 @@
|
||||
transition:fade={{ duration: 150 }}
|
||||
onclick={(e) => {
|
||||
const target = e.target as HTMLElement;
|
||||
if (open && !dialogContainer?.contains(target) && target !== dialogContainer) open = false;
|
||||
if (open && !frozen && !dialogContainer?.contains(target) && target !== dialogContainer)
|
||||
open = false;
|
||||
}}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Escape') {
|
||||
if (e.key === 'Escape' && !frozen) {
|
||||
open = false;
|
||||
}
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user