Improve visuals of Tag component

This commit is contained in:
Henrik Giesel 2021-06-28 16:41:32 +02:00
parent 5505925e64
commit a9538ce6a7
3 changed files with 41 additions and 26 deletions

View file

@ -3,7 +3,8 @@ 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 { getContext, createEventDispatcher } from "svelte";
import { nightModeKey } from "components/contextKeys";
import Badge from "components/Badge.svelte"; import Badge from "components/Badge.svelte";
import { deleteIcon } from "./icons"; import { deleteIcon } from "./icons";
@ -11,22 +12,25 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
function deleteTag(event: Event): void { function deleteTag(): void {
dispatch("tagdelete"); dispatch("tagdelete");
event.stopPropagation();
} }
let isBlink: boolean = false; let flashing: boolean = false;
export function blink() { export function flash() {
isBlink = true; flashing = true;
setTimeout(() => (isBlink = false), 300); setTimeout(() => (flashing = false), 300);
} }
const nightMode = getContext<boolean>(nightModeKey);
</script> </script>
<button <button
class="d-inline-flex align-items-center tag text-nowrap rounded ps-2 pe-1 me-1" class="btn d-inline-flex align-items-center text-nowrap rounded ps-2 pe-1 me-1"
class:blink={isBlink} class:flashing
class:btn-day={!nightMode}
class:btn-night={nightMode}
tabindex="-1" tabindex="-1"
on:click on:click
> >
@ -37,24 +41,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
</button> </button>
<style lang="scss"> <style lang="scss">
$white-translucent: rgba(255, 255, 255, 0.5); @use "ts/sass/button_mixins" as button;
@keyframes blink { @keyframes flash {
0% { 0% {
filter: brightness(1); filter: invert(0);
} }
50% { 50% {
filter: brightness(2); filter: invert(0.4);
} }
100% { 100% {
filter: brightness(1); filter: invert(0);
} }
} }
.tag :global(.delete-icon > svg:hover) {
background-color: $white-translucent;
}
button { button {
padding: 0; padding: 0;
@ -63,8 +63,24 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
outline: none; outline: none;
} }
&.blink { &.flashing {
animation: blink 0.3s linear; animation: flash 0.3s linear;
}
}
@include button.btn-day($with-active: false);
@include button.btn-night($with-active: false);
$white-translucent: rgba(255 255 255 / 0.5);
$dark-translucent: rgba(0 0 0 / 0.2);
:global(.delete-icon > svg:hover) {
.btn-day & {
background-color: $dark-translucent;
}
.btn-night & {
background-color: $white-translucent;
} }
} }
</style> </style>

View file

@ -16,11 +16,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { attachId, getName } from "./tags"; import { attachId, getName } from "./tags";
export let size = isApplePlatform() ? 1.6 : 2.0; export let size = isApplePlatform() ? 1.6 : 2.0;
export let tags: TagType[] = [];
export let suggestions = ["en::idioms", "anki::functionality", "math"]; export let suggestions = ["en::idioms", "anki::functionality", "math"];
export let tags: TagType[] = [];
export function resetTags(names: string[]): void { export function resetTags(names: string[]): void {
tags = names.map(attachId); tags = names.map(attachId);
} }
@ -93,7 +92,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
contained contained
); );
if (contained >= 0) { if (contained >= 0) {
tags[contained].blink(); tags[contained].flash();
return false; return false;
} }
@ -253,7 +252,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
{:else} {:else}
<Tag <Tag
name={tag.name} name={tag.name}
bind:blink={tag.blink} bind:flash={tag.flash}
on:click={() => (active = index)} on:click={() => (active = index)}
on:tagdelete={() => { on:tagdelete={() => {
deleteTagAt(index); deleteTagAt(index);

View file

@ -18,7 +18,7 @@ export function normalizeTagname(tagname: string): string {
export interface Tag { export interface Tag {
id: string; id: string;
name: string; name: string;
blink: () => void; flash: () => void;
} }
const noop = () => {}; const noop = () => {};
@ -27,7 +27,7 @@ export function attachId(name: string): Tag {
return { return {
id: Math.random().toString(36).substring(2), id: Math.random().toString(36).substring(2),
name, name,
blink: noop, flash: noop,
}; };
} }