Spaces:
Running
Running
File size: 3,252 Bytes
d0e9620 47e2c18 d0e9620 47e2c18 d0e9620 797f2cf 47e2c18 d0e9620 47e2c18 d0e9620 797f2cf 47e2c18 d0e9620 797f2cf d0e9620 47e2c18 d0e9620 797f2cf d0e9620 797f2cf d0e9620 797f2cf d0e9620 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
<script lang="ts">
import { Block } from "@gradio/atoms";
import Column from "@gradio/column";
import { Gradio } from "@gradio/utils";
export let elem_id = "";
export let elem_classes: string[] = [];
export let visible = false;
export let allow_user_close = true;
export let gradio: Gradio<{
blur: never;
}>;
let element: HTMLElement | null = null;
let inner_element: HTMLElement | null = null;
const close = () => {
visible = false;
gradio.dispatch("blur");
};
document.addEventListener("keydown", (evt: KeyboardEvent) => {
if (allow_user_close && evt.key === "Escape") {
close();
}
});
</script>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div
class="modal {elem_classes.join(' ')}"
bind:this={element}
class:hide={!visible}
id={elem_id}
on:click={(evt) => {
if (allow_user_close && (evt.target === element || evt.target === inner_element)) {
close();
}
}}
>
<div class="modal-container" bind:this={inner_element} >
<Block allow_overflow={false} elem_classes={["modal-block"]}>
{#if allow_user_close}
<div class="close" on:click={close}>
<svg
width="10"
height="10"
viewBox="0 0 10 10"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 1L9 9"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
d="M9 1L1 9"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div>
{/if}
<Column>
<slot />
</Column>
</Block>
</div>
</div>
<style>
@media (min-width: 640px) {
.modal-container {
max-width: 640px;
}
}
@media (min-width: 768px) {
.modal-container {
max-width: 768px;
}
}
@media (min-width: 1024px) {
.modal-container {
max-width: 1024px;
}
}
@media (min-width: 1280px) {
.modal-container {
max-width: 1280px;
}
}
@media (min-width: 1536px) {
.modal-container {
max-width: 1536px;
}
}
.modal {
position: fixed; /* Stay in place */
z-index: 100; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
z-index: 100;
background-color: rgb(0, 0, 0); /* Fallback color */
background-color: rgba(0, 0, 0, 0.4); /* Black w/ opacity */
backdrop-filter: blur(4px);
}
.modal-container {
position: relative;
padding: 0 var(--size-8);
margin: var(--size-8) auto;
height: 100%;
max-height: calc(100% - var(--size-16));
overflow-y: hidden;
}
.close {
display: flex;
position: absolute;
top: var(--block-label-margin);
right: var(--block-label-margin);
align-items: center;
box-shadow: var(--shadow-drop);
border: 1px solid var(--border-color-primary);
border-top: none;
border-right: none;
border-radius: var(--block-label-right-radius);
background: var(--block-label-background-fill);
padding: 6px;
height: 24px;
overflow: hidden;
color: var(--block-label-text-color);
font: var(--font);
font-size: var(--button-small-text-size);
cursor: pointer;
}
.modal :global(.modal-block) {
max-height: 100%;
overflow-y: auto !important;
}
.hide {
display: none;
}
</style>
|