mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Make tags selectable
This commit is contained in:
parent
0ff0e87dbc
commit
080b80e3ce
3 changed files with 64 additions and 24 deletions
|
@ -10,6 +10,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import { controlPressed, shiftPressed } from "lib/keys";
|
import { controlPressed, shiftPressed } from "lib/keys";
|
||||||
|
|
||||||
export let name: string;
|
export let name: string;
|
||||||
|
export let selected: boolean = false;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
@ -19,19 +20,30 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
let flashing: boolean = false;
|
let flashing: boolean = false;
|
||||||
|
|
||||||
export function flash() {
|
export function flash(): void {
|
||||||
flashing = true;
|
flashing = true;
|
||||||
setTimeout(() => (flashing = false), 300);
|
setTimeout(() => (flashing = false), 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hideDelete = false;
|
let control = false;
|
||||||
|
let shift = false;
|
||||||
|
|
||||||
function setDeleteIcon(event: KeyboardEvent | MouseEvent) {
|
function setDeleteIcon(event: KeyboardEvent | MouseEvent): void {
|
||||||
hideDelete = controlPressed(event) || shiftPressed(event);
|
control = controlPressed(event);
|
||||||
|
shift = shiftPressed(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showDeleteIcon() {
|
$: selectMode = control || shift;
|
||||||
hideDelete = true;
|
|
||||||
|
function onClick(): void {
|
||||||
|
if (shift) {
|
||||||
|
dispatch("tagrange");
|
||||||
|
} else if (control) {
|
||||||
|
console.log("control", control);
|
||||||
|
selected = !selected;
|
||||||
|
} else {
|
||||||
|
dispatch("tagedit");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const nightMode = getContext<boolean>(nightModeKey);
|
const nightMode = getContext<boolean>(nightModeKey);
|
||||||
|
@ -41,18 +53,23 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class="tag btn d-inline-flex align-items-center text-nowrap rounded ps-2 pe-1 me-1"
|
class="tag btn d-inline-flex align-items-center text-nowrap rounded ps-2 pe-1 me-1"
|
||||||
|
class:selected
|
||||||
class:flashing
|
class:flashing
|
||||||
class:hide-delete={hideDelete}
|
class:select-mode={selectMode}
|
||||||
class:btn-day={!nightMode}
|
class:btn-day={!nightMode}
|
||||||
class:btn-night={nightMode}
|
class:btn-night={nightMode}
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
on:mouseleave={showDeleteIcon}
|
|
||||||
on:mousemove={setDeleteIcon}
|
on:mousemove={setDeleteIcon}
|
||||||
on:click
|
on:click={onClick}
|
||||||
>
|
>
|
||||||
<span>{name}</span>
|
<span>{name}</span>
|
||||||
<Badge class="delete-icon rounded ms-1 mt-1" on:click={deleteTag}
|
<Badge
|
||||||
>{@html deleteIcon}</Badge
|
class="delete-icon rounded ms-1 mt-1"
|
||||||
|
on:click={() => {
|
||||||
|
if (!selectMode) {
|
||||||
|
deleteTag();
|
||||||
|
}
|
||||||
|
}}>{@html deleteIcon}</Badge
|
||||||
>
|
>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@ -77,30 +94,49 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
&:focus,
|
&:focus,
|
||||||
&:active {
|
&:active {
|
||||||
outline: none;
|
outline: none;
|
||||||
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.flashing {
|
&.flashing {
|
||||||
animation: flash 0.3s linear;
|
animation: flash 0.3s linear;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.hide-delete:hover :global(.delete-icon) {
|
&.select-mode {
|
||||||
|
cursor: crosshair;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected {
|
||||||
|
box-shadow: 0 0 0 0.25rem transparentize(button.$focus-color, 0.5) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.delete-icon) {
|
||||||
|
.select-mode:hover & {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
:global(.delete-icon > svg:hover) {
|
> :global(svg:hover) {
|
||||||
$white-translucent: rgba(255 255 255 / 0.5);
|
$white-translucent: rgba(255 255 255 / 0.5);
|
||||||
$dark-translucent: rgba(0 0 0 / 0.2);
|
$dark-translucent: rgba(0 0 0 / 0.2);
|
||||||
|
|
||||||
.btn-day & {
|
.btn-day & {
|
||||||
background-color: $dark-translucent;
|
background-color: $dark-translucent;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-night & {
|
.btn-night & {
|
||||||
background-color: $white-translucent;
|
background-color: $white-translucent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@include button.btn-day($with-active: false);
|
@include button.btn-day(
|
||||||
@include button.btn-night($with-active: false);
|
$with-active: false,
|
||||||
|
$with-disabled: false,
|
||||||
|
$with-hover: false
|
||||||
|
);
|
||||||
|
@include button.btn-night(
|
||||||
|
$with-active: false,
|
||||||
|
$with-disabled: false,
|
||||||
|
$with-hover: false
|
||||||
|
);
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -337,7 +337,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<Tag
|
<Tag
|
||||||
name={tag.name}
|
name={tag.name}
|
||||||
bind:flash={tag.flash}
|
bind:flash={tag.flash}
|
||||||
on:click={() => (active = index)}
|
bind:selected={tag.selected}
|
||||||
|
on:tagedit={() => (active = index)}
|
||||||
|
on:tagrange={console.log}
|
||||||
on:tagdelete={() => {
|
on:tagdelete={() => {
|
||||||
deleteTagAt(index);
|
deleteTagAt(index);
|
||||||
saveTags();
|
saveTags();
|
||||||
|
|
|
@ -18,6 +18,7 @@ export function normalizeTagname(tagname: string): string {
|
||||||
export interface Tag {
|
export interface Tag {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
selected: boolean;
|
||||||
flash: () => void;
|
flash: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +28,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,
|
||||||
|
selected: false,
|
||||||
flash: noop,
|
flash: noop,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue