anki/ts/components/Badge.svelte

52 lines
1.1 KiB
Svelte
Raw Normal View History

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
2021-06-21 20:24:15 +02:00
import type { DropdownProps } from "components/dropdown";
import { dropdownKey } from "components/context-keys";
2021-06-21 20:24:15 +02:00
import { onMount, createEventDispatcher, getContext } from "svelte";
let className = "";
export { className as class };
2021-06-24 17:19:42 +02:00
export let tooltip: string | undefined = undefined;
const dispatch = createEventDispatcher();
let spanRef: HTMLSpanElement;
2021-06-21 20:24:15 +02:00
const dropdownProps = getContext<DropdownProps>(dropdownKey) ?? { dropdown: false };
onMount(() => {
dispatch("mount", { span: spanRef });
});
</script>
2021-06-21 20:24:15 +02:00
<span
bind:this={spanRef}
2021-06-24 16:44:08 +02:00
title={tooltip}
2021-06-21 20:24:15 +02:00
class={`badge ${className}`}
class:dropdown-toggle={dropdownProps.dropdown}
{...dropdownProps}
on:click
2021-06-24 14:06:57 +02:00
on:mouseenter
on:mouseleave
2021-06-21 20:24:15 +02:00
>
<slot />
</span>
<style>
.badge {
color: inherit;
}
2021-06-21 20:24:15 +02:00
.dropdown-toggle::after {
display: none;
}
span :global(svg) {
2021-06-24 01:32:54 +02:00
border-radius: inherit;
vertical-align: -0.125rem;
}
</style>