anki/ts/deck-options/TimerOptions.svelte
Matthias Metelka ee9af871b7
Use custom scrollbar in stats screen, use grid layout and tweak CSS (#2154)
* Include base styles in graphs-base.scss

This includes the custom scrollbar styles, which were missing on the stats page.

* Set responsive grid layout on GraphsPage, use TitledContainer component

+ use global button style, tweak input appearance and other small changes

* Improve margins on GraphsPage
2022-11-02 18:23:08 +10:00

103 lines
3.4 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 type Carousel from "bootstrap/js/dist/carousel";
import type Modal from "bootstrap/js/dist/modal";
import DynamicallySlottable from "../components/DynamicallySlottable.svelte";
import Item from "../components/Item.svelte";
import TitledContainer from "../components/TitledContainer.svelte";
import * as tr from "../lib/ftl";
import HelpModal from "./HelpModal.svelte";
import type { DeckOptionsState } from "./lib";
import SettingTitle from "./SettingTitle.svelte";
import SpinBoxRow from "./SpinBoxRow.svelte";
import SwitchRow from "./SwitchRow.svelte";
import type { DeckOption } from "./types";
import Warning from "./Warning.svelte";
export let state: DeckOptionsState;
export let api: Record<string, never>;
const config = state.currentConfig;
const defaults = state.defaults;
$: maximumAnswerSecondsAboveRecommended =
$config.capAnswerTimeToSecs > 600
? tr.deckConfigMaximumAnswerSecsAboveRecommended()
: "";
const settings = {
maximumAnswerSecs: {
title: tr.deckConfigMaximumAnswerSecs(),
help: tr.deckConfigMaximumAnswerSecsTooltip(),
},
showAnswerTimer: {
title: tr.schedulingShowAnswerTimer(),
help: tr.deckConfigShowAnswerTimerTooltip(),
},
};
const helpSections = Object.values(settings) as DeckOption[];
let modal: Modal;
let carousel: Carousel;
function openHelpModal(index: number): void {
modal.show();
carousel.to(index);
}
</script>
<TitledContainer title={tr.deckConfigTimerTitle()}>
<HelpModal
title={tr.deckConfigTimerTitle()}
url="https://docs.ankiweb.net/deck-options.html#timer"
slot="tooltip"
{helpSections}
on:mount={(e) => {
modal = e.detail.modal;
carousel = e.detail.carousel;
}}
/>
<DynamicallySlottable slotHost={Item} {api}>
<Item>
<SpinBoxRow
bind:value={$config.capAnswerTimeToSecs}
defaultValue={defaults.capAnswerTimeToSecs}
min={1}
max={7200}
>
<SettingTitle
on:click={() =>
openHelpModal(
Object.keys(settings).indexOf("maximumAnswerSecs"),
)}>{settings.maximumAnswerSecs.title}</SettingTitle
>
</SpinBoxRow>
</Item>
<Item>
<Warning warning={maximumAnswerSecondsAboveRecommended} />
</Item>
<Item>
<!-- AnkiMobile hides this -->
<div class="show-timer-switch" style="display: contents;">
<SwitchRow
bind:value={$config.showTimer}
defaultValue={defaults.showTimer}
>
<SettingTitle
on:click={() =>
openHelpModal(
Object.keys(settings).indexOf("showAnswerTimer"),
)}>{settings.showAnswerTimer.title}</SettingTitle
>
</SwitchRow>
</div>
</Item>
</DynamicallySlottable>
</TitledContainer>