File size: 2,409 Bytes
8766bc5 | 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 | <script lang="ts">
import { createEventDispatcher, afterUpdate } from "svelte";
import type { SelectData } from "@gradio/utils";
export let value: boolean;
export let value_is_output = false;
export let disabled = false;
export let label: string;
const dispatch = createEventDispatcher<{
change: boolean;
select: SelectData;
input: undefined;
}>();
function handle_change(): void {
dispatch("change", value);
if (!value_is_output) {
dispatch("input");
}
}
afterUpdate(() => {
value_is_output = false;
});
$: value, handle_change();
</script>
<label class:disabled>
<input
bind:checked={value}
on:keydown={(event) => {
if (event.key === "Enter") {
value = !value;
dispatch("select", {
index: 0,
value: label,
selected: value,
});
}
}}
on:input={(evt) => {
value = evt.currentTarget.checked;
dispatch("select", {
index: 0,
value: label,
selected: evt.currentTarget.checked,
});
}}
{disabled}
type="checkbox"
name="test"
data-testid="checkbox"
/>
<span class="ml-2">{label}</span>
</label>
<style>
label {
display: flex;
align-items: center;
cursor: pointer;
color: var(--body-text-color);
font-weight: var(--checkbox-label-text-weight);
font-size: var(--checkbox-label-text-size);
line-height: var(--line-md);
}
label > * + * {
margin-left: var(--size-2);
}
input {
--ring-color: transparent;
position: relative;
box-shadow: var(--input-shadow);
border: 1px solid var(--checkbox-border-color);
border-radius: var(--checkbox-border-radius);
background-color: var(--checkbox-background-color);
line-height: var(--line-sm);
}
input:checked,
input:checked:hover,
input:checked:focus {
border-color: var(--checkbox-border-color-selected);
background-image: var(--checkbox-check);
background-color: var(--checkbox-background-color-selected);
}
input:checked:focus {
background-image: var(--checkbox-check);
background-color: var(--checkbox-background-color-selected);
border-color: var(--checkbox-border-color-focus);
}
input:hover {
border-color: var(--checkbox-border-color-hover);
background-color: var(--checkbox-background-color-hover);
}
input:focus {
border-color: var(--checkbox-border-color-focus);
background-color: var(--checkbox-background-color-focus);
}
input[disabled],
.disabled {
cursor: not-allowed;
}
</style>
|