gradio/js/label/shared/Label.svelte

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

159 lines
3.5 KiB
Svelte
Raw Normal View History

2022-03-03 00:42:43 +08:00
<script lang="ts">
import type { SelectData } from "@gradio/utils";
import { createEventDispatcher } from "svelte";
2022-03-03 00:42:43 +08:00
export let value: {
label?: string;
2022-03-03 00:42:43 +08:00
confidences?: { label: string; confidence: number }[];
};
const dispatch = createEventDispatcher<{ select: SelectData }>();
export let color: string | undefined = undefined;
export let selectable = false;
function get_aria_referenceable_id(elem_id: string): string {
// `aria-labelledby` interprets the value as a space-separated id reference list,
// so each single id should not contain any spaces.
// Ref: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby#benefits_and_drawbacks
return elem_id.replace(/\s/g, "-");
}
2022-03-03 00:42:43 +08:00
</script>
<div class="container">
<h2
class="output-class"
data-testid="label-output-value"
2022-03-03 00:42:43 +08:00
class:no-confidence={!("confidences" in value)}
style:background-color={color || "transparent"}
2022-03-03 00:42:43 +08:00
>
{value.label}
</h2>
{#if typeof value === "object" && value.confidences}
{#each value.confidences as confidence_set, i}
<button
class="confidence-set group"
data-testid={`${confidence_set.label}-confidence-set`}
class:selectable
on:click={() => {
dispatch("select", { index: i, value: confidence_set.label });
}}
>
<div class="inner-wrap">
<meter
aria-labelledby={get_aria_referenceable_id(
`meter-text-${confidence_set.label}`
)}
aria-label={confidence_set.label}
aria-valuenow={Math.round(confidence_set.confidence * 100)}
aria-valuemin="0"
aria-valuemax="100"
class="bar"
min="0"
max="1"
value={confidence_set.confidence}
style="width: {confidence_set.confidence *
100}%; background: var(--stat-background-fill);
"
/>
<dl class="label">
<dt
id={get_aria_referenceable_id(
`meter-text-${confidence_set.label}`
)}
class="text"
>
{confidence_set.label}
</dt>
<div class="line" />
<dd class="confidence">
{Math.round(confidence_set.confidence * 100)}%
</dd>
</dl>
</div>
</button>
{/each}
2022-03-03 00:42:43 +08:00
{/if}
</div>
<style>
.container {
padding: var(--block-padding);
}
.output-class {
display: flex;
justify-content: center;
align-items: center;
padding: var(--size-6) var(--size-4);
Python backend to theming (#2931) * add theme + theme atoms * audio * buttons * chatbot * forms * start file * complete file * fixup workbench * gallery * highlighted text * label * json * upload * 3d model * atoms * chart * md + html * image * plot + build * table * tabs * tooltip * upload * tweaks * tweaks + more tooling * tweaks to padding/ lineheight * app components _ start api docs * format, more api docs * finish api docs * interpretation * todos * tweaks + cleanup * tweaks + cleanup * revert range tweaks * fix notebooks * fix test * remove tw * cleanup + login * fix gitignore * fix types * run css script * fix progress + tweaks * update demos * add css build to static check workflow * tweak ci * fix tests * tweak markdown * tweak chatbot + file * fix tabs * tweak tabs * cleanup * fix api docs * fix example gallery * add gradient to toast * fix min height for interfaces * revert tab changes * update notebooks * changes * changes * change * changes * changes * changes * changes * changes * changes * changes * changes * change * changes * changes * changes * changes * changes * changes * changes * fix * changes * changes * changes * changes * changes * changes * undo radius * undo radius * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * change * undo * Add absolute imports * mock theme in tests * clean * changes * changes --------- Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-03-07 04:52:31 +08:00
color: var(--body-text-color);
font-weight: var(--weight-bold);
Python backend to theming (#2931) * add theme + theme atoms * audio * buttons * chatbot * forms * start file * complete file * fixup workbench * gallery * highlighted text * label * json * upload * 3d model * atoms * chart * md + html * image * plot + build * table * tabs * tooltip * upload * tweaks * tweaks + more tooling * tweaks to padding/ lineheight * app components _ start api docs * format, more api docs * finish api docs * interpretation * todos * tweaks + cleanup * tweaks + cleanup * revert range tweaks * fix notebooks * fix test * remove tw * cleanup + login * fix gitignore * fix types * run css script * fix progress + tweaks * update demos * add css build to static check workflow * tweak ci * fix tests * tweak markdown * tweak chatbot + file * fix tabs * tweak tabs * cleanup * fix api docs * fix example gallery * add gradient to toast * fix min height for interfaces * revert tab changes * update notebooks * changes * changes * change * changes * changes * changes * changes * changes * changes * changes * changes * change * changes * changes * changes * changes * changes * changes * changes * fix * changes * changes * changes * changes * changes * changes * undo radius * undo radius * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * change * undo * Add absolute imports * mock theme in tests * clean * changes * changes --------- Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-03-07 04:52:31 +08:00
font-size: var(--text-xxl);
}
.confidence-set {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: var(--size-2);
Python backend to theming (#2931) * add theme + theme atoms * audio * buttons * chatbot * forms * start file * complete file * fixup workbench * gallery * highlighted text * label * json * upload * 3d model * atoms * chart * md + html * image * plot + build * table * tabs * tooltip * upload * tweaks * tweaks + more tooling * tweaks to padding/ lineheight * app components _ start api docs * format, more api docs * finish api docs * interpretation * todos * tweaks + cleanup * tweaks + cleanup * revert range tweaks * fix notebooks * fix test * remove tw * cleanup + login * fix gitignore * fix types * run css script * fix progress + tweaks * update demos * add css build to static check workflow * tweak ci * fix tests * tweak markdown * tweak chatbot + file * fix tabs * tweak tabs * cleanup * fix api docs * fix example gallery * add gradient to toast * fix min height for interfaces * revert tab changes * update notebooks * changes * changes * change * changes * changes * changes * changes * changes * changes * changes * changes * change * changes * changes * changes * changes * changes * changes * changes * fix * changes * changes * changes * changes * changes * changes * undo radius * undo radius * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * change * undo * Add absolute imports * mock theme in tests * clean * changes * changes --------- Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-03-07 04:52:31 +08:00
color: var(--body-text-color);
line-height: var(--line-none);
font-family: var(--font-mono);
width: 100%;
}
.confidence-set:last-child {
margin-bottom: 0;
}
.inner-wrap {
flex: 1 1 0%;
display: flex;
flex-direction: column;
}
.bar {
appearance: none;
align-self: flex-start;
margin-bottom: var(--size-1);
border-radius: var(--radius-md);
More theme updates (#3497) * changes * changes * changes * changes * changes * Update gradio/themes/base.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update gradio/themes/base.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * changes * changes * changes * changes * changes * undo merge break * changes * changes * changes * fix --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-03-18 08:20:55 +08:00
background: var(--stat-background-fill);
height: var(--size-1);
}
.label {
display: flex;
align-items: baseline;
}
.label > * + * {
margin-left: var(--size-2);
}
.confidence-set:hover .label {
More theme updates (#3497) * changes * changes * changes * changes * changes * Update gradio/themes/base.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update gradio/themes/base.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * changes * changes * changes * changes * changes * undo merge break * changes * changes * changes * fix --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-03-18 08:20:55 +08:00
color: var(--color-accent);
}
.confidence-set:focus .label {
color: var(--color-accent);
}
.text {
line-height: var(--line-md);
text-align: left;
}
.line {
flex: 1 1 0%;
Theme+release (#3494) * changes * changes * changes * changes * changes * Update gradio/themes/base.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update gradio/themes/base.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/06_theming-guide Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * changes * changes * changes * save file * update changelog --------- Co-authored-by: Ali Abid <aabid94@gmail.com>
2023-03-17 22:41:53 +08:00
border: 1px dashed var(--border-color-primary);
padding-right: var(--size-4);
padding-left: var(--size-4);
}
.confidence {
margin-left: auto;
text-align: right;
}
</style>