utils/web_ui/src/test/slider-helpers.ts
Krzysztof kuhy Rudnicki decf5824e6
Some checks failed
dependency freshness / dependencies on newest stable (push) Waiting to run
file length / file-length (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
web_ui tests / test (push) Has been cancelled
web_ui 0.5.0: port to Astro + custom element
RangeSlider.astro + <range-slider> replace the React component.
Pure helpers, tokens.css and range-slider.css are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWYdwRAtMg7ki6TKxuU
2026-11-01 20:03:45 +01:00

37 lines
1.2 KiB
TypeScript

import { RangeSliderElement } from "../range-slider-element.ts";
export const VALUES = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90];
export const TRACK_WIDTH = 1000;
export interface Mounted {
readonly changes: { hi: number; lo: number }[];
readonly element: RangeSliderElement;
}
export function mount(
attributes: Record<string, string> = {},
values: readonly number[] = VALUES,
): Mounted {
const element = new RangeSliderElement();
for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value);
const changes: { hi: number; lo: number }[] = [];
element.addEventListener("change", (event) => {
if (event instanceof CustomEvent) changes.push(event.detail as { hi: number; lo: number });
});
document.body.append(element);
element.values = values;
return { changes, element };
}
export function thumb(element: Element, which: "hi" | "lo"): HTMLElement {
const found = element.querySelector<HTMLElement>(`.slider-${which}`);
if (found === null) throw new Error(`no ${which} thumb`);
return found;
}
export function track(element: Element): HTMLElement {
const found = element.querySelector<HTMLElement>(".slider-track");
if (found === null) throw new Error("no track");
return found;
}