Enable tag delete icon

This commit is contained in:
Henrik Giesel 2021-06-24 01:32:54 +02:00
parent 392bdf6184
commit 77be86ec21
4 changed files with 29 additions and 10 deletions

View file

@ -41,6 +41,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
span :global(svg) { span :global(svg) {
border-radius: inherit;
vertical-align: -0.125rem; vertical-align: -0.125rem;
} }
</style> </style>

View file

@ -3,35 +3,46 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import { createEventDispatcher } from "svelte";
import Badge from "components/Badge.svelte"; import Badge from "components/Badge.svelte";
import TagInputEdit from "./TagInputEdit.svelte"; import TagInputEdit from "./TagInputEdit.svelte";
import { deleteIcon } from "./icons"; import { deleteIcon } from "./icons";
export let name: string; export let name: string;
const dispatch = createEventDispatcher();
let active = false; let active = false;
function tagDelete(event: Event): void {
dispatch("tagdelete", { name });
event.stopPropagation();
}
</script> </script>
{#if active} {#if active}
<TagInputEdit bind:name on:focusout={() => (active = false)} /> <TagInputEdit bind:name on:focusout={() => (active = false)} />
{:else} {:else}
<span <span
class="tag text-nowrap bg-secondary rounded p-1 me-2" class="tag text-nowrap bg-secondary rounded p-1 ps-2 me-2"
on:click|stopPropagation={() => (active = true)} on:click|stopPropagation={() => (active = true)}
> >
<span>{name}</span> <span>{name}</span>
<Badge class="delete-icon">{@html deleteIcon}</Badge> <Badge class="rounded delete-icon" on:click={tagDelete}
>{@html deleteIcon}</Badge
>
</span> </span>
{/if} {/if}
<style lang="scss"> <style lang="scss">
.tag {
/* important for tags with non-latin characters */
line-height: 2ch;
vertical-align: -webkit-baseline-middle;
:global(.delete-icon):hover {
$white-translucent: rgba(255, 255, 255, 0.5); $white-translucent: rgba(255, 255, 255, 0.5);
.tag :global(.delete-icon) {
& > :global(svg) {
vertical-align: text-bottom;
}
& > :global(svg:hover) {
background-color: $white-translucent; background-color: $white-translucent;
} }
} }

View file

@ -18,6 +18,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
inputNew = true; inputNew = true;
tagInputNew.focus(); tagInputNew.focus();
} }
function deleteTag({ detail }: CustomEvent) {
tags.splice(tags.indexOf(detail.name), 1);
tags = tags;
}
</script> </script>
<StickyBottom> <StickyBottom>
@ -25,7 +30,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<Badge class="me-1">{@html tagIcon}</Badge> <Badge class="me-1">{@html tagIcon}</Badge>
{#each tags as tag} {#each tags as tag}
<Tag name={tag} /> <Tag name={tag} on:tagdelete={deleteTag} />
{/each} {/each}
{#if inputNew} {#if inputNew}

View file

@ -63,7 +63,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
on:nameChosen={setTagname} on:nameChosen={setTagname}
on:accept={onAccept} on:accept={onAccept}
> >
<label data-value={name} id={triggerId} class={triggerClass}> <label id={triggerId} class={`p-1 ${triggerClass}`} data-value={name}>
<input <input
type="text" type="text"
size="1" size="1"
@ -82,6 +82,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<style lang="scss"> <style lang="scss">
label { label {
display: inline-grid; display: inline-grid;
&::after, &::after,
input { input {
color: var(--text-fg); color: var(--text-fg);
@ -96,6 +97,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
&::after { &::after {
/* 8 spaces to minimize reflow on clicking tag */ /* 8 spaces to minimize reflow on clicking tag */
content: attr(data-value) " "; content: attr(data-value) " ";