Files
siftlode/frontend/src/components/plexPlayerControls.tsx
T
peter a7d41eb5f3 fix(plex): the player's settings panel is a tab list with named, touch-sized rows
- Its section switch is `ui/Tabs` (new `tone="media"` paint for the dark chrome) with a wired
  tabpanel; the panel opens with the focus on the selected tab.
- On/off rows are `CheckRow` (the whole row, 44 on touch), the "no background" checkbox too.
- Every slider and the four colour wells carry the name their row shows.
- The clock's date-style buttons reach the touch target.
2026-09-27 14:38:27 +02:00

129 lines
3.6 KiB
TypeScript

import { type ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { RotateCcw } from "lucide-react";
import { IconButton } from "./ui/IconButton";
import { Slider as Range, CheckRow } from "./ui/NativeControls";
// --- settings-panel building blocks ------------------------------------------------------------
export function PanelHead({ children }: { children: ReactNode }) {
return (
<div className="px-1 pt-2 pb-1 text-2xs uppercase tracking-wide text-white/50">{children}</div>
);
}
export function Slider({
label,
value,
min,
max,
step,
suffix,
onChange,
onReset,
}: {
label: string;
value: number;
min: number;
max: number;
step: number;
suffix?: string;
onChange: (v: number) => void;
onReset?: () => void;
}) {
const { t } = useTranslation();
return (
<div className="px-1 py-1">
<div className="mb-1 flex items-center justify-between text-[0.75rem] text-white/80">
<span>{label}</span>
<span className="flex items-center gap-1.5">
<span className="tabular-nums text-white/60">
{Number.isInteger(value) ? value : value.toFixed(1)}
{suffix ?? ""}
</span>
{onReset && (
<IconButton
variant="overlay"
onClick={onReset}
label={t("common.resetNamed", { name: label })}
className="-my-1.5"
>
<RotateCcw className="size-3.5!" />
</IconButton>
)}
</span>
</div>
<Range
min={min}
max={max}
step={step}
value={value}
aria-label={label}
onChange={(v) => onChange(v)}
/>
</div>
);
}
export function Toggle({
label,
checked,
onChange,
}: {
label: string;
checked: boolean;
onChange: (v: boolean) => void;
}) {
// The whole row toggles and grows to 44 on touch (CheckRow); the box sits at the row's end.
return (
<CheckRow
checked={checked}
onChange={onChange}
className="w-full flex-row-reverse justify-between px-1 py-1.5 text-[0.75rem] text-white/80"
>
{label}
</CheckRow>
);
}
// A control button with a tooltip that opens ABOVE it (so it never clips off the bottom of the
// viewport, unlike a native title tooltip on the bottom control bar).
export function Ctrl({
label,
onClick,
disabled,
align = "center",
children,
}: {
label: string;
onClick: () => void;
disabled?: boolean;
// Tooltip horizontal anchor: "start"/"end" for edge buttons so it doesn't clip off the viewport.
align?: "start" | "center" | "end";
children: ReactNode;
}) {
const pos =
align === "start" ? "left-0" : align === "end" ? "right-0" : "left-1/2 -translate-x-1/2";
// `will-change-[opacity]` keeps each tooltip on its own compositor layer from the start. Without it
// the browser promotes a tooltip only while its fade runs, and inside the player's scale(1.25)
// the neighbouring glyphs got re-layered with it: every button in the row shimmered as the
// pointer crossed one (owner, E28 audit).
return (
<div className="relative flex group/ctrl">
<IconButton
variant="overlay"
size="player"
round
noTitle
onClick={onClick}
disabled={disabled}
label={label}
>
{children}
</IconButton>
<span
className={`pointer-events-none absolute bottom-full ${pos} mb-2 whitespace-nowrap rounded-sm bg-black/90 px-2 py-1 text-2xs text-white opacity-0 will-change-[opacity] transition group-hover/ctrl:opacity-100`}
>
{label}
</span>
</div>
);
}