anki/ts/deck-options/Switch.svelte

51 lines
1.2 KiB
Svelte
Raw Normal View History

2021-06-12 10:25:11 +02:00
<!--
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 { nightModeKey } from "components/context-keys";
export let id: string | undefined;
2021-06-12 10:25:11 +02:00
export let value: boolean;
export let disabled = false;
const nightMode = getContext<boolean>(nightModeKey);
2021-06-12 10:25:11 +02:00
</script>
<div class="form-check form-switch">
<input
{id}
type="checkbox"
class="form-check-input"
class:nightMode
bind:checked={value}
{disabled}
/>
2021-06-12 10:25:11 +02:00
</div>
<style lang="scss">
2021-06-17 14:11:32 +02:00
.form-switch {
/* bootstrap adds a default 2.5em left pad, which causes */
/* text to wrap prematurely */
2021-06-17 14:11:32 +02:00
padding-left: 0.5em;
}
2021-06-12 10:25:11 +02:00
.form-check-input {
-webkit-appearance: none;
height: 1.6em;
/* otherwise the switch circle shows slightly off-centered */
margin-top: 0;
.form-switch & {
width: 3em;
margin-left: 1.5em;
}
}
.nightMode:not(:checked) {
background-color: var(--frame-bg);
border-color: var(--border);
}
2021-06-12 10:25:11 +02:00
</style>