/** * @file * * Mock of Obsidian's `ToggleComponent`, an on/off switch. */ import type { ToggleComponent as ToggleComponentOriginal, TooltipOptions as TooltipOptionsOriginal } from 'obsidian'; import { ValueComponent } from './ValueComponent.cjs'; /** * Mock of Obsidian's `ToggleComponent`. * * The on/off state is kept in {@link ToggleComponent.on}. As in Obsidian, {@link ToggleComponent.setValue} calls the * change callback only when the value actually changes, and {@link ToggleComponent.onClick} flips the toggle unless * it is disabled. */ export declare class ToggleComponent extends ValueComponent { /** * The callback registered with {@link ToggleComponent.onChange}, if any. */ changeCallback?: (value: boolean) => unknown; /** * Whether the toggle is on. */ on: boolean; /** * The toggle's element. */ toggleEl: HTMLElement; /** * Creates a toggle, initially off, and appends its element to the container. * * @param containerEl - The element to create the toggle in. */ constructor(containerEl: HTMLElement); /** * Mock-only factory: creates a toggle, spyable via `vi.spyOn(ToggleComponent, 'create__')`. * * @param containerEl - The element to create the toggle in. * @returns The new toggle. */ static create__(containerEl: HTMLElement): ToggleComponent; /** * Mock-only: views a value typed as Obsidian's `ToggleComponent` as this mock. * * @param value - The value typed as the original `ToggleComponent`. * @returns The same object, typed as the mock. */ static fromOriginalType3__(value: ToggleComponentOriginal): ToggleComponent; /** * Mock-only: views this mock as Obsidian's `ToggleComponent` type. * * @returns The same object, typed as the original `ToggleComponent`. */ asOriginalType3__(): ToggleComponentOriginal; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(ToggleComponent.prototype, 'constructor3__')`. * * @param _containerEl - The container the toggle was created in. */ constructor3__(_containerEl: HTMLElement): void; /** * Gets whether the toggle is on. * * @returns `true` when on. */ getValue(): boolean; /** * Registers the callback invoked when the value changes, replacing any previous one. * * @param callback - Called with the new value. * @returns This component, for chaining. */ onChange(callback: (value: boolean) => unknown): this; /** * Handles a click: flips the toggle through {@link ToggleComponent.setValue}, unless the toggle is disabled. */ onClick(): void; /** * Disables or enables the toggle, toggling the `is-disabled` class on {@link ToggleComponent.toggleEl}. * * @param disabled - Whether the toggle is disabled. * @returns This component, for chaining. */ setDisabled(disabled: boolean): this; /** * Sets the toggle's tooltip on {@link ToggleComponent.toggleEl} through `setTooltip`, as Obsidian does. * * @param tooltip - The tooltip text. * @param options - Tooltip placement and delay options. * @returns This component, for chaining. */ setTooltip(tooltip: string, options?: TooltipOptionsOriginal): this; /** * Turns the toggle on or off. When the value changes, toggles the `is-enabled` class on * {@link ToggleComponent.toggleEl} and calls the change callback; an unchanged value does nothing. * * @param value - Whether the toggle should be on. * @returns This component, for chaining. */ setValue(value: boolean): this; }