File size: 4,243 Bytes
29580f3 d0f5140 29580f3 d0f5140 2a6062c 29580f3 2a6062c 29580f3 d0f5140 2a6062c 29580f3 d0f5140 29580f3 d0f5140 29580f3 d0f5140 29580f3 d0f5140 29580f3 2a6062c 29580f3 2a6062c 29580f3 d0f5140 29580f3 d0f5140 29580f3 d0f5140 29580f3 2a6062c 29580f3 2a6062c 29580f3 2a6062c 29580f3 |
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 |
<script lang="ts">
import { BaseColorPicker } from "@gradio/colorpicker";
import { BaseButton } from "@gradio/button";
import { BaseDropdown } from "./patched_dropdown/Index.svelte";
import { createEventDispatcher } from "svelte";
import { onMount, onDestroy } from "svelte";
export let label = "";
export let currentLabel = "";
export let choices = []; // [(label, i)]
export let choicesColors = [];
export let color = "";
export let currentColor = "";
export let showRemove = true;
const dispatch = createEventDispatcher<{
change: object;
}>();
function dispatchChange(ret: number) {
dispatch("change", {
label: currentLabel,
color: currentColor,
ret: ret // -1: remove, 0: cancel, 1: change
});
}
function onDropDownChange(event) {
const { detail } = event;
let choice = detail;
if (Number.isInteger(choice)) {
if (Array.isArray(choicesColors) && choice < choicesColors.length) {
currentColor = choicesColors[choice];
}
if (Array.isArray(choices) && choice < choices.length) {
currentLabel = choices[choice][0];
}
} else {
currentLabel = choice;
}
}
function onColorChange(event) {
const { detail } = event;
currentColor = detail;
}
function onDropDownEnter(event) {
onDropDownChange(event);
dispatchChange(1);
}
function handleKeyPress(event: KeyboardEvent) {
switch (event.key) {
case "Enter":
dispatchChange(1);
break;
}
}
onMount(() => {
document.addEventListener("keydown", handleKeyPress);
currentLabel = label;
currentColor = color;
});
onDestroy(() => {
document.removeEventListener("keydown", handleKeyPress);
});
</script>
<div class="modal" id="model-box-edit">
<div class="modal-container">
<span class="model-content">
<div style="margin-right: 10px;">
<BaseDropdown
value={currentLabel}
label="Label"
{choices}
show_label={false}
allow_custom_value={true}
on:change={onDropDownChange}
on:enter={onDropDownEnter}
/>
</div>
<div style="margin-right: 40px; margin-bottom: 8px;">
<BaseColorPicker
value={currentColor}
label="Color"
show_label={false}
on:change={onColorChange}
/>
</div>
<div style="margin-right: 8px;">
<BaseButton
on:click={() => dispatchChange(0)}
>Cancel</BaseButton>
</div>
{#if showRemove}
<div style="margin-right: 8px;">
<BaseButton
variant="stop"
on:click={() => dispatchChange(-1)}
>Remove</BaseButton>
</div>
{/if}
<div>
<BaseButton
variant="primary"
on:click={() => dispatchChange(1)}
>OK</BaseButton>
</div>
</span>
</div>
</div>
<style>
.modal {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: var(--layer-top);
-webkit-backdrop-filter: blur(4px);
backdrop-filter: blur(4px);
}
.modal-container {
border-style: solid;
border-width: var(--block-border-width);
border-color: var(--block-border-color);
margin-top: 10%;
padding: 20px;
box-shadow: var(--block-shadow);
border-color: var(--block-border-color);
border-radius: var(--block-radius);
background: var(--block-background-fill);
position: fixed;
left: 50%;
transform: translateX(-50%);
width: fit-content;
}
.model-content {
display: flex;
align-items: flex-end;
}
</style>
|