Anki/ts/editor/LabelContainer.svelte
Matthias Metelka 3dca559f88 Create separate collapsed field state
this means users can collapse fields with the HTML editor open and it will stay open when the field is expanded again.
2022-08-11 23:52:38 +02:00

68 lines
1.7 KiB
Svelte

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
import { createEventDispatcher, getContext } from "svelte";
import type { Readable } from "svelte/store";
import Badge from "../components/Badge.svelte";
import { directionKey } from "../lib/context-keys";
import * as tr from "../lib/ftl";
import { chevronDown, chevronRight } from "./icons";
export let collapsed: boolean;
const direction = getContext<Readable<"ltr" | "rtl">>(directionKey);
const dispatch = createEventDispatcher();
function toggle() {
dispatch("toggle");
}
$: icon = collapsed ? chevronRight : chevronDown;
$: tooltip = collapsed ? tr.editingExpandField() : tr.editingCollapseField();
</script>
<div
class="label-container"
class:rtl={$direction === "rtl"}
on:mousedown|preventDefault
>
<span class="clickable" on:click|stopPropagation={toggle}>
<span class="chevron">
<Badge {tooltip} iconSize={80} --icon-align="text-bottom"
>{@html icon}</Badge
>
</span>
<slot name="field-name" />
</span>
<slot />
</div>
<style lang="scss">
.label-container {
& .chevron {
opacity: 0.4;
transition: opacity 0.2s ease-in-out;
}
display: flex;
justify-content: space-between;
background-color: var(--label-color, transparent);
padding: 1px 0;
}
.clickable {
cursor: pointer;
&:hover .chevron {
opacity: 1;
}
}
.rtl {
direction: rtl;
}
</style>