mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Revert to pseudo-element approach for field description (#2209)
* Revert to pseudo-element approach for field description to ensure it changes on update. * Simplify CSS
This commit is contained in:
parent
7768262086
commit
fdfdd67c3a
3 changed files with 16 additions and 58 deletions
|
@ -1,52 +0,0 @@
|
||||||
<!--
|
|
||||||
Copyright: Ankitects Pty Ltd and contributors
|
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
||||||
-->
|
|
||||||
<script lang="ts">
|
|
||||||
import { getContext } from "svelte";
|
|
||||||
import type { Readable } from "svelte/store";
|
|
||||||
|
|
||||||
import { directionKey, fontFamilyKey, fontSizeKey } from "../lib/context-keys";
|
|
||||||
import { context } from "./EditingArea.svelte";
|
|
||||||
|
|
||||||
const { content } = context.get();
|
|
||||||
|
|
||||||
const fontFamily = getContext<Readable<string>>(fontFamilyKey);
|
|
||||||
const fontSize = getContext<Readable<number>>(fontSizeKey);
|
|
||||||
const direction = getContext<Readable<"ltr" | "rtl">>(directionKey);
|
|
||||||
|
|
||||||
$: empty = $content.length === 0;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#if empty}
|
|
||||||
<div
|
|
||||||
class="field-description"
|
|
||||||
style:font-family={$fontFamily}
|
|
||||||
style:font-size="{$fontSize}px"
|
|
||||||
style:direction={$direction}
|
|
||||||
>
|
|
||||||
<slot />
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.field-description {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
|
|
||||||
color: var(--fg-subtle);
|
|
||||||
pointer-events: none;
|
|
||||||
|
|
||||||
/* Stay a on single line */
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
|
|
||||||
/* The field description is placed absolutely on top of the editor field */
|
|
||||||
/* So we need to make sure it does not escape the editor field if the */
|
|
||||||
/* description is too long */
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
</style>
|
|
|
@ -57,7 +57,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import EditorToolbar from "./editor-toolbar";
|
import EditorToolbar from "./editor-toolbar";
|
||||||
import type { FieldData } from "./EditorField.svelte";
|
import type { FieldData } from "./EditorField.svelte";
|
||||||
import EditorField from "./EditorField.svelte";
|
import EditorField from "./EditorField.svelte";
|
||||||
import FieldDescription from "./FieldDescription.svelte";
|
|
||||||
import Fields from "./Fields.svelte";
|
import Fields from "./Fields.svelte";
|
||||||
import { alertIcon } from "./icons";
|
import { alertIcon } from "./icons";
|
||||||
import ImageOverlay from "./image-overlay";
|
import ImageOverlay from "./image-overlay";
|
||||||
|
@ -437,6 +436,8 @@ the AddCards dialog) should be implemented in the user of this component.
|
||||||
}}
|
}}
|
||||||
collapsed={fieldsCollapsed[index]}
|
collapsed={fieldsCollapsed[index]}
|
||||||
dupe={cols[index] === "dupe"}
|
dupe={cols[index] === "dupe"}
|
||||||
|
--description-font-size="{field.fontSize}px"
|
||||||
|
--description-content={`"${field.description}"`}
|
||||||
>
|
>
|
||||||
<svelte:fragment slot="field-label">
|
<svelte:fragment slot="field-label">
|
||||||
<LabelContainer
|
<LabelContainer
|
||||||
|
@ -524,11 +525,7 @@ the AddCards dialog) should be implemented in the user of this component.
|
||||||
$focusedInput = null;
|
$focusedInput = null;
|
||||||
}}
|
}}
|
||||||
bind:this={richTextInputs[index]}
|
bind:this={richTextInputs[index]}
|
||||||
>
|
/>
|
||||||
<FieldDescription>
|
|
||||||
{field.description}
|
|
||||||
</FieldDescription>
|
|
||||||
</RichTextInput>
|
|
||||||
</Collapsible>
|
</Collapsible>
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
<svelte:fragment slot="plain-text-input">
|
<svelte:fragment slot="plain-text-input">
|
||||||
|
|
|
@ -224,6 +224,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<div class="rich-text-relative">
|
<div class="rich-text-relative">
|
||||||
<div
|
<div
|
||||||
class="rich-text-editable"
|
class="rich-text-editable"
|
||||||
|
class:empty={$content.length === 0}
|
||||||
bind:this={richTextDiv}
|
bind:this={richTextDiv}
|
||||||
use:attachShadow
|
use:attachShadow
|
||||||
use:attachStyles
|
use:attachStyles
|
||||||
|
@ -252,4 +253,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
.rich-text-relative {
|
.rich-text-relative {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.rich-text-editable.empty::before {
|
||||||
|
position: absolute;
|
||||||
|
color: var(--fg-subtle);
|
||||||
|
content: var(--description-content);
|
||||||
|
font-size: var(--description-font-size, 20px);
|
||||||
|
cursor: text;
|
||||||
|
max-width: 95%;
|
||||||
|
overflow-x: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in a new issue