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:
Matthias Metelka 2022-11-23 07:37:12 +01:00 committed by GitHub
parent 7768262086
commit fdfdd67c3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 58 deletions

View file

@ -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>

View file

@ -57,7 +57,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import EditorToolbar from "./editor-toolbar";
import type { FieldData } from "./EditorField.svelte";
import EditorField from "./EditorField.svelte";
import FieldDescription from "./FieldDescription.svelte";
import Fields from "./Fields.svelte";
import { alertIcon } from "./icons";
import ImageOverlay from "./image-overlay";
@ -437,6 +436,8 @@ the AddCards dialog) should be implemented in the user of this component.
}}
collapsed={fieldsCollapsed[index]}
dupe={cols[index] === "dupe"}
--description-font-size="{field.fontSize}px"
--description-content={`"${field.description}"`}
>
<svelte:fragment slot="field-label">
<LabelContainer
@ -524,11 +525,7 @@ the AddCards dialog) should be implemented in the user of this component.
$focusedInput = null;
}}
bind:this={richTextInputs[index]}
>
<FieldDescription>
{field.description}
</FieldDescription>
</RichTextInput>
/>
</Collapsible>
</svelte:fragment>
<svelte:fragment slot="plain-text-input">

View file

@ -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-editable"
class:empty={$content.length === 0}
bind:this={richTextDiv}
use:attachShadow
use:attachStyles
@ -252,4 +253,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
.rich-text-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>