anki/ts/components/LabelButton.svelte

62 lines
1.5 KiB
Svelte
Raw Normal View History

2021-04-15 15:59:52 +02:00
<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
Insert symbols overlay (#2051) * Add flag for enabling insert symbols feature * Add symbols overlay directory * Detect if :xy is inserted into editable * Allow naive updating of overlay, and special handling of ':' * First step towards better Virtual Element support * Update floating to reference range on insert text * Position SymbolsOverlay always on top or bottom * Add a data-provider to emulate API * Show correct suggestions in symbols overlay * Rename to replacementLength * Allow replacing via clicking in menu * Optionally remove inline padding of Popover * Hide Symbols overlay on blur of content editable * Add specialKey to inputHandler and generalize how arrow movement is detected - This way macOS users can use Ctrl-N to mean down, etc. * Detect special key from within SymbolsOverlay * Implement full backwards search while typing * Allow navigating symbol menu and accepting with enter * Add some entries to data-provider * Satisfy eslint * Generate symbolsTable from sources * Use other github source, allow multiple names In return, symbol must be unique * Automatically scroll in symbols dropdown * Use from npm packages rather than downloading from URL * Remove console.log * Remove print * Add pointerDown event to input-handler - so that SymbolsOverlay can reset on field click * Make tab do the same as enter * Make font a bit smaller but increase relative icon size * Satisfy type requirement of handlerlist * Revert changing default size of DropdownItems * Remove some now unused code for bootstrap dropdowns
2022-09-10 10:46:59 +02:00
import { createEventDispatcher, onMount } from "svelte";
export let id: string | undefined = undefined;
let className: string = "";
export { className as class };
export let primary = false;
export let tooltip: string | undefined = undefined;
export let active = false;
2021-07-05 18:15:03 +02:00
export let disabled = false;
export let tabbable = false;
export let ellipsis = false;
let buttonRef: HTMLButtonElement;
const dispatch = createEventDispatcher();
onMount(() => dispatch("mount", { button: buttonRef }));
2021-03-25 23:32:23 +01:00
</script>
2021-03-29 14:54:10 +02:00
<button
bind:this={buttonRef}
{id}
class="label-button {className}"
class:active
class:primary
class:ellipsis
title={tooltip}
2021-07-05 18:15:03 +02:00
{disabled}
tabindex={tabbable ? 0 : -1}
on:click
on:mousedown|preventDefault
>
<slot />
</button>
2021-03-25 23:32:23 +01:00
<style lang="scss">
@use "sass/button-mixins" as button;
.label-button {
@include button.base($active-class: active);
&.primary {
@include button.base($primary: true);
}
@include button.border-radius;
white-space: nowrap;
&.ellipsis {
overflow: hidden;
text-overflow: ellipsis;
}
padding: 0 calc(var(--buttons-size) / 3);
font-size: var(--font-size);
width: auto;
height: var(--buttons-size);
2021-03-25 23:32:23 +01:00
}
</style>