Files
RuneStone/src/lib/layout/ViewModes.svelte
T
Knotty Wyvern 9fc1490988 Make menus and hover fills translucent over a background image
With a background image, menus use the surface transparency of Appearance
(82% by default) instead of at least 92%, and they keep the blur.
Hovered rows and controls in the work area, hovered menu rows, and the
workspace button use the new --rs-hover-bg token. With an image, it is a
6% veil of the strong text color. The image stays visible, and the hover
shows over light and dark image areas. Without an image, nothing changes.

Silver Serpent dim text is now #c2c6cc. It keeps 4.5:1 contrast on a
hovered row over a white image.

UI-061 replaces the image rule of UI-043. Card 05b9bfa1.
2026-10-30 13:38:47 -07:00

105 lines
4.0 KiB
Svelte

<script lang="ts" module>
/** The view of a document pane. Split is a separate toggle beside Write or Source. */
export type ViewMode = "write" | "source" | "read";
</script>
<script lang="ts">
// The view control of a document pane: Write, Source, and Read in one radio group, then the Split toggle.
// All choices stay visible. Narrow panes show only the icons.
import { t } from "$lib/i18n";
import Icon from "$lib/ui/Icon.svelte";
import type { IconName } from "$lib/ui/IconButton.svelte";
import { attachTooltip } from "$lib/ui/tooltip";
import { commandShortcut } from "./workbenchKeys";
type Option = { value: ViewMode; label: string; icon: IconName; shortcut: string };
type Props = {
view: ViewMode;
split: boolean;
/** Markdown files have Read and Split. Other text files have only Write and Source. */
readable: boolean;
onView: (view: ViewMode) => void;
onSplit: (split: boolean) => void;
};
let { view, split, readable, onView, onSplit }: Props = $props();
let group: HTMLDivElement;
const options: Option[] = $derived([
{ value: "write", label: $t("Write"), icon: "pen", shortcut: commandShortcut("toggle-layout") },
{ value: "source", label: $t("Source"), icon: "code", shortcut: commandShortcut("toggle-layout") },
...(readable ? [{ value: "read" as const, label: $t("Read"), icon: "book-open" as const, shortcut: commandShortcut("toggle-reading") }] : []),
]);
function tooltip(node: HTMLElement, text: string) {
let current = text;
const dispose = attachTooltip(node, () => current);
return { update(value: string) { current = value; }, destroy: dispose };
}
// Arrow keys move the choice, as in each radio group. The group has one Tab stop.
function keydown(event: KeyboardEvent, index: number) {
const last = options.length - 1;
const next = event.key === "ArrowRight" || event.key === "ArrowDown" ? (index + 1) % options.length
: event.key === "ArrowLeft" || event.key === "ArrowUp" ? (index + last) % options.length
: event.key === "Home" ? 0 : event.key === "End" ? last : -1;
if (next < 0) return;
event.preventDefault();
onView(options[next].value);
group.querySelectorAll<HTMLButtonElement>("[role=radio]")[next]?.focus();
}
</script>
<div class="view-modes" role="radiogroup" aria-label={$t("View")} bind:this={group}>
{#each options as option, index (option.value)}
<button type="button" role="radio" aria-checked={option.value === view} aria-label={option.label}
tabindex={option.value === view ? 0 : -1}
use:tooltip={`${option.label} (${option.shortcut})`}
onclick={() => onView(option.value)} onkeydown={event => keydown(event, index)}>
<Icon icon={option.icon} />
</button>
{/each}
</div>
{#if readable}
<button type="button" class="split" aria-pressed={split} aria-label={$t("Split")} use:tooltip={$t("Split: Read beside the editor")} onclick={() => onSplit(!split)}>
<Icon icon="split" />
</button>
{/if}
<style>
.view-modes {
display: inline-flex;
flex: 0 0 auto;
gap: 2px;
padding: 2px;
border: 1px solid var(--rs-border);
border-radius: var(--rs-control-radius);
}
button {
display: inline-flex;
flex: 0 0 auto;
align-items: center;
justify-content: center;
height: 26px;
width: 28px;
padding: 0;
border: 0;
border-radius: var(--rs-control-radius);
background: transparent;
color: var(--rs-text-dim);
}
button :global(svg) { width: 16px; height: 16px; flex-shrink: 0; }
/* Hover gets only a fill. The current choice also gets the selection fill and an accent bar. */
button:hover { background: var(--rs-hover-bg); color: var(--rs-text-strong); }
button[aria-checked="true"], button[aria-pressed="true"] {
background: var(--rs-item-selection-bg);
color: var(--rs-text-strong);
box-shadow: inset 0 -2px 0 var(--rs-accent);
}
/* The controls show icons only (UI-056). The name and the shortcut are in the tooltip and the accessible name. */
.split { width: 32px; height: 32px; border: 1px solid var(--rs-border); }
</style>