/*
* Copyright Notice
* bootstrap5-toggle v5.5.1
* https://palcarazm.github.io/bootstrap5-toggle/
* @author 2011-2014 Min Hur (https://github.com/minhur)
* @author 2018-2019 Brent Ely (https://github.com/gitbrent)
* @author 2022 Pablo Alcaraz Martínez (https://github.com/palcarazm)
* @funding GitHub Sponsors
* @see https://github.com/sponsors/palcarazm
* @license MIT
* @see https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE
*/
/* Copyright Notice
* component-lifecycle v2.1.0
* https://github.com/palcarazm/component-lifecycle#readme
* @author Pablo Alcaraz Martínez
* @see https://github.com/palcarazm/
* @funding GitHub Sponsors
* @see https://github.com/sponsors/palcarazm
* @license MIT
*/
declare enum LifecycleState {
Idle = "idle",
Initialized = "initialized",
Attached = "attached",
Disposed = "disposed",
Destroyed = "destroyed"
}
/**
* Options for the {@link Component} class.
*/
type ComponentOptions = {
/**
* Whether events emitted by this component should bubble up through the DOM.
* @default true
*/
bubbleEvents: boolean;
};
/**
* Event details for lifecycle events (e.g., initialized, attached, disposed, destroyed).
* Reusable type for all lifecycle events.
*
* @template P The prefix used for event names.
*/
type LifecycleEventDetails
= {
component: Component
;
};
/**
* Map of lifecycle events to event details.
*
* @template P The prefix used for event names.
*/
type LifecycleEventMap
= {
initialized: LifecycleEventDetails
;
attached: LifecycleEventDetails
;
disposed: LifecycleEventDetails
;
destroyed: LifecycleEventDetails
;
};
/**
* Event details for transition-related events (e.g., transition-cancelled, transition-invalid).
* Reusable type for all events that include state transition information.
*
* @template P The prefix used for event names.
*/
type TransitionEventDetails
= LifecycleEventDetails
& {
from: LifecycleState;
to: LifecycleState;
reason?: string;
};
/**
* Map of transition events to event details.
*
* @template P The prefix used for event names.
*/
type TransitionEventMap
= {
"transition-cancelled": TransitionEventDetails
;
"transition-invalid": TransitionEventDetails
;
};
/**
* Map of all lifecycle and transition events to event details.
*
* @template P The prefix used for event names.
*/
type BaseEventMap
= LifecycleEventMap
& TransitionEventMap
;
/**
* Helper type to extend the base event map with custom events.
* Automatically includes all base events while allowing additional custom events.
*
* @template P The prefix used for event names.
* @template TCustom Custom event map to merge with base events.
*
* @example
* ```typescript
* // ✅ Valid - no conflicts
* type MyEvents = ExtendableEventMap<"mycomp", {
* "data-loaded": { records: number };
* "validation-failed": { errors: string[] };
* }>;
*
* class DataComponent extends Component<"mycomp", MyEvents> {
* async loadData() {
* this.emit("data-loaded", { records: 42 }); // Included by extension
* this.emit("initialized", { component: this }); // Included by default
* }
* }
*
* // ❌ Invalid - 'initialized' conflicts
* type InvalidEvents = ExtendableEventMap<"mycomp", { initialized: {} }>;
* // Results in: { initialized: "❌ Event key \"initialized\" conflicts with base event. Use a different name." }
* ```
*/
type ExtendableEventMap
= Record> = NoBaseEventMap & Omit, keyof TCustom>;
/**
* Helper type to ensure that custom event keys do not overlap with base events.
*
* @internal Not part of public API.
* @template P The prefix used for event names.
* @template TCustom Custom event map to merge with base events.
* @example
* // ✅ Valid - no conflicts
* type Valid = NoBaseEventMap<{ custom: string }, "mycomp">;
*
* // ❌ Invalid - 'initialized' conflicts
* type Invalid = NoBaseEventMap<{ initialized: {} }, "mycomp">;
* // Results in: { initialized: "❌ Event key \"initialized\" conflicts with base event. Use a different name." }
*/
type NoBaseEventMap = keyof TCustom & keyof BaseEventMap extends never ? TCustom : {
[K in keyof TCustom]: K extends keyof BaseEventMap
? `❌ Event key "${K & string}" conflicts with base event. Use a different name.` : TCustom[K];
};
/**
* Abstract class representing a component in a web application.
*
* @template P The prefix used for event names. Default: `"component"`.
* @template TEventMap The type of the event map. Default: {@link BaseEventMap}.
* @template TOptions The type of the options object. Default: {@link ComponentOptions}.
*/
declare abstract class Component
= BaseEventMap
, TOptions extends ComponentOptions = ComponentOptions> {
readonly element: HTMLElement;
protected abstract readonly PREFIX: P;
private _state;
protected readonly options: TOptions;
/**
* Constructor for Component.
*
* @param {HTMLElement} element - The DOM element this component is attached to.
* @param {Partial} [options] - Optional configuration object.
*/
constructor(element: HTMLElement, options?: Partial);
/**
* Returns the default options for this component class.
*
* @returns The default options configuration
*
* @remarks
* Subclasses should override this method if they add custom options.
* Always call `super.getDefaultOptions()` and spread the result.
*
* @example
* ```typescript
* type CustomOptions = ExtendableComponentOptions<{ customOption: string }>;
* export class CustomOptionsComponent extends Component<
* "custom-options",
* LifecycleEventMap<"custom-options">,
* CustomOptions> {
* protected readonly PREFIX = "custom-options";
*
* protected static getDefaultOptions(): CustomOptions {
* return {
* ...super.getDefaultOptions(),
* customOption: "custom value"
* };
* }
* }
* ```
*/
protected static getDefaultOptions(): ComponentOptions;
/**
* Returns the current lifecycle state of this component.
*
* @returns {LifecycleState} The current lifecycle state of this component.
*/
get state(): LifecycleState;
/**
* Whether this component is in the idle lifecycle state.
*
* @returns {boolean} Whether this component is in the idle lifecycle state.
*/
isIdle(): boolean;
/**
* Whether this component is in the initialized lifecycle state.
*
* @returns {boolean} Whether this component is in the initialized lifecycle state.
*/
isInitialized(): boolean;
/**
* Whether this component is in the attached lifecycle state.
*
* @returns {boolean} Whether this component is in the attached lifecycle state.
*/
isAttached(): boolean;
/**
* Whether this component is in the disposed lifecycle state.
*
* @returns {boolean} Whether this component is in the disposed lifecycle state.
*/
isDisposed(): boolean;
/**
* Whether this component is in the destroyed lifecycle state.
*
* @returns {boolean} Whether this component is in the destroyed lifecycle state.
*/
isDestroyed(): boolean;
/**
* Checks if the component is in the given lifecycle state.
*
* @param {LifecycleState} state The lifecycle state to check against.
* @returns {boolean} Whether the component is in the given lifecycle state.
*/
is(state: LifecycleState): boolean;
/**
* Checks whether a transition to the given lifecycle state is valid.
*
* Transition is valid if the current lifecycle state is included in the
* array of valid transitions for the given lifecycle state.
*
* @param {LifecycleState} next The lifecycle state to transition to.
*
* @returns {boolean} Whether the transition is valid.
*/
protected canTransition(next: LifecycleState): boolean;
/**
* Transitions the component to the given lifecycle state.
*
* If the transition is invalid, the component remains in its current lifecycle state.
* Awaits the corresponding lifecycle hook before completing the transition.
* If the hook returns `{ cancelled: true }`, the transition is abandoned.
*
* @param {LifecycleState} next The lifecycle state to transition to.
* @returns {Promise} A promise that resolves when the transition is complete.
* @remarks Fires:
* - `initialized` If the component transitions to the initialized lifecycle state.
* - `attached` If the component transitions to the attached lifecycle state.
* - `disposed` If the component transitions to the disposed lifecycle state.
* - `destroyed` If the component transitions to the destroyed lifecycle state.
* - `transition-cancelled` If the transition is cancelled by a lifecycle hook.
* - `transition-invalid` If the transition is structurally invalid (invalid lifecycle state graph).
*/
protected transitionTo(next: LifecycleState): Promise;
/**
* Executes a lifecycle state transition, running the associated hook and
* emitting the corresponding lifecycle event if the transition succeeds.
*
* @internal Internal helper: it is **not** a generic event emitter wrapper.
* It is only used for lifecycle-driven transitions.
* @template K extends keyof LifecycleEventMap
* The lifecycle event name to emit after a successful transition.
* @param toState The target lifecycle state to move into.
* @param hook The lifecycle hook to execute before committing the transition.
* If the hook returns `{ cancelled: true }`, the transition is aborted
* and a `"transition-cancelled"` event is emitted instead.
* @param eventName The lifecycle event to emit when the transition completes successfully.
* @returns A promise that resolves once the transition have completed.
*/
private executeTransition;
/**
* Initializes the component.
*
* Transitions the component to the initialized lifecycle state.
* Implementation notes:
* - This method should not be overridden by subclasses. To perform additional initialization tasks, override the `doInit()` method.
* - This method should be called when the component is ready to be initialized.
* @returns {Promise} A promise that resolves when the initialization is complete.
* @remarks Fires:
* - `initialized` If the component transitions to the initialized lifecycle state.
* - `transition-cancelled` If the transition is cancelled by a lifecycle hook.
* - `transition-invalid` If the transition is structurally invalid (invalid lifecycle state graph).
*/
init(): Promise;
/**
* Attaches the component to the DOM.
*
* Transitions the component to the attached lifecycle state.
* Implementation notes:
* - This method should not be overridden by subclasses. To perform additional attachment tasks, override the `doAttach()` method.
* - This method should be called when the component is ready to be attached.
* @returns {Promise} A promise that resolves when the attachment is complete.
* @remarks Fires:
* - `attached` If the component transitions to the attached lifecycle state.
* - `transition-cancelled` If the transition is cancelled by a lifecycle hook.
* - `transition-invalid` If the transition is structurally invalid (invalid lifecycle state graph).
*/
attach(): Promise;
/**
* Disposes the component.
*
* Transitions the component to the disposed lifecycle state.
* Implementation notes:
* - This method should not be overridden by subclasses. To perform additional disposal tasks, override the `doDispose()` method.
* - This method should be called when the component is ready to be disposed.
* @returns {Promise} A promise that resolves when the disposal is complete.
* @remarks Fires:
* - `disposed` If the component transitions to the disposed lifecycle state.
* - `transition-cancelled` If the transition is cancelled by a lifecycle hook.
* - `transition-invalid` If the transition is structurally invalid (invalid lifecycle state graph).
*/
dispose(): Promise;
/**
* Destroys the component.
*
* Transitions the component to the destroyed lifecycle state.
* Implementation notes:
* - This method should not be overridden by subclasses. To perform additional destruction tasks, override the `doDestroy()` method.
* - This method should be called when the component is ready to be destroyed.
* @returns {Promise} A promise that resolves when the destruction is complete.
* @remarks Fires:
* - `destroyed` If the component transitions to the destroyed lifecycle state.
* - `transition-cancelled` If the transition is cancelled by a lifecycle hook.
* - `transition-invalid` If the transition is structurally invalid (invalid lifecycle state graph).
*/
destroy(): Promise;
/**
* Hooks that are called when the component transitions to the initialized lifecycle state.
*
* Implementation notes:
* - Can be overridden by subclasses to perform additional initialization tasks.
* - If async operations are needed, return a promise that resolves when complete.
* - Return `{ cancelled: true, reason: "..." }` to prevent the transition.
*
* @returns {Promise<{ cancelled: boolean; reason?: string }>} A promise that resolves to an object with `cancelled` flag and optional `reason`.
*/
protected doInit(): Promise<{
cancelled: boolean;
reason?: string;
}>;
/**
* Hooks that are called when the component transitions to the attached lifecycle state.
*
* Implementation notes:
* - Can be overridden by subclasses to perform additional attachment tasks.
* - If async operations are needed, return a promise that resolves when complete.
* - Return `{ cancelled: true, reason: "..." }` to prevent the transition.
*
* @returns {Promise<{ cancelled: boolean; reason?: string }>} A promise that resolves to an object with `cancelled` flag and optional `reason`.
*/
protected doAttach(): Promise<{
cancelled: boolean;
reason?: string;
}>;
/**
* Hooks that are called when the component transitions to the disposed lifecycle state.
*
* Implementation notes:
* - Can be overridden by subclasses to perform additional disposal tasks.
* - If async operations are needed, return a promise that resolves when complete.
* - Return `{ cancelled: true, reason: "..." }` to prevent the transition.
*
* @returns {Promise<{ cancelled: boolean; reason?: string }>} A promise that resolves to an object with `cancelled` flag and optional `reason`.
*/
protected doDispose(): Promise<{
cancelled: boolean;
reason?: string;
}>;
/**
* Hooks that are called when the component transitions to the destroyed lifecycle state.
*
* Implementation notes:
* - Can be overridden by subclasses to perform additional destruction tasks.
* - If async operations are needed, return a promise that resolves when complete.
* - Return `{ cancelled: true, reason: "..." }` to prevent the transition.
*
* @returns {Promise<{ cancelled: boolean; reason?: string }>} A promise that resolves to an object with `cancelled` flag and optional `reason`.
*/
protected doDestroy(): Promise<{
cancelled: boolean;
reason?: string;
}>;
/**
* Emits a custom event with the given name and detail.
*
* @template K The type of the event to be emitted.
* @param name The name of the event to be emitted.
* @param detail The detail of the event to be emitted.
*
* @remarks
* - The event name will be prefixed with the component's prefix.
* - Events bubble to the document by default (bubbles: true) unless the component was instantiated with `bubbleEvents: false`.
*/
protected emit(name: K & string, detail: TEventMap[K]): void;
/**
* Listens for the given lifecycle event and calls the provided handler when it is emitted.
*
* @template K The type of the event to be listened for.
* @param name The name of the event to be listened for.
* @param handler The handler to be called when the event is emitted.
*
* @returns This component instance.
*/
on(name: `${P}:${K & string}`, handler: (ev: CustomEvent) => void): this;
/**
* Listens for the given lifecycle event and calls the provided handler when it is emitted, only once.
*
* @template K The type of the event to be listened for.
* @param name The name of the event to be listened for.
* @param handler The handler to be called when the event is emitted.
*
* @returns This component instance.
*/
once(name: `${P}:${K & string}`, handler: (ev: CustomEvent) => void): this;
/**
* Stops listening for the given lifecycle event.
*
* @template K The type of the event to stop listening for.
* @param name The name of the event to stop listening for.
* @param handler The handler to stop calling when the event is emitted.
*
* @returns This component instance.
*/
off(name: `${P}:${K & string}`, handler: (ev: CustomEvent) => void): this;
}
interface ToggleOptions {
onlabel: string;
offlabel: string;
onstyle: ToggleStyle;
offstyle: ToggleStyle;
onvalue: string | null;
offvalue: string | null;
ontitle: string | null;
offtitle: string | null;
size: ToggleSize | "";
style: string;
width: string | null;
height: string | null;
tabindex: number;
tristate: boolean;
name: string | null;
aria: AriaToggleOptions;
tooltip?: TooltipOptions;
}
type AriaToggleOptions = {
label: string;
};
type TooltipOptions = {
placement: PlacementOptions;
title: {
on: string;
off: string;
mixed?: string;
};
};
type UserOptions = Partial & {
on?: string;
off?: string;
width?: string | number;
height?: string | number;
};
type ToggleStyle = "primary" | "secondary" | "success" | "danger" | "warning" | "info" | "light" | "dark" | "outline-primary" | "outline-secondary" | "outline-success" | "outline-danger" | "outline-warning" | "outline-info" | "outline-light" | "outline-dark";
type ToggleSize = "large" | "normal" | "small" | "mini" | "lg" | "md" | "sm" | "xs";
declare enum PlacementOptions {
TOP = "top",
BOTTOM = "bottom",
LEFT = "left",
RIGHT = "right"
}
interface ToggleState {
value: ToggleStateValue;
checked: boolean;
status: ToggleStateStatus;
indeterminate: boolean;
}
declare enum ToggleStateValue {
ON = "on",
OFF = "off",
MIXED = "mixed"
}
declare enum ToggleStateStatus {
ENABLED = "enabled",
DISABLED = "disabled",
READONLY = "readonly"
}
declare enum ToggleEvents {
ON = "on",
OFF = "off",
MIXED = "mixed",
ENABLED = "enabled",
DISABLED = "disabled",
READONLY = "readonly"
}
interface ToggleEventDetail {
state: ToggleState;
}
/**
* Domain events emitted by the Toggle component.
* Keys are the un-prefixed event names; the prefix "toggle:" is added by the base class.
*/
type ToggleDomainEvents = {
"on": ToggleEventDetail;
"off": ToggleEventDetail;
"mixed": ToggleEventDetail;
"enabled": ToggleEventDetail;
"disabled": ToggleEventDetail;
"readonly": ToggleEventDetail;
};
/**
* Full event map of the Toggle component.
* Includes all lifecycle events (initialized, attached, disposed, destroyed, transition-*)
* plus the domain events on/off/mixed/enabled/disabled/readonly.
*/
type ToggleEventMap = ExtendableEventMap<"toggle", ToggleDomainEvents>;
declare class Toggle extends Component<"toggle", ToggleEventMap> {
readonly element: HTMLInputElement & {
bsToggle?: Toggle;
};
protected readonly PREFIX: "toggle";
private readonly userOptions;
private toggleOptions;
private stateReducer;
private domBuilder;
private pointer;
private readonly SCROLL_THRESHOLD;
private suppressExternalSync;
private readonly originalDescriptors;
/**
* Initializes a new instance of the Toggle component.
*
* @param element The checkbox element backing the toggle.
* @param options User-provided options.
*/
constructor(element: HTMLInputElement, options: UserOptions);
/**
* Initializes internal state. No DOM access, no side effects.
* @returns {Promise<{ cancelled: boolean }>} transition result
*/
protected doInit(): Promise<{
cancelled: boolean;
}>;
/**
* Binds the component to the DOM: builds the toggle DOM, binds listeners,
* intercepts input properties, and registers the instance on the element.
* @returns {Promise<{ cancelled: boolean }>} transition result
*/
protected doAttach(): Promise<{
cancelled: boolean;
}>;
/**
* Tears down everything created by doAttach(), including the toggle DOM.
* The original checkbox is restored to the DOM.
* @returns {Promise<{ cancelled: boolean }>} transition result
*/
protected doDispose(): Promise<{
cancelled: boolean;
}>;
/**
* Final teardown. Defensively disposes if still attached (see decision 5b).
* @returns {Promise<{ cancelled: boolean; reason?: string }>} transition result
*/
protected doDestroy(): Promise<{
cancelled: boolean;
reason?: string;
}>;
/**
* Intercepts the following input properties to detect external changes:
* - checked
* - disabled
* - readonly
* - indeterminate
* This method is used to detect changes made to the input element directly,
* rather than through the BootstrapToggle API. It is used to maintain the
* state of the toggle in cases where the user changes the input element
* directly, rather than through the API.
* @returns void
*/
private interceptInputProperties;
/**
* Restores the original input properties of the toggle element.
* This method is used to restore the original descriptors of the input properties
* which were intercepted by the BootstrapToggle to detect external changes.
* @returns void
*/
private restoreInputProperties;
/**
* Handles the change event of the input element of the toggle.
* This event listener is responsible for detecting when the input element
* of the toggle changes its state and triggering the update method to keep the toggle in sync.
*/
private readonly onExternalChange;
/**
* Binds all event listeners for the toggle component, including form reset, pointer, keyboard, and label events.
* This method is called during the attachment phase of the component lifecycle.
* It ensures that the toggle component responds to user interactions and external changes.
*/
private bindEventListeners;
/**
* Unbinds all event listeners for the toggle component, including form reset, pointer, keyboard, and label events.
* This method is called during the disposal phase of the component lifecycle.
* It ensures that the toggle component no longer responds to user interactions and external changes.
*/
private unbindEventListeners;
private bindFormResetListener;
private unbindFormResetListener;
private readonly onFormReset;
/**
* Binds a pointerdown event listener to the root element of the toggle.
* The event listener is responsible for handling pointer events (e.g. mouse clicks, touch events)
* and triggering the toggle's state change when a pointer event occurs.
* The event listener is bound with the passive option, which means that it will not block
* other event listeners from being triggered.
*/
private bindPointerEventListener;
/**
* Unbinds the pointerdown event listener from the root element of the toggle.
* This method is responsible for unbinding the pointerdown event listener that was
* previously bound by the bindPointerEventListener method.
* If the event listener is not bound (i.e. this.eventsBound is false), this method does nothing.
* @returns void
*/
private unbindPointerEventListener;
/**
* Handles pointer down events by initiating the toggle action and setting up
* listeners for pointer movement, release, and cancellation.
*
* The method early exits if:
* - the pointer event is not a primary mouse button click
* - the toggle cannot be interacted with (`disabled` or `readonly`)
* @param e The PointerEvent object representing the pointer down event.
*/
private readonly onPointerDown;
/**
* Handles pointer move events by checking the distance moved from the initial pointer down position.
* If the pointer has moved beyond a certain threshold, the pointer interaction is cancelled.
*
* Allows dragging within the width of the toggle but cancels if vertical movement exceeds the scroll threshold.
* @param e The PointerEvent object representing the pointer move event.
*/
private readonly onPointerMove;
/**
* Handles pointer up events by determining if the pointer interaction
* should trigger a toggle action based on the distance moved.
*
* If the pointer has moved beyond a certain threshold, the pointer interaction is cancelled.
* Allows dragging within the width of the toggle but cancels if vertical movement exceeds the scroll threshold.
* Finally, it cleans up by calling the pointer cancel handler.
*
* If the pointer event is not a primary mouse button click, the interaction is cancelled.
* @param e The PointerEvent object representing the pointer up event.
*/
private readonly onPointerUp;
/**
* Cleans up pointer event listeners after a pointer interaction is completed or cancelled.
*
* This method removes the `pointermove`, `pointerup`, and `pointercancel` event listeners
* from the root element of the toggle.
* However, `pointerdown` listener remains active for future interactions.
*/
private readonly onPointerCancel;
/**
* Binds a keydown event listener to the root element of the toggle.
* The event listener is responsible for handling keydown events
* and triggering the toggle's state change when a keydown event occurs.
*/
private bindKeyboardEventListener;
/**
* Unbinds the keydown event listener from the root element of the toggle.
* This method is responsible for unbinding the keydown event listener that was
* previously bound by the bindKeyboardEventListener method.
* If the event listener is not bound (i.e. this.eventsBound is false), this method does nothing.
* @returns void
*/
private unbindKeyboardEventListener;
private readonly handlerKeyboardEvent;
/**
* Binds a click event listener to all labels that are associated with the toggle's input element.
* The event listener is responsible for handling click events and triggering the toggle's state change when a click event occurs.
* The event listener is bound with the passive option set to false, which means that it will block other event listeners from being triggered until it has finished its execution.
* This method is called by the constructor and is responsible for binding the event listener to the toggle's labels.
* If the toggle's input element does not have an id (i.e. this.element.id is null or undefined), this method does nothing.
* @returns void
*/
private bindLabelEventListener;
/**
* Unbinds the click event listener from all labels that are associated with the toggle's input element.
* This method is responsible for unbinding the event listener that was previously bound by the bindLabelEventListener method.
* If the toggle's input element does not have an id (i.e. this.element.id is null or undefined), this method does nothing.
* @returns void
*/
private unbindLabelEventListener;
private readonly handlerLabelEvent;
/**
* Applies a toggle action to the toggle state and renders the toggle element.
* If the action is successful, this method will render the toggle element with the new state.
* If the silent parameter is false, this method will also trigger the change event.
* @param action The toggle action to apply.
* @param silent A boolean indicating whether to trigger the change event after applying the action.
*/
private apply;
/**
* Toggles the state of the toggle.
* If the toggle is currently in the on state, it will be set to the off state.
* If the toggle is currently in the off state, it will be set to the on state.
* If the toggle is currently in the indeterminate state, it will be set to the on state.
* If the silent parameter is false, this method will also trigger the change event.
* @param silent A boolean indicating whether to trigger the change event after applying the action.
*/
toggle(silent?: boolean): void;
/**
* Sets the toggle state to on.
* If the silent parameter is false, this method will also trigger the change event.
* @param silent A boolean indicating whether to trigger the change event after applying the action.
*/
toggleOn(silent?: boolean): void;
/**
* Sets the toggle state to off.
* If the silent parameter is false, this method will also trigger the change event.
* @param silent A boolean indicating whether to trigger the change event after applying the action.
*/
toggleOff(silent?: boolean): void;
/**
* Sets the toggle state to indeterminate.
* If the silent parameter is false, this method will also trigger the change event.
* @param {boolean} silent A boolean indicating whether to trigger the change event after applying the action.
*/
indeterminate(silent?: boolean): void;
/**
* Sets the toggle state to determinate.
* If the silent parameter is false, this method will also trigger the change event.
* @param {boolean} silent A boolean indicating whether to trigger the change event after applying the action.
*/
determinate(silent?: boolean): void;
/**
* Enables the toggle.
* If the toggle is currently disabled, this method will set the toggle state to enabled.
* If the silent parameter is false, this method will also trigger the change event.
* @param {boolean} silent A boolean indicating whether to trigger the change event after applying the action.
* @returns void
*/
enable(silent?: boolean): void;
/**
* Disables the toggle.
* If the toggle is currently enabled, this method will set the toggle state to disabled.
* If the silent parameter is false, this method will also trigger the change event.
* @param {boolean} silent A boolean indicating whether to trigger the change event after applying the action.
*/
disable(silent?: boolean): void;
/**
* Sets the toggle state to readonly.
* If the toggle is currently disabled or enabled, this method will set the toggle state to readonly.
* If the silent parameter is false, this method will also trigger the change event.
* @param {boolean} silent A boolean indicating whether to trigger the change event after applying the action.
* @returns void
*/
readonly(silent?: boolean): void;
/**
* Synchronizes the toggle state with the input element and renders the toggle.
*/
update(): void;
/**
* Triggers the change event on the toggle's input element and the appropriate toggle event.
* This method is called after a toggle action is applied to notify listeners of the state change.
* @param {ToggleActionType} action The toggle action that was applied.
* @param {ToggleState} state The state of the toggle once the action was applied.
*/
private trigger;
/**
* Returns the corresponding toggle event for the given toggle action and state.
* This method is used to determine which toggle event to trigger after a toggle action is applied.
* @param {ToggleActionType} action The toggle action that was applied.
* @param {ToggleState} state The previous state of the toggle before the action was applied.
* @returns {ToggleEvents} The corresponding toggle event for the given toggle action and state.
*/
private getEventForAction;
/**
* Returns the corresponding toggle event for the given toggle state.
* This method is used to determine which toggle event to trigger after a toggle action is applied.
* @param {ToggleState} state The previous state of the toggle before the action was applied.
* @returns {ToggleEvents} The corresponding toggle event for the given toggle state.
*/
private getValueEvent;
/**
* Rebuilds the toggle in-place, preserving instance identity.
* Emits `toggle:disposed` and `toggle:attached` lifecycle events.
*
* Sequence:
* 1. dispose() → doDispose() unbinds listeners, restores props, tears down DOM
* 2. re-resolve options from element (may have changed)
* 3. attach() → doAttach() rebuilds DOM and re-binds listeners
*
* @returns {Promise} resolves when re-attached.
*/
rerender(): Promise;
}
declare enum ToggleMethods {
ON = "on",
OFF = "off",
TOGGLE = "toggle",
DETERMINATE = "determinate",
INDETERMINATE = "indeterminate",
ENABLE = "enable",
DISABLE = "disable",
READONLY = "readonly",
DESTROY = "destroy",
RERENDER = "rerender"
}
interface BootstrapToggleElement extends HTMLInputElement {
bootstrapToggle(options?: ToggleMethods | Record, silent?: boolean): void;
bsToggle?: Toggle;
}
interface BootstrapToggleElementEventMap extends HTMLElementEventMap {
"toggle:on": CustomEvent;
"toggle:off": CustomEvent;
"toggle:mixed": CustomEvent;
"toggle:enabled": CustomEvent;
"toggle:disabled": CustomEvent;
"toggle:readonly": CustomEvent;
}
export { Toggle as BootstrapToggle, ToggleEvents as Events, ToggleMethods as Methods, ToggleStateStatus as StateStatus, ToggleStateValue as StateValue };
export type { BootstrapToggleElement, BootstrapToggleElementEventMap, ToggleEventDetail as EventDetail, ToggleOptions as Options, ToggleSize as Size, ToggleState as State, ToggleStyle as Style, UserOptions };