Added: SpinnerBox percentage symbol. (#3777)

* Added: Padded percentage symbol

* Added: Floating percentage

* ./check

* half finished comment

* Removed: redundant toStringValue function

* Removed: Accidental import

* Improved pointer-events:none

* Improve percentage alignment

* Improve leftmost percentage alignment

* Fix: Percentage sticks to left

* ./check

* Fix: IOS css

* ./check
This commit is contained in:
Luc Mcgrady 2025-02-06 07:21:26 +00:00 committed by GitHub
parent 93032cdceb
commit dd93691b9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 54 additions and 1 deletions

View file

@ -449,6 +449,7 @@ deck-config-percent-of-reviews =
[one] { $pct }% of { $reviews } review [one] { $pct }% of { $reviews } review
*[other] { $pct }% of { $reviews } reviews *[other] { $pct }% of { $reviews } reviews
} }
deck-config-percent-input = { $pct }%
deck-config-optimizing-preset = Optimizing preset { $current_count }/{ $total_count }... deck-config-optimizing-preset = Optimizing preset { $current_count }/{ $total_count }...
deck-config-fsrs-must-be-enabled = FSRS must be enabled first. deck-config-fsrs-must-be-enabled = FSRS must be enabled first.
deck-config-fsrs-params-optimal = The FSRS parameters currently appear to be optimal. deck-config-fsrs-params-optimal = The FSRS parameters currently appear to be optimal.

View file

@ -40,7 +40,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
// enters '0', if the value gets clamped back to '1', Svelte will think the value hasn't // enters '0', if the value gets clamped back to '1', Svelte will think the value hasn't
// changed, and will skip the UI update. So we manually update the DOM to ensure it stays // changed, and will skip the UI update. So we manually update the DOM to ensure it stays
// in sync. // in sync.
tick().then(() => (input.value = stringValue)); tick().then(() => {
input.value = stringValue;
updatePercentageText(stringValue);
});
} }
/** /**
@ -92,6 +95,24 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
} }
function updatePercentageText(value: string) {
// Separate the % from the padding text.
percentage_text = tr
.deckConfigPercentInput({ pct: value })
.replaceAll("%", "-%-")
.split("-");
}
function onInput() {
updatePercentageText(input.value);
}
// Invisible, used to shift the % sign the correct amount.
let percentage_text: string[];
$: updatePercentageText(stringValue);
// If the input box should be moved right for leading percentage symbol.
$: percentage_padding = percentage && !percentage_text[0] ? "2.2ch" : undefined;
let pressed = false; let pressed = false;
let timeout: number; let timeout: number;
let pressTimer: any; let pressTimer: any;
@ -108,9 +129,22 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
value={stringValue} value={stringValue}
bind:this={input} bind:this={input}
on:blur={update} on:blur={update}
on:input={onInput}
on:focusin={() => (focused = true)} on:focusin={() => (focused = true)}
on:focusout={() => (focused = false)} on:focusout={() => (focused = false)}
style:padding-left={percentage_padding}
/> />
{#if percentage}
<span class="suffix">
{#each percentage_text as str}
{#if str == "%"}
%
{:else}
<span class="invisible">{str}</span>
{/if}
{/each}
</span>
{/if}
{#if isDesktop()} {#if isDesktop()}
<!-- svelte-ignore a11y-click-events-have-key-events --> <!-- svelte-ignore a11y-click-events-have-key-events -->
<div <div
@ -182,6 +216,24 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
.suffix {
position: absolute;
pointer-events: none;
white-space: pre;
left: 0.5em;
top: 1px;
@supports (-webkit-touch-callout: none) {
/* CSS specific to iOS devices */
top: 3.5px;
}
}
.invisible {
color: transparent;
pointer-events: none;
}
input { input {
flex-grow: 1; flex-grow: 1;
border: none; border: none;