Anki/ts/lib/components/TitledContainer.svelte
2025-08-09 16:46:25 +10:00

89 lines
2.1 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 { pageTheme } from "$lib/sveltelib/theme";
const rtl: boolean = window.getComputedStyle(document.body).direction == "rtl";
export let id: string | undefined = undefined;
let className: string = "";
export { className as class };
export let title: string;
export let onTitleClick: ((_e: MouseEvent | KeyboardEvent) => void) | null = null;
</script>
<div
{id}
class="container {className}"
class:light={!$pageTheme.isDark}
class:dark={$pageTheme.isDark}
class:rtl
style:--gutter-block="2px"
style:--container-margin="0"
>
<div class="position-relative">
{#if onTitleClick}
<span
on:click={onTitleClick}
on:keydown={onTitleClick}
role="button"
tabindex="0"
>
<h1>
{title}
</h1>
</span>
{:else}
<h1>
{title}
</h1>
{/if}
<div class="help-badge position-absolute" class:rtl>
<slot name="tooltip" />
</div>
</div>
<slot />
</div>
<style lang="scss">
@use "../sass/elevation" as *;
.container {
width: 100%;
background: var(--canvas-elevated);
border: 1px solid var(--border-subtle);
border-radius: var(--border-radius-medium, 10px);
&.light {
@include elevation(3);
}
&.dark {
@include elevation(4);
}
padding: 1rem 1.75rem 0.75rem 1.25rem;
&.rtl {
padding: 1rem 1.25rem 0.75rem 1.75rem;
}
page-break-inside: avoid;
}
h1 {
border-bottom: 1px solid var(--border);
padding-bottom: 0.25em;
}
.help-badge {
right: 0;
top: 0;
color: #555;
&.rtl {
right: unset;
left: 0;
}
}
:global(.night-mode) .help-badge {
color: var(--fg);
}
</style>