UNPKG

obsidian-dev-utils

Version:

This is the collection of useful functions that you can use for your Obsidian plugin development

70 lines (69 loc) 2.21 kB
/** * @packageDocumentation * * Checkbox component. */ import type { Promisable } from 'type-fest'; import { ValueComponent } from 'obsidian'; import type { ValidatorElement } from '../../../HTMLElement.mjs'; import type { ValidatorComponent } from './ValidatorComponent.mjs'; import type { ValueComponentWithChangeTracking } from './ValueComponentWithChangeTracking.mjs'; /** * A component that displays a checkbox. * * You can add this component using {@link SettingEx.addCheckbox}. * * In order to add the styles for the component, use {@link initPluginContext} in your plugin's `onload()` function. * * Alternatively, you can copy styles from {@link https://github.com/mnaoumov/obsidian-dev-utils/releases/latest/download/styles.css}. */ export declare class CheckboxComponent extends ValueComponent<boolean> implements ValidatorComponent, ValueComponentWithChangeTracking<boolean> { /** * The input element of the checkbox. */ readonly inputEl: HTMLInputElement; /** * The validator element of the checkbox. * * @returns The validator element. */ get validatorEl(): ValidatorElement; private changeCallback?; /** * Creates a new checkbox component. * * @param containerEl - The container element. */ constructor(containerEl: HTMLElement); /** * Gets the value of the checkbox. * * @returns The value of the checkbox. */ getValue(): boolean; /** * Sets the callback to be called when the checkbox is changed. * * @param callback - The callback to be called when the checkbox is changed. * @returns The component. */ onChange(callback: (newValue: boolean) => Promisable<void>): this; /** * Called when the checkbox is changed. */ onChanged(): void; /** * Sets the disabled state of the checkbox. * * @param disabled - The disabled state of the checkbox. * @returns The component. */ setDisabled(disabled: boolean): this; /** * Sets the value of the checkbox. * * @param value - The value to set the checkbox to. * @returns The component. */ setValue(value: boolean): this; }